Example #1
0
        public SavingResult SaveNewRecord(tblPayrollMonth SaveModel)
        {
            SavingResult res = new SavingResult();

            using (dbVisionEntities db = new dbVisionEntities())
            {
                SaveModel.rcuid = (Model.CommonProperties.LoginInfo.LoggedinUser != null ? (int?)Model.CommonProperties.LoginInfo.LoggedinUser.UserID : null);
                SaveModel.rcdt  = DateTime.Now;
                db.tblPayrollMonths.Add(SaveModel);
                db.Entry(SaveModel).State = System.Data.Entity.EntityState.Added;

                //--
                try
                {
                    db.SaveChanges();
                    res.PrimeKeyValue   = SaveModel.PayrollMonthID;
                    res.ExecutionResult = eExecutionResult.CommitedSucessfuly;
                }
                catch (Exception ex)
                {
                    CommonFunctions.GetFinalError(res, ex);
                    return(res);
                }
            }
            return(res);
        }
Example #2
0
        public void FillValue()
        {
            tblPayrollMonth Record = DALObject.GetLatestPayrollMonthByCompanyID(Vision.Model.CommonProperties.LoginInfo.LoggedInCompany.CompanyID);

            if (Record != null)
            {
                txtPayrollStartDate.EditValue  = Record.PayrollMonthStartDate.ToShortDateString();
                txtPayrollEndDate.EditValue    = Record.PayrollMonthEndDate.ToShortDateString();
                txtPreviousMonthName.EditValue = Record.PayrollMonthName;

                txtNextMonthEndDate.EditValue   = Record.PayrollMonthEndDate.AddMonths(1).ToShortDateString();
                txtNextMonthStartDate.EditValue = Record.PayrollMonthEndDate.AddDays(1).ToShortDateString();
                txtNextMonthName.EditValue      = Record.PayrollMonth.AddMonths(1).ToString("MMMM-yyyy");
                //txtPayrollEndDate.EditValue = Record.PayrollMonthEndDate.AddMonths(1).ToShortDateString();
            }
        }
Example #3
0
        public override void SaveRecord(Model.SavingParemeter Paras)
        {
            DialogResult result = MessageBox.Show("Are you sure? you want to close current payroll month?", "Close Payroll month", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                tblPayrollMonth SaveModel = null;
                if (Paras.SavingInterface == SavingParemeter.eSavingInterface.AddNew)
                {
                    SaveModel = new tblPayrollMonth();
                }
                //SaveModel.tblCompany =
                SaveModel.CompanyID             = CommonProperties.LoginInfo.LoggedInCompany.CompanyID;
                SaveModel.PayrollMonthName      = txtNextMonthName.EditValue.ToString();
                SaveModel.PayrollMonth          = Convert.ToDateTime(txtNextMonthName.EditValue);
                SaveModel.PayrollMonthEndDate   = Convert.ToDateTime(txtNextMonthEndDate.EditValue);
                SaveModel.PayrollMonthStartDate = Convert.ToDateTime(txtNextMonthStartDate.EditValue);
                //SaveModel.rcdt = DateTime.Now;
                //SaveModel.rcuid = CommonProperties.LoginInfo.LoggedinUser.UserID;
                SavingParemeter SaveResult = new SavingParemeter();
                SaveResult.SavingResult = DALObject.SaveNewRecord(SaveModel);
                AfterSaving(SaveResult);
            }
        }
