public ActionResult Edit([Bind(Include = "JOBNO,SDATE,EDATE,STAFFCODE,REM,ROWNO,STAMP")] CSJOBSTF cSJOBSTF) { if (ModelState.IsValid) { try { cSJOBSTF.STAMP = cSJOBSTF.STAMP + 1; db.Entry(cSJOBSTF).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { //string message = string.Format("{0}:{1}", // validationErrors.Entry.Entity.ToString(), // validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage); } } } catch (DbUpdateException ex) { UpdateException updateException = (UpdateException)ex.InnerException; if (updateException != null) { if (updateException.InnerException != null) { var sqlException = (FirebirdSql.Data.FirebirdClient.FbException)updateException.InnerException; foreach (var error in sqlException.Errors) { if (error.Message != null) { ModelState.AddModelError(string.Empty, error.Message); } } } else { ModelState.AddModelError(string.Empty, updateException.Message); } } else { ModelState.AddModelError(string.Empty, updateException.Message); } } } ViewBag.STAFFCODE = new SelectList(db.HKSTAFFs, "STAFFCODE", "STAFFDESC", cSJOBSTF.STAFFCODE); return(View(cSJOBSTF)); }
public ActionResult DeleteConfirmed(string id) { CSJOBSTF cSJOBSTF = db.CSJOBSTFs.Find(id); try { db.CSJOBSTFs.Remove(cSJOBSTF); db.SaveChanges(); return(RedirectToAction("Index")); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { //string message = string.Format("{0}:{1}", // validationErrors.Entry.Entity.ToString(), // validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage); } } } catch (DbUpdateException ex) { UpdateException updateException = (UpdateException)ex.InnerException; if (updateException != null) { if (updateException.InnerException != null) { var sqlException = (FirebirdSql.Data.FirebirdClient.FbException)updateException.InnerException; foreach (var error in sqlException.Errors) { if (error.Message != null) { ModelState.AddModelError(string.Empty, error.Message); } } } else { ModelState.AddModelError(string.Empty, updateException.Message); } } else { ModelState.AddModelError(string.Empty, updateException.Message); } } return(View(cSJOBSTF)); }
// GET: CSJOBSTFs/Create public ActionResult Create(string id) { CSJOBSTF cSJOBSTF = new CSJOBSTF(); cSJOBSTF.STAMP = 0; cSJOBSTF.JOBNO = MyHtmlHelpers.ConvertByteStrToId(id); cSJOBSTF.EDATE = new DateTime(3000, 1, 1); cSJOBSTF.SDATE = DateTime.Today; ViewBag.STAFFCODE = new SelectList(db.HKSTAFFs, "STAFFCODE", "STAFFDESC"); ViewBag.Title = "Assign Staff to Job "; return(View("Edit", cSJOBSTF)); }
// GET: CSJOBSTFs/Details/5 public ActionResult Details(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CSJOBSTF cSJOBSTF = db.CSJOBSTFs.Find(id); if (cSJOBSTF == null) { return(HttpNotFound()); } return(View(cSJOBSTF)); }
// GET: CSJOBSTFs/Edit/5 public ActionResult Edit(string id, int row, int?page) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CSJOBSTF cSJOBSTF = db.CSJOBSTFs.Find(MyHtmlHelpers.ConvertByteStrToId(id), row); if (cSJOBSTF == null) { return(HttpNotFound()); } ViewBag.STAFFCODE = new SelectList(db.HKSTAFFs, "STAFFCODE", "STAFFDESC", cSJOBSTF.STAFFCODE); return(View(cSJOBSTF)); }
public ActionResult PostConfirmed(string id) { CSJOBM cSJOBM = db.CSJOBMs.Find(MyHtmlHelpers.ConvertByteStrToId(id)); // Make sure do not remove posted jobs if ((cSJOBM.JOBPOST == "Y") || (cSJOBM.CSJOBDs.Count() == 0) || (cSJOBM.COMPLETE == "Y")) { ModelState.AddModelError(string.Empty, "Cannot repost or post incomplete or completed Jobs"); } else { try { // Remove all details cSJOBM.JOBPOST = "Y"; cSJOBM.STAMP = cSJOBM.STAMP + 1; var lastRec = db.CSJOBSTFs.Where(x => x.JOBNO == cSJOBM.JOBNO).OrderByDescending(y => y.ROWNO).FirstOrDefault(); // Update CSJOBSTF CSJOBSTF cSJOBSTF = new CSJOBSTF(); cSJOBSTF.JOBNO = cSJOBM.JOBNO; cSJOBSTF.SDATE = DateTime.Today; cSJOBSTF.EDATE = new DateTime(3000, 1, 1); cSJOBSTF.STAFFCODE = cSJOBM.JOBSTAFF; cSJOBSTF.STAMP = 0; if (lastRec == null) { cSJOBSTF.ROWNO = 1; } else { cSJOBSTF.ROWNO = lastRec.ROWNO + 1; } db.CSJOBSTFs.Add(cSJOBSTF); // Update CSJOBD foreach (CSJOBD item in cSJOBM.CSJOBDs) { // Update CSJOBST CSJOBST cSJOBST = new CSJOBST(); cSJOBST.JOBNO = item.JOBNO; cSJOBST.CASENO = item.CASENO; cSJOBST.STAMP = 0; cSJOBST.STAGEFR = "Pending"; cSJOBST.STAGETO = "New"; cSJOBST.INDATE = DateTime.Today; cSJOBST.INTIME = DateTime.Now.ToString("HH:mm:ss"); cSJOBST.OUTDATE = new DateTime(3000, 1, 1); cSJOBST.INIDX = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); db.CSJOBSTs.Add(cSJOBST); item.STAGE = "New"; item.STAGEDATE = DateTime.Today; item.STAGETIME = cSJOBST.INTIME; item.STAMP = item.STAMP + 1; db.Entry(item).State = EntityState.Modified; } db.SaveChanges(); int page = (int)Session["CSJOBMPage"]; return(RedirectToAction("Index", new { page = page })); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { //string message = string.Format("{0}:{1}", // validationErrors.Entry.Entity.ToString(), // validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage); } } } catch (DbUpdateException ex) { UpdateException updateException = (UpdateException)ex.InnerException; if (updateException != null) { if (updateException.InnerException != null) { var sqlException = (FirebirdSql.Data.FirebirdClient.FbException)updateException.InnerException; foreach (var error in sqlException.Errors) { if (error.Message != null) { ModelState.AddModelError(string.Empty, error.Message); } } } else { ModelState.AddModelError(string.Empty, updateException.Message); } } else { ModelState.AddModelError(string.Empty, updateException.Message); } } catch (Exception e) { ModelState.AddModelError(string.Empty, e.Message); } } ViewBag.CONO = new SelectList(db.CSCOMSTRs.Select(x => new { CONO = x.CONO, CONAME = x.CONAME + " (" + x.CONO + ")" }).OrderBy(y => y.CONAME), "CONO", "CONAME", cSJOBM.CONO); ViewBag.JOBSTAFF = new SelectList(db.HKSTAFFs, "STAFFCODE", "STAFFDESC", cSJOBM.JOBSTAFF); ViewBag.Title = "Post Job Taking "; return(View("Edit", cSJOBM)); }
public ActionResult Create([Bind(Include = "JOBNO,SDATE,EDATE,STAFFCODE,REM,ROWNO,STAMP")] CSJOBSTF cSJOBSTF) { if (ModelState.IsValid) { CSJOBSTF lastRec = db.CSJOBSTFs.Where(x => x.JOBNO == cSJOBSTF.JOBNO).OrderByDescending(z => z.ROWNO).FirstOrDefault(); int rowno = 1; if (lastRec != null) { rowno = lastRec.ROWNO + 1; lastRec.EDATE = cSJOBSTF.SDATE; lastRec.STAMP = lastRec.STAMP + 1; db.Entry(lastRec).State = EntityState.Modified; } cSJOBSTF.STAMP = 0; cSJOBSTF.ROWNO = rowno; CSJOBM cSJOBM = db.CSJOBMs.Find(cSJOBSTF.JOBNO); cSJOBM.JOBSTAFF = cSJOBSTF.STAFFCODE; cSJOBM.STAMP = cSJOBM.STAMP + 1; try { db.Entry(cSJOBM).State = EntityState.Modified; db.CSJOBSTFs.Add(cSJOBSTF); db.SaveChanges(); int page = (int)Session["CSJOBDPage"]; return(RedirectToAction("Index", "CSJOBDs", new { page = page })); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { //string message = string.Format("{0}:{1}", // validationErrors.Entry.Entity.ToString(), // validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage); } } } catch (DbUpdateException ex) { UpdateException updateException = (UpdateException)ex.InnerException; if (updateException != null) { if (updateException.InnerException != null) { var sqlException = (FirebirdSql.Data.FirebirdClient.FbException)updateException.InnerException; foreach (var error in sqlException.Errors) { if (error.Message != null) { ModelState.AddModelError(string.Empty, error.Message); } } } else { ModelState.AddModelError(string.Empty, updateException.Message); } } else { ModelState.AddModelError(string.Empty, updateException.Message); } } } ViewBag.STAFFCODE = new SelectList(db.HKSTAFFs, "STAFFCODE", "STAFFDESC", cSJOBSTF.STAFFCODE); return(View(cSJOBSTF)); }