protected void ToolbarClick(object sender, RadToolBarEventArgs e) { if (e.Item.Text == "New") { Grid.SelectedIndexes.Clear(); ResetForm(); } else if (e.Item.Text == "Save") { var cProg = new CProgramGroup(); var prog = new Erp2016.Lib.ProgramGroup(); prog.SiteId = CurrentSiteId; if (!string.IsNullOrEmpty(RadComboBoxFaculty.SelectedValue)) { prog.FacultyId = Convert.ToInt32(RadComboBoxFaculty.SelectedValue); } prog.IsActive = RadButtonActive.Checked; prog.Name = tbProgram.Text; prog.Description = tbDescript.Text; prog.CreatedId = CurrentUserId; prog.CreatedDate = DateTime.Now.Date; if (cProg.Add(prog) > 0) { ShowMessage("'" + prog.Name + "' is added."); Grid.Rebind(); } else { ShowMessage("Failed to add"); } } else if (e.Item.Text == "Update") { if (Grid.SelectedValue != null) { var cProg = new CProgramGroup(); var prog = cProg.Get(Convert.ToInt32(Grid.SelectedValue)); if (RadComboBoxFaculty.SelectedValue != null) { prog.FacultyId = Convert.ToInt32(RadComboBoxFaculty.SelectedValue); } prog.Name = tbProgram.Text; prog.IsActive = RadButtonActive.Checked; prog.Description = tbDescript.Text; prog.UpdatedId = CurrentUserId; prog.UpdatedDate = DateTime.Now; if (cProg.Update(prog)) { ShowMessage("'" + prog.Name + "' is updated."); Grid.Rebind(); } else { ShowMessage("Failed to update"); } } } }
public bool Update(ProgramGroup obj) { try { _db.SubmitChanges(); } catch (Exception ex) { Debug.Print(ex.Message); return(false); } return(true); }
public int Add(ProgramGroup obj) { try { _db.ProgramGroups.InsertOnSubmit(obj); _db.SubmitChanges(); } catch (Exception ex) { Debug.Print(ex.Message); return(-1); } return(_db.ProgramGroups.Max(x => x.ProgramGroupId)); }