private void ScatterData()
 {
     try
     {
         TBL_MP_Admin_VoucherNoSetup model = (new ServiceVoucherNoSetup()).GetVoucherSetupDBRecordByID(this.pkID);
         if (model != null)
         {
             cboYears.SelectedItem           = ((List <SelectListItem>)cboYears.DataSource).Where(x => x.ID == model.Fk_YearID).FirstOrDefault();
             txtNoPrefix.Text                = model.NoPrefix.ToString();
             txtSeparator.Text               = txtSeparatorSuffix.Text = model.NoSeperator;
             txtNoPadding.Text               = model.NoPad.ToString();
             txtNoPostFix.Text               = model.NoPostfix;
             txtVoucherNoPreview.Text        = model.VoucherNoPreview;
             chkIs_continuedNextYear.Checked = model.Is_NoContinuedNextYear;
             if (model.NoStartingFrom != null)
             {
                 txtNoStartingFrom.Text = model.NoStartingFrom.ToString();
             }
         }
     }
     catch (Exception ex)
     {
         string errMessage = ex.Message;
         if (ex.InnerException != null)
         {
             errMessage += string.Format("\n{0}", ex.InnerException.Message);
         }
         MessageBox.Show(errMessage, "frmAddEditVoucherNoSetup::ScatterData", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Ejemplo n.º 2
0
        public bool UpdateVoucherNoSetup(TBL_MP_Admin_VoucherNoSetup model)
        {
            bool result = false;

            try
            {
                TBL_MP_Admin_VoucherNoSetup dbModel = _dbContext.TBL_MP_Admin_VoucherNoSetup.Where(x => x.PK_VoucherSetupID == model.PK_VoucherSetupID).FirstOrDefault();
                if (dbModel != null)
                {
                    dbModel.fk_FormID              = model.fk_FormID;
                    dbModel.Fk_YearID              = model.Fk_YearID;
                    dbModel.NoPrefix               = model.NoPrefix;
                    dbModel.NoSeperator            = model.NoSeperator;
                    dbModel.NoPad                  = model.NoPad;
                    dbModel.NoPostfix              = model.NoPostfix;
                    dbModel.Is_NoContinuedNextYear = model.Is_NoContinuedNextYear;
                    dbModel.NoStartingFrom         = model.NoStartingFrom;

                    dbModel.LastModifiedBy   = model.LastModifiedBy;
                    dbModel.LastModifiedDate = model.LastModifiedDate;
                    _dbContext.SaveChanges();
                    result = true;
                }
            }
            catch (Exception ex)
            {
                string errMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errMessage += string.Format("\n{0}", ex.InnerException.Message);
                }
                MessageBox.Show(errMessage, "ServiceVoucherNoSetup::UpdateVoucherNoSetup", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(result);
        }
Ejemplo n.º 3
0
        public TBL_MP_Admin_VoucherNoSetup GetVoucherSetupDBRecordByID(int pkID)
        {
            TBL_MP_Admin_VoucherNoSetup model = null;

            try
            {
                model = _dbContext.TBL_MP_Admin_VoucherNoSetup.Where(x => x.PK_VoucherSetupID == pkID).FirstOrDefault();
            }
            catch (Exception ex)
            {
                string errMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errMessage += string.Format("\n{0}", ex.InnerException.Message);
                }
                MessageBox.Show(errMessage, "ServiceVoucherNoSetup::GetVoucherSetupDBRecordByID", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(model);
        }
Ejemplo n.º 4
0
        public int AddNewVoucherNoSetup(TBL_MP_Admin_VoucherNoSetup model)
        {
            int newID = 0;

            try
            {
                _dbContext.TBL_MP_Admin_VoucherNoSetup.Add(model);
                _dbContext.SaveChanges();
                newID = model.PK_VoucherSetupID;
            }
            catch (Exception ex)
            {
                string errMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errMessage += string.Format("\n{0}", ex.InnerException.Message);
                }
                MessageBox.Show(errMessage, "ServiceVoucherNoSetup::AddNewVoucherNoSetup", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(newID);
        }
Ejemplo n.º 5
0
        public string GenerateNewProjectNumber(int currFinYear, int currBrachID, int companyID)
        {
            string keyCode = string.Empty;
            int    intPreviousYearCount = 0;
            int    cnt;
            string strNumber;
            string strQuery = string.Empty;

            try
            {
                TBL_MP_Admin_VoucherNoSetup objVoucherSetup = (from xx in _dbContext.TBL_MP_Admin_VoucherNoSetup
                                                               where xx.fk_FormID == (int)DB_FORM_IDs.PROJECT &&
                                                               xx.Fk_YearID == currFinYear &&
                                                               xx.Fk_BranchID == currBrachID
                                                               select xx).FirstOrDefault();

                strQuery = string.Format("SELECT count(*) FROM TBL_MP_PMC_ProjectMaster WHERE ProjectNumber NOT LIKE '%AMMEND%' and FK_YearID={0} AND FK_BranchID={1} AND FK_CompanyID={2}",
                                         currFinYear, currBrachID, companyID);
                cnt = _dbContext.Database.SqlQuery <int>(strQuery).FirstOrDefault();
                // IF NO. CONTINUED FROM PREVIOUS YEAR GENERATE NEXT NUMBER BY REFEREING PREVIOUS YEAR MAX. NUMBER
                if (objVoucherSetup.Is_NoContinuedNextYear)
                {
                    TBL_MP_Admin_VoucherNoSetup objVoucherSetupPrevYear = (from xx in _dbContext.TBL_MP_Admin_VoucherNoSetup
                                                                           where xx.fk_FormID == (int)DB_FORM_IDs.PROJECT &&
                                                                           xx.Fk_YearID == currFinYear - 1 &&
                                                                           xx.Fk_BranchID == currBrachID
                                                                           select xx).FirstOrDefault();
                    TBL_MP_PMC_ProjectMaster lastProjectPrevYear = (from xx in _dbContext.TBL_MP_PMC_ProjectMaster
                                                                    where xx.FK_YearID == currFinYear - 1 &&
                                                                    xx.FK_BranchID == currBrachID &&
                                                                    xx.FK_CompanyID == companyID
                                                                    orderby xx.CreatedDatetime descending
                                                                    select xx).FirstOrDefault();
                    if (lastProjectPrevYear != null)
                    {
                        string lstnumber = lastProjectPrevYear.ProjectNumber.Replace(objVoucherSetupPrevYear.NoPrefix, "").Replace(objVoucherSetupPrevYear.NoPostfix, "").Replace(objVoucherSetupPrevYear.NoSeperator, "");
                        intPreviousYearCount = int.Parse(lstnumber);
                    }
                    else
                    {
                        intPreviousYearCount = 1;
                    }

                    cnt += intPreviousYearCount;
                }
                else
                {
                    cnt += (int)objVoucherSetup.NoStartingFrom;
                }

                strNumber = cnt.ToString().PadLeft(objVoucherSetup.NoPad, '0');
                //0083

                keyCode += objVoucherSetup.NoPrefix + objVoucherSetup.NoSeperator + strNumber + objVoucherSetup.NoSeperator + objVoucherSetup.NoPostfix;
                // XL/SO/0083/2018-19
            }
            catch (Exception ex)
            {
                string errMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errMessage += string.Format("\n{0}", ex.InnerException.Message);
                }
                MessageBox.Show(errMessage, "ServiceProject::GenerateNewProjectNumber", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(keyCode);
        }
Ejemplo n.º 6
0
        public string GenerateNewLoanRequestNumber(int currFinYear, int currBrachID, int companyID)
        {
            string keyCode = string.Empty;
            int    intPreviousYearCount = 0;
            int    cnt;
            string strNumber;
            string strQuery = string.Empty;

            try
            {
                // 0123
                TBL_MP_Admin_VoucherNoSetup objAdvanceSetup = (from xx in _dbContext.TBL_MP_Admin_VoucherNoSetup
                                                               where xx.fk_FormID == (int)DB_FORM_IDs.LOAN_REQUEST &&
                                                               xx.Fk_YearID == currFinYear &&
                                                               xx.Fk_BranchID == currBrachID
                                                               select xx).FirstOrDefault();


                if (objAdvanceSetup == null)
                {
                    string strMessage = "Unable to locate Voucher No. setup for the selected Financial Year or Branch";
                    MessageBox.Show(strMessage, "Caution", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(string.Empty);
                }

                strQuery = string.Format("SELECT count(*) FROM TBL_MP_HR_LoanRequestApplication WHERE FK_YearID={0} AND FK_BranchID={1} AND FK_CompanyID={2}",
                                         currFinYear, currBrachID, companyID);
                cnt = _dbContext.Database.SqlQuery <int>(strQuery).FirstOrDefault();
                // IF NO. CONTINUED FROM PREVIOUS YEAR GENERATE NEXT NUMBER BY REFEREING PREVIOUS YEAR MAX. NUMBER
                if (objAdvanceSetup.Is_NoContinuedNextYear)
                {
                    TBL_MP_Admin_VoucherNoSetup objVoucherSetupPrevYear = (from xx in _dbContext.TBL_MP_Admin_VoucherNoSetup
                                                                           where xx.fk_FormID == (int)DB_FORM_IDs.LOAN_REQUEST &&
                                                                           xx.Fk_YearID == currFinYear - 1 &&
                                                                           xx.Fk_BranchID == currBrachID
                                                                           select xx).FirstOrDefault();
                    TBL_MP_HR_LoanRequestApplication lastLeavePrevYear = (from xx in _dbContext.TBL_MP_HR_LoanRequestApplication
                                                                          where xx.FK_YearID == currFinYear - 1 &&
                                                                          xx.FK_BranchID == currBrachID &&
                                                                          xx.FK_CompanyID == companyID
                                                                          orderby xx.LoanRequestDate descending
                                                                          select xx).FirstOrDefault();
                    if (lastLeavePrevYear != null)
                    {
                        string lstnumber = lastLeavePrevYear.LoanRequestNo.Replace(objVoucherSetupPrevYear.NoPrefix, "").Replace(objVoucherSetupPrevYear.NoPostfix, "").Replace(objVoucherSetupPrevYear.NoSeperator, "");
                        intPreviousYearCount = int.Parse(lstnumber);
                    }
                    else
                    {
                        intPreviousYearCount = 1;
                    }

                    cnt += intPreviousYearCount;
                }
                else
                {
                    cnt += (int)objAdvanceSetup.NoStartingFrom;
                }

                strNumber = cnt.ToString().PadLeft(objAdvanceSetup.NoPad, '0');
                //0083

                keyCode += objAdvanceSetup.NoPrefix + objAdvanceSetup.NoSeperator + strNumber + objAdvanceSetup.NoSeperator + objAdvanceSetup.NoPostfix;
                // XL/SO/0083/2018-19
            }
            catch (Exception ex)
            {
                string errMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errMessage += string.Format("\n{0}", ex.InnerException.Message);
                }
                MessageBox.Show(errMessage, "ServiceLoanRequest::GenerateNewLoanRequestNumber", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(keyCode);
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            TBL_MP_Admin_VoucherNoSetup model    = null;
            ServiceVoucherNoSetup       _service = new ServiceVoucherNoSetup();

            try
            {
                errorProvider1.Clear();
                if (!this.ValidateChildren())
                {
                    return;
                }
                if (pkID == 0)
                {
                    model = new TBL_MP_Admin_VoucherNoSetup();
                }
                else
                {
                    model = _service.GetVoucherSetupDBRecordByID(this.pkID);
                }

                //gather data from controls inot model
                model.fk_FormID              = this.FORM_ID;
                model.Fk_YearID              = ((SelectListItem)cboYears.SelectedItem).ID;
                model.NoPrefix               = txtNoPrefix.Text;
                model.NoSeperator            = txtSeparator.Text;
                model.NoPad                  = int.Parse(txtNoPadding.Text);
                model.NoPostfix              = txtNoPostFix.Text;
                model.VoucherNoPreview       = txtVoucherNoPreview.Text;
                model.Is_NoContinuedNextYear = chkIs_continuedNextYear.Checked;

                if (chkIs_continuedNextYear.Checked)
                {
                    model.NoStartingFrom = null;
                }
                else
                {
                    model.NoStartingFrom = int.Parse(txtNoStartingFrom.Text);
                }

                if (pkID == 0)
                {
                    model.FK_PreparedBy   = Program.CURR_USER.EmployeeID;
                    model.CreatedDatetime = AppCommon.GetServerDateTime();
                    model.Fk_BranchID     = Program.CURR_USER.BranchID;
                    _service.AddNewVoucherNoSetup(model);
                }
                else
                {
                    model.LastModifiedBy   = Program.CURR_USER.EmployeeID;
                    model.LastModifiedDate = AppCommon.GetServerDateTime();
                    _service.UpdateVoucherNoSetup(model);
                }

                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                string errMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errMessage += string.Format("\n{0}", ex.InnerException.Message);
                }
                MessageBox.Show(errMessage, "frmAddEditVoucherNoSetup::btnSave_Click", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }