private void btSave_Click(object sender, RoutedEventArgs e) { // save in database //insert InventoryExport BUS_InventoryExport export = new BUS_InventoryExport(); String newExportID = export.Create(tbEmployeeName.Text, tbDate.Text, tbDescription.Text); //MessageBox.Show(newImportID); //insert InventoryImportdetails if (newExportID == null) { return; } List <String> sqlString = new List <string>(); if (list.Count.Equals(0)) { MessageBox.Show($"Danh sách nguyên vật liệu, thiết bị không được để trống!"); return; } foreach (InventoryExportDetailObject obj in list) { int amountInExport; int temp1 = -1, temp2 = -1; if (int.TryParse(obj.amount, out amountInExport)) { if (mapNameAmountInStock[obj.name] < amountInExport) { MessageBox.Show($"Số lượng của {obj.name} trong kho chỉ còn {mapNameAmountInStock[obj.name]}!"); export.Delete(newExportID); return; } } if (!int.TryParse(obj.amount, out temp2) || temp2 <= 0) { MessageBox.Show($"Số lượng của {obj.name} không hợp lệ!"); export.Delete(newExportID); return; } //if (tbDescription.Text.Length ==0) //{ // MessageBox.Show($"Vui lòng nhập lí do !"); // export.Delete(newExportID); // return; //} string temp = $"insert into InventoryExportDetail values ('{newExportID}','{obj.id}','{obj.amount}')"; sqlString.Add(temp); } BUS_InventoryExportDetail detail = new BUS_InventoryExportDetail(); detail.ImportList(sqlString); var screen = new InventoryExport(_context); if (screen != null) { this._context.StackPanelMain.Children.Clear(); this._context.StackPanelMain.Children.Add(screen); } }
public void LoadData() { Dictionary <String, int> mapNameAmount = new Dictionary <string, int>(); Dictionary <String, String> mapNameUnit = new Dictionary <string, string>(); //mapping name with unit & import amount //With import amount BUS_InventoryImportDetail import = new BUS_InventoryImportDetail(); DataTable temp = import.SelectAllImportDetailGroupByName(); foreach (DataRow row in temp.Rows) { string name = row["Tên"].ToString(); string amount = row["Số lượng"].ToString(); mapNameAmount[name] = int.Parse(amount); } //With unit BUS_Material mater = new BUS_Material(); DataTable tempMater = mater.selectAll(); foreach (DataRow row in tempMater.Rows) { string name = row["MaterialName"].ToString(); string unit = row["Unit"].ToString(); mapNameUnit[name] = unit; } //calculate amount in stock = import - export (if have) BUS_InventoryExportDetail export = new BUS_InventoryExportDetail(); DataTable temp1 = export.SelectAllExportDetailGroupByName(); foreach (DataRow row in temp1.Rows) { string name = row["Tên"].ToString(); string amount = row["Số lượng"].ToString(); if (mapNameAmount.ContainsKey(name)) { mapNameAmount[name] -= int.Parse(amount); } } //finally get the amount of mater in stock (if not import yet then: amount =0 ) foreach (KeyValuePair <string, string> name in mapNameUnit) { int amount = 0; if (mapNameAmount.ContainsKey(name.Key)) { amount = mapNameAmount[name.Key]; } if (amount == 0) { continue; } mainList.Add(new MAterialObject() { name = name.Key, amount = amount.ToString(), unit = name.Value, IsSelected = false });; } this.dataGridMaterialExport.ItemsSource = mainList; }
public void Delete(String id) { BUS_InventoryExportDetail detail = new BUS_InventoryExportDetail(); BUS_InventoryExport export = new BUS_InventoryExport(); detail.Delete(id); export.Delete(id); LoadData(); }
public Dictionary <String, int> loadAmountofMaterial() { Dictionary <String, int> mapNameAmount = new Dictionary <string, int>(); Dictionary <String, String> mapNameUnit = new Dictionary <string, string>(); //With import amount BUS_InventoryImportDetail import = new BUS_InventoryImportDetail(); DataTable temp = import.SelectAllImportDetailGroupByName(); foreach (DataRow row in temp.Rows) { string name = row["Tên"].ToString(); string amount = row["Số lượng"].ToString(); string use = row["isUse"].ToString(); if (use == "1") { mapNameAmount[name] = int.Parse(amount); } } //With unit BUS_Material mater = new BUS_Material(); DataTable tempMater = mater.selectAll(); foreach (DataRow row in tempMater.Rows) { string name = row["MaterialName"].ToString(); string unit = row["Unit"].ToString(); string use = row["isUse"].ToString(); if (use == "1") { mapNameUnit[name] = unit; } } //calculate amount in stock = import - export (if have) BUS_InventoryExportDetail export = new BUS_InventoryExportDetail(); DataTable temp1 = export.SelectAllExportDetailGroupByName(); foreach (DataRow row in temp1.Rows) { string name = row["Tên"].ToString(); string amount = row["Số lượng"].ToString(); if (mapNameAmount.ContainsKey(name)) { mapNameAmount[name] -= int.Parse(amount); } } foreach (KeyValuePair <string, string> name in mapNameUnit) { if (!mapNameAmount.ContainsKey(name.Key)) { mapNameAmount[name.Key] = 0; } } //MessageBox.Show(mapNameAmount.Count.ToString()); return(mapNameAmount); }
public void LoadData() { btBack.IsEnabled = false; list.Clear(); Dictionary <String, int> mapNameAmount = new Dictionary <string, int>(); Dictionary <String, String> mapNameUnit = new Dictionary <string, string>(); //mapping name with unit & import amount //With import amount BUS_InventoryImportDetail import = new BUS_InventoryImportDetail(); DataTable temp = import.SelectAllImportDetailGroupByName(); foreach (DataRow row in temp.Rows) { string name = row["Tên"].ToString(); string amount = row["Số lượng"].ToString(); string use = row["isUse"].ToString(); if (use == "1") { mapNameAmount[name] = int.Parse(amount); } else { materialInUse.Add(name); } } //With unit BUS_Material mater = new BUS_Material(); DataTable tempMater = mater.selectAll(); foreach (DataRow row in tempMater.Rows) { string name = row["MaterialName"].ToString(); string unit = row["Unit"].ToString(); string use = row["isUse"].ToString(); if (use == "1") { mapNameUnit[name] = unit; } } //calculate amount in stock = import - export (if have) BUS_InventoryExportDetail export = new BUS_InventoryExportDetail(); DataTable temp1 = export.SelectAllExportDetailGroupByName(); foreach (DataRow row in temp1.Rows) { string name = row["Tên"].ToString(); string amount = row["Số lượng"].ToString(); if (mapNameAmount.ContainsKey(name)) { mapNameAmount[name] -= int.Parse(amount); } materialInUse.Add(name); } //finally get the amount of mater in stock (if not import yet then: amount =0 ) int number0 = 1; foreach (KeyValuePair <string, string> name in mapNameUnit) { int amount = 0; if (mapNameAmount.ContainsKey(name.Key)) { amount = mapNameAmount[name.Key]; } list.Add(new InventoryObject() { Name = name.Key, Amount = amount.ToString(), Unit = name.Value }); number0++; } BUS_Parameter busParameter = new BUS_Parameter(); int rowPerSheet = busParameter.GetValue("RowInList"); if (list.Count % rowPerSheet == 0) { lblMaxPage.Content = list.Count / rowPerSheet; } else { lblMaxPage.Content = list.Count / rowPerSheet + 1; } if (int.Parse(lblMaxPage.Content.ToString()) == 0) { this.tbNumPage.Text = "0"; } if (int.Parse(lblMaxPage.Content.ToString()) == 1) { btNext.IsEnabled = false; } else { btNext.IsEnabled = true; } splitDataGrid(1); }