private void btnSave_Click(object sender, EventArgs e) { string valid = ValidateFields(); if (valid == "true") { if (XtraMessageBox.Show("Are You Sure, You want to save this Transaction?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Disposal dis = new Disposal(); Balance bal = new Balance(); ReceiveDoc rec = new ReceiveDoc(); DataTable dtAdjVal = (DataTable)AdjustmentGrid.DataSource; for (int i = 0; i < dtAdjVal.Rows.Count; i++) { dis.AddNew(); dis.StoreId = Convert.ToInt32(cboStores.EditValue); dis.ItemID = Convert.ToInt32(dtAdjVal.Rows[i]["ID"]); dis.ApprovedBy = txtApprovedBy.Text; DateTime xx = dtAdjustDate.Value; dtAdjustDate.CustomFormat = "MM/dd/yyyy"; DateTime dtRec = new DateTime(); dis.Date = ConvertDate.DateConverter(dtAdjustDate.Text); dtRec = ConvertDate.DateConverter(dtAdjustDate.Text); dis.RefNo = txtRefNo.Text; dis.BatchNo = dtAdjVal.Rows[i]["Batch No"].ToString(); double price = ((Convert.ToDouble(dtAdjVal.Rows[i]["BU Qty"]) != 0) ? (Convert.ToDouble(dtAdjVal.Rows[i]["Price"]) / Convert.ToDouble(dtAdjVal.Rows[i]["BU Qty"])) : 0); dis.Cost = price; dis.Remark = txtRemark.Text; if (dtAdjVal.Rows[i]["Losses"].ToString() != "") { if (Convert.ToInt64(dtAdjVal.Rows[i]["Losses"]) <= Convert.ToInt64(dtAdjVal.Rows[i]["BU Qty"])) { dis.Losses = true; dis.Quantity = Convert.ToInt64(dtAdjVal.Rows[i]["Losses"]); } else { XtraMessageBox.Show("You can't loss more quantity than what you have in the store!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); ResetFields(); return; } } else { dis.Losses = false; dis.Quantity = Convert.ToInt64(dtAdjVal.Rows[i]["Adjustment"]); } dis.ReasonId = Convert.ToInt32(dtAdjVal.Rows[i]["Reason"]); if (VisibilitySetting.HandleUnits == 1) { dis.UnitID = 0; } else if (VisibilitySetting.HandleUnits == 2) { dis.UnitID = Convert.ToInt32(dtRecGrid.Rows[i]["UnitID"]); } else if (VisibilitySetting.HandleUnits == 3) { dis.UnitID = Convert.ToInt32(dtRecGrid.Rows[i]["UnitID"]); } dis.RecID = Convert.ToInt32(dtAdjVal.Rows[i]["RecID"]); dis.EurDate = dtAdjustDate.Value; dis.Save(); rec.LoadByPrimaryKey(Convert.ToInt32(dtAdjVal.Rows[i]["RecID"])); if (rec.RowCount > 0) { if (dis.Losses) { rec.QuantityLeft = rec.QuantityLeft - dis.Quantity; if (rec.QuantityLeft == 0) { rec.Out = true; } else { rec.Out = false; } // rec.UnitID = Convert.ToInt32(dtAdjVal.Rows[i]["UnitID"]); rec.Save(); //Log Activity, ActivityID for save is 1 // logger.SaveAction(1, 1, "Transaction\\LossesAdjustment.cs", "Loss/Adjustmet of " + dis.Quantity +" LOSS has been made."); } else { rec.QuantityLeft = rec.QuantityLeft + dis.Quantity; if (rec.QuantityLeft != 0) { rec.Out = false; } else { rec.Out = true; } rec.Save(); //Log Activity, ActivityID for save is 1 //logger.SaveAction(1, 1, "Transaction\\LossesAdjustment.cs", "Loss/Adjustmet of " + dis.Quantity + " ADJUSTMENT has been made."); } } dtAdjustDate.Value = xx; } XtraMessageBox.Show("Transaction successfully Saved!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); ResetFields(); } } else { XtraMessageBox.Show(valid, "Validation", MessageBoxButtons.OK, MessageBoxIcon.Stop); } }
private void btnSave_Click(object sender, EventArgs e) { string valid = ValidateFields(); if (valid == "true") { if (XtraMessageBox.Show("Are You Sure, You want to save this Transaction?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Disposal dis = new Disposal(); Balance bal = new Balance(); ReceiveDoc rec = new ReceiveDoc(); DataTable dtAdjVal = (DataTable)AdjustmentGrid.DataSource; for (int i = 0; i < dtAdjVal.Rows.Count; i++) { dis.AddNew(); dis.StoreId = Convert.ToInt32(cboStores.EditValue); dis.ItemID = Convert.ToInt32(dtAdjVal.Rows[i]["ID"]); dis.ApprovedBy = txtApprovedBy.Text; DateTime xx = dtAdjustDate.Value; dtAdjustDate.CustomFormat = "MM/dd/yyyy"; DateTime dtRec = new DateTime(); dis.Date = ConvertDate.DateConverter(dtAdjustDate.Text); dtRec = ConvertDate.DateConverter(dtAdjustDate.Text); dis.RefNo = txtRefNo.Text; dis.BatchNo = dtAdjVal.Rows[i]["Batch No"].ToString(); double price = ((Convert.ToDouble(dtAdjVal.Rows[i]["BU Qty"]) != 0) ? (Convert.ToDouble(dtAdjVal.Rows[i]["Price"]) / Convert.ToDouble(dtAdjVal.Rows[i]["BU Qty"])) : 0); dis.Cost = price; dis.Remark = txtRemark.Text; if (dtAdjVal.Rows[i]["Losses"].ToString() != "") { if (Convert.ToInt64(dtAdjVal.Rows[i]["Losses"]) <= Convert.ToInt64(dtAdjVal.Rows[i]["BU Qty"])) { dis.Losses = true; dis.Quantity = Convert.ToInt64(dtAdjVal.Rows[i]["Losses"]); } else { XtraMessageBox.Show("You can't loss more quantity than what you have in the store!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); ResetFields(); return; } } else { dis.Losses = false; dis.Quantity = Convert.ToInt64(dtAdjVal.Rows[i]["Adjustment"]); } // dis.ReasonId = Convert.ToInt32(dtAdjVal.Rows[i]["Reason"]); dis.ReasonId = Convert.ToInt16(lkReason.EditValue); if (VisibilitySetting.HandleUnits == 1) { dis.UnitID = 0; } else if (VisibilitySetting.HandleUnits == 2) { dis.UnitID = Convert.ToInt32(dtRecGrid.Rows[i]["UnitID"]); } else if (VisibilitySetting.HandleUnits == 3) { dis.UnitID = Convert.ToInt32(dtRecGrid.Rows[i]["UnitID"]); } dis.RecID = Convert.ToInt32(dtAdjVal.Rows[i]["RecID"]); dis.EurDate = dtAdjustDate.Value; dis.Save(); rec.LoadByPrimaryKey(Convert.ToInt32(dtAdjVal.Rows[i]["RecID"])); if (rec.RowCount > 0) { if (dis.Losses) { rec.QuantityLeft = rec.QuantityLeft - dis.Quantity; if (rec.QuantityLeft == 0) { rec.Out = true; } else { rec.Out = false; } // rec.UnitID = Convert.ToInt32(dtAdjVal.Rows[i]["UnitID"]); rec.Save(); //Log Activity, ActivityID for save is 1 // logger.SaveAction(1, 1, "Transaction\\LossesAdjustment.cs", "Loss/Adjustmet of " + dis.Quantity +" LOSS has been made."); } else { rec.QuantityLeft = rec.QuantityLeft + dis.Quantity; if (rec.QuantityLeft != 0) { rec.Out = false; } else { rec.Out = true; } rec.Save(); //Log Activity, ActivityID for save is 1 //logger.SaveAction(1, 1, "Transaction\\LossesAdjustment.cs", "Loss/Adjustmet of " + dis.Quantity + " ADJUSTMENT has been made."); } } dtAdjustDate.Value = xx; } XtraMessageBox.Show("Transaction successfully Saved!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); GeneralInfo gn = new GeneralInfo(); gn.LoadAll(); if (gn.UsesModel) { int userID = MainWindow.LoggedinId; User us = new User(); us.LoadByPrimaryKey(userID); string printedby = string.Format("Printed by {0} on {1} , HCMIS {2}", us.FullName, DateTime.Today.ToShortDateString(), Program.HCMISVersionString); var modelprint = new LossAdjustmentModel22 { PrintedBy = { Text = printedby } }; // gridAdjView.ActiveFilterString = String.Format("[Reason] ==11"); // gridAdjView.RefreshData(); DataView dt = (DataView)gridAdjView.DataSource; // dt.RowFilter =(String.Format("[Reason]=11")); DataTable tbl1 = dt.ToTable(); if (tbl1.Rows.Count > 0) { tbl1.TableName = "Model22"; var dtset = new DataSet(); dtset.Tables.Add(tbl1.Copy()); modelprint.ReportUnit = DevExpress.XtraReports.UI.ReportUnit.TenthsOfAMillimeter; modelprint.PaperKind = System.Drawing.Printing.PaperKind.Custom; //modelprint.PageHeight = modelprint.PageHeight / 10; //Convert.ToInt32(BLL.Settings.PaperHeightCredit); // modelprint.PageWidth = modelprint.PageHeight / 10; //Convert.ToInt32(BLL.Settings.PaperWidthCredit); modelprint.DataSource = dtset; modelprint.Landscape = true; //XtraMessageBox.Show(string.Format("You are about to print {0} pages!", modelprint.PrintingSystem.Pages.Count), "Success", MessageBoxButtons.OK, // MessageBoxIcon.Information); modelprint.ShowPreviewDialog(); } } ResetFields(); } } else { XtraMessageBox.Show(valid, "Validation", MessageBoxButtons.OK, MessageBoxIcon.Stop); } }