Example #4
0
        public override void FillSelectedRecordInContent(object RecordToFill)
        {
            tblCompany      EditingRecord       = DALObject.FindSaveModelByPrimeKey(((CompanyEditListModel)RecordToFill).CompanyID);
            tblPayrollMonth EditingPayrollMonth = PayrollMonthDAL.GetLatestPayrollMonthByCompanyID(((CompanyEditListModel)RecordToFill).CompanyID);

            bool editable = PayrollMonthDAL.IsPayrollMonthEditable(((CompanyEditListModel)RecordToFill).CompanyID);

            txtCode.Text        = EditingRecord.CompanyCode.ToString();
            txtCompanyName.Text = EditingRecord.CompanyName;

            lookupCurrency.EditValue = EditingRecord.CurrencyID;

            CompanyLogoSelectedFileName = EditingRecord.CompanyLogoFileName;

            if (System.IO.File.Exists(CompanyLogoSelectedFileName))
            {
                var x = Path.GetFullPath(CompanyLogoSelectedFileName);

                Image img;
                using (var bmpTemp = new Bitmap(CompanyLogoSelectedFileName))
                {
                    img = new Bitmap(bmpTemp);
                }

                peLogo.Image = img;
            }
            //CompanyLogoSelectedFileName = null;

            txtAddressLine1.Text = EditingRecord.Address1;
            txtAddressLine2.Text = EditingRecord.Address2;
            txtAddressLine3.Text = EditingRecord.Address3;

            lookupCity.EditValue = EditingRecord.CityID;
            txtAddressLine1.Text = EditingRecord.Address1;
            lookupCity.EditValue = EditingRecord.CityID;
            txtPin.Text          = EditingRecord.PIN;

            txtPhoneNo2.Text  = EditingRecord.Phone2;
            txtMobileNo2.Text = EditingRecord.MobileNo2;

            txtEMailID.Text = EditingRecord.EMailID;
            txtWebsite.Text = EditingRecord.Website;
            deBusinessStartedFrom.EditValue = EditingRecord.BusinessStartedFrom;

            txtPhone1.Text    = EditingRecord.Phone1;
            txtPhoneNo2.Text  = EditingRecord.Phone2;
            txtMobileNo1.Text = EditingRecord.MobileNo1;
            txtMobileNo2.Text = EditingRecord.MobileNo2;
            txtEMailID.Text   = EditingRecord.EMailID;
            txtWebsite.Text   = EditingRecord.Website;

            txtIncorporationNo.Text       = EditingRecord.IncorporationNo;
            deIncorporationDate.EditValue = EditingRecord.IncorporationDate;
            txtPINNo.Text      = EditingRecord.PINNo_RegNo;
            txtNSSFNo.Text     = EditingRecord.NSSFNo;
            txtNHIFNo.Text     = EditingRecord.NHIFNo;
            txtPFNo.Text       = EditingRecord.PFNo;
            txtSACCORegNo.Text = EditingRecord.SaccoRegNo;

            txtBank1_AcNo.Text       = EditingRecord.Bank1_AccountNo;
            txtBank1_Name.Text       = EditingRecord.Bank1_Name;
            txtBank1_BranchName.Text = EditingRecord.Bank1_BranchName;
            txtBank1_Currency.Text   = EditingRecord.Bank1_Currency;

            txtBank2_AcNo.Text       = EditingRecord.Bank2_AccountNo;
            txtBank2_Name.Text       = EditingRecord.Bank2_Name;
            txtBank2_BranchName.Text = EditingRecord.Bank2_BranchName;
            txtBank2_Currency.Text   = EditingRecord.Bank2_Currency;

            txtBank3_AcNo.Text       = EditingRecord.Bank3_AccountNo;
            txtBank3_Name.Text       = EditingRecord.Bank3_Name;
            txtBank3_BranchName.Text = EditingRecord.Bank3_BranchName;
            txtBank3_Currency.Text   = EditingRecord.Bank3_Currency;

            if (EditingPayrollMonth != null)
            {
                payRollStartDate.Text         = EditingPayrollMonth.PayrollMonthStartDate.ToShortDateString();
                payRollEndDate.Text           = EditingPayrollMonth.PayrollMonthEndDate.ToShortDateString();
                payrollMonthDateEdit.DateTime = EditingPayrollMonth.PayrollMonthEndDate.Date;
            }

            if (editable == false)
            {
                lcgPayrollMonth.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
            }
            else
            {
                lcgPayrollMonth.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
            }
        }
Example #5
0
        public override void SaveRecord(Model.SavingParemeter Paras)
        {
            DAL.tblCompany SaveModel = null;

            DAL.tblPayrollMonth PayRollMonth = null;


            if (Paras.SavingInterface == SavingParemeter.eSavingInterface.AddNew || EditRecordDataSource == null)
            {
                SaveModel = new tblCompany();
            }
            else
            {
                SaveModel = DALObject.FindSaveModelByPrimeKey(((CompanyEditListModel)EditRecordDataSource).CompanyID);

                PayRollMonth = PayrollMonthDAL.GetLatestPayrollMonthByCompanyID(((CompanyEditListModel)EditRecordDataSource).CompanyID);
                //DO SOMETHING HERE FOR PAYROLLMONTH
                if (SaveModel == null)
                {
                    Paras.SavingResult = new SavingResult();
                    Paras.SavingResult.ExecutionResult = eExecutionResult.ValidationError;
                    Paras.SavingResult.ValidationError = "Can not edit. Selected record not found, it may be deleted by another user.";
                    return;
                }
            }

            // on Creating new company or while editing there is no month exists.
            if (PayRollMonth == null)
            {
                PayRollMonth = new tblPayrollMonth()
                {
                    tblCompany = SaveModel
                };
            }


            SaveModel.CompanyCode = Model.CommonFunctions.ParseInt(txtCode.Text) + 1;
            SaveModel.CompanyName = txtCompanyName.Text;
            if (Paras.SavingInterface == SavingParemeter.eSavingInterface.AddNew)
            {
                SaveModel.BusinessStartedFrom = (DateTime)deBusinessStartedFrom.EditValue;
            }
            SaveModel.CurrencyID = (int)lookupCurrency.EditValue;
            //SaveModel.CompanyLogoFileName = CompanyLogoSelectedFileName;

            SaveModel.Address1 = txtAddressLine1.Text;
            SaveModel.Address2 = txtAddressLine2.Text;
            SaveModel.Address3 = txtAddressLine3.Text;

            SaveModel.CityID = (int)lookupCity.EditValue;
            SaveModel.PIN    = txtPin.Text;

            SaveModel.Phone1    = txtPhone1.Text;
            SaveModel.Phone2    = txtPhoneNo2.Text;
            SaveModel.MobileNo1 = txtMobileNo1.Text;
            SaveModel.MobileNo2 = txtMobileNo2.Text;
            SaveModel.EMailID   = txtEMailID.Text;
            SaveModel.Website   = txtWebsite.Text;

            SaveModel.IncorporationNo   = txtIncorporationNo.Text;
            SaveModel.IncorporationDate = deIncorporationDate.DateTime;
            SaveModel.PINNo_RegNo       = txtPINNo.Text;
            SaveModel.NSSFNo            = txtNSSFNo.Text;
            SaveModel.NHIFNo            = txtNHIFNo.Text;
            SaveModel.PFNo       = txtPFNo.Text;
            SaveModel.SaccoRegNo = txtSACCORegNo.Text;

            SaveModel.Bank1_AccountNo  = txtBank1_AcNo.Text;
            SaveModel.Bank1_Name       = txtBank1_Name.Text;
            SaveModel.Bank1_BranchName = txtBank1_BranchName.Text;
            SaveModel.Bank1_Currency   = txtBank1_Currency.Text;

            SaveModel.Bank2_AccountNo  = txtBank2_AcNo.Text;
            SaveModel.Bank2_Name       = txtBank2_Name.Text;
            SaveModel.Bank2_BranchName = txtBank2_BranchName.Text;
            SaveModel.Bank2_Currency   = txtBank2_Currency.Text;

            SaveModel.Bank3_AccountNo  = txtBank3_AcNo.Text;
            SaveModel.Bank3_Name       = txtBank3_Name.Text;
            SaveModel.Bank3_BranchName = txtBank3_BranchName.Text;
            SaveModel.Bank3_Currency   = txtBank3_Currency.Text;

            PayRollMonth.PayrollMonthStartDate = payRollStartDate.DateTime;
            PayRollMonth.PayrollMonthEndDate   = payRollEndDate.DateTime;
            PayRollMonth.PayrollMonthName      = payRollEndDate.DateTime.ToString("MMMM-yyyy"); //this is not user selectable
            PayRollMonth.PayrollMonth          = payRollEndDate.DateTime.Date;

            long?CopySettingsFromCompanyID = null;

            //if(lcgSettings.Visibility != DevExpress.XtraLayout.Utils.LayoutVisibility.Never)
            //{
            //    CopySettingsFromCompanyID = (long?)lookupCopySettingFromCompany.EditValue;
            //}

            /// In Editing if logo image is cleared
            if (SaveModel.CompanyLogoFileName != null && CompanyLogoSelectedFileName == null)
            {
                try
                {
                    File.Delete(SaveModel.CompanyLogoFileName);
                }
                catch (Exception) { }
                SaveModel.CompanyLogoFileName = null;
            }

            Paras.SavingResult = DALObject.SaveNewRecord(SaveModel, CopySettingsFromCompanyID, PayRollMonth);


            /// CompanyLogoSelectedFileName != null -- it means user has changed logo image
            if (CompanyLogoSelectedFileName != null &&
                Paras.SavingResult.ExecutionResult == eExecutionResult.CommitedSucessfuly &&
                SaveModel.CompanyLogoFileName != CompanyLogoSelectedFileName)
            {
                string LogoImageCopiedFileName = null;

                // to seperate both process file copy and saving file name in db, so that if exception occures than we can get in which part the exception occured
                bool IsFileCopied = false;

                // Copieng Image File
                if (System.IO.File.Exists(CompanyLogoSelectedFileName))
                {
                    string ImageDirectory = null;
                    if (CommonProperties.LoginInfo.SoftwareSettings.DocumentLocation_EmployeeImage != null)
                    {
                        ImageDirectory = CommonProperties.LoginInfo.SoftwareSettings.DocumentLocation_EmployeeImage + @"\Logo\";
                    }
                    else
                    {
                        ImageDirectory = @"\..\IMAGES\Logo\";
                        System.IO.Directory.CreateDirectory(ImageDirectory);
                    }

                    if (!Directory.Exists(ImageDirectory))
                    {
                        Directory.CreateDirectory(ImageDirectory);
                    }

                    LogoImageCopiedFileName = ImageDirectory + "" + ((int)Paras.SavingResult.PrimeKeyValue).ToString() + System.IO.Path.GetExtension(CompanyLogoSelectedFileName);
                    IsFileCopied            = false;

                    try
                    {
                        if (File.Exists(LogoImageCopiedFileName))
                        {
                            File.Delete(LogoImageCopiedFileName);
                        }
                        File.Copy(CompanyLogoSelectedFileName, LogoImageCopiedFileName);
                        IsFileCopied = true;
                    }
                    catch (Exception ex)
                    {
                        ex = DAL.CommonFunctions.GetFinalError(ex);
                        Paras.SavingResult.MessageAfterSave = "Error while trying to copy log image file. Please check following error \r\n" + ex.Message;
                    }

                    // if file successfully copied only then save file name
                    if (IsFileCopied)
                    {
                        SavingResult res = DALObject.SaveLogoFileName((int)Paras.SavingResult.PrimeKeyValue, LogoImageCopiedFileName);
                        if (res.ExecutionResult != eExecutionResult.CommitedSucessfuly && res.ExecutionResult != eExecutionResult.NotExecutedYet)
                        {
                            if (res.ExecutionResult == eExecutionResult.ErrorWhileExecuting)
                            {
                                Paras.SavingResult.MessageAfterSave = "Error while saving logo image file name.\r\n" + (res.Exception != null ? res.Exception.Message : "");
                            }
                            else if (res.ExecutionResult == eExecutionResult.ValidationError)
                            {
                                Paras.SavingResult.MessageAfterSave = "Error while saving logo image file name \r\n" + res.ValidationError;
                            }
                        }
                    }
                }
            }

            base.SaveRecord(Paras);
        }
