private void SaveBtn_Click(object sender, RoutedEventArgs e) { if (Authenticated.IndexOf("SaveKitchens") == -1 && Authenticated.IndexOf("CheckAllKitchens") == -1) { LogIn logIn = new LogIn(); logIn.ShowDialog(); } else { SqlConnection con = new SqlConnection(Classes.DataConnString); SqlConnection con2 = new SqlConnection(Classes.DataConnString); DataTable DT = new DataTable(); if (Code_txt.Text == "") { MessageBox.Show("Code Field Can't Be Empty"); return; } for (int i = 0; i < Stores_DGV.Items.Count; i++) { if (Code_txt.Text == ((DataRowView)Stores_DGV.Items[i]).Row.ItemArray[0].ToString()) { MessageBox.Show("This Code Is Not Avaliable"); return; } } if (IsMain.IsChecked == true) { con.Open(); string s = string.Format("select IsMain from Setup_Kitchens where IsMain='True' and RestaurantID='{0}'", ResturantCode); SqlCommand cmd = new SqlCommand(s, con); if (cmd.ExecuteScalar() != null) { MessageBox.Show("Can't be more Than Main Kitchen !"); return; } } try { string FiledSelection = "Code,Name,Name2,IsMain,IsOutlet,IsActive,RestaurantID,Create_Date,WS,UserID"; string values = string.Format("'{0}', N'{1}', N'{2}', '{3}','{4}','{5}','{6}',{7},'{8}','{9}'", Code_txt.Text, Name_txt.Text, Name2_txt.Text, IsMain.IsChecked, IsOutlet.IsChecked, Active_chbx.IsChecked, ResturantCode, "GETDATE()", Classes.WS, MainWindow.UserID); Classes.InsertRow("Setup_Kitchens", FiledSelection, values); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { con.Close(); MainUiFormat(); Stores_DGV.DataContext = null; FillDGV(ResturantCode); } if (IsMain.IsChecked == true || IsOutlet.IsChecked == true) { string FiledSelectionKitchenItems = "KitchenID,ItemID,RestaurantID,MinQty,MaxQty,shulfID"; string FiledSelectionItems = "KitchenID,ItemID,RestaurantID,Qty,Units,Last_Cost,Current_Cost,Net_Cost"; string FiledSelectionItemsYear = "ItemID,Restaurant_ID,Kitchen_ID,Year"; string valuesItems = ""; string ValuesKitchenItems = ""; string ValuesItemsYear = ""; string Comma = ""; try { DT = Classes.RetrieveData("Code", "Setup_Items"); int NumOfItemsPerRec = DT.Rows.Count % 1000; int NumOfItems = 0; if (DT.Rows.Count > 0) { if (DT.Rows.Count > 1000) { for (int i = 0; i <= NumOfItemsPerRec; i++) { for (int q = NumOfItems; q < (i + 1) * 1000; q++) { ValuesKitchenItems = Comma + string.Format("('{0}','{1}','{2}','0','0','0')", Code_txt.Text, DT.Rows[q].ItemArray[0], ResturantCode); valuesItems = Comma + string.Format("('{0}','{1}','{2}','0','','','0','')", Code_txt.Text, DT.Rows[q].ItemArray[0], ResturantCode); ValuesItemsYear = Comma + string.Format("('{0}','{1}','{2}','{3}')", DT.Rows[q].ItemArray[0], ResturantCode, Code_txt.Text, MainWindow.CurrentYear); Comma = ","; } NumOfItems = (i + 1) * 1000; } Classes.InsertRows("Setup_KitchenItems", FiledSelectionKitchenItems, ValuesKitchenItems); Classes.InsertRows("ItemsYear", FiledSelectionItemsYear, ValuesItemsYear); Classes.InsertRows("Items", FiledSelectionItems, valuesItems); } else { for (int i = 0; i < DT.Rows.Count; i++) { ValuesKitchenItems += Comma + string.Format("('{0}','{1}','{2}','0','0','0')", Code_txt.Text, DT.Rows[i].ItemArray[0], ResturantCode); valuesItems += Comma + string.Format("('{0}','{1}','{2}','0','','','','')", Code_txt.Text, DT.Rows[i].ItemArray[0], ResturantCode); ValuesItemsYear += Comma + string.Format("('{0}','{1}','{2}','{3}')", DT.Rows[i].ItemArray[0], ResturantCode, Code_txt.Text, MainWindow.CurrentYear); Comma = ","; } Classes.InsertRows("Setup_KitchenItems", FiledSelectionKitchenItems, ValuesKitchenItems); Classes.InsertRows("ItemsYear", FiledSelectionItemsYear, ValuesItemsYear); Classes.InsertRows("Items", FiledSelectionItems, valuesItems); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { con.Close(); con2.Close(); } } MessageBox.Show("Saved Successfully"); } }