private void LoadDropDown() { try { List <Segment> lstSegment = new SegmentDAL().GetSegments().Where(x => x.Status == "A" && x.AccountCodeFlag == false).OrderBy(x => x.SegmentOrder).ToList(); gvSegmentDLLs.DataSource = lstSegment; gvSegmentDLLs.DataBind(); //GridView: Period List <PeriodMenguru> lstPeriodMengurus = new PeriodMengurusDAL().GetPeriodMengurus().Where(x => x.Status == "A" && x.MengurusYear > DateTime.Now.Year) .OrderBy(x => x.MengurusYear).ThenBy(x => x.FieldMenguru.FieldMengurusDesc).ToList(); List <FieldMenguru> obj = new FieldMenguruDAL().GetFieldMengurus().Where(x => x.Status == "F").ToList(); Session["FixedFieldMengurus"] = obj; foreach (FieldMenguru item in obj) { PeriodMenguru pm = new PeriodMenguru(); pm.PeriodMengurusID = item.FieldMengurusID; pm.MengurusYear = DateTime.Now.Year; pm.FieldMenguru = new FieldMenguru { FieldMengurusDesc = item.FieldMengurusDesc }; lstPeriodMengurus.Add(pm); } gvPeriod.DataSource = lstPeriodMengurus.Select(x => new { x.PeriodMengurusID, x.MengurusYear, x.FieldMenguru.FieldMengurusDesc }); gvPeriod.DataBind(); } catch (Exception ex) { ((SiteMaster)this.Master).ShowMessage("Error", "An error occurred", ex, true); } }
private void GetData() { try { List <PeriodMengurusGridHelper> data = new PeriodMengurusDAL().GetPeriodMengurus() .Select(x => new PeriodMengurusGridHelper() { PeriodMengurusID = x.PeriodMengurusID, FieldMengurusID = x.FieldMengurusID, FieldMengurus = x.FieldMenguru.FieldMengurusDesc, MengurusYear = x.MengurusYear, Status = ((x.Status == "A") ? "A" : "D") }).OrderBy(x => x.MengurusYear).ToList(); Session["PeriodMenguruData"] = data; BindGrid(); LoadDropDown(); } catch (Exception ex) { ((SiteMaster)this.Master).ShowMessage("Error", "An error occurred", ex, true); } }
private void GetData() { try { List <AccountCode> lstAccountCode = new AccountCodeDAL().GetAccountCodes().Where(x => x.Status == "A").ToList(); List <AccountCode> AccountCodesData = new List <AccountCode>(); if (AuthUser.JuncUserRoles.FirstOrDefault().RoleID == 3 || AuthUser.JuncUserRoles.FirstOrDefault().RoleID == 4) { AccountCodesData = lstAccountCode; } else { AccountCodesData = AuthUser.UserMengurusWorkflows.Where(x => x.Status == "A").Select(x => x.AccountCode1).ToList(); if (AccountCodesData.Count == 0) { lstAccountCode = new List <AccountCode>(); } else { List <string> lstprntcodes = AccountCodesData.Select(x => x.ParentAccountCode).Distinct().ToList(); while (lstprntcodes.Count > 0) { List <AccountCode> lstprnts = lstAccountCode.Where(x => lstprntcodes.Contains(x.AccountCode1)).ToList(); foreach (AccountCode o in lstprnts) { if (AccountCodesData.Where(x => x.AccountCode1 == o.AccountCode1).Count() == 0) { AccountCodesData.Add(o); } } lstprntcodes = lstprnts.Select(x => x.ParentAccountCode).Distinct().ToList(); } } } Session["AccountCodesData"] = lstAccountCode; List <int> lstperiod = GetSelectedPeriods(); List <PeriodMenguru> PeriodData = new PeriodMengurusDAL().GetPeriodMengurus().Where(x => x.Status == "A" && lstperiod.Contains(x.PeriodMengurusID)) .OrderBy(x => x.MengurusYear).ThenBy(x => x.FieldMenguru.FieldMengurusDesc).ToList(); List <PeriodMenguru> FixedData = ((List <FieldMenguru>)Session["FixedFieldMengurus"]).Where(x => lstperiod.Contains(x.FieldMengurusID)) .Select(x => new PeriodMenguru { PeriodMengurusID = lstperiod.Contains(x.FieldMengurusID) ? x.FieldMengurusID : 0, MengurusYear = DateTime.Now.Year, FieldMenguru = new FieldMenguru { FieldMengurusID = x.FieldMengurusID, FieldMengurusDesc = x.FieldMengurusDesc, Status = x.Status } }).OrderBy(x => x.MengurusYear).ThenBy(x => x.FieldMenguru.FieldMengurusDesc).ToList(); FixedData.AddRange(PeriodData); Session["PeriodData"] = FixedData; bool CanEdit = false; List <BudgetMenguru> BudgetData = new BudgetMengurusDAL().GetBudgetMengurusStatus(GetSelectedSegmentDetails(), ref CanEdit) .Where(x => x.Status == "A") .Select(x => new BudgetMenguru { BudgetMengurusID = 0, AccountCode = x.AccountCode, PeriodMengurusID = x.PeriodMengurusID, Status = x.Status, Remarks = string.Empty, Amount = (AccountCodesData.Where(y => y.ParentAccountCode == x.AccountCode).Count() == 0) ? x.Amount : 0 }) .GroupBy(x => new { x.AccountCode, x.PeriodMengurusID, x.Status }) .Select(x => new BudgetMenguru { AccountCode = x.Key.AccountCode, PeriodMengurusID = x.Key.PeriodMengurusID, Status = x.Key.Status, Amount = x.Sum(y => y.Amount) }) .ToList(); Session["BudgetData"] = BudgetData; Session["CanEdit"] = CanEdit; if (!CanEdit) { chkKeterangan.Checked = false; chkPengiraan.Checked = false; } } catch (Exception ex) { ((SiteMaster)this.Master).ShowMessage("Error", "An error occurred", ex, true); } }
protected void btnSave_Click(object sender, EventArgs e) { try { int FieldID = new FieldMenguruDAL().GetFieldMengurus().Where(x => x.FieldMengurusDesc.Contains("Anggaran Dipohon") && x.Status == "A").Select(y => y.FieldMengurusID).FirstOrDefault(); if ((Helper.PageMode)Session["PeriodMenguruPageMode"] == Helper.PageMode.New) { if (new PeriodMengurusDAL().GetPeriodMengurus().Where(x => x.FieldMengurusID == FieldID && x.MengurusYear == Convert.ToInt32(ddlYear.SelectedValue)).Count() > 0) { ((SiteMaster)this.Master).ShowMessage("Failure", "Period Mengurus already exists"); return; } PeriodMenguru objPeriodMenguru = new PeriodMenguru(); objPeriodMenguru.FieldMengurusID = FieldID; objPeriodMenguru.MengurusYear = Convert.ToInt32(ddlYear.SelectedValue); objPeriodMenguru.Status = new Helper().GetItemStatusEnumValueByName(ddlStatus.SelectedValue); objPeriodMenguru.CreatedBy = LoggedInUser.UserID; objPeriodMenguru.CreatedTimeStamp = DateTime.Now; objPeriodMenguru.ModifiedBy = LoggedInUser.UserID; objPeriodMenguru.ModifiedTimeStamp = DateTime.Now; if (new PeriodMengurusDAL().InsertPeriodMenguru(objPeriodMenguru)) { ((SiteMaster)this.Master).ShowMessage("Success", "Period Mengurus saved successfully"); } else { ((SiteMaster)this.Master).ShowMessage("Failure", "An error occurred while saving Period Mengurus"); } } else if ((Helper.PageMode)Session["PeriodMenguruPageMode"] == Helper.PageMode.Edit) { PeriodMenguru objPeriodMenguru = (PeriodMenguru)Session["SelectedPeriodMenguru"]; PeriodMenguru pm = new PeriodMengurusDAL().GetPeriodMengurus().Where(x => x.FieldMengurusID == FieldID && x.MengurusYear == Convert.ToInt32(ddlYear.SelectedValue)).FirstOrDefault(); if (pm != null) { if (pm.PeriodMengurusID != objPeriodMenguru.PeriodMengurusID) { ((SiteMaster)this.Master).ShowMessage("Failure", "Period Mengurus already exists"); return; } } objPeriodMenguru.FieldMengurusID = FieldID; objPeriodMenguru.MengurusYear = Convert.ToInt32(ddlYear.SelectedValue); objPeriodMenguru.Status = new Helper().GetItemStatusEnumValueByName(ddlStatus.SelectedValue); objPeriodMenguru.ModifiedBy = LoggedInUser.UserID; objPeriodMenguru.ModifiedTimeStamp = DateTime.Now; if (new PeriodMengurusDAL().UpdatePeriodMenguru(objPeriodMenguru)) { ((SiteMaster)this.Master).ShowMessage("Success", "Period Mengurus updated successfully"); } else { ((SiteMaster)this.Master).ShowMessage("Failure", "An error occurred while updating Period Mengurus"); } } GetData(); ClearPageData(); EditForm.Visible = false; } catch (Exception ex) { ((SiteMaster)this.Master).ShowMessage("Error", "An error occurred", ex, true); } }