public static void InsertDisposalItem(DisposalDetailed aDesposalDetailed) { if (Helper.Instance.con.State == ConnectionState.Closed) { try { Helper.Instance.con.Open(); SqlCommand cmd = new SqlCommand("INSERT INTO DisposalDetailed (ItemID,ItemDescription,Qty,UnitCost,Date,TotalPerUnit,GeneralNumber,IsRevised) VALUES" + "(@ItemID,@ItemDescription,@Qty,@UnitCost,@Date,@TotalPerUnit,@GeneralNumber,@IsRevised)", Helper.Instance.con); cmd.Parameters.Add("@ItemID", SqlDbType.Int).Value = aDesposalDetailed.Disposal_Detailed_ItemID; cmd.Parameters.Add("@ItemDescription", SqlDbType.NVarChar).Value = aDesposalDetailed.Disposal_Detailed_ItemDescription; cmd.Parameters.Add("@Qty", SqlDbType.Float).Value = aDesposalDetailed.Disposal_Detailed_Qty; cmd.Parameters.Add("@UnitCost", SqlDbType.Float).Value = aDesposalDetailed.Disposal_Detailed_UnitCost; cmd.Parameters.Add("@Date", SqlDbType.Date).Value = aDesposalDetailed.Disposal_Detailed_Date; cmd.Parameters.Add("@TotalPerUnit", SqlDbType.Float).Value = aDesposalDetailed.Disposal_Detailed_TotalPerUnit; cmd.Parameters.Add("@GeneralNumber", SqlDbType.Int).Value = aDesposalDetailed.Disposal_Detailed_GeneralNumber; cmd.Parameters.Add("@IsRevised", SqlDbType.Int).Value = 0; cmd.ExecuteNonQuery(); Helper.Instance.con.Close(); } catch (Exception ex) { MessageBox.Show("ERROR IN DisposalDetailed MGMT (InsertItem FUNCTION) EX=" + ex.Message); } finally { Helper.Instance.con.Close(); } } }
private bool AddDisposalGeneral() { if (TeldgView.Rows.Count > 0) { if (DisposalReasonComboBox.SelectedValue == null) { MessageBox.Show(MsgTxt.PleaseSelectTxt + " " + MsgTxt.DisposalReasonTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Hand); return(false); } DisposalGeneral aDisposalGeneral = FillDisposalGeneral(); if (aDisposalGeneral == null) { MessageBox.Show(MsgTxt.UnexpectedError, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (!DisposalGeneralMgmt.InsertDisposal(aDisposalGeneral)) { return(false); } DisposalDetailed aDisposalDetailed = new DisposalDetailed(); foreach (DataGridViewRow r in TeldgView.Rows) { if (!r.IsNewRow) { aDisposalDetailed.Disposal_Detailed_ItemID = ItemsMgmt.SelectItemIDByBarcode(TeldgView.Rows[r.Index].Cells["Barcode"].Value.ToString()); aDisposalDetailed.Disposal_Detailed_ItemDescription = TeldgView.Rows[r.Index].Cells["Description"].Value.ToString(); aDisposalDetailed.Disposal_Detailed_Date = DateTime.Now.ToShortDateString(); double TestParser = 0; if (double.TryParse(TeldgView.Rows[r.Index].Cells["Qty"].Value.ToString(), out TestParser)) { aDisposalDetailed.Disposal_Detailed_Qty = TestParser;//double.Parse(TeldgView.Rows[r.Index].Cells["Qty"].Value.ToString()); } else { TestParser = 1; } aDisposalDetailed.Disposal_Detailed_UnitCost = double.Parse(TeldgView.Rows[r.Index].Cells["PricePerUnit"].Value.ToString()); aDisposalDetailed.Disposal_Detailed_TotalPerUnit = double.Parse(TeldgView.Rows[r.Index].Cells["PriceTotal"].Value.ToString()); aDisposalDetailed.Disposal_Detailed_GeneralNumber = aDisposalGeneral.Disposal_General_Number; DisposalDetailedMgmt.InsertDisposalItem(aDisposalDetailed); string Barcode = TeldgView.Rows[r.Index].Cells["Barcode"].Value.ToString(); ItemsMgmt.UpdateItemQtyByBarcode(Barcode, ItemsMgmt.SelectItemQtyByBarcode(Barcode), (0 - TestParser));//0-qty wich is negative to be subtracted from orginnal } } return(true); } else { MessageBox.Show(MsgTxt.NotItemsTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } }