private void PrepareForm() { try { ServiceInventoryItems _service = new ServiceInventoryItems(); if (this.CategoryID != 0) { TBL_MP_Master_Inventory_Category cat = _service.GetInventoryCategoriesDBItem(this.CategoryID); if (cat != null) { this.Text = "Add New Specification for " + cat.Inv_Category; int newSequence = _service.GetGetNextSequenceNumberOfInventoryLevelForCategory(CategoryID); txtSequence.Text = newSequence.ToString(); } } if (this.InventoryLevelID != 0) { TBL_MP_Master_Inventory_Level level = _service.GetInventoryLevelDBItem(this.InventoryLevelID); if (level != null) { txtLevelName.Text = level.Inventory_Level; txtSequence.Text = level.Sequence.ToString(); } } } catch (Exception) { throw; } }
private void btnSave_Click(object sender, EventArgs e) { try { ServiceInventoryItems _service = new ServiceInventoryItems(); if (this.ValidateChildren()) { if (this.InventoryLevelID == 0) { TBL_MP_Master_Inventory_Level newLevel = new TBL_MP_Master_Inventory_Level(); newLevel.Fk_InvCategory_ID = this.CategoryID; newLevel.Inventory_Level = txtLevelName.Text.Trim(); newLevel.Sequence = int.Parse(txtSequence.Text); newLevel.IsActive = true; this.InventoryLevelID = _service.AddNewInventoryLevel(newLevel); } else { TBL_MP_Master_Inventory_Level level = _service.GetInventoryLevelDBItem(this.InventoryLevelID); if (level != null) { level.Fk_InvCategory_ID = this.CategoryID; level.Inventory_Level = txtLevelName.Text.Trim(); level.Sequence = int.Parse(txtSequence.Text); _service.UpdateInventoryLevel(level); } } this.DialogResult = DialogResult.OK; } } catch (Exception ex) { MessageBox.Show(ex.Message, "frmAddEditInventoryLevel::btnSave_Click", MessageBoxButtons.OK, MessageBoxIcon.Error); } }