Exemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            var rec = new ReceiveDoc();

            var itm = new Items();
            //var itemprogram = new ProgramProduct();
            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)
                {
                    try
                    {
                        for (int i = 0; i < dtRecGrid.Rows.Count; i++)
                        {
                            if (dtRecGrid.Rows[i]["Expiry Date"] != DBNull.Value)
                            {
                                if (Convert.ToDateTime(dtRecGrid.Rows[i]["Expiry Date"]) <= DateTime.Now)
                                {
                                    var dialog =
                                        XtraMessageBox.Show(
                                            "The item " + dtRecGrid.Rows[i]["Item Name"].ToString() +
                                            " has already expired.  Are you sure you want to receive it?", "Warning",
                                            MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                                    if (dialog == DialogResult.No)
                                    {
                                        return;
                                    }
                                }
                            }
                            rec.AddNew();
                            rec.StoreID    = Convert.ToInt32(cboStores.EditValue);
                            rec.RefNo      = txtRefNo.Text.Trim();
                            rec.Remark     = txtRemark.Text;
                            rec.ReceivedBy = txtReceivedBy.Text;

                            DateTime xx = dtRecDate.Value;
                            dtRecDate.CustomFormat = "MM/dd/yyyy";
                            DateTime dtRec = new DateTime();
                            rec.Date = ConvertDate.DateConverter(dtRecDate.Text);

                            dtRec = ConvertDate.DateConverter(dtRecDate.Text);
                            dtRecDate.IsGregorianCurrentCalendar = true;

                            rec.EurDate = dtRecDate.Value;

                            dtRecDate.IsGregorianCurrentCalendar = false;

                            rec.ItemID = Convert.ToInt32(dtRecGrid.Rows[i][0]);

                            switch (VisibilitySetting.HandleUnits)
                            {
                            case 1:
                                rec.UnitID     = 0;
                                rec.QtyPerPack = Convert.ToInt32(dtRecGrid.Rows[i]["Qty/Pack"]);
                                break;

                            case 2:
                                rec.UnitID     = Convert.ToInt32(dtRecGrid.Rows[i]["UnitID"]);
                                rec.QtyPerPack = 1;
                                break;

                            case 3:
                                rec.UnitID     = Convert.ToInt32(dtRecGrid.Rows[i]["UnitID"]);
                                rec.QtyPerPack = 1;
                                break;
                            }
                            rec.NoOfPack = Convert.ToInt32(dtRecGrid.Rows[i]["Pack Qty"]);

                            rec.Quantity     = rec.NoOfPack * rec.QtyPerPack;
                            rec.QuantityLeft = rec.Quantity;
                            if (dtRecGrid.Rows[i]["Price/Pack"] != null &&
                                dtRecGrid.Rows[i]["Price/Pack"].ToString() != "")
                            {
                                double pre = Convert.ToDouble(dtRecGrid.Rows[i]["Price/Pack"]) / rec.QtyPerPack;
                                rec.Cost = Convert.ToDouble(pre);
                            }
                            else
                            {
                                rec.Cost = 0;
                            }
                            itm.LoadByPrimaryKey(Convert.ToInt32(dtRecGrid.Rows[i]["ID"]));
                            rec.BatchNo = dtRecGrid.Rows[i][8].ToString();
                            if (dtRecGrid.Rows[i]["Expiry Date"] != DBNull.Value)
                            {
                                rec.ExpDate = Convert.ToDateTime(dtRecGrid.Rows[i]["Expiry Date"]);
                            }
                            if (dtRecGrid.Rows[i]["Internal Drug Code"] != DBNull.Value)
                            {
                                rec.InternalDrugCode = Convert.ToString(dtRecGrid.Rows[i]["Internal Drug Code"]);
                            }
                            rec.SupplierID   = Convert.ToInt32(cboSupplier.EditValue);
                            rec.SubProgramID = Convert.ToInt32(cboProgram.EditValue);

                            ProgramProduct pr = new ProgramProduct();
                            pr.LoadByProgramProductByItemId(rec.ItemID, rec.StoreID);
                            if (pr.RowCount == 0)
                            {
                                pr.AddNew();
                                pr.ItemID    = rec.ItemID;
                                pr.ProgramID = (rec.StoreID == 8)? 1000: 1001;
                                pr.StoreID   = rec.StoreID;
                                pr.Save();
                            }

                            string batch = DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() +
                                           DateTime.Now.Minute.ToString() + rec.ItemID.ToString();
                            rec.LocalBatchNo = batch;

                            rec.Out         = false;
                            rec.IsApproved  = false;
                            dtRecDate.Value = xx;
                            rec.Save();

                            //check if there is any data on stockoutLog about this item on this store
                            //and update its enddate to today
                            StockoutLog stockoutLog    = new StockoutLog();
                            DataTable   tblStockoutLog = stockoutLog.LoadByStoreAndItemId(rec.ItemID, rec.StoreID, true);
                            if (tblStockoutLog != null)
                            {
                                if (tblStockoutLog.Rows.Count > 0)
                                {
                                    stockoutLog.LoadByPrimaryKey(int.Parse(tblStockoutLog.Rows[0]["ID"].ToString()));
                                    stockoutLog.EndDate = DateTime.Today;
                                    stockoutLog.Save();
                                }
                            }

                            //itemprogram.LoadByOldProgramIdAndItemId(Convert.ToInt32(cboStores.EditValue),
                            //                                        Convert.ToInt32(dtRecGrid.Rows[i][0]),
                            //                                        Convert.ToInt32(cboProgram.EditValue));
                            //if (itemprogram.RowCount != 0)
                            //{
                            //    continue;
                            //}
                            //itemprogram.AddNew();
                            //itemprogram.StoreID = Convert.ToInt32(cboStores.EditValue);
                            //itemprogram.ItemID = Convert.ToInt32(dtRecGrid.Rows[i][0]);
                            //itemprogram.ProgramID = Convert.ToInt32(cboProgram.EditValue);
                            //itemprogram.Save();
                        }
                        XtraMessageBox.Show("Transaction Successfully Saved!", "Success", MessageBoxButtons.OK,
                                            MessageBoxIcon.Information);
                        ResetFields();

                        //  mgr.CommitTransaction();
                    }
                    catch (Exception exp)
                    {
                        //mgr.RollbackTransaction();
                        BLL.User user = new User();
                        user.LoadByPrimaryKey(MainWindow.LoggedinId);
                        if (user.UserType == UserType.Constants.SYSTEM_ADMIN)
                        {
                            XtraMessageBox.Show(exp.Message);
                        }
                        else
                        {
                            XtraMessageBox.Show("Saving Error!", "Error", MessageBoxButtons.OK);
                        }
                    }
                }
            }
            else
            {
                XtraMessageBox.Show(valid, "Validation", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }
Exemplo n.º 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            var rec = new ReceiveDoc();

            var itm = new Items();
            //var itemprogram = new ProgramProduct();
            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)
                {
                    try
                    {
                        for (int i = 0; i < dtRecGrid.Rows.Count; i++)
                        {
                            if (dtRecGrid.Rows[i]["Expiry Date"] != DBNull.Value)
                            {
                                if (Convert.ToDateTime(dtRecGrid.Rows[i]["Expiry Date"]) <= DateTime.Now)
                                {
                                    var dialog =
                                        XtraMessageBox.Show(
                                            "The item " + dtRecGrid.Rows[i]["Item Name"].ToString() +
                                            " has already expired.  Are you sure you want to receive it?", "Warning",
                                            MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                                    if (dialog == DialogResult.No)
                                    {
                                        return;
                                    }
                                }
                            }
                            rec.AddNew();
                            rec.StoreID    = Convert.ToInt32(cboStores.EditValue);
                            rec.RefNo      = txtRefNo.Text.Trim();
                            rec.Remark     = txtRemark.Text;
                            rec.ReceivedBy = txtReceivedBy.Text;

                            DateTime xx = dtRecDate.Value;
                            dtRecDate.CustomFormat = "MM/dd/yyyy";
                            DateTime dtRec = new DateTime();
                            rec.Date = ConvertDate.DateConverter(dtRecDate.Text);

                            dtRec = ConvertDate.DateConverter(dtRecDate.Text);
                            dtRecDate.IsGregorianCurrentCalendar = true;

                            rec.EurDate = dtRecDate.Value;

                            dtRecDate.IsGregorianCurrentCalendar = false;

                            rec.ItemID = Convert.ToInt32(dtRecGrid.Rows[i][0]);

                            switch (VisibilitySetting.HandleUnits)
                            {
                            case 1:
                                rec.UnitID     = 0;
                                rec.QtyPerPack = Convert.ToInt32(dtRecGrid.Rows[i]["Qty/Pack"]);
                                break;

                            case 2:
                                rec.UnitID     = Convert.ToInt32(dtRecGrid.Rows[i]["UnitID"]);
                                rec.QtyPerPack = 1;
                                break;

                            case 3:
                                rec.UnitID     = Convert.ToInt32(dtRecGrid.Rows[i]["UnitID"]);
                                rec.QtyPerPack = 1;
                                break;
                            }
                            rec.NoOfPack = Convert.ToInt32(dtRecGrid.Rows[i]["Pack Qty"]);

                            rec.Quantity     = rec.NoOfPack * rec.QtyPerPack;
                            rec.QuantityLeft = rec.Quantity;
                            if (dtRecGrid.Rows[i]["Price/Pack"] != null &&
                                dtRecGrid.Rows[i]["Price/Pack"].ToString() != "")
                            {
                                double pre = Convert.ToDouble(dtRecGrid.Rows[i]["Price/Pack"]) / rec.QtyPerPack;
                                rec.Cost = Convert.ToDouble(pre);
                            }
                            else
                            {
                                rec.Cost = 0;
                            }
                            itm.LoadByPrimaryKey(Convert.ToInt32(dtRecGrid.Rows[i]["ID"]));
                            rec.BatchNo = dtRecGrid.Rows[i][8].ToString();
                            if (dtRecGrid.Rows[i]["Expiry Date"] != DBNull.Value)
                            {
                                rec.ExpDate = Convert.ToDateTime(dtRecGrid.Rows[i]["Expiry Date"]);
                            }
                            if (dtRecGrid.Rows[i]["Internal Drug Code"] != DBNull.Value)
                            {
                                rec.InternalDrugCode = Convert.ToString(dtRecGrid.Rows[i]["Internal Drug Code"]);
                            }
                            rec.SupplierID   = Convert.ToInt32(cboSupplier.EditValue);
                            rec.SubProgramID = Convert.ToInt32(cboProgram.EditValue);

                            ProgramProduct pr = new ProgramProduct();
                            pr.LoadByProgramProductByItemId(rec.ItemID, rec.StoreID);
                            if (pr.RowCount == 0)
                            {
                                pr.AddNew();
                                pr.ItemID    = rec.ItemID;
                                pr.ProgramID = (rec.StoreID == 8)? 1000: 1001;
                                pr.StoreID   = rec.StoreID;
                                pr.Save();
                            }

                            string batch = DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() +
                                           DateTime.Now.Minute.ToString() + rec.ItemID.ToString();
                            rec.LocalBatchNo = batch;

                            rec.Out         = false;
                            rec.IsApproved  = false;
                            dtRecDate.Value = xx;
                            rec.Save();

                            //check if there is any data on stockoutLog about this item on this store
                            //and update its enddate to today
                            StockoutLog stockoutLog    = new StockoutLog();
                            DataTable   tblStockoutLog = stockoutLog.LoadByStoreAndItemId(rec.ItemID, rec.StoreID, true);
                            if (tblStockoutLog != null)
                            {
                                if (tblStockoutLog.Rows.Count > 0)
                                {
                                    stockoutLog.LoadByPrimaryKey(int.Parse(tblStockoutLog.Rows[0]["ID"].ToString()));
                                    stockoutLog.EndDate = DateTime.Today;
                                    stockoutLog.Save();
                                }
                            }

                            //itemprogram.LoadByOldProgramIdAndItemId(Convert.ToInt32(cboStores.EditValue),
                            //                                        Convert.ToInt32(dtRecGrid.Rows[i][0]),
                            //                                        Convert.ToInt32(cboProgram.EditValue));
                            //if (itemprogram.RowCount != 0)
                            //{
                            //    continue;
                            //}
                            //itemprogram.AddNew();
                            //itemprogram.StoreID = Convert.ToInt32(cboStores.EditValue);
                            //itemprogram.ItemID = Convert.ToInt32(dtRecGrid.Rows[i][0]);
                            //itemprogram.ProgramID = Convert.ToInt32(cboProgram.EditValue);
                            //itemprogram.Save();
                        }
                        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 Model19
                            {
                                PrintedBy = { Text = printedby },
                                xrStore   = { Text = cboStores.Text }
                            };

                            var tbl1 = ((DataTable)receivingGrid.DataSource);
                            tbl1.TableName = "Model19";
                            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();

                        //  mgr.CommitTransaction();
                    }
                    catch (Exception exp)
                    {
                        //mgr.RollbackTransaction();
                        BLL.User user = new User();
                        user.LoadByPrimaryKey(MainWindow.LoggedinId);
                        if (user.UserType == UserType.Constants.SYSTEM_ADMIN)
                        {
                            XtraMessageBox.Show(exp.Message);
                        }
                        else
                        {
                            XtraMessageBox.Show("Saving Error!", "Error", MessageBoxButtons.OK);
                        }
                    }
                }
            }
            else
            {
                XtraMessageBox.Show(valid, "Validation", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }