Exemplo n.º 1
0
        private void LockerTransaction(ACMSDAL.ConnectionProvider connProvider, ACMSLogic.POS pos)
        {
            if (pos.NCategoryID == 15)
            {
                if (pos.POSLockerAction == ACMSLogic.POS.LockerAction.Return)
                {
                    // Locker Return.

                    ACMSDAL.TblLocker sqlLocker = new ACMSDAL.TblLocker();
                    sqlLocker.MainConnectionProvider = connProvider;

                    DataTable table = sqlLocker.GetOccupiedLocker(pos.StrBranchCode, pos.StrMembershipID);

                    if (table == null || table.Rows.Count == 0)
                    {
                        throw new Exception("No lockers have been rented.");
                    }

                    ACMSDAL.TblBranch sqlBranch = new ACMSDAL.TblBranch();
                    sqlBranch.MainConnectionProvider = connProvider;

                    sqlBranch.StrBranchCode = pos.StrBranchCode;
                    sqlBranch.SelectOne();

                    int gracePeriod =  ACMS.Convert.ToInt32(sqlBranch.NLockerGracePeriod);

                    foreach (DataRow r in pos.ReceiptItemsTable.Rows)
                    {

                        string nLockerNo = r["strCode"].ToString();

                        DataRow[] lockerRows = table.Select("nLockerNo = " + nLockerNo);

                        if (lockerRows.Length > 0)
                        {
                            DataRow lockerRow = lockerRows[0];

                            DateTime dtExpiryDate = ACMS.Convert.ToDateTime(lockerRow["dtExpiry"]);

                            TimeSpan span = DateTime.Today.Subtract(dtExpiryDate.Date);

                            if (span.Days > gracePeriod)
                                throw new Exception(string.Format("locker No : {0} have exceed the grace period.", nLockerNo));

                            lockerRow["strMembershipID"] = DBNull.Value;
                            lockerRow["strReceiptNo"] = DBNull.Value;
                            lockerRow["dtExpiry"] = DBNull.Value;
                            lockerRow["nStatusID"] = 0;
                        }
                    }

                    sqlLocker.SaveData(table);
                }
                else if (pos.POSLockerAction == ACMSLogic.POS.LockerAction.Extend)
                {
                    ACMSDAL.TblLocker sqllocker = new ACMSDAL.TblLocker();
                    sqllocker.MainConnectionProvider = connProvider;

                    DataTable table = sqllocker.GetOccupiedLocker(pos.StrBranchCode, pos.StrMembershipID);

                    if (table.Rows.Count > 0)
                    {
                        foreach (DataRow r in pos.ReceiptItemsTable.Rows)
                        {
                            string nLockerNo = r["strCode"].ToString();

                            DataRow[] lockerRows = table.Select("nLockerNo = " + nLockerNo);

                            if (lockerRows.Length > 0)
                            {
                                DataRow lockerRow = lockerRows[0];

                                DateTime expiryDate = ACMS.Convert.ToDateTime(lockerRow["dtExpiry"]);

                                int months = ACMS.Convert.ToInt32(r["nQuantity"]);

                                if (DateTime.Now.Year == 2015 && (DateTime.Now.Month == 3 || DateTime.Now.Month == 4) && (pos.StrBranchCode == "TO" || pos.StrBranchCode == "SM" || pos.StrBranchCode == "HM" || pos.StrBranchCode == "TS" || pos.StrBranchCode == "BJ" || pos.StrBranchCode == "SV") && ACMS.Convert.ToInt32(r["nQuantity"]) >= 3)
                                {
                                    int nFreeMonth;
                                    nFreeMonth = months / 3;

                                    DialogResult result1 = MessageBox.Show("Member entitled " + nFreeMonth.ToString() + " month free extension for locker ID " + nLockerNo.ToString() + ". Do you want to give the free extension?", "Warning",
                                            MessageBoxButtons.YesNo);
                                    if (result1 == DialogResult.Yes)
                                    {
                                        expiryDate = expiryDate.AddMonths(months + nFreeMonth);
                                    }
                                    else
                                        expiryDate = expiryDate.AddMonths(months);
                                }
                                else
                                    expiryDate = expiryDate.AddMonths(months);

                                //lockerRow["dtExpiry"] = expiryDate.AddDays(-1);
                                lockerRow["dtExpiry"] = expiryDate;
                            }
                        }
                        sqllocker.SaveData(table);
                    }
                }
                else if (pos.POSLockerAction == ACMSLogic.POS.LockerAction.New)
                {

                    ACMSDAL.TblLocker sqllocker = new ACMSDAL.TblLocker();
                    sqllocker.MainConnectionProvider = connProvider;

                    foreach (DataRow r in pos.ReceiptItemsTable.Rows)
                    {
                        if (r["strDescription"].ToString() != "Locker Deposit")
                        {
                            int nlockerNO = ACMS.Convert.ToInt32(r["strCode"]);
                            int months =  ACMS.Convert.ToInt32(r["nQuantity"]);

                            sqllocker.NLockerNo = nlockerNO;
                            sqllocker.SelectOne();

                            if (DateTime.Now.Year == 2015 && (DateTime.Now.Month == 3 || DateTime.Now.Month == 4) && (pos.StrBranchCode == "TO" || pos.StrBranchCode == "SM" || pos.StrBranchCode == "HM" || pos.StrBranchCode == "TS" || pos.StrBranchCode == "BJ" || pos.StrBranchCode == "SV") && ACMS.Convert.ToInt32(r["nQuantity"]) >= 3)
                            {
                                int nFreeMonth;
                                nFreeMonth = months / 3;

                                DialogResult result1 = MessageBox.Show("Member entitled " + nFreeMonth.ToString() + " month free extension for locker ID " + nlockerNO .ToString() + ". Do you want to give the free extension?", "Warning",
                                        MessageBoxButtons.YesNo);
                                if (result1 == DialogResult.Yes)
                                {
                                    sqllocker.DtExpiry = DateTime.Today.AddMonths(months+nFreeMonth).AddDays(-1);
                                }
                                else
                                    sqllocker.DtExpiry = DateTime.Today.AddMonths(months).AddDays(-1);
                            }
                            else
                                sqllocker.DtExpiry = DateTime.Today.AddMonths(months).AddDays(-1);

                            sqllocker.StrBranchCode = pos.StrBranchCode;
                            sqllocker.StrMembershipID = pos.StrMembershipID;
                            sqllocker.StrReceiptNo = pos.StrReceiptNo;
                            sqllocker.NStatusID = 1;
                            sqllocker.Update();
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void OnConfirmLockerDeposit()
        {
            ACMSDAL.TblBranch branch = new ACMSDAL.TblBranch();
            branch.StrBranchCode = myPOS.StrBranchCode;
            branch.SelectOne();

            decimal lockerDeposit = ACMS.Convert.ToDecimal(branch.MLockerDepositRate);

            ACMSDAL.TblMember member = new ACMSDAL.TblMember();
            member.StrMembershipID = myPOS.StrMembershipID;
            member.SelectOne();

            if (myPOS.ReceiptItemsTable.Rows.Count == 0)
            {
                ACMSDAL.TblLocker sqlLocker = new ACMSDAL.TblLocker();

                DataTable table = sqlLocker.GetOccupiedLocker(myPOS.StrBranchCode, myPOS.StrMembershipID);

                if (table.Rows.Count > 0)
                {
                    MessageBox.Show(this, "Please return your locker before a new Deposit can make.");
                    return;
                }

                if (!member.FLockerDeposit.IsNull)
                {
                    if (member.FLockerDeposit.IsTrue)
                        MessageBox.Show(this, "Deposit has been saved in system.");
                    else
                    {
                        DialogResult result = MessageBox.Show(this, string.Format("Locker Deposit is $ {0}, Continue?", lockerDeposit), "Add Deposit", MessageBoxButtons.OKCancel);
                        if (result == DialogResult.OK)
                            myPOS.NewReceiptEntry(myPOS.StrMembershipID, -1, "Locker Deposit", 1, lockerDeposit, myPOS.StrMembershipID);
                    }
                }
                else
                {
                    DialogResult result = MessageBox.Show(this, string.Format("Locker Deposit is $ {0}, Continue?", lockerDeposit), "Add Deposit", MessageBoxButtons.OKCancel);
                    if (result == DialogResult.OK)
                        myPOS.NewReceiptEntry(myPOS.StrMembershipID, -1, "Locker Deposit", 1, lockerDeposit, myPOS.StrMembershipID);
                }
            }
            else
            {
                MessageBox.Show(this, "Only one deposit is allow in one receipt.");
            }
        }