public bool DeleteProject(int ProjectID, int deletedBy) { try { TBL_MP_PMC_ProjectMaster model = _dbContext.TBL_MP_PMC_ProjectMaster.Where(x => x.PK_ProjectID == ProjectID).FirstOrDefault(); if (model != null) { model.IsActive = false; model.IsDeleted = true; model.DeletedBy = deletedBy; model.DeleteDateTime = AppCommon.GetServerDateTime(); _dbContext.SaveChanges(); } } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "ServiceProject::DeleteProject", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(true); }
public string GetProjectSiteAddress(int projectID) { string strAddress = string.Empty; try { TBL_MP_PMC_ProjectMaster dbProject = _dbContext.TBL_MP_PMC_ProjectMaster.Where(x => x.PK_ProjectID == projectID).FirstOrDefault(); int SiteAddressID = dbProject.SiteClientAddressID; Tbl_MP_Master_Party_Address dbAddress = _dbContext.Tbl_MP_Master_Party_Address.Where(x => x.PK_AddressID == SiteAddressID).FirstOrDefault(); strAddress = dbAddress.Address; strAddress += string.Format("\n{0} {1}, {2}", dbAddress.TBL_MP_Master_City.CityName, dbAddress.TBL_MP_Master_State.StateName, dbAddress.TBL_MP_Master_Country.CountryName ); } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "ServiceProject::GetProjectSiteAddress", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(strAddress); }
private void btnOK_Click(object sender, EventArgs e) { TBL_MP_PMC_ProjectMaster model = null; ServiceProject serviceProject = new ServiceProject(); try { if (!this.ValidateChildren()) { return; } if (this.ProjectID == 0) { model = new TBL_MP_PMC_ProjectMaster(); } else { model = serviceProject.GetProjectDBInfoByID(this.ProjectID); } #region GATHER DATA INTO MODEL FROM VIEW model.ProjectNumber = txtProjectNo.Text; model.ProjectName = txtProjectName.Text.Trim(); model.ProjectDate = dtProjectDate.Value; model.StartDate = dtProjectStartDate.Value; model.EndDate = dtProjectEndDate.Value; model.FK_ProjectStatusID = ((SelectListItem)cboProjectStatus.SelectedItem).ID; model.BillingClientID = selectedBillingClientID; model.BillingClientAddressID = selectedBillingAddressID; model.SiteClientID = selectedSiteClientID; model.SiteClientAddressID = selectedSiteAddressID; #endregion if (this.ProjectID == 0) { model.FK_CompanyID = Program.CURR_USER.CompanyID; model.FK_YearID = Program.CURR_USER.FinYearID; model.FK_BranchID = Program.CURR_USER.BranchID; model.CreatedBy = Program.CURR_USER.EmployeeID; model.CreatedDatetime = AppCommon.GetServerDateTime(); this.ProjectID = serviceProject.AddNewProject(model); } else { model.ModifiedBy = Program.CURR_USER.EmployeeID; model.ModifiedDatetime = AppCommon.GetServerDateTime(); serviceProject.UpdateProject(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, "frmAddEditProject::btnOK_Click", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public bool UpdateProject(TBL_MP_PMC_ProjectMaster model) { bool result = false; try { TBL_MP_PMC_ProjectMaster dbModel = _dbContext.TBL_MP_PMC_ProjectMaster.Where(x => x.PK_ProjectID == model.PK_ProjectID).FirstOrDefault(); if (dbModel != null) { dbModel.ProjectName = model.ProjectName; dbModel.ProjectDate = model.ProjectDate; dbModel.StartDate = model.StartDate; dbModel.EndDate = model.EndDate; dbModel.BillingClientID = model.BillingClientID; dbModel.BillingClientAddressID = model.BillingClientAddressID; dbModel.SiteClientID = model.SiteClientID; dbModel.SiteClientAddressID = model.SiteClientAddressID; dbModel.ModifiedBy = model.ModifiedBy; dbModel.ModifiedDatetime = AppCommon.GetServerDateTime(); _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, "ServiceProject::UpdateProject", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(result); }
public ProjectGeneralInfo GetProjectGeneralInfo(int ProjID) { ProjectGeneralInfo model = null; try { TBL_MP_PMC_ProjectMaster dbmodel = _dbContext.TBL_MP_PMC_ProjectMaster.Where(x => x.PK_ProjectID == ProjID).FirstOrDefault(); if (dbmodel != null) { model = new ProjectGeneralInfo(); model.ProjectID = dbmodel.PK_ProjectID; model.ProjectCode = dbmodel.ProjectNumber; model.ProjectName = dbmodel.ProjectName; if (dbmodel.ProjectDate != null) { model.EntryDate = (DateTime)dbmodel.ProjectDate; } else { model.EntryDate = null; } if (dbmodel.StartDate != null) { model.StartDate = (DateTime)dbmodel.StartDate; } else { model.StartDate = null; } if (dbmodel.EndDate != null) { model.EndDate = (DateTime)dbmodel.EndDate; } else { model.EndDate = null; } model.ProjectStatus = dbmodel.FK_ProjectStatusID.ToString(); model.BillingClientID = (int)dbmodel.BillingClientID; model.BillingClientAddressID = dbmodel.BillingClientAddressID; model.SiteClientID = (int)dbmodel.SiteClientID; model.SiteClientAddressID = dbmodel.SiteClientAddressID; model.IsActive = dbmodel.IsActive; } } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "ServiceProject::GetProjectGeneralInfo", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(model); }
private void ScatterData() { this.Cursor = Cursors.WaitCursor; try { TBL_MP_PMC_ProjectMaster model = (new ServiceProject()).GetProjectDBInfoByID(this.ProjectID); if (model != null) { txtProjectNo.Text = model.ProjectNumber; txtProjectName.Text = model.ProjectName; dtProjectDate.Value = model.ProjectDate; dtProjectStartDate.Value = model.StartDate; dtProjectEndDate.Value = model.EndDate; cboProjectStatus.SelectedItem = ((List <SelectListItem>)cboProjectStatus.DataSource).Where(x => x.ID == model.FK_ProjectStatusID).FirstOrDefault(); cboBillingClient.SelectedItem = ((List <SelectListItem>)cboBillingClient.DataSource).Where(x => x.ID == model.BillingClientID).FirstOrDefault(); this.selectedBillingClientID = (int)model.BillingClientID; PopulateBillingClientAddresses(); foreach (DataGridViewRow row in gridClientBillingAddress.Rows) { if (int.Parse(row.Cells["ID"].Value.ToString()) == model.BillingClientAddressID) { row.Cells["ISActive"].Value = true; this.selectedBillingAddressID = model.BillingClientAddressID; } } cboSiteClient.SelectedItem = ((List <SelectListItem>)cboSiteClient.DataSource).Where(x => x.ID == model.SiteClientID).FirstOrDefault(); this.selectedSiteClientID = (int)model.SiteClientID; PopulateSiteClientAddresses(); foreach (DataGridViewRow row in gridClientSiteAddress.Rows) { if (int.Parse(row.Cells["ID"].Value.ToString()) == model.SiteClientAddressID) { row.Cells["ISActive"].Value = true; this.selectedSiteAddressID = model.SiteClientAddressID; } } } } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "frmAddEditProject::Scatterdata", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.Cursor = Cursors.Default; }
public TBL_MP_PMC_ProjectMaster GetProjectDBInfoByID(int projectID) { TBL_MP_PMC_ProjectMaster model = null; try { model = _dbContext.TBL_MP_PMC_ProjectMaster.Where(x => x.PK_ProjectID == projectID).FirstOrDefault(); } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "ServiceProject::GetProjectDBInfoByID", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(model); }
public int AddNewProject(TBL_MP_PMC_ProjectMaster model) { int newID = 0; try { //model.ProjectNumber = this.GenerateNewProjectNumber(model.FK_YearID, model.FK_BranchID, model.FK_CompanyID); _dbContext.TBL_MP_PMC_ProjectMaster.Add(model); _dbContext.SaveChanges(); newID = model.PK_ProjectID; } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "ServiceProject::AddNewProject", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(newID); }
public bool SetProjectGeneralInfo(ProjectGeneralInfo model) { bool result = false; try { TBL_MP_PMC_ProjectMaster dbModel = _dbContext.TBL_MP_PMC_ProjectMaster.Where(x => x.PK_ProjectID == model.ProjectID).FirstOrDefault(); if (dbModel != null) { dbModel.ProjectNumber = model.ProjectCode; dbModel.ProjectName = model.ProjectName; dbModel.ProjectDate = (DateTime)model.EntryDate; dbModel.StartDate = (DateTime)model.StartDate; dbModel.EndDate = (DateTime)model.EndDate; dbModel.BillingClientID = model.BillingClientID; dbModel.BillingClientAddressID = model.BillingClientAddressID; dbModel.SiteClientID = model.SiteClientID; dbModel.SiteClientAddressID = model.SiteClientAddressID; dbModel.FK_ProjectStatusID = int.Parse(model.ProjectStatus); dbModel.IsActive = model.IsActive; _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, "ServiceProject::SetProjectGeneralInfo", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(result); }
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); }
public void PopulateProjectGeneralInfo() { this.Cursor = Cursors.WaitCursor; Application.UseWaitCursor = true; ServiceProject _service = new ServiceProject(); try { SelectListItem selItem = null; List <SelectListItem> lst = _service.GetAllProjectStatuses(); TBL_MP_PMC_ProjectMaster model = (new ServiceProject()).GetProjectDBInfoByID(this.SelectedProjectID); if (model != null) { headerGroupMain.ValuesPrimary.Heading = model.ProjectNumber; selItem = lst.Where(x => x.ID == model.FK_ProjectStatusID).FirstOrDefault(); txtStatus.Text = selItem.Description; txtProjectNo.Text = model.ProjectNumber; txtProjectName.Text = model.ProjectName; dtProjectDate.Value = (DateTime)model.ProjectDate; dtProjectStartDate.Value = (DateTime)model.StartDate; dtProjectEndDate.Value = (DateTime)model.EndDate; // txtBillingAddress.Text = Project_generalInfo.BillingClientAddressID.ToString(); // txtClientAddress.Text = Project_generalInfo.SiteClientAddressID.ToString(); ServiceProject serviceProject = new ServiceProject(); txtBillingAddress.Text = serviceProject.GetProjectBillingAddress((int)model.PK_ProjectID); txtClientAddress.Text = serviceProject.GetProjectSiteAddress((int)model.PK_ProjectID); lblCreatedDateTime.Text = model.CreatedDatetime.ToString(); lblModifiedDateTime.Text = model.ModifiedDatetime.ToString(); ServiceEmployee emp = new ServiceEmployee(); List <SelectListItem> lst1 = emp.GetAllEmployees(); selItem = lst1.Where(x => x.ID == model.CreatedBy).FirstOrDefault(); lblCreatedBy.Text = selItem.Description; List <SelectListItem> lst2 = emp.GetAllEmployees(); selItem = lst2.Where(x => x.ID == model.ModifiedBy).FirstOrDefault(); lblModifiedBy.Text = selItem.Description; TBL_MP_Admin_Company_Master myComp = (new ServiceMASTERS()).MyCompanyInfo(); if (myComp != null) { txtCompanyAddress.Text = myComp.Address; } } else { txtProjectNo.Text = txtProjectName.Text = txtStatus.Text = txtBillingAddress.Text = txtClientAddress.Text = txtCompanyAddress.Text = string.Empty; dtProjectDate.Checked = dtProjectStartDate.Checked = dtProjectEndDate.Checked = false; } } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "ControlProjectGeneralInfo::PopulateProjectGeneralInfo", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.Cursor = Cursors.Default; Application.UseWaitCursor = false; }