/// <summary> /// Create a static list from the item grid /// </summary> public void CreateStaticList(string UserID, string ListName, GridView ItemsGrid) { string ItemNo; DateTime ListDate = DateTime.Now; //try //{ foreach (GridViewRow row in ItemsGrid.Rows) { ItemNo = row.Cells[0].Text; string SqlStatement = "insert into CPRStaticItemLists "; SqlStatement += " (ItemNo, ListType, ListDate, UserID, EntryID, EntryDt) values ("; SqlStatement += " '" + ItemNo.Substring(0, 14) + "', "; SqlStatement += " '" + ListName + "', "; SqlStatement += " convert(datetime,'" + ListDate.ToString() + "'), "; SqlStatement += " '" + UserID.TrimEnd() + "', "; SqlStatement += " '" + UserID.TrimEnd() + "', "; SqlStatement += " convert(datetime,'" + ListDate.ToString() + "') ) "; SqlHelper.ExecuteNonQuery(connectionString, CommandType.Text, SqlStatement); } //} //catch (Exception ex) //{ //} }
/// <summary> /// Load items in ReportItemsGrid into CPRCurItems for report /// </summary> public void LoadCurrentItems(string UserID, GridView ItemsGrid) { string ItemNo; DateTime ListDate = DateTime.Today; // clear out Items for user string SqlStatement = "delete from CPRCurItems "; SqlStatement += " where UserID = '" + UserID.TrimEnd() + "' "; SqlHelper.ExecuteNonQuery(connectionString, CommandType.Text, SqlStatement); //try //{ foreach (GridViewRow row in ItemsGrid.Rows) { ItemNo = row.Cells[0].Text; SqlStatement = "insert into CPRCurItems "; SqlStatement += " (ItemNo, UserID, EntryID, EntryDt) values ("; SqlStatement += " '" + ItemNo.Substring(0, 14) + "', "; SqlStatement += " '" + UserID.TrimEnd() + "', "; SqlStatement += " '" + UserID.TrimEnd() + "', "; SqlStatement += " convert(datetime,'" + ListDate.ToString() + "') ) "; SqlHelper.ExecuteNonQuery(connectionString, CommandType.Text, SqlStatement); } //} //catch (Exception ex) //{ //} }
private void button4_Click(object sender, EventArgs e) { SqlConnection Connection = new SqlConnection(Con.ConnectionString()); if (Cat.SelectedIndex == -1) { toolStripStatusLabel1.Text = "Please Select a Catagory"; Cat.Focus(); } else if (SubCat.SelectedIndex == -1) { toolStripStatusLabel1.Text = "Please Select Sub Catagory "; SubCat.Focus(); } else if (ItemNo.Text.ToString().Trim(' ') == "") { toolStripStatusLabel1.Text = "Please Enter Item No"; ItemNo.Text = ""; ItemNo.Focus(); } else if (Units.Text.ToString().Trim(' ') == "") { toolStripStatusLabel1.Text = "Please Enter Units"; Units.Text = ""; Units.Focus(); } else if (StockPrice.Text.ToString().Trim(' ') == "") { toolStripStatusLabel1.Text = "Please Enter Stock Price"; StockPrice.Text = ""; StockPrice.Focus(); } else if (SalesPrice.Text.ToString().Trim(' ') == "") { toolStripStatusLabel1.Text = "Please Enter Sales Price"; SalesPrice.Text = ""; SalesPrice.Focus(); } else if (UnitsInStock.Text.ToString().Trim(' ') == "") { toolStripStatusLabel1.Text = "Please Enter how many Units have in Stock"; UnitsInStock.Text = ""; UnitsInStock.Focus(); } else if (ROL.Text.ToString().Trim(' ') == "") { toolStripStatusLabel1.Text = "Please Enter ReOrder Level"; ROL.Text = ""; ROL.Focus(); } else if (Convert.ToDecimal(Profit.Text) < 0) { MessageBox.Show("Your Stock price larger than Sales Price" + Environment.NewLine + "Enter Correct Value or Change the Discount Rate", "Data Entry Problem", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);; SalesPrice.Focus(); } else { try { Connection.Open(); if (button4.Text.ToString() == "Save") { SqlCommand INSERT = new SqlCommand("INSERT INTO ItemList(ItemNo,Descriptions,Units,Catagory,SubCatagory,StockPrice,SalesPrice,Discount,UnitsInStock,ROL) VALUES(@ItemNo,@Descriptions,@Units,@Catagory,@SubCatagory,@StockPrice,@SalesPrice,@Discount,@UnitsInStock,@ROL)", Connection); INSERT.Parameters.AddWithValue("@ItemNo", ItemNo.Text.ToString()); INSERT.Parameters.AddWithValue("@Descriptions", Des.Text.ToString()); INSERT.Parameters.AddWithValue("@Units", Units.Text.ToString()); INSERT.Parameters.AddWithValue("@Catagory", Cat.SelectedItem.ToString()); INSERT.Parameters.AddWithValue("@SubCatagory", SubCat.SelectedItem.ToString()); INSERT.Parameters.AddWithValue("@StockPrice", Convert.ToDecimal(StockPrice.Text)); INSERT.Parameters.AddWithValue("@SalesPrice", Convert.ToDecimal(SalesPrice.Text)); INSERT.Parameters.AddWithValue("@Discount", Convert.ToInt16(Discount.Text)); INSERT.Parameters.AddWithValue("@UnitsInStock", Convert.ToInt64(UnitsInStock.Text)); INSERT.Parameters.AddWithValue("@ROL", Convert.ToInt32(ROL.Text)); if (INSERT.ExecuteNonQuery() == 1) { toolStripStatusLabel1.Text = "Sucessfully Saved"; ItemNo2.Items.Add(ItemNo.Text.ToString()); ItemNo.Text = ""; Des.Text = ""; Units.Text = ""; StockPrice.Clear(); SalesPrice.Text = ""; Discount.Text = ""; UnitsInStock.Text = ""; ROL.Text = ""; Profit.Text = "0.0"; ItemNo.Focus(); } else { toolStripStatusLabel1.Text = "Error Item Not Saved"; } } else { SqlCommand UPDES = new SqlCommand("UPDATE ItemList SET Descriptions=@Descriptions WHERE ItemNo=@ItemNo", Connection); UPDES.Parameters.AddWithValue("@Descriptions", Des.Text.ToString()); UPDES.Parameters.AddWithValue("@ItemNo", ItemNo.Text.ToString()); SqlCommand UPUNIT = new SqlCommand("UPDATE ItemList SET Units=@Units WHERE ItemNo=@ItemNo", Connection); UPUNIT.Parameters.AddWithValue("@Units", Units.Text.ToString()); UPUNIT.Parameters.AddWithValue("@ItemNo", ItemNo.Text.ToString()); SqlCommand UPCAT = new SqlCommand("UPDATE ItemList SET Catagory=@Catagory WHERE ItemNo=@ItemNo", Connection); UPCAT.Parameters.AddWithValue("@Catagory", Cat.SelectedItem.ToString()); UPCAT.Parameters.AddWithValue("@ItemNo", ItemNo.Text.ToString()); SqlCommand UPSUBCAT = new SqlCommand("UPDATE ItemList SET SubCatagory=@SubCatagory WHERE ItemNo=@ItemNo", Connection); UPSUBCAT.Parameters.AddWithValue("@SubCatagory", SubCat.SelectedItem.ToString()); UPSUBCAT.Parameters.AddWithValue("@ItemNo", ItemNo.Text.ToString()); SqlCommand UPSTOCKPRICE = new SqlCommand("UPDATE ItemList SET StockPrice=@StockPrice WHERE ItemNo=@ItemNo", Connection); UPSTOCKPRICE.Parameters.AddWithValue("@StockPrice", Convert.ToDecimal(StockPrice.Text)); UPSTOCKPRICE.Parameters.AddWithValue("@ItemNo", ItemNo.Text.ToString()); SqlCommand UPSALESPRICE = new SqlCommand("UPDATE ItemList SET SalesPrice=@SalesPrice WHERE ItemNo=@ItemNo", Connection); UPSALESPRICE.Parameters.AddWithValue("@SalesPrice", Convert.ToDecimal(SalesPrice.Text)); UPSALESPRICE.Parameters.AddWithValue("@ItemNo", ItemNo.Text.ToString()); SqlCommand UPDISCOUNT = new SqlCommand("UPDATE ItemList SET Discount=@Discount WHERE ItemNo=@ItemNo", Connection); UPDISCOUNT.Parameters.AddWithValue("@Discount", Convert.ToInt16(Discount.Text)); UPDISCOUNT.Parameters.AddWithValue("@ItemNo", ItemNo.Text.ToString()); SqlCommand UPUNITSINSTOCK = new SqlCommand("UPDATE ItemList SET UnitsInStock=@UnitsInStock WHERE ItemNo=@ItemNo", Connection); UPUNITSINSTOCK.Parameters.AddWithValue("@UnitsInStock", Convert.ToInt64(UnitsInStock.Text)); UPUNITSINSTOCK.Parameters.AddWithValue("@ItemNo", ItemNo.Text.ToString()); SqlCommand UPROL = new SqlCommand("UPDATE ItemList SET ROL=@ROL WHERE ItemNo=@ItemNo", Connection); UPROL.Parameters.AddWithValue("@ROL", Convert.ToInt32(ROL.Text)); UPROL.Parameters.AddWithValue("@ItemNo", ItemNo.Text.ToString()); int a, b, c, d, ei, f, g, h, i; a = UPDES.ExecuteNonQuery(); b = UPUNIT.ExecuteNonQuery(); c = UPSTOCKPRICE.ExecuteNonQuery(); d = UPSALESPRICE.ExecuteNonQuery(); ei = UPDISCOUNT.ExecuteNonQuery(); f = UPUNITSINSTOCK.ExecuteNonQuery(); g = UPROL.ExecuteNonQuery(); h = UPCAT.ExecuteNonQuery(); i = UPSUBCAT.ExecuteNonQuery(); if ((a == 1) && (b == 1) && (c == 1) && (d == 1) && (ei == 1) && (f == 1) && (g == 1) && (h == 1) && (i == 1)) { toolStripStatusLabel1.Text = "Update Sucessfully"; ItemNo.Text = ""; Des.Text = ""; Units.Text = ""; StockPrice.Text = ""; SalesPrice.Text = ""; Discount.SelectedIndex = 0; UnitsInStock.Text = ""; ROL.Text = ""; Profit.Text = "0.0"; Cat.Focus(); } else { toolStripStatusLabel1.Text = "Error, Item Not Updated"; } } Connection.Close(); } catch { } } }
private void TestItem_Load(object sender, EventArgs e) { int i; string[] p; int index, pi, no; index = 1; pi = 0; configti = "d:\\Itemconfig.txt"; p = new string[6]; foreach (Control item in this.Controls) { if (item.GetType() == typeof(System.Windows.Forms.ComboBox) && item.Name.StartsWith("comboBox")) { comboxList2.Add(item.Name, (ComboBox)item); } } ItemNo.Items.Add("1"); ItemNo.Items.Add("2"); for (i = 0; i < 2; i++) { string actual_test = "comboBox" + (i + 1).ToString(); comboxList2[actual_test].Items.Add("DWX_1817_12&0C"); comboxList2[actual_test].Items.Add("DWX_1817_34&03"); comboxList2[actual_test].Items.Add("TH2883_1817_12&0C"); comboxList2[actual_test].Items.Add("TH2883_1817_34&03"); comboxList2[actual_test].Items.Add("DWX_1829"); comboxList2[actual_test].Items.Add("TH2883_1829"); comboxList2[actual_test].Items.Add("TH2839_1829"); comboxList2[actual_test].Items.Add("DWX_1818&0C"); comboxList2[actual_test].Items.Add("TH2883_1818&0C"); comboxList2[actual_test].Items.Add("TH2839_1818"); comboxList2[actual_test].Items.Add("DWX_18764.5_Open&0C"); comboxList2[actual_test].Items.Add("DWX_18764.5_Short&0C"); comboxList2[actual_test].Items.Add("DWX_18764.9_Open&0C"); comboxList2[actual_test].Items.Add("DWX_18764.9_Short&0C"); comboxList2[actual_test].Items.Add("DWX_18763.8_Open&0C"); comboxList2[actual_test].Items.Add("DWX_18763.8_Short&0C"); comboxList2[actual_test].Items.Add("DWX_18765.3_Open&0C"); comboxList2[actual_test].Items.Add("DWX_18765.3_Short&0C"); comboxList2[actual_test].Items.Add("DWX_18765.9_Open&0C"); comboxList2[actual_test].Items.Add("DWX_18765.9_Short&0C"); comboxList2[actual_test].Items.Add("TH2883_18764.5_Open&0C"); comboxList2[actual_test].Items.Add("TH2883_18764.5_Short&0C"); comboxList2[actual_test].Items.Add("TH2883_18764.9_Open&0C"); comboxList2[actual_test].Items.Add("TH2883_18764.9_Short&0C"); comboxList2[actual_test].Items.Add("TH2883_18763.8_Open&0C"); comboxList2[actual_test].Items.Add("TH2883_18763.8_Short&0C"); comboxList2[actual_test].Items.Add("TH2883_18765.3_Open&0C"); comboxList2[actual_test].Items.Add("TH2883_18765.3_Short&0C"); comboxList2[actual_test].Items.Add("TH2883_18765.9_Open&0C"); comboxList2[actual_test].Items.Add("TH2883_18765.9_Short&0C"); comboxList2[actual_test].Items.Add("DWX_1877_Open&0C"); comboxList2[actual_test].Items.Add("DWX_1877_Short&0C"); comboxList2[actual_test].Items.Add("TH2883_1877_Open&0C"); comboxList2[actual_test].Items.Add("TH2883_1877_Short&0C"); comboxList2[actual_test].Items.Add("DWX_0075&0C"); comboxList2[actual_test].Items.Add("TH2883_0075&0C"); comboxList2[actual_test].Items.Add("TH2839_0075"); } fs4 = new FileStream(configti, FileMode.Open); sr4 = new StreamReader(fs4); while (!sr4.EndOfStream) { str = sr4.ReadLine(); p[pi] = str; pi = pi + 1; // MessageBox.Show(comstr); } fs4.Close(); no = int.Parse(p[0]); index = ItemNo.FindString(p[0]); ItemNo.SelectedIndex = index; for (i = 0; i < no; i++) { string actual_test = "comboBox" + (i + 1).ToString(); index = comboxList2[actual_test].FindString(p[i + 1]); comboxList2[actual_test].SelectedIndex = index; } }
public string GetDisplayText(string sep) { return(ItemNo.ToString(format: "d7") + " " + description + " " + "(" + price.ToString("c") + ")"); }