private void FormFiscalPeriod_Load(object sender, EventArgs e) { contxt = new PMModel(); period = new FiscalPeriod(); LoadPeriods(); LoadStatus(); isNew = false; isEdit = false; isFormLoading = false; }
private void dgvFP_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (!isFormLoading) { period = (FiscalPeriod)dgvFP.Rows[e.RowIndex].DataBoundItem; isNew = false; isEdit = true; state = FORMSTATE.EDIT; SetButtons(); ShowObject(); } }
private bool CheckValidityPeriod() { bool validity = false; period = contxt.FiscalPeriods.FirstOrDefault(o => o.FromDate.Value.Month == dtM.Value.Month && o.FromDate.Value.Year == dtM.Value.Year); if (period != null) { if (period.Status == 0) { validity = true; } } return(validity); }
private void OpenClosePeriod() { period = contxt.FiscalPeriods.FirstOrDefault(o => o.FromDate.Value.Month == dtM.Value.Month && o.FromDate.Value.Year == dtM.Value.Year); if (period == null) { period = new FiscalPeriod(); period.FromDate = new DateTime(dtM.Value.Year, dtM.Value.Month, 1); period.Todate = period.FromDate.Value.AddMonths(1).AddDays(period.FromDate.Value.Day * -1); period.Status = chkClose.Checked ? 1 : 0;; contxt.FiscalPeriods.Add(period); contxt.Entry(period).State = System.Data.Entity.EntityState.Added; contxt.SaveChanges(); } else { period.Status = chkClose.Checked ? 1 : 0; contxt.Entry(period).State = System.Data.Entity.EntityState.Modified; contxt.SaveChanges(); } }
private void Save() { if (isNew) { contxt.FiscalPeriods.Add(period); contxt.Entry(period).State = System.Data.Entity.EntityState.Added; contxt.SaveChanges(); contxt.Entry(period).Reload(); } if (isEdit) { FiscalPeriod ptemp = contxt.FiscalPeriods.FirstOrDefault(o => o.id == period.id); if (ptemp != null) { ptemp.FromDate = period.FromDate; ptemp.Todate = period.Todate; ptemp.Status = period.Status; contxt.Entry(ptemp).State = System.Data.Entity.EntityState.Modified; contxt.SaveChanges(); contxt.Entry(period).Reload(); } } //throw new NotImplementedException(); }