/// <summary> /// Saves Category/Sub Category related information /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, EventArgs e) { if (txtCategory.Text != "" || txtCatCode.Text != "") { if (cboCategory.Visible) { SubCategory subCat = new SubCategory(); if (_catId != 0) { subCat.LoadByPrimaryKey(_catId); } else { subCat.AddNew(); } subCat.CategoryId = Convert.ToInt32(cboCategory.SelectedValue); subCat.SubCategoryName = txtCategory.Text; subCat.Description = txtDescription.Text; subCat.SubCategoryCode = txtCatCode.Text; subCat.Save(); } else { Category cat = new Category(); if (_catId != 0) { cat.LoadByPrimaryKey(_catId); } else { cat.AddNew(); } cat.CategoryName = txtCategory.Text; cat.Description = txtDescription.Text; cat.CategoryCode = txtCatCode.Text; cat.Save(); } PopulateCategoryTree(); ResetCategoryForm(); } else { if (txtCatCode.Text == "") { txtCatCode.BackColor = Color.FromArgb(251, 214, 214); } if (txtCategory.Text == "") { txtCategory.BackColor = Color.FromArgb(251, 214, 214); } } }
/// <summary> /// Handles the treeCategory focused node changed and updates the form accordingly /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void treeCategory_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e) { Category cat = new Category(); SubCategory subCat = new SubCategory(); if (treeCategory.Selection.Count == 0) { return; } string value = treeCategory.Selection[0].GetValue("ID").ToString(); int categoryId = Convert.ToInt32(value.Substring(1)); string type = "cat"; if (value.Substring(0, 1) == "S") { type = "sub"; } else if (value == "P999") { type = "All"; } if (type == "cat") { cat.LoadByPrimaryKey(categoryId); cboCategory.SelectedValue = categoryId.ToString(); cboCategory.Visible = false; txtCategory.Text = cat.CategoryName; txtCatCode.Text = cat.CategoryCode; txtDescription.Text = cat.Description; _catId = cat.ID; } else if (type == "sub") { subCat.LoadByPrimaryKey(categoryId); cboCategory.Visible = true; cboCategory.SelectedValue = subCat.CategoryId.ToString(); txtCategory.Text = subCat.SubCategoryName; txtCatCode.Text = subCat.SubCategoryCode; txtDescription.Text = subCat.Description; _catId = subCat.ID; } btnSave.Text = "Update"; }
private void btnSave_Click(object sender, EventArgs e) { Items itm = new Items(); if (_itemId != 0) { itm.LoadByPrimaryKey(_itemId); } else { itm.AddNew(); itm.IsInHospitalList = true; Items itms = new Items(); itm.ID = itms.GetNextItemID(); itm.StorageTypeID = 1; itm.NearExpiryTrigger = 0; } itm.IINID = Convert.ToInt32(cboIIN.SelectedValue); //itm.StockCode = txtCatCode.Text + "-" + txtStockCode.Text; itm.StockCode = txtStockCode.Text; itm.Code = txtStock2.Text; itm.StockCodeDACA = txtStock3.Text; itm.Strength = txtStrength.Text; itm.DosageFormID = Convert.ToInt32(cboDosageForm.SelectedValue); itm.IsDiscontinued = ckIsDiscontinued.Checked; itm.IsFree = ckIsFree.Checked; itm.EDL = ckIsEDL.Checked; itm.UnitID = Convert.ToInt32(cboUnit.SelectedValue); itm.Pediatric = ckIsPedatric.Checked; itm.Refrigeratored = ckIsRefrigerated.Checked; itm.NeedExpiryBatch = true; itm.Save(); ProductsCategory prodCate = new ProductsCategory(); foreach (ListViewItem lstC in lstCat.Items) { int catId = Convert.ToInt32(lstC.Tag); if (prodCate.CategoryExists(itm.ID, catId)) { continue; } prodCate.AddNew(); prodCate.ItemId = itm.ID; prodCate.SubCategoryID = catId; prodCate.Save(); } if (itm.IsColumnNull("StockCode")) { // Update the Stock Code prodCate.Rewind(); SubCategory sc = new SubCategory(); sc.LoadByPrimaryKey(prodCate.SubCategoryID); if (sc.RowCount > 0) { itm.StockCode = string.Format("{0}.{1}.{2}.{3}", sc.SubCategoryCode, 1, itm.DosageFormID, 1); itm.Save(); } } XtraMessageBox.Show("Item is Saved Successfully!", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); }