private static Hashtable stockItemIdTable() { Hashtable ht = new Hashtable(); stockitem3 st = new stockitem3(); StockItemDB3 stockitemdb = new StockItemDB3(); List <stockitem3> StockItems = stockitemdb.getStockItems(); foreach (stockitem3 sitem in StockItems) { try { string id = sitem.StockItemID; string key = id.Substring(0, 6); string value = id.Substring(6, 4); if (ht.ContainsKey(key)) { ht[key] = value; } else { ht.Add(key, value); } } catch (Exception ex) { } } return(ht); }
private void grdList_CellContentClick_1(object sender, DataGridViewCellEventArgs e) { try { // pnlActionButtons.Visible = false; lblActionHeader.Visible = false; if (e.RowIndex < 0) { return; } string columnName = grdList.Columns[e.ColumnIndex].Name; if (columnName.Equals("Edit") || columnName.Equals("Approve") || columnName.Equals("LoadDocument") || columnName.Equals("View") || columnName.Equals("ViewDocument")) { clearData(); setButtonVisibility(columnName); prevsitem = new stockitem3(); int rowID = e.RowIndex; try { prevsitem.StockItemID = grdList.Rows[e.RowIndex].Cells["StockItemID"].Value.ToString(); prevsitem.Name = grdList.Rows[e.RowIndex].Cells["Description"].Value.ToString(); prevsitem.documentStatus = Convert.ToInt32(grdList.Rows[e.RowIndex].Cells["DocumentStatus"].Value.ToString()); prevsitem.CreateUser = grdList.Rows[e.RowIndex].Cells["CreateUser"].Value.ToString(); prevsitem.ForwarderList = grdList.Rows[e.RowIndex].Cells["ForwarderLists"].Value.ToString(); } catch (Exception ez) { } //--------Load Documents if (columnName.Equals("LoadDocument")) { string hdrString = "StockItemID" + prevsitem.StockItemID + "\n" + "StockItem name:" + prevsitem.Name; string dicDir = Main.documentDirectory + "\\" + docID; string subDir = prevsitem.StockItemID + "-" + prevsitem.Name; FileManager.LoadDocuments load = new FileManager.LoadDocuments(dicDir, subDir, docID, hdrString); load.ShowDialog(); this.RemoveOwnedForm(load); btnCancel_Click_1(null, null); return; } //-------- if (columnName.Equals("ViewDocument")) { return; } btnSave.Text = "Update"; //dtDate.Value = DateTime.Parse(grdList.Rows[e.RowIndex].Cells[0].Value.ToString()); txtStockItemID.Text = grdList.Rows[e.RowIndex].Cells[0].Value.ToString(); txtName.Text = grdList.Rows[e.RowIndex].Cells[1].Value.ToString(); txtReorderLevel.Text = grdList.Rows[e.RowIndex].Cells[2].Value.ToString(); cmbGroup1Select.SelectedIndex = cmbGroup1Select.FindString(grdList.Rows[e.RowIndex].Cells["Group1Code"].Value.ToString()); cmbGroup2Select.SelectedIndex = cmbGroup2Select.FindString(grdList.Rows[e.RowIndex].Cells["Group2Code"].Value.ToString()); cmbGroup3Select.SelectedIndex = cmbGroup3Select.FindString(grdList.Rows[e.RowIndex].Cells["Group3Code"].Value.ToString()); cmbUnit.SelectedIndex = cmbUnit.FindStringExact(grdList.Rows[e.RowIndex].Cells["Unit"].Value.ToString()); if (columnName.Equals("Approve")) { string gd1 = cmbGroup1Select.SelectedItem.ToString().Trim().Substring(0, cmbGroup1Select.SelectedItem.ToString().Trim().IndexOf('-')); string gd2 = cmbGroup2Select.SelectedItem.ToString().Trim().Substring(0, cmbGroup2Select.SelectedItem.ToString().Trim().IndexOf('-')); string gd3 = cmbGroup3Select.SelectedItem.ToString().Trim().Substring(0, cmbGroup3Select.SelectedItem.ToString().Trim().IndexOf('-')); string itc = gd1 + gd2 + gd3; id = CreateStockItemID(itc); } } pnlCVINRInner.Visible = true; pnlCVINROuter.Visible = true; pnlList.Visible = false; } catch (Exception ex) { } }
private void btnSave_Click_1(object sender, EventArgs e) { Boolean status = true; try { stockitem3 sitem = new stockitem3(); StockItemDB3 stockitemdb = new StockItemDB3(); //cvi.ConversionDate = dtDate.Value; try { sitem.Group1Code = cmbGroup1Select.SelectedItem.ToString().Trim().Substring(0, cmbGroup1Select.SelectedItem.ToString().Trim().IndexOf('-')); sitem.Group1CodeDescription = cmbGroup1Select.SelectedItem.ToString().Trim().Substring(cmbGroup1Select.SelectedItem.ToString().Trim().IndexOf('-') + 1); } catch (Exception) { sitem.Group1Code = ""; sitem.Group1CodeDescription = ""; } try { sitem.Group2Code = cmbGroup2Select.SelectedItem.ToString().Trim().Substring(0, cmbGroup2Select.SelectedItem.ToString().Trim().IndexOf('-')); sitem.Group2CodeDescription = cmbGroup2Select.SelectedItem.ToString().Trim().Substring(cmbGroup2Select.SelectedItem.ToString().Trim().IndexOf('-') + 1); } catch (Exception) { sitem.Group2Code = ""; sitem.Group2CodeDescription = ""; } try { sitem.Group3Code = cmbGroup3Select.SelectedItem.ToString().Trim().Substring(0, cmbGroup3Select.SelectedItem.ToString().Trim().IndexOf('-')); sitem.Group3CodeDescription = cmbGroup3Select.SelectedItem.ToString().Trim().Substring(cmbGroup3Select.SelectedItem.ToString().Trim().IndexOf('-') + 1); } catch (Exception) { sitem.Group3Code = ""; sitem.Group3CodeDescription = ""; } try { sitem.Unit = cmbUnit.SelectedItem.ToString().Trim().Substring(0, cmbUnit.SelectedItem.ToString().Trim().IndexOf('-')); sitem.UnitDescription = cmbUnit.SelectedItem.ToString().Trim().Substring(cmbUnit.SelectedItem.ToString().Trim().IndexOf('-') + 1); } catch (Exception) { sitem.Unit = ""; sitem.UnitDescription = ""; } //sitem.StockItemID = CreateStockItemID(itc); sitem.Name = txtName.Text; sitem.ReorderLevel = Convert.ToInt32(txtReorderLevel.Text); sitem.ForwarderList = prevsitem.ForwarderList; System.Windows.Forms.Button btn = sender as System.Windows.Forms.Button; string btnText = btn.Text; if (stockitemdb.validateStockItem(sitem)) { if (btnText.Equals("Update")) { if (stockitemdb.updateStockItem(sitem, prevsitem)) { MessageBox.Show("Stock Item updated"); closeAllPanels(); listOption = 1; ListStockItem(listOption); } else { status = false; MessageBox.Show("Failed to Update Stock Item"); } } else if (btnText.Equals("Save")) { sitem.documentStatus = 1;//created if (stockitemdb.insertStockItem(sitem)) { MessageBox.Show("Stock Item Added"); closeAllPanels(); listOption = 1; ListStockItem(listOption); } else { status = false; MessageBox.Show("Failed to Insert Stock Item"); } } } else { MessageBox.Show("Stock Item Data Validation failed"); } } catch (Exception ex) { MessageBox.Show("Failed Adding / Editing Stock Item"); } if (status) { setButtonVisibility("btnEditPanel"); //activites are same for cancel, forward,approve, reverse and save } }