I am trying to make a restaurant form which stores data to a database when a user orders food. If the user comes again and enters his first and last name, the other data, like food and pickup option, should be filed automatically. For the food, I have a checkbox.
Here is the insert code:
string strCheckValue = "";
if (CheckBox1.Checked)
{
strCheckValue = strCheckValue + "," + CheckBox1.Text;
}
if (CheckBox2.Checked)
{
strCheckValue = strCheckValue + "," + CheckBox2.Text;
}
if (CheckBox3.Checked)
{
strCheckValue = strCheckValue + "," + CheckBox3.Text;
}
if (CheckBox4.Checked)
{
strCheckValue = strCheckValue + "," + CheckBox4.Text;
}
if (CheckBox5.Checked)
{
strCheckValue = strCheckValue + "," + CheckBox5.Text;
}
if (CheckBox6.Checked)
{
strCheckValue = strCheckValue + "," + CheckBox6.Text;
}
if (CheckBox7.Checked)
{
strCheckValue = strCheckValue + "," + CheckBox7.Text;
}
The strCheckValue is stored in the database and gives result like this:
,Samosa,Biryani,Naan
Now I want to select all the food items a user previously selected while ordering the food when he hits remember me button.
For that my code is:
//checkbox value display
CheckBox1.Checked = false;
CheckBox2.Checked = false;
CheckBox3.Checked = false;
CheckBox4.Checked = false;
CheckBox5.Checked = false;
CheckBox6.Checked = false;
CheckBox7.Checked = false;
string aa = dr["ctm_food"].ToString();
string[] a = aa.Split(',');
Label10.Text = a[2].ToString();
foreach (Control cc in this.Controls)
{
if(cc is CheckBox)
{
CheckBox b = (CheckBox)cc;
for(int j=1; j<a.Length; j++)
{
if (a[j].ToString() == b.Text)
{
b.Checked = true;
}
}
}
}
In label10, I can see the food that the user ordered. But the checkbox is not getting selected. What will be the right approach to complete this exercise?
I believe this.Controls does not contain your checkboxes. It will also simplify your code if you'd keep all checkbox references in one place.
CheckBox[] checkboxes = new CheckBox[] {
CheckBox1, CheckBox2, CheckBox3, CheckBox4, CheckBox5, CheckBox6, CheckBox7
};
string aa = dr["ctm_food"].ToString();
string[] a = aa.Split(',');
Label10.Text = a[2].ToString();
foreach (CheckBox b in checkboxes) {
b.Checked = false;
for (int j = 1; j < a.Length; j++) {
if (a[j].ToString() == b.Text) {
b.Checked = true;
}
}
}
Related
I have a gridview in which every row contains a checkbox for selection. That selection will be used for Approve or Reject purpose.
But issue here is If I select 2 rows from the gridview it loops atleast 4-5 times and gives me multiple emails of the same row.
Below is my code. Please suggest.
protected void btnApproveCMM_Click(object sender, EventArgs e)
{
string strDate = "";
string strMailContent = "";
DataTable dtApprove = new DataTable();
CommonDB ObjDB = new CommonDB();
try
{
bool flgCMM = false;
IPColoFields ObjIPColoFields = new App_Code.IPColoFields();
List<IPColoBilling_BKP.App_Code.UMS.UMSGroupDetails> UMSGroupDetails = (List<IPColoBilling_BKP.App_Code.UMS.UMSGroupDetails>)Session["lstUMSGroupDetails"];
Session["lstUMSGroupDetails"] = UMSGroupDetails;
string strApprove = "";
if (ViewState["CheckedCheckboxes_CMM"] != null)
{
foreach (GridViewRow row in grdDisplayCMMData.Rows)
{
if (((CheckBox)row.FindControl("chkApprRejCMM")).Checked)
{
Label SAPID_CMM = (Label)row.FindControl("lblSAP_ID_CMM");
Label ID = (Label)row.FindControl("lblID_CMM");
int Id = Convert.ToInt32(ID.Text);
ObjIPColoFields.Unique_Id = Id;
ObjIPColoFields.UMS_GRP_BY_ID = intCurrentGrpId;
ObjIPColoFields.UMS_GRP_BY_NAME = strCurrentGrp;
ObjIPColoFields.UMS_GRP_TO_ID = UMSGroupDetails[1].GroupID;
ObjIPColoFields.UMS_GRP_TO_NAME = UMSGroupDetails[1].GroupName;
ObjIPColoFields.FCA_STATUS = "1";
ObjIPColoFields.LAST_UPDATED_BY = lblUserName.Text;
strDate = DateTime.Now.ToString();
strApprove = CommonDB.Approve_IPCOLO_CMMLevel(ObjIPColoFields);
if (ObjIPColoFields.Unique_Id != null || ObjIPColoFields.Unique_Id != 0)
{
strMailContent = Get_Email_Content(ObjIPColoFields.LAST_UPDATED_BY, SAPID_CMM.Text, strIPCOLO_CMM, Convert.ToString(Id), strDate, "Approved");
SendEmail(lblUserName.Text, strMailContent, strIPCOLO_CMM);
}
}
}
}
BindCMMData();
if (flgCMM == false)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Please check atleast one row'); window.location ='IpColoDefault.aspx';", true);
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Record Approved successfully'); window.location ='IpColoDefault.aspx';", true);
}
}
catch (Exception ex)
{
string strErrorMsg = ex.Message.ToString() + " " + "StackTrace :" + ex.StackTrace.ToString();
CommonDB.WriteLog("ERROR:" + strErrorMsg, ConfigurationManager.AppSettings["IPCOLO_LOG"].ToString());
}
}
Use this code
foreach (GridViewRow row in grdDisplayCMMData.Rows)
{
if (((Checkbox)row.FindControl("chkApprRejCMM")).Checked)
{
Label SAPID_CMM = (Label)row.FindControl("lblSAP_ID_CMM");
ObjIPColoFields.Unique_Id = Id;
ObjIPColoFields.UMS_GRP_BY_ID = intCurrentGrpId;
ObjIPColoFields.UMS_GRP_BY_NAME = strCurrentGrp;
ObjIPColoFields.UMS_GRP_TO_ID = UMSGroupDetails[1].GroupID;
ObjIPColoFields.UMS_GRP_TO_NAME = UMSGroupDetails[1].GroupName;
ObjIPColoFields.FCA_STATUS = "1";
ObjIPColoFields.LAST_UPDATED_BY = lblUserName.Text;
strDate = DateTime.Now.ToString();
strApprove = CommonDB.Approve_IPCOLO_CMMLevel(ObjIPColoFields);
if (ObjIPColoFields.Unique_Id != null || ObjIPColoFields.Unique_Id != 0)
{
strMailContent = Get_Email_Content(ObjIPColoFields.LAST_UPDATED_BY, SAPID_CMM.Text, strIPCOLO_CMM, Convert.ToString(Id), strDate, "Approved");
SendEmail(lblUserName.Text, strMailContent, strIPCOLO_CMM);
}
}
}
I have a listbox in which my selected products are stored like this ...
'Product name'.padright(30) 'price' 'quantity'
listBox1.Items.Add(details.Name.PadRight(30) + details.Price.ToString() + " " + 1 );
but when I read price of a product it selects price and quantity
string currentPriceString = foundItem.Replace(details.Name.PadRight(30), "");
string quantityString = foundItem.Replace(details.Name.PadRight(33), "");
I only want price in currentPriceString and quantity in quantityString
here is complete code of this method
private void ProductButton_Click(object sender, EventArgs e)
{
Button ProductButton = sender as Button;
DataAccess dataAccess = new DataAccess();
int ProductID = Convert.ToInt32(ProductButton.Tag);
Details details = dataAccess.ReadProductDetails(ProductID);
decimal price = details.Price;
string foundItem = CheckProductInListBox(details.Name);
if (!String.IsNullOrEmpty(foundItem))
{
string currentPriceString = foundItem.Replace(details.Name.PadRight(30), "");
decimal currentPriceValue;
string quantityString = foundItem.Replace(details.Name.PadRight(33), "");
int quantiy;
MessageBox.Show(currentPriceString);
if (Decimal.TryParse(currentPriceString, out currentPriceValue))
{
quantiy = Convert.ToInt16(quantityString);
currentPriceValue += price;
quantiy++;
string newItem = details.Name.PadRight(30) + currentPriceValue.ToString() + quantiy.ToString();
int index = listBox1.Items.IndexOf(foundItem);
listBox1.Items[index] = newItem;
}
else
{
MessageBox.Show("Error");
}
}
else
{
listBox1.Items.Add(details.Name.PadRight(30) + details.Price.ToString() + " " + 1 );
}
}
private string CheckProductInListBox(string name)
{
foreach (string item in listBox1.Items)
{
if (item.Contains(name))
{
return item;
}
}
return String.Empty;
}
On replacing (foundItem.Replace(details.Name.PadRight(33), "");), you are just removing the name part from the string, so the price and quantity will be there for sure.
You should can try this code,
// suppose your found text is like this,
//foundItem = "AMIT".PadRight(30) + "200" + " " + "1";
You can get price and quantity separately like below:
string currentPriceQuantityString = foundItem.Replace(details.Name.PadRight(30), "");
//currentPriceQuantityString => "200 1"
string[] strArray = currentPriceQuantityString.Split();
string currentPriceString = strArray[0]; //currentPriceString => "200"
string quantityString = strArray[1]; //quantityString => "1"
Side note:
I guess your line:
listBox1.Items.Add(details.Name.PadRight(30) + details.Price.ToString() + " " + 1 );
..should be:
listBox1.Items.Add(details.Name.PadRight(30) + details.Price.ToString() + " " + "1" );
I have a system which inserts some recopies into a table. The thing is when I click the update button repeatedly it insert duplicate records into my database. Please help me to fix it.
Note: When I try to use the data in the table, these duplicate data does crash the program.
private void button1_Click(object sender, EventArgs e)
{
(sender as Button).Enabled = false;
string ItemCode;
string ItemDesc;
string ItID;
string InItID;
decimal EntQty;
string EntUOM;
decimal TQty;
string NewRec;
bool Prt;
TQty = 0;
foreach (DataRow RowVal in dataSetMaster.ITEM_LINE)//
{
ItemCode = RowVal["InITCode"].ToString();
ItemDesc = RowVal["InITDesc"].ToString();
ItID = RowVal["ItemID"].ToString();
InItID = RowVal["Ingredient_ItemID"].ToString();
EntQty = Convert.ToDecimal(RowVal["Entry_Qty"].ToString());
TQty = Convert.ToDecimal(RowVal["T_Qty"].ToString());
NewRec = RowVal["NewRec"].ToString();
EntUOM = RowVal["Entry_UOM"].ToString();
Prt = Convert.ToBoolean(RowVal["Print"].ToString());
// MessageBox.Show("Items in the grid " + ItemCode + " == " + ItemDesc+" /"+Convert.ToString(EntQty)+" / "+Convert.ToString(TQty));
string ComdTextItemCode;
string ComdTextItemCodeInsert;
string Itcode;
Itcode = TextBoxCode.Text.Trim();
string X1;
X1 = "TEST";
sqlConnection1.Open();
if (NewRec == "True")
{
Guid newGuid;
Guid newGuid2;
if (Guid.TryParseExact(ItID, "D", out newGuid))
{
Console.WriteLine("Converted {0} to a Guid", ItID);
}
else
{
Console.WriteLine("Unable to convert {0} to a Guid",
ItID);
}
if (Guid.TryParseExact(InItID, "D", out newGuid2))
{
Console.WriteLine("Converted {0} to a Guid", InItID);
}
else
{
Console.WriteLine("Unable to convert {0} to a Guid",
InItID);
}
// MessageBox.Show("Test");
Guid ItmID = newGuid;
Guid IngItmID = newGuid2;
Guid GuItem_LineID = Guid.NewGuid();
//INSERT INTO ITEM_LINE (Item_LineID,ItemID,Ingredient_ItemID,Entry_Qty,Entry_UOM) VALUES (convert(uniqueidentifier, #Item_LineID),convert(uniqueidentifier, #ItemID),convert(uniqueidentifier, #Ingredient_ItemID),#Entry_Qty,#Entry_UOM)
ComdTextItemCodeInsert = "INSERT INTO ITEM_LINE (Item_LineID,ItemID,Ingredient_ItemID,Entry_Qty,Entry_UOM,[Print],T_Qty)" +
"VALUES (convert(uniqueidentifier, #Item_LineID),convert(uniqueidentifier, #ItemID),convert(uniqueidentifier, #Ingredient_ItemID),#Entry_Qty,#Entry_UOM,#Print,#T_Qty)";
sqlInsertItemDtl.CommandText = ComdTextItemCodeInsert;
sqlInsertItemDtl.Parameters["#Item_LineID"].Value = GuItem_LineID;
sqlInsertItemDtl.Parameters["#ItemID"].Value = ItmID; // roleID;
sqlInsertItemDtl.Parameters["#Ingredient_ItemID"].Value = IngItmID;
sqlInsertItemDtl.Parameters["#Entry_Qty"].Value = EntQty;
sqlInsertItemDtl.Parameters["#Entry_UOM"].Value = EntUOM;
sqlInsertItemDtl.Parameters["#Print"].Value = Prt;
sqlInsertItemDtl.Parameters["#T_Qty"].Value = TQty;
sqlDADetail.InsertCommand.ExecuteNonQuery();
}
else
{
ComdTextItemCode = "UPDATE ITEM_LINE SET ITEM_LINE.T_Qty=" + #TQty +",ITEM_LINE.[Print]='"+ #Prt +
"' WHERE ITEM_LINE.ItemID=convert(uniqueidentifier,'" + ItID + "') AND ITEM_LINE.Ingredient_ItemID=convert(uniqueidentifier,'" + InItID + "')";
sqlUpdateDtl.CommandText = ComdTextItemCode;
sqlDADetail.UpdateCommand.ExecuteNonQuery();
}
sqlConnection1.Close();
}
MessageBox.Show("Material Master updated.");
}
how to recognize new line c# while uploading word documents..? i have to give next line as a new word in word document here what is happening means if i add three or more words in .doc in separate line its taking as one word i want to separate the words but if i give a space after a word it is taking as expected without giving space if i start a new word in new line its taking as one word
money
power
cash
moneypowercash
like this iam getting here if i give space after these words its getting as expected
how to resolve this issue here i will give my code to generating this keyword
protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
if (cmbDepartment.SelectedValue != "0" && cmbDocumentType.SelectedValue != "0")
{
TodayDate = DateTime.Today.ToString("yyyy-MM-dd");
TempFolder = System.Configuration.ConfigurationManager.AppSettings["TempWorkFolder"];
TextReader reader = new FilterReader(TempFolder + Session["EncyptImgName"]);
StringBuilder Keywords = new StringBuilder();
using (reader)
{
Keywords = Keywords.Append(reader.ReadToEnd());
}
//remove common words
string[] removablewords = { ":", ".", "~"};
foreach (string st in removablewords)
{
Keywords.Replace(st, " ");
}
//Reomve unwated spaces
while (Keywords.ToString().Contains(" "))
{
Keywords.Replace(" ", " ");
}
string str = Keywords.ToString();
Keywords.Clear();
Keywords.Append("<words><s>" + str.Replace(" ", "</s><s>") + "</s></words>");
string xml = Keywords.ToString();
XElement items = XElement.Parse(xml);
var groups = from t in items.Descendants("s")
group t by t.Value.ToLower() into g
select new KeyFrequency(g.Key, g.Count());
groups = groups.OrderByDescending(g => g.Frequency).Take(15);
keyvalues = new List<string>();
foreach (KeyFrequency g in groups)
{
keyvalues.Add(g.Key);
}
for (key = 0; key < keyvalues.Count && key < 10; key++)
{
Button btn = (Button)pnlKeywords.FindControl("Button" + Convert.ToString(key + 1));
btn.Visible = true;
btn.Text = keyvalues[key];
btn.CommandArgument = keyvalues[key];
}
if (key < 10)
{
for (key = key; key < 10; key++)
{
Button btn = (Button)pnlKeywords.FindControl("Button" + Convert.ToString(key + 1));
btn.Visible = false;
}
}
else
{
AsyncFileUpload1.BackColor = System.Drawing.Color.Red;
}
}
}
catch (Exception ex)
{
Button1.Text = "Keywords Not Available for This Document";
Button1.CommandArgument = null;
Button2.Visible = false;
Button3.Visible = false;
Button4.Visible = false;
Button5.Visible = false;
Button6.Visible = false;
Button7.Visible = false;
Button8.Visible = false;
Button9.Visible = false;
Button10.Visible = false;
}
}
For each new line, try replacing \n with "</w:t><w:br/><w:t>". It worked for me.
string.Replace("\n", "</w:t><w:br/><w:t>")
Here is my case: i can retrieved the data from the database, but when i run the program and filled up the Quantity column (on the third line), the error says: index was out of range. Anyone know why is this happen? (When i tried to fill the Quantity column (on third line), the error appeared) <-- shown in the picture below.
Here is the images of my program:
Here is the images of where the error is pointed:
Here is the full code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Windows.Forms;
namespace Sell_System
{
public partial class Form2 : Form
{
string connectionString = (#"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\Archives\Projects\Program\Sell System\Sell System\App_Data\db1.accdb;Persist Security Info=False;");
private Form1 firstForm;
private List<List<TextBox>> textBoxCodeContainer = new List<List<TextBox>>();
private List<List<TextBox>> textBoxQuantityContainer = new List<List<TextBox>>();
private List<List<TextBox>> textBoxDescContainer = new List<List<TextBox>>();
private List<List<TextBox>> textBoxSubTotalContainer = new List<List<TextBox>>();
private List<List<TextBox>> textBoxTotalContainer = new List<List<TextBox>>();
private List<List<TextBox>> textBoxAllTotalContainer = new List<List<TextBox>>();
public Form2()
{
InitializeComponent();
}
public Form2(Form1 firstForm)
: this()
{
this.firstForm = firstForm;
}
private void Form2_Load(object sender, EventArgs e)
{
UpdateTextPosition();
OleDbDataReader dReader;
OleDbConnection conn = new OleDbConnection(connectionString);
conn.Open();
OleDbCommand cmd = new OleDbCommand("SELECT [Code] FROM [Data]", conn);
dReader = cmd.ExecuteReader();
AutoCompleteStringCollection codesCollection = new AutoCompleteStringCollection();
while (dReader.Read())
{
string numString = dReader[0].ToString().PadLeft(4, '0');
codesCollection.Add(numString);
}
dReader.Close();
conn.Close();
if (firstForm.comboBox1.SelectedIndex == 0)
{
label1.Text = "Code:";
label1.Location = new Point(60, 125);
label2.Text = "Welcome to the Selling System.";
label2.Location = new Point(600, 0);
label3.Text = "Quantity:";
label3.Location = new Point(155, 125);
label4.Text = "Description:";
label4.Location = new Point(580, 125);
label5.Text = "Sub Total on Rp:";
label5.Location = new Point(1020, 125);
label6.Text = "Total on Rp:";
label6.Location = new Point(1210, 125);
label7.Text = "Total on Rp:";
label7.Location = new Point(1080, 580);
}
else if (firstForm.comboBox1.SelectedIndex == 1)
{
label1.Text = "Kode:";
label1.Location = new Point(60, 125);
label2.Text = "Selamat datang di Selling System.";
label2.Location = new Point(600, 0);
label3.Text = "Banyaknya:";
label3.Location = new Point(145, 125);
label4.Text = "Keterangan:";
label4.Location = new Point(580, 125);
label5.Text = "Sub Total di Rp:";
label5.Location = new Point(1020, 125);
label6.Text = "Total di Rp:";
label6.Location = new Point(1210, 125);
label7.Text = "Total di Rp:";
label7.Location = new Point(1080, 580);
}
//****TextBox for Code****
for (int y = 0; y <= 16; y++)
{
textBoxCodeContainer.Add(new List<TextBox>());
textBoxCodeContainer[0].Add(new TextBox());
textBoxCodeContainer[0][y].Size = new Size(100, 50);
textBoxCodeContainer[0][y].Location = new Point(25, 150 + (y * 25));
textBoxCodeContainer[0][y].TextChanged += new System.EventHandler(this.textBox_TextChanged);
textBoxCodeContainer[0][y].AutoCompleteMode = AutoCompleteMode.Suggest;
textBoxCodeContainer[0][y].AutoCompleteSource = AutoCompleteSource.CustomSource;
textBoxCodeContainer[0][y].AutoCompleteCustomSource = codesCollection;
Controls.Add(textBoxCodeContainer[0][y]);
}
//****TextBox for Quantity****
for (int y = 0; y <= 16; y++)
{
textBoxQuantityContainer.Add(new List<TextBox>());
textBoxQuantityContainer[0].Add(new TextBox());
textBoxQuantityContainer[0][y].Size = new Size(100, 50);
textBoxQuantityContainer[0][y].Location = new Point(125, 150 + (y * 25));
textBoxQuantityContainer[0][y].TextChanged += new System.EventHandler(this.textBox_TextChanged);
Controls.Add(textBoxQuantityContainer[0][y]);
}
//****TextBox for Description****
for (int y = 0; y <= 16; y++)
{
textBoxDescContainer.Add(new List<TextBox>());
textBoxDescContainer[0].Add(new TextBox());
textBoxDescContainer[0][y].Size = new Size(750, 50);
textBoxDescContainer[0][y].Location = new Point(225, 150 + (y * 25));
Controls.Add(textBoxDescContainer[0][y]);
}
//****TextBox for Sub Total****
for (int y = 0; y <= 16; y++)
{
textBoxSubTotalContainer.Add(new List<TextBox>());
textBoxSubTotalContainer[0].Add(new TextBox());
textBoxSubTotalContainer[0][y].Size = new Size(175, 50);
textBoxSubTotalContainer[0][y].Location = new Point(975, 150 + (y * 25));
Controls.Add(textBoxSubTotalContainer[0][y]);
}
//****TextBox for Total****
for (int y = 0; y <= 16; y++)
{
textBoxTotalContainer.Add(new List<TextBox>());
textBoxTotalContainer[0].Add(new TextBox());
textBoxTotalContainer[0][y].Size = new Size(175, 50);
textBoxTotalContainer[0][y].Location = new Point(1150, 150 + (y * 25));
textBoxTotalContainer[0][y].TextChanged += new System.EventHandler(this.textBox_TextChanged);
Controls.Add(textBoxTotalContainer[0][y]);
}
//****TextBox for Total All****
textBoxAllTotalContainer.Size = new Size(175, 50);
textBoxAllTotalContainer.Location = new Point(1150, 575);
textBoxAllTotalContainer.TextChanged += new System.EventHandler(this.textBox_TextChanged);
Controls.Add(textBoxAllTotalContainer);
}
private void UpdateTextPosition()
{
Graphics g = this.CreateGraphics();
Double startingPoint = (this.Width / 2) - (g.MeasureString(this.Text.Trim(), this.Font).Width / 2);
Double widthOfASpace = g.MeasureString(" ", this.Font).Width;
String tmp = " ";
Double tmpWidth = 0;
while ((tmpWidth + widthOfASpace) < startingPoint)
{
tmp += " ";
tmpWidth += widthOfASpace;
}
this.Text = tmp + this.Text.Trim();
}
private void UpdateDatas()
{
int codeValue = 0;
int index = 0;
string query = "SELECT [Description], [Price] FROM [Data] WHERE [Code] IN (";
OleDbDataReader dReader;
OleDbConnection conn = new OleDbConnection(connectionString);
conn.Open();
if (int.TryParse(this.textBoxCodeContainer[0][0].Text, out codeValue))
{
query = query + codeValue.ToString();
}
if (int.TryParse(this.textBoxCodeContainer[0][1].Text, out codeValue))
{
query = query + "," + codeValue.ToString();
}
if (int.TryParse(this.textBoxCodeContainer[0][2].Text, out codeValue))
{
query = query + "," + codeValue.ToString();
}
if (int.TryParse(this.textBoxCodeContainer[0][3].Text, out codeValue))
{
query = query + "," + codeValue.ToString();
}
if (int.TryParse(this.textBoxCodeContainer[0][4].Text, out codeValue))
{
query = query + "," + codeValue.ToString();
}
if (int.TryParse(this.textBoxCodeContainer[0][5].Text, out codeValue))
{
query = query + "," + codeValue.ToString();
}
if (int.TryParse(this.textBoxCodeContainer[0][6].Text, out codeValue))
{
query = query + "," + codeValue.ToString();
}
if (int.TryParse(this.textBoxCodeContainer[0][7].Text, out codeValue))
{
query = query + "," + codeValue.ToString();
}
if (int.TryParse(this.textBoxCodeContainer[0][8].Text, out codeValue))
{
query = query + "," + codeValue.ToString();
}
if (int.TryParse(this.textBoxCodeContainer[0][9].Text, out codeValue))
{
query = query + "," + codeValue.ToString();
}
if (int.TryParse(this.textBoxCodeContainer[0][10].Text, out codeValue))
{
query = query + "," + codeValue.ToString();
}
if (int.TryParse(this.textBoxCodeContainer[0][11].Text, out codeValue))
{
query = query + "," + codeValue.ToString();
}
if (int.TryParse(this.textBoxCodeContainer[0][12].Text, out codeValue))
{
query = query + "," + codeValue.ToString();
}
if (int.TryParse(this.textBoxCodeContainer[0][13].Text, out codeValue))
{
query = query + "," + codeValue.ToString();
}
if (int.TryParse(this.textBoxCodeContainer[0][14].Text, out codeValue))
{
query = query + "," + codeValue.ToString();
}
if (int.TryParse(this.textBoxCodeContainer[0][15].Text, out codeValue))
{
query = query + "," + codeValue.ToString();
}
if (int.TryParse(this.textBoxCodeContainer[0][16].Text, out codeValue))
{
query = query + "," + codeValue.ToString();
}
query = query + ")";
OleDbCommand cmd = new OleDbCommand(query, conn);
cmd.Parameters.Add("Code", System.Data.OleDb.OleDbType.Integer);
dReader = cmd.ExecuteReader();
while (dReader.Read())
{
if (textBoxCodeContainer[0][index].TextLength != 0)
{
this.textBoxDescContainer[0][index].Text = dReader["Description"].ToString();
this.textBoxSubTotalContainer[0][index].Text = dReader["Price"].ToString();
}
index += 1;
}
dReader.Close();
conn.Close();
}
private void UpdatePrice()
{
if (textBoxQuantityContainer[0][0].Text == "")
{
textBoxTotalContainer[0][0].Text = "";
}
else if (textBoxQuantityContainer[0][0].Text == "1")
{
textBoxTotalContainer[0][0].Text = textBoxSubTotalContainer[0][0].Text;
textBoxAllTotalContainer.Text = textBoxTotalContainer[0][0].Text;
}
if (textBoxQuantityContainer[0][1].Text == "")
{
textBoxTotalContainer[0][1].Text = "";
}
else if (textBoxQuantityContainer[0][1].Text == "1")
{
textBoxTotalContainer[0][1].Text = textBoxSubTotalContainer[0][1].Text;
textBoxAllTotalContainer.Text = textBoxTotalContainer[0][1].Text;
}
if (textBoxQuantityContainer[0][2].Text == "")
{
textBoxTotalContainer[0][2].Text = "";
}
else if (textBoxQuantityContainer[0][2].Text == "1")
{
textBoxTotalContainer[0][2].Text = textBoxSubTotalContainer[0][2].Text;
textBoxAllTotalContainer.Text = textBoxTotalContainer[0][2].Text;
}
if (textBoxQuantityContainer[0][3].Text == "")
{
textBoxTotalContainer[0][3].Text = "";
}
else if (textBoxQuantityContainer[0][3].Text == "1")
{
textBoxTotalContainer[0][3].Text = textBoxSubTotalContainer[0][3].Text;
textBoxAllTotalContainer.Text = textBoxTotalContainer[0][3].Text;
}
if (textBoxQuantityContainer[0][4].Text == "")
{
textBoxTotalContainer[0][4].Text = "";
}
else if (textBoxQuantityContainer[0][4].Text == "1")
{
textBoxTotalContainer[0][4].Text = textBoxSubTotalContainer[0][4].Text;
textBoxAllTotalContainer.Text = textBoxTotalContainer[0][4].Text;
}
if (textBoxQuantityContainer[0][5].Text == "")
{
textBoxTotalContainer[0][5].Text = "";
}
else if (textBoxQuantityContainer[0][5].Text == "1")
{
textBoxTotalContainer[0][5].Text = textBoxSubTotalContainer[0][5].Text;
textBoxAllTotalContainer.Text = textBoxTotalContainer[0][5].Text;
}
if (textBoxQuantityContainer[0][6].Text == "")
{
textBoxTotalContainer[0][6].Text = "";
}
else if (textBoxQuantityContainer[0][6].Text == "1")
{
textBoxTotalContainer[0][6].Text = textBoxSubTotalContainer[0][6].Text;
textBoxAllTotalContainer.Text = textBoxTotalContainer[0][6].Text;
}
if (textBoxQuantityContainer[0][7].Text == "")
{
textBoxTotalContainer[0][7].Text = "";
}
else if (textBoxQuantityContainer[0][7].Text == "1")
{
textBoxTotalContainer[0][7].Text = textBoxSubTotalContainer[0][7].Text;
textBoxAllTotalContainer.Text = textBoxTotalContainer[0][7].Text;
}
if (textBoxQuantityContainer[0][8].Text == "")
{
textBoxTotalContainer[0][8].Text = "";
}
else if (textBoxQuantityContainer[0][8].Text == "1")
{
textBoxTotalContainer[0][8].Text = textBoxSubTotalContainer[0][8].Text;
textBoxAllTotalContainer.Text = textBoxTotalContainer[0][8].Text;
}
if (textBoxQuantityContainer[0][9].Text == "")
{
textBoxTotalContainer[0][9].Text = "";
}
else if (textBoxQuantityContainer[0][9].Text == "1")
{
textBoxTotalContainer[0][9].Text = textBoxSubTotalContainer[0][9].Text;
textBoxAllTotalContainer.Text = textBoxTotalContainer[0][9].Text;
}
if (textBoxQuantityContainer[0][10].Text == "")
{
textBoxTotalContainer[0][10].Text = "";
}
else if (textBoxQuantityContainer[0][10].Text == "1")
{
textBoxTotalContainer[0][10].Text = textBoxSubTotalContainer[0][10].Text;
textBoxAllTotalContainer.Text = textBoxTotalContainer[0][10].Text;
}
if (textBoxQuantityContainer[0][11].Text == "")
{
textBoxTotalContainer[0][11].Text = "";
}
else if (textBoxQuantityContainer[0][11].Text == "1")
{
textBoxTotalContainer[0][11].Text = textBoxSubTotalContainer[0][11].Text;
textBoxAllTotalContainer.Text = textBoxTotalContainer[0][11].Text;
}
if (textBoxQuantityContainer[0][12].Text == "")
{
textBoxTotalContainer[0][12].Text = "";
}
else if (textBoxQuantityContainer[0][12].Text == "1")
{
textBoxTotalContainer[0][12].Text = textBoxSubTotalContainer[0][12].Text;
textBoxAllTotalContainer.Text = textBoxTotalContainer[0][12].Text;
}
if (textBoxQuantityContainer[0][13].Text == "")
{
textBoxTotalContainer[0][13].Text = "";
}
else if (textBoxQuantityContainer[0][13].Text == "1")
{
textBoxTotalContainer[0][13].Text = textBoxSubTotalContainer[0][13].Text;
textBoxAllTotalContainer.Text = textBoxTotalContainer[0][13].Text;
}
if (textBoxQuantityContainer[0][14].Text == "")
{
textBoxTotalContainer[0][14].Text = "";
}
else if (textBoxQuantityContainer[0][14].Text == "1")
{
textBoxTotalContainer[0][14].Text = textBoxSubTotalContainer[0][14].Text;
textBoxAllTotalContainer.Text = textBoxTotalContainer[0][14].Text;
}
if (textBoxQuantityContainer[0][15].Text == "")
{
textBoxTotalContainer[0][15].Text = "";
}
else if (textBoxQuantityContainer[0][15].Text == "1")
{
textBoxTotalContainer[0][15].Text = textBoxSubTotalContainer[0][15].Text;
textBoxAllTotalContainer.Text = textBoxTotalContainer[0][15].Text;
}
if (textBoxQuantityContainer[0][16].Text == "")
{
textBoxTotalContainer[0][16].Text = "";
}
else if (textBoxQuantityContainer[0][16].Text == "1")
{
textBoxTotalContainer[0][16].Text = textBoxSubTotalContainer[0][16].Text;
textBoxAllTotalContainer.Text = textBoxTotalContainer[0][16].Text;
}
}
private void textBox_TextChanged(object sender, EventArgs e)
{
UpdateDatas();
UpdatePrice();
}
}
}
Here is my problem: "i am confuse, when i try assign a value for "textBoxAllTotalContainer.Text = textBoxTotalContainer[0][0].Text", the code is working. but, when i tried "textBoxAllTotalContainer.Text = textBoxTotalContainer[0][one(1)]", the screen stucked in there (I have to stop debugging from Visual Studio)"
textBoxTotalContainer contains 17 textboxes, therefore, i used [0][0] to [0][16], and textBoxAllTotalContainer contains 1 textbox, so i just used textBoxAllTotalContainer.Text
Note: "Keyword (one), it suppose to be "1" <-- number, i wrote (one), because when i tried changed the [0][(Here supposed to be "1")], the text automatically changed to linked image"
Issue: **"When i tried the code
else if (textBoxQuantityContainer[0][0].Text == "1")
{
textBoxTotalContainer[0][0].Text = textBoxSubTotalContainer[0][0].Text;
textBoxAllTotalContainer.Text = textBoxTotalContainer[0][0].Text;
}
the textbox for alltotalcontainer is on (Total on Rp, the textbox is on after words) in the image shown above, the textboxes for subtotal is on (Sub Total on Rp), the textboxes for totalcontainer is on (Total on Rp, the textboxes are on below words), the textboxes for quantitycontainer is on (Quantity). In code above, shown that textbox 1 on textboxtotalcontainer are same with the textbox 1 on subtotalcontainer, and alltotalcontainer is same with totalcontainer.**
But, below code it not working, and the screen stucked on there (the mouse dissappear and i cant do anything, unless i press SHIFT + F5 on Visual Studio):
else if (textBoxQuantityContainer[0][1].Text == "1")
{
textBoxTotalContainer[0][1].Text = textBoxSubTotalContainer[0][1].Text;
textBoxAllTotalContainer.Text = textBoxTotalContainer[0][1].Text;
}
Thanks
You get that error when you try to access an element in a collection that doesn't exist.
For example, if you have a list of strings...
List<string> myList = new List {"one", "two", "three"};
...and try to access the fourth element with myList[3], you'll get that error.
Either textBoxAllTotalContainer[0][2] doesn't exist, or textBoxTotalContainer[0][2]. Can't tell from the error in your picture. Place a breakpoint on that line and check both objects.
Looks like your stop condition is wrong.
you have the following code for initializing textBoxAllTotalContainer:
//****TextBox for Total All****
for (int y = 0; y <= 1; y++)
{
textBoxAllTotalContainer.Add(new List<TextBox>());
textBoxAllTotalContainer[0].Add(new TextBox());
textBoxAllTotalContainer[0][y].Size = new Size(175, 50);
textBoxAllTotalContainer[0][y].Location = new Point(1150, 575);
textBoxAllTotalContainer[0][y].TextChanged += new System.EventHandler(this.textBox_TextChanged);
Controls.Add(textBoxAllTotalContainer[0][y]);
}
Note that the loop is itterating only twice.
Therefore textBoxAllTotalContainer[0][0] and textBoxAllTotalContainer[0][1] are created.
but when you try to access textBoxAllTotalContainer[0][2] you hit the exception because the location is really out of the list's range as the exception specifies.