Example #6
0
        public SavingResult SaveNewRecord(tblCompany SaveModel, long?CopySettingsFromCompanyID, tblPayrollMonth PayRollMonth)
        {
            SavingResult res = new SavingResult();

            //-- Perform Validation
            //res.ExecutionResult = eExecutionResult.ValidationError;
            //res.ValidationError = "Validation error message";
            //return res;

            //--
            using (dbVisionEntities db = new dbVisionEntities())
            {
                //tblCompany SaveModel;
                if (SaveModel.CompanyName == "")
                {
                    res.ValidationError = "Can not accept blank value. Please enter Country Name.";
                    res.ExecutionResult = eExecutionResult.ValidationError;
                    return(res);
                }
                else if (IsDuplicateRecord(SaveModel.CompanyName, SaveModel.CompanyID, db))
                {
                    res.ValidationError = "Can not accept duplicate value. The Company Name is already exists.";
                    res.ExecutionResult = eExecutionResult.ValidationError;
                    return(res);
                }

                bool IsNewCompany = (SaveModel.CompanyID == 0);
                //tblAdditionalItemMaster RoundOffItem = null;
                //tblPriceList DefaultPriceList = null;
                //tblAccount CashAccount = null;

                if (SaveModel.CompanyID == 0) // New Entry
                {
                    SaveModel.rcuid = (Model.CommonProperties.LoginInfo.LoggedinUser != null ?
                                       (int?)Model.CommonProperties.LoginInfo.LoggedinUser.UserID : null);
                    SaveModel.rcdt = DateTime.Now;
                    db.tblCompanies.Add(SaveModel);

                    db.tblFinPeriods.Add(new tblFinPeriod()
                    {
                        FinPeriodName = SaveModel.BusinessStartedFrom.Date.Year.ToString() + "-*",
                        FinPeriodFrom = SaveModel.BusinessStartedFrom.Date,
                        tblCompany    = SaveModel,
                        rcdt          = DateTime.Now
                    });
                }
                else
                {
                    SaveModel.reuid = Model.CommonProperties.LoginInfo.LoggedinUser.UserID;
                    SaveModel.redt  = DateTime.Now;
                    db.tblCompanies.Attach(SaveModel);
                    db.Entry(SaveModel).State = System.Data.Entity.EntityState.Modified;
                }

                if (PayRollMonth.PayrollMonthID == 0)
                {
                    PayRollMonth.tblCompany = SaveModel;
                    PayRollMonth.rcdt       = DateTime.Now;
                    PayRollMonth.rcuid      = CommonProperties.LoginInfo.LoggedinUser.UserID;

                    db.tblPayrollMonths.Add(PayRollMonth);
                }
                else
                {
                    PayRollMonth.redt  = DateTime.Now;
                    PayRollMonth.reuid = CommonProperties.LoginInfo.LoggedinUser.UserID;

                    db.tblPayrollMonths.Attach(PayRollMonth);
                    db.Entry(PayRollMonth).State = System.Data.Entity.EntityState.Modified;
                }

                //--
                try
                {
                    db.SaveChanges();
                    res.PrimeKeyValue   = SaveModel.CompanyID;
                    res.ExecutionResult = eExecutionResult.CommitedSucessfuly;
                }
                catch (Exception ex)
                {
                    CommonFunctions.GetFinalError(res, ex);
                    return(res);
                }

                //DAL.Settings.SettingsDAL SettingDALObj = new SettingsDAL();
                //if (RoundOffItem != null)
                //{
                //    // If completed successfully and new company created then move newly added round off item's id in setting
                //    SettingDALObj.SaveSettingL1("RoundOffAddLessID", RoundOffItem.AdditionaItemID, SaveModel.CompanyID);
                //    SettingDALObj.SaveSettingL1("ApplyRoundOff", true, SaveModel.CompanyID);
                //}
                //if(CashAccount != null)
                //{
                //    // Default cash Account id
                //    SettingDALObj.SaveSettingL1("SaleInvoiceDefaultAccountID", CashAccount.AccountID, SaveModel.CompanyID);
                //}
            }
            return(res);
        }