protected void btnAdd_Click(object sender, EventArgs e) { PeriodBiz pBiz = new PeriodBiz(); lwg_Period p; if (string.IsNullOrEmpty(hdfID.Value)) { p = new lwg_Period(); lblNote.Text = "Insert error, please try again"; } else { p = pBiz.GetByID(int.Parse(hdfID.Value)); lblNote.Text = "Update error, please try again"; } if (p != null) { p.Name = txtName.Text; if (pBiz.SavePeriod(p)) { rptPeriod.DataSource = pBiz.GetListPeriod(); rptPeriod.DataBind(); txtName.Text = string.Empty; pnEditPeriod.Visible = false; pnListPeriods.Visible = true; return; } } lblNote.Visible = true; }
protected void rptPeriod_ItemCommand(object source, RepeaterCommandEventArgs e) { PeriodBiz pBiz = new PeriodBiz(); lwg_Period p = pBiz.GetByID(int.Parse(e.CommandArgument.ToString())); if (e.CommandName.Equals("EDIT")) { if (p != null) { btnAdd.Text = "Update"; txtTitle.Text = "Update Period"; hdfID.Value = e.CommandArgument.ToString(); pnEditPeriod.Visible = true; pnListPeriods.Visible = false; txtName.Text = p.Name; } } else if (e.CommandName.Equals("DELETE")) { if (p != null) { if (pBiz.DeletePeriod(p)) { BindingPeriod(); } } } }
public bool SavePeriod(lwg_Period p) { if (p != null) { if (p.PeriodId > 0) { lwg_Period c = dbContext.lwg_Period.SingleOrDefault(ht => ht.PeriodId == p.PeriodId); if (c != null) { c.Name = p.Name; } else { return(false); } } else { if (dbContext.lwg_Period.Count() > 0) { p.PeriodId = dbContext.lwg_Period.OrderByDescending(pe => pe.PeriodId).First().PeriodId + 1; } else { p.PeriodId = 1; } dbContext.lwg_Period.Add(p); } dbContext.SaveChanges(); return(true); } return(false); }
public bool DeletePeriod(lwg_Period p) { if (p != null) { if (!dbContext.lwg_Catalog.Any(cl => cl.PeriodId == p.PeriodId)) { dbContext.lwg_Period.Remove(p); dbContext.SaveChanges(); return(true); } } return(false); }
public bool CheckAndInsertPeriod(string periodName, int catalogID) { lwg_Period lwg = dbContext.lwg_Period.SingleOrDefault(o => o.Name.ToLower().Equals(periodName.ToLower())); if (lwg == null) { lwg = new lwg_Period(); lwg.Name = periodName; SavePeriod(lwg); } if (!dbContext.lwg_PeriodMapping.Any(o => o.CatalogID == catalogID && o.PeriodID == lwg.PeriodId)) { lwg_PeriodMapping periodMapping = new lwg_PeriodMapping(); periodMapping.PeriodID = lwg.PeriodId; periodMapping.CatalogID = catalogID; dbContext.lwg_PeriodMapping.Add(periodMapping); dbContext.SaveChanges(); return(true); } return(false); }