|
where view doesn't know about presenter, just raises events... presenter knows views controls (idk how to do the one where to make the presenter as if it was calling a console, for unit tests...)
1. should view contain ui logic, or all logic is in the presenter?
2. if view event is raised, should presenter call view's method or should presenter do the magic and tell view what control to change?
3. We're using a single form like sidebar with many usercontrols in the main panel, should presenters be separate from each other? even the main one?
4. When calling dispose to save resources, what happens to the presenter it's associated to? i get an error because the view is not there because deleted, check if null, create one with unity? what lifetime manager? should i dispose presenter too? how do i recreate it then if yes?
5. unity what lifetime manager is best? it's in the program.cs
thank you all in adv )
|
|
|
|
|
Hi
I try to load txt file data in record list in object but error msg stops code running. the error is below.
Severity Code Description Project File Line Suppression State
Error CS1955 Non-invocable member 'StreamReader' cannot be used like a method. metjelentes C:\Users\Dell\source\repos\metjelentes\metjelentes\Program.cs 21 Active
<pre>using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections.Generic;
namespace metjelentes
{
class adatok
{
public string telepules = " ";
public string ido = " ";
public string szeliranyes_erosseg = " ";
public int homerseklet = 0;
}
class beolvasas
{
public void beolvas()
{
string olvas = @"c:\Users\Public\textfiles\tavirathu13.txt";
using (StreamReader sr = StreamReader(olvas, Encoding.Default))
{
List<adatok> lista = new List<adatok>();
while (!sr.EndOfStream)
{
string sor = sr.ReadLine();
string[] elemek = sor.Split(' ');
lista.Add(new adatok());
}
}
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
|
|
|
|
|
Remove the ( between using and streamreader
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
You have this:
using (StreamReader sr = StreamReader(olvas, Encoding.Default))
You have to "new up" a StreamReader to get an object for it:
using (StreamReader sr = new StreamReader(olvas, Encoding.Default))
|
|
|
|
|
In general, "Non-invocable member 'xxxxxx' cannot be used like a method" means you forgot the "new" in object creation.
Truth,
James
|
|
|
|
|
Hi everyone,
I created two kind of programming codes. The first one, I simply use HTTPListener class in .NET. The last one, I use a complex method with more than one thread to treat entering SOAP Request. For them, I return SOAP Response. These solutions runs perfectly within Windows Forms Application (of course, by moving the content of OnStart within the click of start button).
But, I have a big problem. The BeginGetContext of HTTPListener seems to be quiet and never react or trigger just within Windows Service. I don't think this issue is normal. These two algorithms runs without issue within Windows Forms Application. Naturally, if I start the Windows Service, the Windows Forms Application doesn't listen in same time. I only run one of them at once.
I have a valid self signed certificate. It runs under Windows Forms Application with no issue. I use the same for Windows Service, except with using OnStart and OnStop. Only at this moment, the situation is problematic.
I delete and add a SSL Certificate each time to be sure that I have loaded certificate within Windows.
I prefer to have simplicity with programming code. I am a fan to "keep it simple". I don't care to keep any of them. I want the best one.
Do you experiment this behavior in your life? I transfer many application from Windows Forms Application to Windows Service without any kind of issue in the past.
If I execute the DOS command : " telnet localhost 30010 ", the Windows Service listen really the port of communication 30010. But, the BeginGetContext didn't trigger to my function ListenerCallback or ContextReady like it is supposed to do.
I read basic documentations concerning HTTPListener class. I control the situation within Windows Forms Application. All methods runs perfectly. This is just if I use the Windows Service. The BeginGetContext doesn't react like it is supposed to react within Windows Service environment.
First one :
public partial class SOAPServer_Service : ServiceBase {
public string ErrorMessage = "";
private HttpListener Listener;
public SOAPServer_Service() {
InitializeComponent();
}
protected void OnStart(string[] args) {
try {
this.ErrorMessage = "";
string Port = "30010",
HashCertificat = "8f3146c64cb75a716a3543dfc10c2967acab9471",
URLEnvironment = "https://10.182.133.101:30010/WS/";
Process ProcessusDelete = new Process();
ProcessStartInfo StartInfoDelete = new ProcessStartInfo();
StartInfoDelete.WindowStyle = ProcessWindowStyle.Hidden;
StartInfoDelete.FileName = "cmd.exe";
StartInfoDelete.Arguments = "/C C:\\Windows\\System32\\netsh http delete sslcert ipport=0.0.0.0:" + Port;
StartInfoDelete.Verb = "runas";
ProcessusDelete.StartInfo = StartInfoDelete;
ProcessusDelete.Start();
ProcessusDelete.WaitForExit(10000);
ProcessusDelete.Close();
Process ProcessusAdd = new Process();
ProcessStartInfo StartInfoAdd = new ProcessStartInfo();
StartInfoAdd.WindowStyle = ProcessWindowStyle.Hidden;
StartInfoAdd.FileName = "cmd.exe";
StartInfoAdd.Arguments = "/C C:\\Windows\\System32\\netsh http add sslcert ipport=0.0.0.0:" + Port + " certhash=" + HashCertificat + " appid={e2eaacd9-92e6-43cc-b51c-7a7887149607}";
StartInfoAdd.Verb = "runas";
ProcessusAdd.StartInfo = StartInfoAdd;
ProcessusAdd.Start();
ProcessusAdd.WaitForExit(10000);
ProcessusAdd.Close();
if (HttpListener.IsSupported) {
if (this.Listener == null) {
this.Listener = new HttpListener();
}
this.Listener.Prefixes.Add(URLEnvironment);
this.Listener.Start();
IAsyncResult Result = this.Listener.BeginGetContext(new AsyncCallback(this.ListenerCallback), this.Listener);
} else {
this.ErrorMessage = "The operating system is not up to date!";
return false;
}
} catch (Exception E) {
this.ErrorMessage = this.GetCompleteException(E);
using (FileStream fs = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Exception_OnStart.txt", FileMode.Create)) {
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8)) {
sw.WriteLine(this.ErrorMessage);
}
}
}
}
protected override void OnStop() {
try {
this.ErrorMessage = "";
if (this.Listener != null) {
this.Listener.Close();
this.Listener = null;
}
} catch (Exception E) {
this.ErrorMessage = this.GetCompleteException(E);
using (FileStream fs = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Exception_OnStop.txt", FileMode.Create)) {
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8)) {
sw.WriteLine(this.ErrorMessage);
}
}
}
}
private void ListenerCallback(IAsyncResult Result) {
try {
string SOAPRequest = "",
SOAPResponse = "";
this.ErrorMessage = "";
HttpListenerContext Context = this.Listener.EndGetContext(Result);
HttpListenerRequest Request = Context.Request;
HttpListenerResponse Response = Context.Response;
if (Request.HasEntityBody) {
Stream S = Request.InputStream;
StreamReader SR = new StreamReader(S, Encoding.UTF8);
SOAPRequest = SR.ReadToEnd();
SR.Close();
S.Close();
using (FileStream fsIn = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Trace_Request_" + DateTime.Now.ToString("s").Replace("/", "").Replace("-", "").Replace(":", "") + ".xml", FileMode.Create)) {
using (StreamWriter swIn = new StreamWriter(fsIn, Encoding.UTF8)) {
swIn.WriteLine(SOAPRequest);
}
}
using (FileStream fsOut = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Trace_Response_" + DateTime.Now.ToString("s").Replace("/", "").Replace("-", "").Replace(":", "") + ".xml", FileMode.Create)) {
using (StreamWriter swOut = new StreamWriter(fsOut, Encoding.UTF8)) {
swOut.WriteLine(SOAPResponse);
}
}
byte[] byteSOAPResponse = UTF8Encoding.UTF8.GetBytes(SOAPResponse);
using (Stream StreamSender = Response.OutputStream) {
StreamSender.Write(byteSOAPResponse, 0, byteSOAPResponse.Length);
StreamSender.Close();
}
Response.Close();
Result = this.Listener.BeginGetContext(new AsyncCallback(this.ListenerCallback), this.Listener);
}
} catch (Exception E) {
this.ErrorMessage = this.RecupereException(E);
using (FileStream fs = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Exception_ListenerCallback_" + DateTime.Now.ToString("s").Replace("/", "").Replace("-", "").Replace(":", "") + ".txt", FileMode.Create)) {
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8)) {
swEntree.WriteLine("TryCatch : ");
swEntree.WriteLine(this.ErrorMessage);
}
}
return;
}
}
protected string RecupereException(Exception E) {
string M = "";
while (E != null) {
M += E.Message;
E = E.InnerException;
}
return M;
}
}
Second one :
public partial class SOAPServer_Service : ServiceBase {
public string ErrorMessage = "";
private int NbrThread = 5;
private SOAPServer_OSS ServerSOAP;
public SOAPServer_Service() {
InitializeComponent();
this.ServerSOAP = new SOAPServer_OSS(this.NbrThread);
}
protected void OnStart(string[] args) {
try {
this.ServerSOAP.Start();
} catch (Exception E) {
this.ErrorMessage = this.GetCompleteException(E);
using (FileStream fs = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Exception_OnStart.txt", FileMode.Create)) {
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8)) {
sw.WriteLine(this.ErrorMessage);
}
}
}
}
protected override void OnStop() {
try {
this.ServerSOAP.Stop();
} catch (Exception E) {
this.ErrorMessage = this.GetCompleteException(E);
using (FileStream fs = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Exception_OnStop.txt", FileMode.Create)) {
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8)) {
sw.WriteLine(this.ErrorMessage);
}
}
}
}
protected string GetCompleteException(Exception E) {
string M = "";
while (E != null) {
M += E.Message;
E = E.InnerException;
}
return M;
}
}
class SOAPServer_OSS : IDisposable {
private readonly HttpListener listener;
private readonly Thread listenerThread;
private readonly Thread[] thread;
private readonly ManualResetEvent state_listener,
state_queue;
private Queue<HttpListenerContext> queue;
public string port = "30010",
hashCertificat = "8f3146c64cb75a716a3543dfc10c2967acab9471";
public SOAPServer_OSS(int NbrThread) {
this.thread = new Thread[NbrThread];
this.queue = new Queue<HttpListenerContext>();
this.state_listener = new ManualResetEvent(false);
this.state_queue = new ManualResetEvent(false);
this.listener = new HttpListener();
this.listenerThread = new Thread(this.HandleRequests);
}
protected string GetCompleteException(Exception E) {
string M = "";
while (E != null) {
M += E.Message;
E = E.InnerException;
}
return M;
}
public void Start() {
try {
Process ProcessusDelete = new Process();
ProcessStartInfo StartInfoDelete = new ProcessStartInfo();
StartInfoDelete.WindowStyle = ProcessWindowStyle.Hidden;
StartInfoDelete.FileName = "cmd.exe";
StartInfoDelete.Arguments = "/C C:\\Windows\\System32\\netsh http delete sslcert ipport=0.0.0.0:" + this.port;
StartInfoDelete.Verb = "runas";
ProcessusDelete.StartInfo = StartInfoDelete;
ProcessusDelete.Start();
ProcessusDelete.WaitForExit(10000);
ProcessusDelete.Close();
Process ProcessusAdd = new Process();
ProcessStartInfo StartInfoAdd = new ProcessStartInfo();
StartInfoAdd.WindowStyle = ProcessWindowStyle.Hidden;
StartInfoAdd.FileName = "cmd.exe";
StartInfoAdd.Arguments = "/C C:\\Windows\\System32\\netsh http add sslcert ipport=0.0.0.0:" + this.port + " certhash=" + this.hashCertificat + " appid={e2eaacd9-92e6-43cc-b51c-7a7887149607}";
StartInfoAdd.Verb = "runas";
ProcessusAdd.StartInfo = StartInfoAdd;
ProcessusAdd.Start();
ProcessusAdd.WaitForExit(10000);
ProcessusAdd.Close();
this.listener.Prefixes.Add(String.Format(@"https://+:{0}/WS/", this.port));
this.listener.Start();
this.listenerThread.Start();
for (int i = 0; i < this.thread.Length; i++) {
this.thread[i] = new Thread(this.Worker);
this.thread[i].Name = "Thread_" + (i + 1).ToString();
this.thread[i].Start();
}
} catch (Exception E) {
this.ErrorMessage = this.GetCompleteException(E);
using (FileStream fsEntree = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Exception_SOAPServer_Start.txt", FileMode.Create)) {
using (StreamWriter swEntree = new StreamWriter(fsEntree, Encoding.UTF8)) {
swEntree.WriteLine(this.ErrorMessage);
}
}
}
}
public void Dispose() { this.Stop(); }
public void Stop() {
try {
this.state_listener.Set();
this.listenerThread.Join();
foreach (Thread T in this.thread) {
T.Join();
}
this.listener.Stop();
} catch (Exception E) {
this.ErrorMessage = this.GetCompleteException(E);
using (FileStream fsEntree = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Exception_Stop.txt", FileMode.Create)) {
using (StreamWriter swEntree = new StreamWriter(fsEntree, Encoding.UTF8)) {
swEntree.WriteLine(this.ErrorMessage);
}
}
}
}
private void HandleRequests() {
try {
while (this.listener.IsListening) {
var context = this.listener.BeginGetContext(this.ContextReady, null);
WaitHandle[] wait = new[] { this.state_listener, context.AsyncWaitHandle };
if (0 == WaitHandle.WaitAny(wait)) {
return;
}
}
} catch (Exception E) {
this.ErrorMessage = this.GetCompleteException(E);
using (FileStream fsEntree = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Exception_HandleRequests.txt", FileMode.Create)) {
using (StreamWriter swEntree = new StreamWriter(fsEntree, Encoding.UTF8)) {
swEntree.WriteLine(this.ErrorMessage);
}
}
}
}
private void ContextReady(IAsyncResult ar) {
try {
lock (this.queue) {
this.queue.Enqueue(this.listener.EndGetContext(ar));
this.state_queue.Set();
}
} catch (Exception E) {
this.ErrorMessage = this.GetCompleteException(E);
using (FileStream fsEntree = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Exception_ContextReady.txt", FileMode.Create)) {
using (StreamWriter swEntree = new StreamWriter(fsEntree, Encoding.UTF8)) {
swEntree.WriteLine(this.ErrorMessage);
}
}
}
}
private void Worker() {
try {
WaitHandle[] wait = new[] { this.state_queue, this.state_listener };
while (0 == WaitHandle.WaitAny(wait)) {
HttpListenerContext context;
lock (this.queue) {
if (this.queue.Count > 0) {
context = this.queue.Dequeue();
} else {
this.state_queue.Reset();
continue;
}
}
this.ProcessRequest(context);
}
} catch (Exception E) {
this.ErrorMessage = this.GetCompleteException(E);
using (FileStream fsEntree = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Exception_Worker.txt", FileMode.Create)) {
using (StreamWriter swEntree = new StreamWriter(fsEntree, Encoding.UTF8)) {
swEntree.WriteLine(this.ErrorMessage);
}
}
}
}
private void ProcessRequest(HttpListenerContext Contexte) {
try {
HttpListenerRequest Request = Contexte.Request;
HttpListenerResponse Response = Contexte.Response;
if (Request.HasEntityBody) {
Stream S = Request.InputStream;
StreamReader SR = new StreamReader(S, Encoding.UTF8);
SOAPRequest = SR.ReadToEnd();
SR.Close();
S.Close();
using (FileStream fsIn = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Trace_Request_" + DateTime.Now.ToString("s").Replace("/", "").Replace("-", "").Replace(":", "") + ".xml", FileMode.Create)) {
using (StreamWriter swIn = new StreamWriter(fsIn, Encoding.UTF8)) {
swIn.WriteLine(SOAPRequest);
}
}
using (FileStream fsOut = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Trace_Response_" + DateTime.Now.ToString("s").Replace("/", "").Replace("-", "").Replace(":", "") + ".xml", FileMode.Create)) {
using (StreamWriter swOut = new StreamWriter(fsOut, Encoding.UTF8)) {
swOut.WriteLine(SOAPResponse);
}
}
byte[] byteSOAPResponse = UTF8Encoding.UTF8.GetBytes(SOAPResponse);
using (Stream StreamSender = Response.OutputStream) {
StreamSender.Write(byteSOAPResponse, 0, byteSOAPResponse.Length);
StreamSender.Close();
}
Response.Close();
}
} catch (Exception E) {
this.ErrorMessage = this.GetCompleteException(E);
using (FileStream fsEntree = new FileStream(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Exception_ProcessRequest_" + DateTime.Now.ToString("s").Replace("/", "").Replace("-", "").Replace(":", "") + ".txt", FileMode.Create)) {
using (StreamWriter swEntree = new StreamWriter(fsEntree, Encoding.UTF8)) {
swEntree.WriteLine("TryCatch : ");
swEntree.WriteLine(this.ErrorMessage);
}
}
}
}
}
Do you have any suggestions?
|
|
|
|
|
Sometimes one try-catch is sufficient.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Hi Gerry Schmitz,
I know this, but I might to throw again the exception. This is more simple to debug like this. Each catched exception is specific. I know exactly within the specific method where it crashes. I am sorry! If we find the problem, I will make another code with just one try-catch and I will post to you.
Other than that, do you know where I made a mistake? I recall to you that this code runs perfectly within Windows Forms Application.
Have a nice day my friend!
|
|
|
|
|
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
1) What WaitForPendingFinalizers does ?
it suspend the current thread and clear the memory?
2) Why GC.Collect(); called twice when we use GC.WaitForPendingFinalizers(); ?
3) GC.WaitForPendingFinalizers(); slow down the performance of the application....why ?
Thanks
|
|
|
|
|
|
I am trying to find data in xml file using LINQ but my ANY() or WHERE clause found no data. what is the problem in my approach not clear.
I have a xml file which which has been created by Dataset WriteXml() function. that file i am querying by LINQ and data not found occur.
See my XML structure
<?xml version="1.0" standalone="yes"?>
<TER_ViewAll>
<dgvViewAll_Vertical>
<Section_x0020_>ML</Section_x0020_>
<LineItem>BofA Merrill Lynch</LineItem>
<Revise_x0020_Date>01-16-2018</Revise_x0020_Date>
<_x0032_010_x0020_FYA>1608.6500</_x0032_010_x0020_FYA>
<_x0032_011_x0020_FYA>1429.0610</_x0032_011_x0020_FYA>
<_x0032_012_x0020_FYA>1656.7500</_x0032_012_x0020_FYA>
<_x0032_013_x0020_FYA>1427.9330</_x0032_013_x0020_FYA>
<_x0031_Q_x0020_2014A>321.0100</_x0031_Q_x0020_2014A>
<_x0032_Q_x0020_2014A>525.5670</_x0032_Q_x0020_2014A>
<_x0033_Q_x0020_2014A>478.0100</_x0033_Q_x0020_2014A>
<_x0034_Q_x0020_2014A>323.2360</_x0034_Q_x0020_2014A>
<_x0032_014_x0020_FYA>1647.8230</_x0032_014_x0020_FYA>
<_x0031_Q_x0020_2015A>342.4010</_x0031_Q_x0020_2015A>
<_x0032_Q_x0020_2015A>512.7390</_x0032_Q_x0020_2015A>
<_x0033_Q_x0020_2015A>465.9940</_x0033_Q_x0020_2015A>
<_x0034_Q_x0020_2015A>318.4440</_x0034_Q_x0020_2015A>
<_x0032_015_x0020_FYA>1639.5780</_x0032_015_x0020_FYA>
<_x0031_Q_x0020_2016A>430.9940</_x0031_Q_x0020_2016A>
<_x0032_Q_x0020_2016A>531.7920</_x0032_Q_x0020_2016A>
<_x0033_Q_x0020_2016A>410.4750</_x0033_Q_x0020_2016A>
<_x0034_Q_x0020_2016A>379.9890</_x0034_Q_x0020_2016A>
<_x0032_016_x0020_FYA>1753.2500</_x0032_016_x0020_FYA>
<_x0031_Q_x0020_2017A>456.9130</_x0031_Q_x0020_2017A>
<_x0032_Q_x0020_2017A>696.9010</_x0032_Q_x0020_2017A>
<_x0033_Q_x0020_2017A>503.3780</_x0033_Q_x0020_2017A>
<_x0034_Q_x0020_2017A />
<_x0032_017_x0020_FYA />
<_x0031_Q_x0020_2018A />
<_x0032_Q_x0020_2018A />
<_x0033_Q_x0020_2018A />
<_x0034_Q_x0020_2018A />
<_x0032_018_x0020_FYA />
<_x0031_Q_x0020_2019A />
<_x0032_Q_x0020_2019A />
<_x0033_Q_x0020_2019A />
<_x0034_Q_x0020_2019A />
<_x0032_019_x0020_FYA />
<_x0031_Q_x0020_2020A />
<_x0032_Q_x0020_2020A />
<_x0033_Q_x0020_2020A />
<_x0034_Q_x0020_2020A />
<_x0032_020_x0020_FYA />
<_x0031_Q_x0020_2021E />
<_x0032_Q_x0020_2021E />
<_x0033_Q_x0020_2021E />
<_x0034_Q_x0020_2021E />
<_x0032_021_x0020_FYE />
<_x0031_Q_x0020_2022E />
<_x0032_Q_x0020_2022E />
<_x0033_Q_x0020_2022E />
<_x0034_Q_x0020_2022E />
<_x0032_022_x0020_FYE />
<GroupKey>Consensus Model~Net Revenue~TRIN~NBM~~1~ML</GroupKey>
</dgvViewAll_Vertical>
</TER_ViewAll>
the above xml is one records and xml file has many records like above one. i load that xml file by data ser and querying by LINQ. this way i am querying.
private void button1_Click(object sender, EventArgs e)
{
string QCViewPath_savepath = @"C:\RDSS WorkBench_Stage\Data\TER\TER_QC-ViewwAll.xml";
DataSet ds = new DataSet();
ds.ReadXml(QCViewPath_savepath);
if (ds.Tables[0].AsEnumerable().Any(a => a.Field<string>("Section ") == "ML"
&& a.Field<string>("GroupKey").Contains("Consensus Model")
&& a.Field<string>("GroupKey").Contains("Net Revenue")
&& a.Field<string>("GroupKey").Contains("NBM")
&& a.Field<string>("GroupKey").Contains("1")
&& a.Field<string>("GroupKey").Contains("ML")
))
{
ds.Tables[0].AsEnumerable().Where(a => a.Field<string>("Section ") == "ML"
&& a.Field<string>("GroupKey").Split('~')[0].Trim() == "Consensus Model"
&& a.Field<string>("GroupKey").Split('~')[1].Trim() == "Net Revenue"
&& a.Field<string>("GroupKey").Split('~')[3].Trim() == "NBM"
&& a.Field<string>("GroupKey").Split('~')[4].Trim() == "1"
&& a.Field<string>("GroupKey").Split('~')[5].Trim() == "ML"
).ToList<DataRow>()
.ForEach(r =>
{
r["2010 FYA"] = 1200;
});
}
}
My object is to update data table periodical value and save that data at last after all update. after querying data table i am getting Enumeration yielded no results
please help with rectified code. Thanks
modified 10-Apr-21 8:01am.
|
|
|
|
|
You have no field in your XML called "Section ":
if (ds.Tables[0].AsEnumerable().Any(a => a.Field<string>("Section ") == "ML"
&& ...
))
So the first test will always fail.
You have "Section_x0020_" but no "Section " ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Sir xml was created by data table writexml function data looks like & see how Section element looks in xml <section_x0020_>ZB that is why we need to add space end of Section other wise program will throw run time error.
<dgvViewAll_Vertical>
<Section_x0020_>ZB</Section_x0020_>
<LineItem>B. Riley Securities</LineItem>
<Revise_x0020_Date>02-09-2021</Revise_x0020_Date>
<_x0032_010_x0020_FYA />
<_x0032_011_x0020_FYA />
<_x0032_012_x0020_FYA />
<_x0032_013_x0020_FYA />
<_x0031_Q_x0020_2014A />
<_x0032_Q_x0020_2014A />
<_x0033_Q_x0020_2014A />
<_x0034_Q_x0020_2014A />
<_x0032_014_x0020_FYA />
<_x0031_Q_x0020_2015A />
<_x0032_Q_x0020_2015A />
<_x0033_Q_x0020_2015A />
<_x0034_Q_x0020_2015A />
<_x0032_015_x0020_FYA />
<_x0031_Q_x0020_2016A />
<_x0032_Q_x0020_2016A>3333.3865</_x0032_Q_x0020_2016A>
<_x0033_Q_x0020_2016A>3878.1150</_x0033_Q_x0020_2016A>
<_x0034_Q_x0020_2016A>4376.5020</_x0034_Q_x0020_2016A>
<_x0032_016_x0020_FYA />
<_x0031_Q_x0020_2017A>3340.3645</_x0031_Q_x0020_2017A>
<_x0032_Q_x0020_2017A>3711.3744</_x0032_Q_x0020_2017A>
<_x0033_Q_x0020_2017A>4310.8500</_x0033_Q_x0020_2017A>
<_x0034_Q_x0020_2017A>5041.2855</_x0034_Q_x0020_2017A>
<_x0032_017_x0020_FYA>16403.8744</_x0032_017_x0020_FYA>
<_x0031_Q_x0020_2018A>4867.8009</_x0031_Q_x0020_2018A>
<_x0032_Q_x0020_2018A>5167.5060</_x0032_Q_x0020_2018A>
<_x0033_Q_x0020_2018A />
<_x0034_Q_x0020_2018A />
<_x0032_018_x0020_FYA />
<_x0031_Q_x0020_2019A />
<_x0032_Q_x0020_2019A>3545.9127</_x0032_Q_x0020_2019A>
<_x0033_Q_x0020_2019A>3308.1080</_x0033_Q_x0020_2019A>
<_x0034_Q_x0020_2019A>3911.1380</_x0034_Q_x0020_2019A>
<_x0032_019_x0020_FYA />
<_x0031_Q_x0020_2020A>2798.3300</_x0031_Q_x0020_2020A>
<_x0032_Q_x0020_2020A>3054.0900</_x0032_Q_x0020_2020A>
<_x0033_Q_x0020_2020A>$3,851.0000</_x0033_Q_x0020_2020A>
<_x0034_Q_x0020_2020A>4495.1620</_x0034_Q_x0020_2020A>
<_x0032_020_x0020_FYA>14198.5820</_x0032_020_x0020_FYA>
<_x0031_Q_x0020_2021E>4187.6225</_x0031_Q_x0020_2021E>
<_x0032_Q_x0020_2021E>4701.8271</_x0032_Q_x0020_2021E>
<_x0033_Q_x0020_2021E>4902.8013</_x0033_Q_x0020_2021E>
<_x0034_Q_x0020_2021E>4929.6456</_x0034_Q_x0020_2021E>
<_x0032_021_x0020_FYE>18721.8968</_x0032_021_x0020_FYE>
<_x0031_Q_x0020_2022E>4980.5665</_x0031_Q_x0020_2022E>
<_x0032_Q_x0020_2022E>5074.0862</_x0032_Q_x0020_2022E>
<_x0033_Q_x0020_2022E>5281.4401</_x0033_Q_x0020_2022E>
<_x0034_Q_x0020_2022E>5307.0933</_x0034_Q_x0020_2022E>
<_x0032_022_x0020_FYE>20643.1862</_x0032_022_x0020_FYE>
<_x0031_Q_x0020_2023E>4201.8093</_x0031_Q_x0020_2023E>
<_x0032_Q_x0020_2023E>4211.1577</_x0032_Q_x0020_2023E>
<_x0033_Q_x0020_2023E>4220.5062</_x0033_Q_x0020_2023E>
<_x0034_Q_x0020_2023E>4220.5062</_x0034_Q_x0020_2023E>
<_x0032_023_x0020_FYE>16853.9796</_x0032_023_x0020_FYE>
<GroupKey>Consensus Model~Total Revenue~TRIN~NBM~~1~ZB</GroupKey>
</dgvViewAll_Vertical>
|
|
|
|
|
So what? You STILL don't have anything in that XML called "Section".
If this XML is being written incorrectly, I think the problem would come down to the code that generated the original datatable and/or the code that wrote it to the file.
|
|
|
|
|
The underscore character '_' is not a "special character" in XML data - it does not indicate to anything standard that the hex value between a pair of underscores should be treated as a single Unicode character. It's just a valid character in an element name, is all. So an XML element called "Section_x0020_" is not equivalent to a table column called "Section " or even "Section" - it becomes a column named "Section_x0020_" is all.
Even if it was - which it isn't - ending a field or element name with an "invisible character" would be a very poor practice!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Just as a thought, see here: The Naming of Parts[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
I think the preference depends on who is doing the reading (reading it out loud) and how much wine is involved.
|
|
|
|
|
Yes issue fixed. sharing working code.
string QCViewPath_savepath = @"C:\Test.xml";
DataSet ds = new DataSet();
ds.ReadXml(QCViewPath_savepath);
if (ds.Tables[0].AsEnumerable().Any(a => a.Field<string>("Section ") == "ML"
&& a.Field<string>("GroupKey").Split('~')[0].Trim() == "Consensus Model"
&& a.Field<string>("GroupKey").Split('~')[1].Trim() == "Net Revenue"
&& a.Field<string>("GroupKey").Split('~')[3].Trim() == "NBM"
&& a.Field<string>("GroupKey").Split('~')[5].Trim() == "1"
&& a.Field<string>("GroupKey").Split('~')[6].Trim() == "ML"
))
{
ds.Tables[0].AsEnumerable().Where(a => a.Field<string>("Section ") == "ML"
&& a.Field<string>("GroupKey").Split('~')[0].Trim() == "Consensus Model"
&& a.Field<string>("GroupKey").Split('~')[1].Trim() == "Net Revenue"
&& a.Field<string>("GroupKey").Split('~')[3].Trim() == "NBM"
&& a.Field<string>("GroupKey").Split('~')[5].Trim() == "1"
&& a.Field<string>("GroupKey").Split('~')[6].Trim() == "ML"
).ToList<DataRow>()
.ForEach(r =>
{
r["2010 FYA"] = 1200;
});
}
|
|
|
|
|
.Any(...) followed by .Where(...).ToList() will be rather inefficient. Just call .Where(...).ToList() ; if there are no matching elements, the list will be empty.
You'd also be better skipping the .ToList() , and using a foreach loop instead. You're not changing anything that would cause the "collection was modified" error, or cause rows to be skipped, so you don't need the extra overhead of a List<T> .
IEnumerable<DataRow> recordsToUpdate = ds.Tables[0].AsEnumerable().Where(a => ...);
foreach (DataRow row in recordsToUpdate)
{
row["2010 FYA"] = 1200;
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks for the guide line.
|
|
|
|
|
Hello
I find on the internet many slider on the internet from 0-10 and so on but I don't find any for hour and minute.
I am trying to make something like this (jquery): https://codepen.io/caseymhunt/pen/kertA
I don't know how I can make in C# winform. I just need to able select beginning and ending of the hour and minute. When moving the slider then increasing and decreasing with 15 minutes.
Is there an open source for this or how I can make this? The design can be basic too, I just need the function to work.
I don't have any idea how to make this possible.
Thank you in advance all of the answers.
|
|
|
|
|
Create a UserControl, and start there.
Give it a fixed height, and add four "points": minimum, maximum, low, high.
These are probably integer values which do not relate in any way directly to hours and minutes, so the control can be flexible.
Handle the Paint event to draw the control and two "handles" that you can move.
Handle the MouseDown, MouseUp, and MouseMove events to let you move the handles.
As they move, update the low and high values.
Provide properties to read the values, and in there translate the integers to hours and minutes - perhaps return a timespan? One digit move could be your fifteen minutes.
Provide an event to indicate "slider changed" so the outside world can react to it.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
put two System.Windows.Forms.TrackBar Controls on a form: tBarHour, tBarMinute. Configure:
this.tBarHour.LargeChange = 4;
this.tBarHour.Location = new System.Drawing.Point(280, 148);
this.tBarHour.Maximum = 23;
this.tBarHour.Name = "tBarHour";
this.tBarHour.Size = new System.Drawing.Size(375, 45);
this.tBarHour.TabIndex = 11;
this.tBarHour.Value = 12;
this.tBarHour.ValueChanged += new System.EventHandler(this.tBarHourMinute_ValueChanged);
this.tBarMinute.LargeChange = 10;
this.tBarMinute.Location = new System.Drawing.Point(280, 200);
this.tBarMinute.Maximum = 59;
this.tBarMinute.Name = "tBarMinute";
this.tBarMinute.Size = new System.Drawing.Size(375, 45);
this.tBarMinute.TabIndex = 12;
this.tBarMinute.ValueChanged += new System.EventHandler(this.tBarHourMinute_ValueChanged); The Minimum TrackBar value is #0 by default.
Set the ValueChanged event handler for both TrackBars to:
private TimeSpan tSpan;
private string tSpanStr;
private void tBarHourMinute_ValueChanged(object sender, EventArgs e)
{
tSpan = new TimeSpan(0, tBarHour.Value, tBarMinute.Value, 0);
tSpanStr = tSpan.ToString());
}
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
modified 9-Apr-21 11:39am.
|
|
|
|
|
I have the following query.
There is a one-to-many relationship between Jobs->JobSequenceSheets.
I'm joining to JobSequenceSheets. But what I really want is just the COUNT of the JobSequenceSheets records for each Job record.
I'm not sure how to do this. Can someone help?
var datas = (from j in dc.Jobs
join p in dc.Projects on j.ProjectId equals p.Id
join cty in dc.Cities on p.CityId equals cty.Id
join cl in dc.CompanyLocations on p.LocationId equals cl.Id
let jsdr = dc.JobStartDateRevisions.Where(q => q.JobId == j.Id)
.OrderByDescending(q => q.Revision)
.Take(1)
.FirstOrDefault()
join jss in dc.JobSequenceSheets on j.Id equals jss.JobId
let lots = dc.JobSequenceSheets.Where(q => q.JobId == j.Id).Count()
where (jsdr != null && jsdr.StartDate >= startDate && jsdr.StartDate <= endDate)
select new
{
JobId = j.Id,
JobNumber = j.JobNumber,
Lots = j.Lots,
StartDate = jsdr.StartDate,
ProjectId = p.Id,
ProjectNumber = p.ProjectNumber,
ProjectName = p.ProjectName,
CityId = cty.Id,
City = cty.City1,
LocationId = cl.Id,
Location = cl.Location,
}).OrderBy(x => x.Location)
.ThenBy(x => x.ProjectName)
.ThenBy(x => x.StartDate).ToList();
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|