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(); }