|
Bugger that looked really useful but it is in c#7, VS 2017. We are stuck with 2015.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
public static class PredicateBuilder
{
public static Expression<Func<T, bool>> True<T>() { return f => true; }
public static Expression<Func<T, bool>> False<T>() { return f => false; }
public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> expr1,
Expression<Func<T, bool>> expr2)
{
var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());
return Expression.Lambda<Func<T, bool>>
(Expression.OrElse(expr1.Body, invokedExpr), expr1.Parameters);
}
public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> expr1,
Expression<Func<T, bool>> expr2)
{
var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());
return Expression.Lambda<Func<T, bool>>
(Expression.AndAlso(expr1.Body, invokedExpr), expr1.Parameters);
}
}
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
It will cause an error because you are assigning IQueryable to List.
You can try this:
results = query.Where(predicate).ToList();
return results
I didn't used PredicateBuilder but i used System.Linq.Dynamic to create dynamic filtering or order by.
[Signature space for sale]
|
|
|
|
|
Hi All
I have an xml file.
<?xml version="1.0" encoding="utf-8"?>
<Achievements>
<Achievement number="208">
<Target>100</Target>
<CurrentStatus>0</CurrentStatus>
<AchievementText>Collect 150 Stars</AchievementText>
<Header>Star Genius</Header>
<Reward>500</Reward>
<Experience>10</Experience>
<AchievementCollected>False</AchievementCollected>
<AchievementCompleted>False</AchievementCompleted>
<Test>7</Test>
</Achievement>
<Achievement number="209">
<Target>100</Target>
<CurrentStatus>0</CurrentStatus>
<AchievementText>Collect 200 Stars</AchievementText>
<Header>Star Genius</Header>
<Reward>500</Reward>
<Experience>10</Experience>
<AchievementCollected>False</AchievementCollected>
<AchievementCompleted>False</AchievementCompleted>
<Test>8</Test>
</Achievement>
<Achievement number="210">
<Target>100</Target>
<CurrentStatus>0</CurrentStatus>
<AchievementText>Collect 250 Stars</AchievementText>
<Header>Star Genius</Header>
<Reward>500</Reward>
<Experience>10</Experience>
<AchievementCollected>False</AchievementCollected>
<AchievementCompleted>False</AchievementCompleted>
<Test>9</Test>
</Achievement>
<Achievement number="211">
<Target>100</Target>
<CurrentStatus>0</CurrentStatus>
<AchievementText>Collect 300 Stars</AchievementText>
<Header>Star Genius</Header>
<Reward>500</Reward>
<Experience>10</Experience>
<AchievementCollected>False</AchievementCollected>
<AchievementCompleted>False</AchievementCompleted>
<Test>10</Test>
</Achievement>
<Achievement number="6">
<Target>1</Target>
<CurrentStatus>1</CurrentStatus>
<AchievementText>Collect 1 Star </AchievementText>
<Header>Star Collector</Header>
<Reward>100</Reward>
<Experience>10</Experience>
<AchievementCollected>True</AchievementCollected>
<AchievementCompleted>True</AchievementCompleted>
<Test>200</Test>
</Achievement>
<Achievement number="7">
<Target>5</Target>
<CurrentStatus>5</CurrentStatus>
<AchievementText>Collect 5 Star </AchievementText>
<Header>Star Collector</Header>
<Reward>100</Reward>
<Experience>10</Experience>
<AchievementCollected>True</AchievementCollected>
<AchievementCompleted>True</AchievementCompleted>
<Test>300</Test>
</Achievement>
<Achievement number="8">
<Target>10</Target>
<CurrentStatus>10</CurrentStatus>
<AchievementText>Collect 10 Star </AchievementText>
<Header>Star Collector</Header>
<Reward>100</Reward>
<Experience>10</Experience>
<AchievementCollected>True</AchievementCollected>
<AchievementCompleted>True</AchievementCompleted>
<Test>400</Test>
</Achievement>
<Achievement number="9">
<Target>25</Target>
<CurrentStatus>25</CurrentStatus>
<AchievementText>Collect 25 Star </AchievementText>
<Header>Star Collector</Header>
<Reward>100</Reward>
<Experience>10</Experience>
<AchievementCollected>True</AchievementCollected>
<AchievementCompleted>True</AchievementCompleted>
<Test>500</Test>
</Achievement>
<Achievement number="10">
<Target>30</Target>
<CurrentStatus>30</CurrentStatus>
<AchievementText>Collect 50 Star </AchievementText>
<Header>Star Collector</Header>
<Reward>100</Reward>
<Experience>10</Experience>
<AchievementCollected>True</AchievementCollected>
<AchievementCompleted>True</AchievementCompleted>
<Test>600</Test>
</Achievement>
<Achievement number="11">
<Target>40</Target>
<CurrentStatus>40</CurrentStatus>
<AchievementText>Collect 100 Stars</AchievementText>
<Header>Star Genius</Header>
<Reward>500</Reward>
<Experience>10</Experience>
<AchievementCollected>True</AchievementCollected>
<AchievementCompleted>True</AchievementCompleted>
<Test>700</Test>
</Achievement>
</Achievements>
In the Achievement number is randomly printed. So i have to avoid this. Whatever no may there. it should be reprinted by 1 to end no . that means
<?xml version="1.0" encoding="utf-8"?>
<Achievements>
<Achievement number="1">
<Target>100</Target>
<CurrentStatus>0</CurrentStatus>
<AchievementText>Collect 150 Stars</AchievementText>
<Header>Star Genius</Header>
<Reward>500</Reward>
<Experience>10</Experience>
<AchievementCollected>False</AchievementCollected>
<AchievementCompleted>False</AchievementCompleted>
<Test>7</Test>
</Achievement>
<Achievement number="2">
<Target>100</Target>
<CurrentStatus>0</CurrentStatus>
<AchievementText>Collect 200 Stars</AchievementText>
<Header>Star Genius</Header>
<Reward>500</Reward>
<Experience>10</Experience>
<AchievementCollected>False</AchievementCollected>
<AchievementCompleted>False</AchievementCompleted>
<Test>8</Test>
</Achievement>
<Achievement number="3">
<Target>100</Target>
<CurrentStatus>0</CurrentStatus>
<AchievementText>Collect 250 Stars</AchievementText>
<Header>Star Genius</Header>
<Reward>500</Reward>
<Experience>10</Experience>
<AchievementCollected>False</AchievementCollected>
<AchievementCompleted>False</AchievementCompleted>
<Test>9</Test>
</Achievement>
<Achievement number="4">
<Target>100</Target>
<CurrentStatus>0</CurrentStatus>
<AchievementText>Collect 300 Stars</AchievementText>
<Header>Star Genius</Header>
<Reward>500</Reward>
<Experience>10</Experience>
<AchievementCollected>False</AchievementCollected>
<AchievementCompleted>False</AchievementCompleted>
<Test>10</Test>
</Achievement>
<Achievement number="5">
<Target>1</Target>
<CurrentStatus>1</CurrentStatus>
<AchievementText>Collect 1 Star </AchievementText>
<Header>Star Collector</Header>
<Reward>100</Reward>
<Experience>10</Experience>
<AchievementCollected>True</AchievementCollected>
<AchievementCompleted>True</AchievementCompleted>
<Test>200</Test>
</Achievement>
<Achievement number="6">
<Target>5</Target>
<CurrentStatus>5</CurrentStatus>
<AchievementText>Collect 5 Star </AchievementText>
<Header>Star Collector</Header>
<Reward>100</Reward>
<Experience>10</Experience>
<AchievementCollected>True</AchievementCollected>
<AchievementCompleted>True</AchievementCompleted>
<Test>300</Test>
</Achievement>
<Achievement number="7">
<Target>10</Target>
<CurrentStatus>10</CurrentStatus>
<AchievementText>Collect 10 Star </AchievementText>
<Header>Star Collector</Header>
<Reward>100</Reward>
<Experience>10</Experience>
<AchievementCollected>True</AchievementCollected>
<AchievementCompleted>True</AchievementCompleted>
<Test>400</Test>
</Achievement>
<Achievement number="8">
<Target>25</Target>
<CurrentStatus>25</CurrentStatus>
<AchievementText>Collect 25 Star </AchievementText>
<Header>Star Collector</Header>
<Reward>100</Reward>
<Experience>10</Experience>
<AchievementCollected>True</AchievementCollected>
<AchievementCompleted>True</AchievementCompleted>
<Test>500</Test>
</Achievement>
<Achievement number="9">
<Target>30</Target>
<CurrentStatus>30</CurrentStatus>
<AchievementText>Collect 50 Star </AchievementText>
<Header>Star Collector</Header>
<Reward>100</Reward>
<Experience>10</Experience>
<AchievementCollected>True</AchievementCollected>
<AchievementCompleted>True</AchievementCompleted>
<Test>600</Test>
</Achievement>
<Achievement number="10">
<Target>40</Target>
<CurrentStatus>40</CurrentStatus>
<AchievementText>Collect 100 Stars</AchievementText>
<Header>Star Genius</Header>
<Reward>500</Reward>
<Experience>10</Experience>
<AchievementCollected>True</AchievementCollected>
<AchievementCompleted>True</AchievementCompleted>
<Test>700</Test>
</Achievement>
</Achievements>
How can i make the C# code for that.... How to check the achivement number
start to end...
start 1 to end = how much count ...
C#...
how can i do it..
code project is very weell
|
|
|
|
|
What code have you got so far? Have you read the XML in yet?
This space for rent
|
|
|
|
|
You deserialize it; and then sort the resulting "Achievent" list.
Convert object to xml in C#
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
in this case, my program gets an error and not functions. I want to create Diffie hellman implementations using an image but my image cannot read. anybody can help me.
|
|
|
|
|
Member 13838063 wrote: anybody can help me
No, I'm sorry - but we can't.
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
So tell us what the error message is, when it occurs, and show us the relevant code fragments that generate the problem. Then tell us what you have done to fix the problem and what effects that had. the better the information you give us, the better the solution we can give you.
Help us to help you!
Sent from my Amstrad PC 1640
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Might be wise to learn how to load an image first, before diving in too deep.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
When I run my C# windows form application that contains Crystal Report. It's asking me to enter the credential for the MySQL db every time. Even though I entered the correct user name and password. it is saying my user name or password is wrong. I have checked the credential many times and entered password is correct.
Code :
private void cmdPrintReport_Click(object sender, EventArgs e)
{
CrystalReport_Quotation1.SetDatabaseLogon("DB_USER_AFDR", "1237894560");
crvQuotation.ReportSource = CrystalReport_Quotation1;
crvQuotation.Refresh();
}
|
|
|
|
|
you able to login with these same credentials to your database directly?
modified 20-Sep-20 21:01pm.
|
|
|
|
|
Contact Crystal Reports on their forum[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Hello,
I plan to make each tab pages at different sizes. Once I go to properties and change the size it doesn't allow to change. What's the way to do this?
modified 13-Feb-19 21:02pm.
|
|
|
|
|
Think about it: you can't have a set of tab pages that are all different sizes - because they all have to fit inside the same frame, and if the page size changed, so would the frame have to - which would make navigating kinda difficult and very ugly. You can have the frame allow for scroll bars (but even that should be pretty minimal if you can).
Given that tab pages are supposed to be showing related information, it's quite likely that you really need to rethink your UI design using different controls, or your users are going to hate it.
Sent from my Amstrad PC 1640
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
In WPF, tabs will "size to their content" unless you specifically override with sizing information.
The window can resize as well along with the visible tab.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Dear All,
We need code or library to use it in c# windows forms application to connect to a device connected to PC by USB.
The device Connected to PC "A" and I remotely Logged In to Server "B" and use a system in server "B",
I need to connect to the Device on the PC "A" from the server "B".
It is slimier to USB Network Gate but i need it to be in my c# code not a third party tool.
Please Help Me ASAP if you can
Thank You ALL
|
|
|
|
|
Create a small service and install it on PC "A", that accepts or sends xml or json messages over http or tcp. Let the C# program on server "B" ask PC "A" to read te USB device. The messages could optionally be encrypted later.
|
|
|
|
|
|
What is the format of a SQLConnection connection string that is passed in the constructor method? I have run a search engine search online and all I could find so far is examples like:
"Data Source=(local);Initial Catalog=AdventureWorks; Integrated Security=SSPI;";
"User Id=sa;Server=localhost;Initial Catalog=Test;"
The examples raises questions. Since the SQL Server Management Studio (SSMS) program offers a different set of fields during start up in order to connect to a database, I have to ask how does "Server type, "Server name", "Authentication", "User name" and "Password". Also, is "Catalog" another name for a database table?
|
|
|
|
|
|
i want to create table in RichTextBox.it is done using string builder class but i want to print this richtextbox table with other controls on a single report.Is it possible to print Richtextbox Table format with other controls ?
|
|
|
|
|
Most likely, yes. Assuming you know how to structure a printed page.
|
|
|
|
|
Hi,
Perhaps this article of Howard 9448490 here on CP is of some help:
A Simple RTF Print Form[^]
With friendly greetings,
Eric Goedhart
|
|
|
|
|
Hi, I inherited a program from a programmer that has since left the company. He built it with threading and the program crashes I think due to starting more threads than the system can handle. I am thinking that I need to implement a Thread Pool for this code, and am unsure how I should do that not having done it before, and complicating the matter of modifying the existing code.
So, here is the existing code that uses the threading;
using my.data;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Threading;
namespace CnaFirmware
{
public class DbUpdateFromField
{
Dictionary<string, CNA> cnas;
ConcurrentQueue<string> ConsoleQueue;
EventWaitHandle UpdateComplete;
ClsUdpDispatcher UdpDispatcher;
List<string> updates;
class CNA
{
public string ip;
public string firmware;
public int cktid;
public bool updated;
public bool error;
public CNA(string i, string f, int c)
{
this.ip = i;
this.firmware = f;
this.cktid = c;
this.updated = false;
this.error = false;
}
}
public DbUpdateFromField(ClsUdpDispatcher disp, ConcurrentQueue<string> q, EventWaitHandle op_done)
{
UdpDispatcher = disp;
ConsoleQueue = q;
UpdateComplete = op_done;
Log("start");
updates = new List<string>();
cnas = new Dictionary<string, CNA>();
new Thread(() => Start()).Start();
}
void Start()
{
GetIpList();
GetCnaData();
}
void Log(string s)
{
ConsoleQueue.Enqueue("DbUpdate: " + s);
}
void GetCnaData()
{
SqlConnection DB;
foreach (var v in cnas)
{
new Thread(() => GetCnaInfo(v.Value)).Start();
}
bool done;
do
{
Thread.Sleep(50);
done = true;
foreach (var v in cnas)
{
if (!v.Value.updated && !v.Value.error) done = false;
}
} while (!done);
if (updates.Count > 0)
{
Log(string.Format("Sending {0} updates to database...", updates.Count));
using (DB = new SqlConnection(Globals.ConnectionString))
{
try
{
DB.Open();
}
catch (Exception ex)
{
Log(ex.Message);
return;
}
try
{
using (SqlCommand sql = new SqlCommand())
{
sql.Connection = DB;
foreach (string query in updates)
{
sql.CommandText = query;
sql.ExecuteNonQuery();
Thread.Sleep(10);
}
}
}
catch (Exception ex)
{
Log(ex.Message);
return;
}
}
}
else
{
Log("No updates");
}
Log("Operation complete");
UpdateComplete.Set();
}
void SendGetConfig(string ip, ConcurrentQueue<UdpMessage> C)
{
byte[] msg = new byte[11];
msg[0] = 1;
msg[7] = 5;
msg[8] = 0x42;
UdpDispatcher.Send(new UdpMessage(ip, 20367, msg, 11), C);
}
void GetCnaInfo(CNA cna)
{
int WaitTicks;
ConcurrentQueue<UdpMessage> CnaRxQ = new ConcurrentQueue<UdpMessage>();
int tries = 0;
while (++tries < 4)
{
WaitTicks = 0;
SendGetConfig(cna.ip, CnaRxQ);
while (++WaitTicks < 100)
{
if (CnaRxQ.TryDequeue(out UdpMessage msg))
{
ushort label = (ushort)((msg.data[7] << 8) + (ushort)msg.data[8]);
if (label == 0x0543)
{
if (msg.data[0] > 1)
{
string firmware = string.Format("{0}.{1}.{2}", msg.data[1], msg.data[2], msg.data[3]);
cna.updated = true;
if (cna.firmware == firmware)
{
Log(string.Format("Skipping {0}: firmware is current", cna.ip));
}
else
{
Log("Updating " + cna.ip);
QueryBuilder qb = new QueryBuilder("update cna_firmware set firmware_rev = ");
qb.AddString(firmware, QBOptions.NONE);
qb.Query += " where ip_address = ";
qb.AddString(cna.ip, QBOptions.NONE);
updates.Add(qb.Query);
}
return;
}
else
{
Log(string.Format("Skipping {0}: unexpected data received", cna.ip));
return;
}
}
else
{
Log(string.Format("Skipping {0}: unexpected data received", cna.ip));
return;
}
}
Thread.Sleep(100);
}
}
Log("Unable to fetch config data from " + cna.ip);
cna.error = true;
}
void GetIpList()
{
SqlConnection DB;
string query;
using (DB = new SqlConnection(Globals.ConnectionString))
{
try
{
DB.Open();
}
catch (Exception)
{
UpdateComplete.Set();
return;
}
query = "select ip_address, n_cktid, firmware_rev from cna_firmware order by ip_address";
try
{
using (SqlCommand sql = new SqlCommand(query, DB))
{
using (SqlDataReader dr = sql.ExecuteReader())
{
if (dr.HasRows)
{
while (dr.Read())
{
int ckt = Sql.Read<int>(dr, "n_cktid");
string ip = Sql.Read<string>(dr, "ip_address");
string fw = Sql.Read<string>(dr, "firmware_rev");
if (cnas.ContainsKey(ip)) continue;
cnas.Add(ip, new CNA(ip, fw, ckt));
}
}
}
}
}
catch (Exception ex)
{
Log(ex.Message);
}
}
}
}
}
Thanks,
|
|
|
|
|
Quote: He built it with threading and the program crashes
Stop right there and describe the crash, any exceptions you get, and any related messages you may dig out of the Application Event Log.
Beyond this one statement, everything else you said is mere speculation without any understanding of the underlying problem. That's a recipe for a lot of wasted time.
Research the problem, not the proposed "solution".
|
|
|
|
|