예제 #1
0
        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);
            }
        }