示例#1
0
        private void cxButtonOk_Click(object sender, EventArgs e)
        {
            if (cxIntRate.EditValue == null || (cxIntRate.EditValue != null && string.IsNullOrEmpty(cxIntRate.EditValue.ToString())))
            {
                XtraMessageBox.Show("Enter the Interest Rate.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (cxMemo1.EditValue == null || (cxMemo1.EditValue != null && string.IsNullOrEmpty(cxMemo1.EditValue.ToString())))
            {
                XtraMessageBox.Show("Enter the Remarks/Reason for Change.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (cxEffDate.EditValue == null || (cxEffDate.EditValue != null && string.IsNullOrEmpty(cxEffDate.EditValue.ToString())))
            {
                XtraMessageBox.Show("Enter the Effective Date.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            DateTime startDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);

            if (cxEffDate.EditValue != null && Convert.ToDateTime(cxEffDate.EditValue).Date < startDate)
            {
                XtraMessageBox.Show("Effective date should be of Current or Later month.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (cxGrid1DBTableView1.SelectedRowsCount == 0)
            {
                XtraMessageBox.Show("Atleast one company must be selected.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            str_comp = string.Empty;

            // This table is for saving interest rate
            DataTable dtRateTable = new DataTable("InterestRate");

            dtRateTable.Columns.Add("COMPANY_ID", typeof(decimal));
            dtRateTable.Columns.Add("INTEREST_RATE", typeof(decimal));
            dtRateTable.Columns.Add("CREATED_BY", typeof(string));
            dtRateTable.Columns.Add("CREATED_ON", typeof(DateTime));
            dtRateTable.Columns.Add("INT_EFFECTIVE_DATE", typeof(DateTime));
            dtRateTable.Columns.Add("REMARKS", typeof(string));

            // This table is for saving history interest rate
            DataTable dtHistory = new DataTable();

            dtHistory.Columns.Add("COMPANY_ID");
            dtHistory.Columns.Add("PREV_INTEREST_RATE");
            dtHistory.Columns.Add("REMARKS");
            dtHistory.Columns.Add("CREATED_BY");
            dtHistory.Columns.Add("CREATED_ON");
            dtHistory.Columns.Add("PREV_INT_EFFECTIVE_DATE");
            dtHistory.Columns.Add("INTEREST_RATE_HISTORY_ID");

            var rows = cxGrid1DBTableView1.GetSelectedRows();

            for (int i = 0; i < rows.Length; i++)
            {
                var drSelected = cxGrid1DBTableView1.GetDataRow(rows[i]);

                // If exist in interest rate table
                var dtIntRate = dal.RetrieveMaster("I", Convert.ToDecimal(drSelected["COMPANY_ID"]));

                DataRow dr = null;
                if (dtIntRate != null && dtIntRate.Rows.Count > 0)
                {
                    dtRateTable.ImportRow(dtIntRate.Rows[0]);
                    dr = dtRateTable.Rows[dtRateTable.Rows.Count - 1];
                }
                else
                {
                    dr = dtRateTable.NewRow();
                    dr["COMPANY_ID"]         = drSelected["COMPANY_ID"];
                    dr["INTEREST_RATE"]      = cxIntRate.EditValue;
                    dr["CREATED_BY"]         = ProfitCashflow.oPcfDM.UserName;
                    dr["CREATED_ON"]         = DateTime.Now;
                    dr["INT_EFFECTIVE_DATE"] = Convert.ToDateTime(cxEffDate.EditValue).Date;
                    dr["REMARKS"]            = cxMemo1.EditValue;
                    dtRateTable.Rows.Add(dr);
                }

                if (dtIntRate.Rows.Count > 0)
                {
                    int notExistInHistory = dal.CheckMaster(drSelected["COMPANY_ID"].ToString(), ((DateTime?)cxEffDate.EditValue).Value.Date);
                    if (notExistInHistory == 0)
                    {
                        pOrgIntRate    = Convert.ToDecimal(dtIntRate.Rows[0]["INTEREST_RATE"].ToString());
                        pOrgIntEffDate = Convert.ToDateTime(dtIntRate.Rows[0]["INT_EFFECTIVE_DATE"]).Date;
                        pOrgRemarks    = dtIntRate.Rows[0]["REMARKS"] != null ? dtIntRate.Rows[0]["REMARKS"].ToString() : string.Empty;

                        dr["INTEREST_RATE"]      = cxIntRate.EditValue;
                        dr["INT_EFFECTIVE_DATE"] = Convert.ToDateTime(cxEffDate.EditValue).Date;
                        dr["CREATED_BY"]         = ProfitCashflow.oPcfDM.UserName;
                        dr["REMARKS"]            = cxMemo1.EditValue;
                        dr.AcceptChanges();
                        dr.SetModified();

                        if (Convert.ToDateTime(dtIntRate.Rows[0]["INT_EFFECTIVE_DATE"]).Date != Convert.ToDateTime(cxEffDate.EditValue).Date)
                        {
                            var id = dal.RetrieveMaxInterestRateId();

                            DataRow dr1 = dtHistory.NewRow();
                            dr1["COMPANY_ID"]               = dtIntRate.Rows[0]["COMPANY_ID"];
                            dr1["PREV_INTEREST_RATE"]       = pOrgIntRate;
                            dr1["REMARKS"]                  = pOrgRemarks;
                            dr1["CREATED_BY"]               = ProfitCashflow.oPcfDM.UserName;
                            dr1["CREATED_ON"]               = DateTime.Now;
                            dr1["PREV_INT_EFFECTIVE_DATE"]  = pOrgIntEffDate;
                            dr1["INTEREST_RATE_HISTORY_ID"] = id;
                            dtHistory.Rows.Add(dr1);
                        }
                    }
                    else
                    {
                        str_comp = str_comp + drSelected[1].ToString() + ",";
                    }
                }
                else
                {
                    dr.AcceptChanges();
                    dr.SetAdded();
                }
            }

            if (str_comp != string.Empty)
            {
                XtraMessageBox.Show("Interest rate has already been defined for company " + str_comp + " for the entered effective date." + System.Environment.NewLine + "Hence the rate cannot be changed.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (dtRateTable.GetChanges() != null)
            {
                dal.UpdateInterestRate("I", dtRateTable);
            }

            if (dtHistory.GetChanges() != null)
            {
                dal.UpdateInterestRate("H", dtHistory.GetChanges());
            }

            this.Close();
        }
        private bool SaveInterestRate()
        {
            cxDBCurrencyEdit1.DoValidate();
            cxDBDateEdit1.DoValidate();
            cxDBMemo1.DoValidate();

            if (!Validation())
            {
                return(false);
            }

            dnInterest.Buttons.DoClick(dnInterest.Buttons.EndEdit);

            if (isIns)
            {
                dr = dt.Rows[0];    //dr = dt.NewRow();
                dr["COMPANY_ID"] = cxLookupComboBoxCompany.EditValue.ToString();
                dr["CREATED_BY"] = ProfitCashflow.oPcfDM.UserName;
                dr["CREATED_ON"] = DateTime.Now;
                //dt.Rows.Add(dr);
                pOrgIntRate    = null;
                pOrgIntEffDate = null;
                pOrgRemarks    = string.Empty;
            }

            // XE-30494
            //if ((pOrgIntRate == null || (cxDBCurrencyEdit1.EditValue != null && string.IsNullOrWhiteSpace(cxDBCurrencyEdit1.EditValue.ToString()))) &&
            //    (string.IsNullOrWhiteSpace(pOrgIntEffDate.ToString()) ||
            //        (cxDBDateEdit1.EditValue != null && string.IsNullOrWhiteSpace(cxDBDateEdit1.EditValue.ToString()))) &&
            //    (string.IsNullOrWhiteSpace(pOrgRemarks) ||
            //        (cxDBDateEdit1.EditValue != null && string.IsNullOrWhiteSpace(cxDBDateEdit1.EditValue.ToString()))))
            //{
            //    return false;
            //}

            if (dt.GetChanges() == null)
            {
                return(false);
            }

            if (pOrgIntRate != Convert.ToDecimal(cxDBCurrencyEdit1.EditValue))
            {
                dr["CREATED_ON"] = DateTime.Now;
            }

            DataTable dataTab = dal.RetrieveMaster("I", Convert.ToDecimal(cxLookupComboBoxCompany.EditValue));

            if (dataTab.Rows.Count > 0)
            {
                pOrgIntRate    = Convert.ToDecimal(dataTab.Rows[0]["INTEREST_RATE"].ToString());
                pOrgIntEffDate = Convert.ToDateTime(dataTab.Rows[0]["INT_EFFECTIVE_DATE"]);
                pOrgRemarks    = dataTab.Rows[0]["REMARKS"] != null ? dataTab.Rows[0]["REMARKS"].ToString() : string.Empty;
            }

            // save interest rate
            dal.UpdateInterestRate("I", dt.GetChanges());
            dt.AcceptChanges();

            // save interest rate history
            if (pOrgIntEffDate != null && (pOrgIntEffDate.Value.Date != Convert.ToDateTime(cxDBDateEdit1.EditValue).Date))
            {
                if (!(isIns) && (pOrgIntRate != Convert.ToDecimal(cxDBCurrencyEdit1.EditValue)))
                {
                    var       id        = dal.RetrieveMaxInterestRateId();
                    DataTable dtHistory = new DataTable();
                    dtHistory.Columns.Add("COMPANY_ID");
                    dtHistory.Columns.Add("PREV_INTEREST_RATE");
                    dtHistory.Columns.Add("REMARKS");
                    dtHistory.Columns.Add("CREATED_BY");
                    dtHistory.Columns.Add("CREATED_ON");
                    dtHistory.Columns.Add("PREV_INT_EFFECTIVE_DATE");
                    dtHistory.Columns.Add("INTEREST_RATE_HISTORY_ID");

                    DataRow dr = dtHistory.NewRow();
                    dr["COMPANY_ID"]               = dt.Rows[0]["COMPANY_ID"];
                    dr["PREV_INTEREST_RATE"]       = pOrgIntRate;
                    dr["REMARKS"]                  = pOrgRemarks;
                    dr["CREATED_BY"]               = ProfitCashflow.oPcfDM.UserName;
                    dr["CREATED_ON"]               = DateTime.Now;
                    dr["PREV_INT_EFFECTIVE_DATE"]  = pOrgIntEffDate;
                    dr["INTEREST_RATE_HISTORY_ID"] = id;

                    dtHistory.Rows.Add(dr);
                    dal.UpdateInterestRate("H", dtHistory.GetChanges());
                }
            }

            isIns = false;
            cxImageComboBoxShowCompanies.Enabled = true;
            cxLookupComboBoxCompany.Enabled      = true;

            return(true);
        }