|
Hi Griff. The Threads are all running. Output is created from all the Threads. However, I display some totals on screen for the user to verify against. It will output the totals for two of the threads run after each other, but when running the third and fourth thread I get no totals output to screen. I have tested by adding the totals to a messagebox after it is supposed to be output to the label and that works.
Below is the code. It might be long but this is what I have.
#region Set Text Code
public delegate void SetText(Control ctrl, string str);
public delegate void SetLabel(Control lblctrl, string filename);
private delegate void updateBar();
private void setText(Control ctrl, string str)
{
if (this.WindowState == FormWindowState.Minimized)
return;
if (ctrl.InvokeRequired)
ctrl.BeginInvoke(new SetText(setText), new object[] { ctrl, str });
else
ctrl.Text = str;
}
private void setFilename(Control lblctrl, string filename)
{
if (this.WindowState == FormWindowState.Minimized)
return;
if (lblctrl.InvokeRequired)
lblctrl.BeginInvoke(new SetLabel(setFilename), new object[] { lblctrl, filename });
else
lblctrl.Text = filename;
}
private void finalizeProcess()
{
GC.Collect();
}
#endregion
#region Open File Dialog Code
private void button3_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() != DialogResult.OK)
{
return;
}
else
{
txtboxSelectFile.Text = openFileDialog1.FileName;
}
}
#endregion
#region Select File Code
private void btnStart_Click(object sender, EventArgs e)
{
setText(this, "Checking Process Selection");
if (chkboxHolders.CheckState == CheckState.Unchecked && chkboxCert.CheckState == CheckState.Unchecked &&
chkboxPiadd.CheckState == CheckState.Unchecked && chkboxDivRecords.CheckState == CheckState.Unchecked)
{
MessageBox.Show("Please make a valid processing selection", "Invalid Process Selection",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
if (chkboxHolders.Checked)
{
setText(this, "Holder File Processing Selected");
processHolders();
}
if (chkboxCert.Checked)
{
setText(this, "Certificate File Processing Selected");
processCerts();
}
if (chkboxPiadd.Checked)
{
setText(this, "Payment Instruction File Processing Selected");
processDiv();
}
if (chkboxDivRecords.Checked)
{
setText(this, "Create Dividend Files");
processDividends();
}
}
}
#endregion
#region All Threading Code
private void processHolders()
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
ThreadStart starthld = new ThreadStart(convertHolders);
Thread threadhld = new Thread(starthld);
threadhld.Start();
}
}
private void processCerts()
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
ThreadStart startcert = new ThreadStart(convertCert);
Thread threadcert = new Thread(startcert);
threadcert.Start();
}
}
private void processDiv()
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
ThreadStart startdiv = new ThreadStart(convertDiv);
Thread threaddiv = new Thread(startdiv);
threaddiv.Start();
}
}
private void processDividends()
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
ThreadStart startdivs = new ThreadStart(convertDividendPayments);
Thread threaddivs = new Thread(startdivs);
threaddivs.Start();
}
}
#endregion
#region All Processing Code
private void convertHolders()
{
string infile;
infile = txtboxSelectFile.Text;
string outfile;
outfile = saveFileDialog1.FileName;
string holdline;
StreamReader sr = new StreamReader(infile);
StreamWriter sw = new StreamWriter(outfile);
setText(this, "Start Holder File Conversion");
int holdercount = 0;
Int64 currentbal = 0;
Int64 oldbal = 0;
long ShareTotal = 0;
long ShareOld = 0;
while (!sr.EndOfStream)
{
holdline = sr.ReadLine();
string HID = holdline.Substring(0, 10);
string Title = holdline.Substring(10, 45).Trim();
string Surname = holdline.Substring(55, 100).Trim();
string FirstName = holdline.Substring(155, 100).Trim();
string OtherNames = holdline.Substring(255, 100).TrimEnd();
string Gender = holdline.Substring(355, 1);
string Addr1 = holdline.Substring(356, 35).TrimEnd();
string Addr2 = holdline.Substring(396, 35).TrimEnd();
string Addr3 = holdline.Substring(436, 35).TrimEnd();
string Addr4 = holdline.Substring(476, 35).TrimEnd();
string Addr5 = holdline.Substring(516, 35).TrimEnd();
string PostCode = holdline.Substring(556, 10).TrimEnd();
string Nationality = holdline.Substring(566, 25).TrimEnd();
string BranchCode = holdline.Substring(591, 6);
string AccountNumber = holdline.Substring(597, 16);
string AccountType = holdline.Substring(613, 2);
string NationalId = holdline.Substring(615, 16).TrimEnd();
string TotalShares = holdline.Substring(631, 18);
string FullName = Title + " " + FirstName + " " + Surname;
int namelen = FullName.Length;
int namerem = namelen - 35;
currentbal = Convert.ToInt64(TotalShares);
string OldBalance = holdline.Substring(649, 18);
oldbal = Convert.ToInt64(OldBalance);
setText(this, "Processing HolderID: " + HID);
if(namelen > 35)
{
sw.Write(" ".PadRight(5, ' ') + "NAADD" + " ".PadRight(7, ' ') + "C" + HID +
FullName.Substring(0, 35).PadRight(35, ' ') + FullName.Substring(35, namerem).PadRight(35, ' ') +
Addr1.PadRight(35, ' ') + Addr2.PadRight(35, ' ') + Addr3.PadRight(35, ' ') + Addr4.PadRight(35, ' ') +
Addr5.PadRight(35, ' ') + " ".PadRight(35, ' ') + PostCode.PadRight(5, ' ') + "ZAF" +
"IND" + " ".PadRight(57, ' ') + HID.PadRight(12, ' ') + " ".PadRight(13, ' '));
}
else if (namelen <= 35)
{
sw.Write(" ".PadRight(5, ' ') + "NAADD" + " ".PadRight(7, ' ') + "C" + HID + FullName.Trim().PadRight(35, ' ') +
Addr1.PadRight(35, ' ') + Addr2.PadRight(35, ' ') + Addr3.PadRight(35, ' ') + Addr4.PadRight(35, ' ') +
Addr5.PadRight(35, ' ') + " ".PadRight(70, ' ') + PostCode.PadRight(5, ' ') + "ZAF" +
"IND" + " ".PadRight(57, ' ') + HID.PadRight(12, ' ') + " ".PadRight(13, ' '));
}
if (NationalId == "" || NationalId.Length < 13)
{
sw.Write(" ".PadRight(1142, ' ') + " ".PadRight(1456, ' ') + Environment.NewLine);
}
else
{
sw.Write("Z" + NationalId.PadRight(16, ' ') + " ".PadRight(1125, ' ') + " ".PadRight(1456, ' ') + Environment.NewLine);
}
ShareTotal = ShareTotal + currentbal;
ShareOld = ShareOld + oldbal;
holdercount++;
}
sr.Close();
sw.Close();
setFilename(lblShareTotals, ShareTotal.ToString());
setFilename(lblHolderTotal, holdercount.ToString());
setFilename(lblOldBalanceTotals, ShareOld.ToString());
this.progressBar1.Invoke(new updateBar(this.finalizeProcess));
MessageBox.Show("Completed Processing Holder File", "Holder File Completed",
MessageBoxButtons.OK, MessageBoxIcon.Information);
setText(this, "Holder File Processing Completed");
}
private void convertCert()
{
string infile;
infile = txtboxSelectFile.Text;
string outfile;
outfile = saveFileDialog1.FileName;
string holdline;
Int64 currentbal = 0;
long ShareTotal = 0;
int totaltrans = 0;
StreamReader sr = new StreamReader(infile);
StreamWriter sw = new StreamWriter(outfile);
setText(this, "Start Certificate File Conversion");
while (!sr.EndOfStream)
{
holdline = sr.ReadLine();
string HID = holdline.Substring(0, 10);
string day = holdline.Substring(10, 2);
string month = holdline.Substring(13, 2);
string year = holdline.Substring(16, 4);
string cert = holdline.Substring(20, 10).Trim();
string transaction = holdline.Substring(30, 55).TrimEnd();
string shares = holdline.Substring(85, 18);
setText(this, "Processing HolderID: " + HID);
if (chkoxCreateCerts.Checked)
{
if (shares != "000000000000000000")
{
sw.WriteLine(" ".PadRight(5, ' ') + "CAPIN" + " ".PadRight(8, ' ') +
day + month + year.Substring(2, 2) + "+" + shares.Substring(4, 14) + "000000" +
"ORD" + "ZAF" + " ".PadRight(5, ' ') + "C" + HID + " ".PadRight(10, ' ') +
cert.PadLeft(12, '0') + " ".PadRight(2911, ' '));
currentbal = Convert.ToInt64(shares);
ShareTotal = ShareTotal + currentbal;
}
}
else
{
if (shares != "000000000000000000")
{
sw.WriteLine(" ".PadRight(5, ' ') + "ADJIN" + " ".PadRight(8, ' ') +
day + month + year.Substring(2, 2) + "+" + shares.Substring(4, 14) + "000000" +
"ORD" + "ZAF" + " ".PadRight(5, ' ') + "C" + HID + " ".PadRight(10, ' ') +
cert.PadLeft(12, '0') + " ".PadRight(2911, ' '));
currentbal = Convert.ToInt64(shares);
ShareTotal = ShareTotal + currentbal;
}
}
totaltrans++;
}
setFilename(lblCertificateTotals, totaltrans.ToString());
setFilename(lblCertificateBalance, ShareTotal.ToString());
sr.Close();
sw.Close();
this.progressBar1.Invoke(new updateBar(this.finalizeProcess));
MessageBox.Show("Completed Processing Certificate File", "Certificate File Completed",
MessageBoxButtons.OK, MessageBoxIcon.Information);
setText(this, "Certificate File Processing Completed");
}
private void convertDiv()
{
string infile;
infile = txtboxSelectFile.Text;
string outfile;
outfile = saveFileDialog1.FileName;
string holdline;
int totalCount = 0;
StreamReader sr = new StreamReader(infile);
StreamWriter swb = new StreamWriter(outfile);
setText(this, "Start Payment Instruction Conversion");
while (!sr.EndOfStream)
{
holdline = sr.ReadLine();
string HID = holdline.Substring(0, 10);
string BranchCode = holdline.Substring(591, 6);
string AccountNumber = holdline.Substring(597, 16);
string shares = holdline.Substring(85, 18);
string newBranch = BranchCode.Substring(0, 3) + "-" + BranchCode.Substring(3, 3);
setText(this, "Processing HolderID: " + HID);
if (BranchCode != " ")
{
if (shares != "000000000000000000")
{
swb.WriteLine(" ".PadRight(5, ' ') + "PIADD" + " ".PadRight(7, ' ') + "C" + HID + "10" +
"D" + " " + newBranch.PadRight(10, ' ') + AccountNumber.PadRight(16, ' ') + " ".PadRight(2940, ' '));
totalCount++;
}
}
}
sr.Close();
swb.Close();
setFilename(lblPaymentInstrucTotals, totalCount.ToString());
this.progressBar1.Invoke(new updateBar(this.finalizeProcess));
MessageBox.Show("Completed PIADD Conversion", "PIADD Conversion Message",
MessageBoxButtons.OK, MessageBoxIcon.Information);
setText(this, "Payment Instruction File Processing Completed");
}
private void convertDividendPayments()
{
string filePath;
string inFile;
string holdLine;
inFile = txtboxSelectFile.Text;
filePath = folderBrowserDialog1.SelectedPath;
long TotalGross = 0;
long TotalTax = 0;
long TotalNet = 0;
Int64 gross = 0;
Int64 tax = 0;
Int64 net = 0;
StreamReader sr = new StreamReader(inFile);
StreamWriter swp = new StreamWriter(Path.Combine(filePath, "er_au_xxxx_seqmpd.temp"));
setText(this, "Starting Payment File Conversions");
while (!sr.EndOfStream)
{
holdLine = sr.ReadLine();
string DividendNumber = holdLine.Substring(0, 9).TrimEnd();
string CADescription = holdLine.Substring(9, 55);
string HolderRef = holdLine.Substring(64, 10);
string PaymentType = holdLine.Substring(74, 1);
string PaymentRef = holdLine.Substring(75, 10);
string LdrBal = holdLine.Substring(85, 18);
string GrossAmount = holdLine.Substring(103, 18);
string TaxAmount = holdLine.Substring(121, 18);
string NetAmount = holdLine.Substring(139, 18);
string PaymentStatus = holdLine.Substring(157, 1);
string PaymentDate = holdLine.Substring(158, 10);
gross = Convert.ToInt64(GrossAmount);
tax = Convert.ToInt64(TaxAmount);
net = Convert.ToInt64(NetAmount);
setText(this, "Processing HolderID: " + HolderRef);
swp.Write("C" + HolderRef + "DIV" + DividendNumber + PaymentRef.Substring(2, 8).PadLeft(8, '0'));
if (PaymentType == "E")
{
swp.Write("D" + PaymentDate.Substring(0, 2) + PaymentDate.Substring(3, 2) + PaymentDate.Substring(6, 4));
}
else
{
swp.Write(PaymentType + " ".PadRight(8, ' '));
}
swp.Write(GrossAmount.Substring(7, 11) + "00" + TaxAmount.Substring(7, 11) + "00" + NetAmount.Substring(7, 11) + "00" + "S");
if (PaymentStatus == "P")
{
swp.Write("2");
}
if (PaymentStatus == "C")
{
swp.Write("3");
}
if (PaymentStatus == "U")
{
swp.Write("1");
}
if (PaymentStatus == "R")
{
swp.Write("E");
}
swp.Write("R" + " ".PadRight(24, ' ') + Environment.NewLine);
TotalGross = TotalGross + gross;
TotalTax = TotalTax + tax;
TotalNet = TotalNet + net;
}
sr.Close();
swp.Close();
setFilename(lblGrossTotals, TotalGross.ToString());
setFilename(lblTaxTotals, TotalTax.ToString());
setFilename(lblNetTotals, TotalNet.ToString());
this.progressBar1.Invoke(new updateBar(this.finalizeProcess));
MessageBox.Show("Completed Dividend Payment Processing", "Dividend Processing",
MessageBoxButtons.OK, MessageBoxIcon.Information);
setText(this, "Dividend File Processing Completed");
}
#endregion
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Without actually running it, I can't see anything obviously wrong.
Since this is the code that (doesn't) show the problem, I would be tempted to try
private void setFilename(Control lblctrl, string filename)
{
Console.WriteLine("setFileName Entered: " + lblCtrl.Name + " : " + filename);
if (this.WindowState == FormWindowState.Minimized)
return;
Console.WriteLine("setFileName PreInvokeCheck: " + lblCtrl.Name + " : " + filename);
if (lblctrl.InvokeRequired)
{
Console.WriteLine("setFileName BeginInvoke: " + lblCtrl.Name + " : " + filename);
lblctrl.BeginInvoke(new SetLabel(setFilename), new object[] { lblctrl, filename });
}
else
{
Console.WriteLine("setFileName Direct: " + lblCtrl.Name + " : " + filename);
lblctrl.Text = filename;
}
}
Or equivilent to check if it gets to the "setFileName Direct" bit when you don't get the label written. It may give a clue to what is going on (or worse, remove the problem)If Barbie is so popular, why do you have to buy her friends?
Eagles may soar, but weasels don't get sucked into jet engines.
If at first you don't succeed, destroy all evidence that you tried.
|
|
|
|
|
Thanks mate. I will give it a go and post back. It is just strange that it does it for two consecutive runs but for the third and fourth it doesn't. And it doesn't matter in what order it is run or not. Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Hi,
you are not supposed to touch a Control from a thread that did not create the Control. While your code is using several InvokeRequired/Invoke patterns, it is also not using them in several locations, see:
1.
if (this.WindowState == FormWindowState.Minimized)
is probably OK, but not documented to be OK
2.
infile = txtboxSelectFile.Text;
is probably not OK (not documented, I guess it is not OK for Controls that allow text editing)
3.
outfile = saveFileDialog1.FileName;
is most likely not OK, file dialogs are known to be critical (e.g. you need STAThread for them)
IMO you should fix all of the above.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
Hi Guys,
I'm trying to do something that looks easy but for some reason doesn't work.
I have a window service which loads .dll's that are in a different directory every couple of minutes.
I need to update those .dll's every now an than so I created an AppDomin and from there I want to load the .dll's in to the main AppDomain.
The strange thing is when I try to load a .dll I get an exception that the .dll can't be found.
Here's the source code:
AppDomainSetup AppDomSetup = new AppDomainSetup();
AppDomSetup.ApplicationName = "Service Name";
AppDomSetup.ApplicationBase = Application.StartupPath;
AppDomSetup.PrivateBinPath = "alerts";
AppDomSetup.ShadowCopyFiles = "true";
AppDomSetup.CachePath = Path.Combine(Application.StartupPath, "_cache");
m_FilesDomain = AppDomain.CreateDomain("Ksm Scheduler", null , AppDomSetup);
m_FilesDomain.Load("alert1.dll");
The 'PrivateBinPath' property points to the directory that contains the .dll's.
The 'cache path' folder IS CREATED but I get an exception. When I place the .dll's in the 'ApplicationBase' directory i.e. in the directory of the .exe file, the .dll is loaded.
Thanks for any help,
Avi
|
|
|
|
|
Don't have an answer to your immediate questions, but a couple of queries. Firstly, are all these DLLs .NET assemblies? Are you using shadowing so you don't lock the file in question so it can be altered elsewhere? When a dll is changed, do you want to unload the last one and replace it with the new one?
The bit which sounds really odd is loading the dll into the main application domain (which you can't unload). Do you not want to create a new domain, load the dlls in there and then unload it when they need to be updated?Regards,
Rob Philpott.
|
|
|
|
|
Hi Rob,
1. Rob Philpott wrote: are all these DLLs .NET assemblies?
Yes, all the DLL's .NET assemblies.
2. Rob Philpott wrote: Are you using shadowing so you don't lock the file in question so it can be altered elsewhere?
Yes I'm.
3. Rob Philpott wrote: When a dll is changed, do you want to unload the last one and replace it with the new one?
Yes, exactly.
Rob Philpott wrote: Do you not want to create a new domain, load the dlls in there and then unload it when they need to be updated?
I DO want to create a NEW domain, which I did, but for some reason the .dll aren't loaded into it. Besides, Although I don't understand how the .dll file, after is was updated, gets updated also in the new doamin without me unloading it i.e. I don't want to unload the .dll when it's changed. That is the whole purpose of shdowing, right? ( or wrong?)
One more important thing.
If I place the .dll's inside the ApplicationBase directory, the .dll's ARE loaded. When I create the new domain I give it a AppDomainSetup object with all the details. I assign to the PrivateBinPath the folder which the .dll's reside ( the folder is inside the main application folder, of course)
|
|
|
|
|
Hi
Is there any open source library C#/C++/C which will give me the delta changes of file (it can be any type)?
Thanks ...
|
|
|
|
|
Hello All,
I have an issues, i want to cancel the dropdown from being opened after validating the dropdown button clicked.
i tried with setting droppeddown property to true as suggested by one of the member from this forum in earlier post. But that is also not avoiding the dropdown from being opened.
I also tried to override the wndProc method and canceling the event it self but that is also not working . Please suggest me what i need to do so that i can avoid the dropdown after custom validation.
Thanks in Advance.
Ron
|
|
|
|
|
Hello, I think this can be done by intercepting WM_COMMAND message in "WndProc" method.
this may help
public class SuperComboBox:ComboBox
{
public class DropDownValidate:EventArgs
{
public bool AllowDropDown{get;set;}
public DropDownValidate()
{
this.AllowDropDown = true;
}
}
private const int WM_COMMAND = 0x0111;
public event EventHandler<DropDownValidate> ValidateOnDropDown;
private bool _haltDrop;
protected virtual void OnValidateDropDown(DropDownValidate e)
{
if (this.ValidateOnDropDown != null)
this.ValidateOnDropDown(this, e);
}
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_COMMAND)
{
var validationArg = new DropDownValidate();
this.OnValidateDropDown(validationArg);
_haltDrop = !validationArg.AllowDropDown;
if (_haltDrop) return;
}
base.WndProc(ref m);
}
}
Good luck
|
|
|
|
|
I have a project with many object within objects and it take a while for it to refresh when the data is changed or the form is resized. I think I have too many daisy chained events occuring.
I notice that when the Visual C# produces code it will put the "new" declarations before the SuspendLayout statement.
Object = new MediaIcon;
this.SuspendLayout();
Object.Left = 10;
.....
this.Controls.Add(Object);
this.ResumeLayout(false);
this.PerformLayout();
this is simple for a one of object, but when you have an array of them can you put the new commands within the bounds of the Suspend/Resume??
this.SuspendLayout();
Object = new MediaIcon[25];
for (int n = 0; n < 25; n++)
{
Object[n] = new MediaIcon();
Object[n].Tag = n;
.....
Object[n].Enter += new System.EventHandler(ClickButton);
this.Controls.Add(Object[n]);
}
FunctionIndex = MainForm.FunctionIndex;
this.Resize += new System.EventHandler(this.MediaBrowserClass_Resize);
this.Enter += new System.EventHandler(this.MediaBrowserClass_Enter);
this.ResumeLayout(false);
this.PerformLayout();
Could the way I am using the Suspend/Resume be the root cause of my slow refreshing?
Thank you in advance
|
|
|
|
|
Douglas Kirk wrote: I notice that when the Visual C# produces code it will put the "new" declarations before the SuspendLayout statement.
So what? The new control hasn't been added to the form's Controls collection yet, so it's not going to affect the layout of the form. it's perfectly logical to place the new outside of the suspend/resume layout block.
Douglas Kirk wrote: this is simple for a one of object, but when you have an array of them can you put the new commands within the bounds of the Suspend/Resume??
You can, but it doesn't change anything at all.
Douglas Kirk wrote: Could the way I am using the Suspend/Resume be the root cause of my slow refreshing?
No. Creating controls is a very expensive operation. If you're doing this on every refresh of the form, your creating a ton of controls every time something is dragged over your form.
|
|
|
|
|
Hi,
1.
please always show code inside PRE tags (e.g. use the "code block" widget), that makes it much more readable.
I may have overlooked something as it is now.
2.
Douglas Kirk wrote: can you put the new commands within the bounds of the Suspend/Resume??
yes. And IMO it won't make a difference.
3.
Douglas Kirk wrote: this.Controls.Add(Object[n]);
When you need to add a number of Controls, it is sometimes faster to use Controls.AddRange(), which Visual Designer also does.
4.
Not sure how long your constructors take, e.g. new MediaIcon(); that would depend on your code (not shown).
5.
Douglas Kirk wrote: it take a while for it to refresh when ... the form is resized.
That is not related to the code shown; it tells me your form probably is too complex. How many Controls are there? Do they overlap? Are there any background images? playing with transparency?
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
modified on Friday, February 12, 2010 4:44 AM
|
|
|
|
|
Hi friends
How to read news from a rss feed in c#
thanks in advance-kk.tvm-
|
|
|
|
|
|
You can use Rss Toolkit[^] or just parse it yourself as it is just an xml.
|
|
|
|
|
I have a List of rows/classes returned from a strong-typed DataSet.
I've written a lambda statement on it to return all of the rows that match the lambda.
I pass the lambda statement through a Select method on the IEnumerable List.
At the end of the select method I have the option to select the Min() method.
However, the Min statement returns a bool from this implementation.
I'm trying to get the min value of the column referenced in the lambda.
What do I need to do to get the Min to return an int based on a given int column in the result set?
|
|
|
|
|
Without seeing your code, it's impossible to say where you screwed up.
|
|
|
|
|
As far as I have been able to tell setting e.Handled to true does absolutely nothing. I'm wondering why it's even available for the KeyDown event. Could someone please tell me?
I have looked at the documentation for the textbox control and the KeyDown checks the value and sets some class variable, then the KeyPress checks that variable and sets e.Handled based on the value of the variable.
Thank you.- Kalvin
|
|
|
|
|
If you derive a class from TextBox, handle KeyDown event, and set Handled to true, that control will not pass the key press events to the underlying Win32 text box control, but it will still display the characters that the user typed. Set it to false so that the underlying Win32 text box control can do the default handling.
|
|
|
|
|
Hello,
I am using a combo box in my Datagridview C# windows forms .Net 2.0,
I am adding the combo box at design time , it seems to work fine when I use the collection and populate it.
But when I fill the datagridview with fill command and the values from the fill command does not exist in the combobox I get an error.
So I need a combo box which is editable.So that user can select values from combo box or write his own values.
After populating the combobox. The values in the combo box must change according to the row selected.
Is it possible using datagridview.
Thanks if anyone would help
|
|
|
|
|
I have two tables on a database where I need to gather information for a report. I have built a select statement and run it through an Odbc.DataReader. Stepping through the debugger, once ExecuteReader is executed the program stalls, for a period of minutes. Is there anyway to make this select statement more efficient?
The fields that start with INV are in the NINVREC table. The fields that start with MISCITEM are in the MISCITEM table.
The matching keys are MISCITEM-SERIAL-NBR and INV-MK-SERIAL-NBR.
The database is read only.
OdbcDataReader DbReader;
OdbcConnection DbConnection = new OdbcConnection("DSN=rsss");
OdbcCommand DbCommand = DbConnection.CreateCommand();
DbCommand.CommandText = "SELECT MISCITEM-DATE, MISCITEM-SERIAL-NBR, INV-MK-SERIAL-NBR, MISCITEM-MODEL-NBR, MISCITEM-CUST-ACCT-NBR, MISCITEM-EXCHANGE-MODEL-NBR, " +
" INV-SELL-PRICE,INV-ORIGINAL-COST, MISCITEM-ACTUAL-COST, MISCITEM-SALESMAN-1, MISCITEM-TICKET-NBR, MISCITEM-STORE FROM MISCITEM " +
" INNER JOIN NINVREC ON MISCITEM-SERIAL-NBR=INV-MK-SERIAL-NBR " +
" WHERE (MISCITEM-DATE >= '" + strEOMDate + "' AND MISCITEM-DATE <= '" + dtProcDate1.ToString("yyyy-MM-dd") + "') AND (INV-STATUS = 'S')" +
" GROUP BY MISCITEM-STORE, MISCITEM-DATE ORDER BY MISCITEM-STORE, MISCITEM-DATE";
try
{
DbConnection.Open();
DbReader = DbCommand.ExecuteReader();
while(DbReader.Read()) Jude
|
|
|
|
|
The query itself doesn't look like the problem.
Without really knowing the DB it's tough to say, but you might consider putting indexes on serial number columns in both tables. You might also include the MiscItem-Date in the index you create on the MiscItem table.
|
|
|
|
|
Unfortunately it is a read only database...or should I say we only have read only access for reporting purposes. Jude
|
|
|
|
|
Is MISCITEM-DATE a DateTime or a SmallDateTime, there can often be issues when querying on columns and the optimzer decides to convert a datetime in order not to lose percision. This may be even more possible because you have the line MISCITEM-DATE <= '" + dtProcDate1.ToString("yyyy-MM-dd") + "' . I would try paramaterizing your query.
DbCommand.CommandText =
"SELECT MISCITEM-DATE, MISCITEM-SERIAL-NBR, INV-MK-SERIAL-NBR, MISCITEM-MODEL-NBR, MISCITEM-CUST-ACCT-NBR, MISCITEM-EXCHANGE-MODEL-NBR, " +
" INV-SELL-PRICE,INV-ORIGINAL-COST, MISCITEM-ACTUAL-COST, MISCITEM-SALESMAN-1, MISCITEM-TICKET-NBR, MISCITEM-STORE FROM MISCITEM " +
" INNER JOIN NINVREC ON MISCITEM-SERIAL-NBR=INV-MK-SERIAL-NBR " +
" WHERE (MISCITEM-DATE >= @Date1 AND MISCITEM-DATE <= @Date2) AND (INV-STATUS = 'S')" +
" GROUP BY MISCITEM-STORE, MISCITEM-DATE ORDER BY MISCITEM-STORE, MISCITEM-DATE";
DbCommand.Paramaters.Add("@Date1", OdbcType.DateTime)
DbCommand.Paramaters["@Date1"].Value = strEOMDate;
DbCommand.Paramaters.Add("@Date2", OdbcType.DateTime)
DbCommand.Paramaters["@Date2"].Value = dtProcDate1;
try
{
DbConnection.Open();
DbReader = DbCommand.ExecuteReader();
while(DbReader.Read())
|
|
|
|
|