public ActionResult InsertAndAppr(Document model) { using (DLSMEntities context = new DLSMEntities()) { using (var dbContextTransaction = context.Database.BeginTransaction()) { string avbError = CheckAvailable(model); string snError = CheckSerialOut(model); if (avbError == "Y" && snError == "Y") { try { Document w = context.Documents.Where(p => (p.DocNo == model.DocNo)).FirstOrDefault(); if (w != null) { return(Json("เลขที่เอกสาร นี้มีอยู่แล้วในระบบ")); } context.Documents.Add(model); context.SaveChanges(); model.DocDetailList.RemoveAt(0); foreach (var i in model.DocDetailList) { DocumentDetail dd = new DocumentDetail(); dd.DocID = model.ID; dd.PdID = i.PdID; dd.Qty = i.Qty; dd.RemainQty = i.RemainQty; dd.SerialBegin = i.SerialBegin; dd.SerialEnd = i.SerialEnd; dd.IpProperty = i.IpProperty; dd.TrnType = "O"; context.DocumentDetails.Add(dd); } context.SaveChanges(); // Execute store procudure var docid = model.ID; var userid = int.Parse(Session["UserID"].ToString()); var result = context.sp_ProcessDocument(docid, userid).ToList(); if (result[0].ID == 0) { context.SaveChanges(); dbContextTransaction.Commit(); } } catch (Exception ex) { dbContextTransaction.Rollback(); return(Json(ex.InnerException.Message)); } } } } return(Json("success")); }
public ActionResult ReceiveBack(Document model) { var oldstatus = model.Status; using (DLSMEntities context = new DLSMEntities()) { using (var dbContextTransaction = context.Database.BeginTransaction()) { string snError = CheckSerialIn(model); if (snError == "Y") { try { //Update Status var upd = (from d in context.Documents where d.ID == model.ID select d).ToList().SingleOrDefault(); upd.Status = model.Status; upd.Remark = model.Remark; context.SaveChanges(); // Execute store procudure var docid = model.ID; var userid = int.Parse(Session["UserID"].ToString()); var result = context.sp_ProcessDocument(docid, userid).ToList(); if (result[0].ID == 0) { context.SaveChanges(); dbContextTransaction.Commit(); } else { dbContextTransaction.Rollback(); } } catch (Exception ex) { dbContextTransaction.Rollback(); //Update Status var upd = (from d in context.Documents where d.ID == model.ID select d).ToList().SingleOrDefault(); upd.Status = oldstatus; context.SaveChanges(); return(Json(ex.InnerException.Message)); } } else { return(Json(snError != "Y" ? snError : "")); } } } return(Json("success")); }
public ActionResult Create([Bind(Include = "ID,Name")] TopicGroup topicGroup) { if (ModelState.IsValid) { var context = new DLSMEntities(); TopicGroup t = context.TopicGroups.Where(p => p.Name == topicGroup.Name).FirstOrDefault(); if (t != null) { // Cannot delete becasue Topic group is using another process TempData["Msg"] = "ชื่อกลุ่มปัญหานี้มีอยู่แล้วในระบบ"; return(RedirectToAction("Create", new { ViewBag.Msg })); } else { db.TopicGroups.Add(topicGroup); db.SaveChanges(); } return(RedirectToAction("Index")); } ViewBag.ID = new SelectList(db.Issues, "ID", "Subject", topicGroup.ID); ViewBag.ID = new SelectList(db.Topics, "ID", "Subject", topicGroup.ID); return(View(topicGroup)); }
public ActionResult Create([Bind(Include = "WhID,PdID,Qty,Borrow,Transfer,CheckStatus")] Stock stock) { if (ModelState.IsValid) { db.Stocks.Add(stock); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PdID = new SelectList(db.Products, "ID", "Code", stock.PdID); ViewBag.WhID = new SelectList(db.Warehouses, "ID", "Code", stock.WhID); return(View(stock)); }
public ActionResult Create([Bind(Include = "ID,Subject,Symptom,Cause,Solving,CreateBy,CreateDate,TgID,LocationID")] Topic topic) { if (ModelState.IsValid) { db.Topics.Add(topic); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ID = new SelectList(db.Issues, "ID", "Subject", topic.ID); ViewBag.ID = new SelectList(db.TopicGroups, "ID", "Name", topic.ID); return(View(topic)); }
public ActionResult Create(TransferStaff transferStaff) { transferStaff.IsActive = 1; db.TransferStaffs.Add(transferStaff); db.SaveChanges(); return(Json("success")); //return RedirectToAction("Index"); //ViewBag.StID = db.Staffs.ToList(); //ViewBag.WhID = db.Warehouses.ToList(); //ViewBag.ToWhID = db.Warehouses.ToList(); //return View(transferStaff); }
public ActionResult SendApprove(Document model) { Document w = db.Documents.Where(p => (p.DocNo == model.DocNo) && (p.ID != model.ID)).FirstOrDefault(); if (w != null) { return(Json("เลขที่เอกสาร นี้มีอยู่แล้วในระบบ")); } //Update Status var context = new DLSMEntities(); var upd = (from d in context.Documents where d.ID == model.ID select d).ToList().SingleOrDefault(); upd.Status = model.Status; context.SaveChanges(); foreach (var i in model.DocDetailList) { //Update to Unlock Row List <Stock> res = (from s in db.Stocks where s.WhID == model.WhID && s.PdID == i.PdID select s).ToList(); res.ForEach(o => o.CheckStatus = "N"); db.SaveChanges(); } return(Json("success")); }
public void ProcessRequest(HttpContext context) { try { PersonImageRequest parm = new PersonImageRequest(); using (StreamReader sr = new StreamReader(context.Request.InputStream)) { String data = sr.ReadToEnd(); parm = new JavaScriptSerializer().Deserialize <PersonImageRequest>(data); } PersonImageResponse ap = new PersonImageResponse(); using (DLSMEntities db = new DLSMEntities()) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { var result = db.sp_ApiPersonImage((parm.citizenId)).ToList(); if (result.Count() > 0) { db.SaveChanges(); dbContextTransaction.Commit(); ap.resultcode = "1"; ap.person_image = result[0].PartData; ap.citizenId = parm.citizenId; ap.message = "OK"; } else { dbContextTransaction.Rollback(); ap.resultcode = "0"; ap.message = "not found"; } } catch (Exception ex) { dbContextTransaction.Rollback(); ap.resultcode = "0"; ap.message = ex.InnerException == null ? (ex.Message == null ? "Error: PersonImage catch 2" : ex.Message) : ex.InnerException.Message + " StackTrace:" + ex.StackTrace; } } } string json = new JavaScriptSerializer().Serialize(ap); context.Response.ContentType = "text/javascript"; context.Response.Write(json); } catch (Exception ex) { PersonImageResponse ap = new PersonImageResponse(); ap.resultcode = "0"; ap.message = ex.InnerException == null ? (ex.Message == null ? "Error: PersonImage catch 1" : ex.Message) : ex.InnerException.Message + " StackTrace:" + ex.StackTrace; string json = new JavaScriptSerializer().Serialize(ap); context.Response.ContentType = "text/javascript"; context.Response.Write(json); } }
public ActionResult Check(CheckCardSerialRequest model) { ApiResult ap = new ApiResult(); using (DLSMEntities context = new DLSMEntities()) { using (var dbContextTransaction = context.Database.BeginTransaction()) { try { var result = context.sp_ApiCheckCardSerial(model.WhID, model.SerialNo).ToList(); if (result.Count() > 0) { context.SaveChanges(); dbContextTransaction.Commit(); ap.Code = "1"; } else { dbContextTransaction.Rollback(); ap.Code = "2"; } } catch (Exception ex) { dbContextTransaction.Rollback(); ap.Code = "0"; ap.Message = ex.Message; } } } return(Json(ap)); }
public ActionResult InsertStaff(Staff model) { using (DLSMEntities context = new DLSMEntities()) { using (var dbContextTransaction = context.Database.BeginTransaction()) { try { Staff w = context.Staffs.Where(p => p.UserLogin == model.UserLogin).FirstOrDefault(); if (w != null) { return(Json("UserLogin นี้มีอยู่แล้วในระบบ")); } model.UserPassword = Hash(model.UserPassword); context.Staffs.Add(model); context.SaveChanges(); StaffID = model.ID; model.StWh.RemoveAt(0); foreach (var a in model.StWh) { StaffWarehouse SW = new StaffWarehouse(); SW.StID = StaffID; SW.WhID = a.WhID; SW.IsManager = a.IsManager; context.StaffWarehouses.Add(SW); } context.SaveChanges(); dbContextTransaction.Commit(); } catch (Exception ex) { dbContextTransaction.Rollback(); return(Json(ex.InnerException.Message)); } } } return(Json(StaffID)); }
public ActionResult Create([Bind(Include = "ID,DocNo,DocDate,CreateBy,DocType,WhID,SpID,Remark,Status,ApproveDate,ApproveBy,ProcessDate,ProcessBy,ToWhID")] Document document) { if (ModelState.IsValid) { db.Documents.Add(document); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CreateBy = new SelectList(db.Staffs, "ID", "Name", document.CreateBy); ViewBag.SpID = new SelectList(db.Suppliers, "ID", "Name", document.SpID); return(View(document)); }
public ActionResult DeleteConfirmed(int id) { db.WorkSationDetails.RemoveRange(db.WorkSationDetails.Where(x => x.WsID == id)); db.SaveChanges(); db.WorkSationStaffs.RemoveRange(db.WorkSationStaffs.Where(x => x.WsID == id)); db.SaveChanges(); WorkStation workStation = db.WorkStations.Find(id); db.WorkStations.Remove(workStation); db.SaveChanges(); TempData["Msg"] = "ลบข้อมูลเรียบร้อยแล้ว"; return(RedirectToAction("Index")); }
public ActionResult InsertMinStock(int whid, int pdid, int minstock, int predict) { using (DLSMEntities context = new DLSMEntities()) { using (var dbContextTransaction = context.Database.BeginTransaction()) { try { var wh = context.WarehouseMinimums.SingleOrDefault(x => x.WhID == whid && x.PdID == pdid); if (wh == null) { //insert WarehouseMinimum min = new WarehouseMinimum(); min.WhID = whid; min.PdID = pdid; min.MinStock = minstock; min.PredictMonth = (predict == 0 ? min.PredictMonth : predict); context.WarehouseMinimums.Add(min); context.SaveChanges(); } else { var mm = context.WarehouseMinimums.Where(o => o.PdID == pdid && o.WhID == whid).FirstOrDefault(); WarehouseMinimum min = context.WarehouseMinimums.Find(mm.ID); min.WhID = whid; min.PdID = pdid; min.MinStock = minstock; min.PredictMonth = (predict == 0 ? min.PredictMonth : (int?)predict); context.Entry(min).State = EntityState.Modified; context.SaveChanges(); } dbContextTransaction.Commit(); return(Json("success", JsonRequestBehavior.AllowGet)); } catch (Exception ex) { dbContextTransaction.Rollback(); return(Json("fail", JsonRequestBehavior.AllowGet)); } } } }
public ActionResult Create(Category category) { var context = new DLSMEntities(); Category c = context.Categories.Where(p => p.Code == category.Code || p.Name == category.Name).FirstOrDefault(); if (c != null) { // Cannot delete becasue Topic group is using another process //TempData["Msg"] = "รหัส หรือ ชื่อกลุ่มวัสดุอุปกรณ์นี้มีอยู่แล้วในระบบ"; return(Json("รหัส หรือ ชื่อกลุ่มวัสดุนี้มีอยู่แล้วในระบบ")); } else { db.Categories.Add(category); db.SaveChanges(); return(Json("success")); } //return RedirectToAction("Index"); }
public ActionResult Edit([Bind(Include = "ID,Name,UserLogin,UserPassword,UgID,TelNo,Email")] Staff staff) { if (ModelState.IsValid) { db.Entry(staff).State = EntityState.Modified; db.SaveChanges(); StaffID = staff.ID; //Delete old data StaffWarehouse sf = db.StaffWarehouses.Find(StaffID); db.StaffWarehouses.Remove(sf); db.SaveChanges(); staff.StWh.RemoveAt(0); foreach (var a in staff.StWh) { StaffWarehouse SW = new StaffWarehouse(); SW.StID = StaffID; SW.WhID = a.WhID; SW.IsManager = a.IsManager; db.StaffWarehouses.Add(SW); db.SaveChanges(); } return(Json("success")); } ViewBag.ID = new SelectList(db.UserGroups, "ID", "Name", staff.ID); return(View(staff)); }
public ActionResult Create([Bind(Include = "ID,Code,Name,NameEN,TelNo,Email,IsMain,LocationName,Latitude,Longitude,PvID")] Warehouse warehouse) { if (ModelState.IsValid) { var context = new DLSMEntities(); Warehouse w = context.Warehouses.Where(p => p.Code.Equals(warehouse.Code) || p.Name.Equals(warehouse.Name)).FirstOrDefault(); if (w != null) { return(Json("รหัส หรือ ชื่อสำนักงานขนส่งนี้มีอยู่แล้วในระบบ")); } else { db.Warehouses.Add(warehouse); db.SaveChanges(); int WarehouseID = warehouse.ID; return(Json(WarehouseID));; } } return(View(warehouse)); }
public ActionResult Reject(Document model) { //Update Status var context = new DLSMEntities(); var upd = (from d in context.Documents where d.ID == model.ID select d).ToList().SingleOrDefault(); upd.Status = model.Status; upd.Remark = model.Remark; context.SaveChanges(); return(Json("success")); }
public ActionResult Create(Supplier supplier) { if (ModelState.IsValid) { var context = new DLSMEntities(); Supplier c = context.Suppliers.Where(p => p.Name == supplier.Name).FirstOrDefault(); if (c != null) { // Cannot delete becasue Topic group is using another process //TempData["Msg"] = "ชื่อผู้จำหน่ายนี้มีอยู่แล้วในระบบ"; //return RedirectToAction("Create", new { ViewBag.Msg }); return(Json("ชื่อผู้ประกอบการนี้มีอยู่แล้วในระบบ")); } else { db.Suppliers.Add(supplier); db.SaveChanges(); } return(Json("success")); } return(View(supplier)); }
public ActionResult Create(Product product) { var context = new DLSMEntities(); Product pp = context.Products.Where(p => p.Code == product.Code || p.Name == product.Name).FirstOrDefault(); if (pp != null) { return(Json("รหัส หรือ ชื่อวัสดุนี้มีอยู่แล้วในระบบ")); } else { //bool check = product.SerialControl == "on" ? true : false; bool check = product.SerialControl.ToLower() == "true" ? true : false; if (check == true) { product.SerialControl = "Y"; } else { product.SerialControl = "N"; } bool check2 = product.IsAsset.ToLower() == "true" ? true : false; if (check2 == true) { product.IsAsset = "Y"; } else { product.IsAsset = "N"; } product.MinStock = 0; db.Products.Add(product); db.SaveChanges(); return(Json("success")); } }
public void ProcessRequest(HttpContext context) { UpdatePrintStatusRequest parm = new UpdatePrintStatusRequest(); using (StreamReader sr = new StreamReader(context.Request.InputStream)) { String data = sr.ReadToEnd(); parm = new JavaScriptSerializer().Deserialize <UpdatePrintStatusRequest>(data); } ApiResult ap = new ApiResult(); using (DLSMEntities db = new DLSMEntities()) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { var result = db.sp_ApiUpdatePrintStatus(parm.SerialNo, parm.Status, parm.PrinterStatus); if (result.ToString() == "1") { db.SaveChanges(); dbContextTransaction.Commit(); ap.Code = "1"; } else { dbContextTransaction.Rollback(); ap.Code = "0"; ap.Message = "Update Print Error"; } } catch (Exception ex) { dbContextTransaction.Rollback(); ap.Code = "0"; ap.Message = ex.Message; } } } string json = new JavaScriptSerializer().Serialize(ap); context.Response.ContentType = "text/javascript"; context.Response.Write(json); }
//public ActionResult Create(string Menu,string Parent,string UserGroupName) public ActionResult Create(Permission p) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { UserGroup ug = new UserGroup(); ug.Name = p.UserGroupName; db.UserGroups.Add(ug); db.SaveChanges(); int UgID = ug.ID; if (p.Menu != null && p.Menu.Count() > 0) { foreach (var i in p.Menu) { var mod = db.Modules.SingleOrDefault(x => x.Name == i.ModuleName); Permission per = new Permission(); per.MdCode = mod.Code; per.UgID = UgID; per.Active = 1; db.Permissions.Add(per); } } db.SaveChanges(); dbContextTransaction.Commit(); return(Json("success")); } catch (Exception ex) { dbContextTransaction.Rollback(); return(Json("failed")); } } }
public ActionResult SendApprove(Document model) { Document w = db.Documents.Where(p => (p.DocNo == model.DocNo) && (p.ID != model.ID)).FirstOrDefault(); if (w != null) { return(Json("เลขที่เอกสาร นี้มีอยู่แล้วในระบบ")); } //Update Status var context = new DLSMEntities(); var upd = (from d in context.Documents where d.ID == model.ID select d).ToList().SingleOrDefault(); upd.Status = model.Status; context.SaveChanges(); return(Json("success")); }
protected String MdmAuthen(Staff UserDetail) { var userInfo = _mdmServiceWrapper.GetUserInfoAsync( new MdmAuthenticationInput(UserDetail.UserLogin, UserDetail.UserPassword)).Result; if (userInfo != null) { using (var _db = new DLSMEntities()) { var storeUserInfo = _mapper.Map <GetUserInfo>(userInfo); _db.GetUserInfoes.Add(storeUserInfo); _db.SaveChanges(); } } string retcode = null; using (DLSMEntities db = new DLSMEntities()) { try { var respget = _mdmServiceWrapper .GetUserInfoAsync(new MdmAuthenticationInput(UserDetail.UserLogin, passold)).Result; var gui = _mapper.Map <GetUserInfo>(respget); db.GetUserInfoes.Add(gui); db.SaveChanges(); retcode = "1"; } catch (Exception ex) { retcode = "0"; message = "authenUser Result: Error กรุณาติดต่อเจ้าหน้าที่"; } } return(retcode); }
public ActionResult Create([Bind(Include = "ID,Name,UserLogin,UserPassword,UgID,TelNo,Email")] Staff staff) { DLSMEntities db = new DLSMEntities(); Staff stf = new Staff(); stf.Name = staff.Name; stf.UserLogin = staff.UserLogin; stf.UserPassword = Hash(staff.UserPassword); stf.UgID = staff.UgID; stf.TelNo = staff.TelNo; stf.Email = staff.Email; db.Staffs.Add(stf); db.SaveChanges(); StaffID = stf.ID; ViewBag.Warehouselist = new SelectList(db.Warehouses, "ID", "Name"); ViewBag.UgID = new SelectList(db.UserGroups, "ID", "Name"); ViewData["StaffID"] = StaffID; return(View()); }
public ActionResult Approve(Document model) { var oldstatus = model.Status; using (DLSMEntities context = new DLSMEntities()) { using (var dbContextTransaction = context.Database.BeginTransaction()) { if (model.Status.ToString() == "3") { string avbError = CheckAvailable(model); string snError = CheckSerialOut(model); if (avbError == "Y" && snError == "Y") { try { model.DocDate = model.DocDate.Value.AddYears(-543); //Update Status ของ 3 เพราะ Out var upd = (from d in context.Documents where d.ID == model.ID select d).ToList().SingleOrDefault(); upd.Status = model.Status; upd.Remark = model.Remark; context.SaveChanges(); // Execute store procudure var docid = model.ID; var userid = int.Parse(Session["UserID"].ToString()); var result = context.sp_ProcessDocument(docid, userid).ToList(); if (result[0].ID == 0) { context.SaveChanges(); dbContextTransaction.Commit(); } else { dbContextTransaction.Rollback(); throw new Exception(); } } catch (Exception ex) { dbContextTransaction.Rollback(); //Update Status var upd = (from d in context.Documents where d.ID == model.ID select d).ToList().SingleOrDefault(); upd.Status = oldstatus; context.SaveChanges(); return(Json(ex.Message)); } } } if (model.Status.ToString() == "6") { try { string snError2 = CheckSerialIn(model); if (snError2 == "Y") { //Update Status ของ 6 เพราะ In var upd2 = (from d in context.Documents where d.ID == model.ID select d).ToList().SingleOrDefault(); upd2.Status = model.Status; upd2.Remark = model.Remark; context.SaveChanges(); // Execute store procudure var docid = model.ID; var userid = int.Parse(Session["UserID"].ToString()); var result = context.sp_ProcessDocument(docid, userid).ToList(); if (result[0].ID == 0) { context.SaveChanges(); dbContextTransaction.Commit(); } else { dbContextTransaction.Rollback(); throw new Exception(); } } else { //return Json(); dbContextTransaction.Rollback(); throw new Exception(snError2 != "Y" ? snError2 : ""); } } catch (Exception ex) { dbContextTransaction.Rollback(); //Update Status var upd = (from d in context.Documents where d.ID == model.ID select d).ToList().SingleOrDefault(); upd.Status = oldstatus; context.SaveChanges(); return(Json(ex.Message)); } } } } return(Json("success")); }
public void ProcessRequest(HttpContext context) { try { SaveCardRequest parm = new SaveCardRequest(); using (StreamReader sr = new StreamReader(context.Request.InputStream)) { String data = sr.ReadToEnd(); parm = new JavaScriptSerializer().Deserialize <SaveCardRequest>(data); cardEIN = parm.CardEIN; } SaveCardResponse ap = new SaveCardResponse(); using (DLSMEntities db = new DLSMEntities()) { db.Database.Connection.Open(); using (var dbContextTransaction = db.Database.BeginTransaction()) { try { var result = db.sp_ApiSaveCard(parm.addrNo, parm.ampDesc, parm.ampDescEng, parm.birthDateStr, parm.birthFlag, parm.distDesc, parm.distDescEng, parm.docNo, parm.docType, parm.reqMasRef, parm.expDateStr, parm.fname, parm.fnameEng, parm.issDateStr, parm.issOffLocCode, parm.lane, parm.lname, parm.lnameEng, parm.locFullDesc, parm.message, parm.natDesc, parm.offLocDesc, parm.offLocEngDesc, parm.offRegDesc, parm.offRegEngDesc, parm.pcNo, parm.pltCode, parm.pltDesc, parm.pltEngDesc, parm.pltNo, parm.pltPrnDesc, parm.prevExpDateStr, parm.prevIssDateStr, parm.prevOffLocDesc, parm.prevOffRegDesc, parm.prevOffRegEngDesc, parm.prevPltDesc, parm.prevPltNo, parm.prvCode, parm.prvDesc, parm.prvDescEng, parm.rcpNo, parm.reqDateStr, parm.reqNo, parm.reqTrDesc, parm.sex, parm.soi, parm.street, parm.titleAbrev, parm.titleDesc, parm.titleEngAbrev, parm.villageNo, parm.zipCode, parm.alienFlag, parm.ccFlag, parm.DCICode, parm.conditionDesc, parm.organDonateFlag, parm.TRSFlag, parm.firstIssueDateStr, parm.pltDescShort, parm.pltNo1, parm.pltNo2, parm.prevPltDescShort, parm.prevPltNo1, parm.prevPltNo2, parm.pltNoEng, parm.WH_ID, parm.staffId, parm.workstationId, parm.productType, parm.CardEIN, parm.qrCode).ToList(); if (result[0].seqno > 0) { db.SaveChanges(); dbContextTransaction.Commit(); ap.resultCode = "1"; ap.cardEIN = parm.CardEIN; ap.message = "OK"; } else { if (db.Database.Connection != null) { try { dbContextTransaction.Rollback(); } catch { } } ap.cardEIN = parm.CardEIN; ap.resultCode = "0"; ap.message = "not found"; } //dbContextTransaction.Rollback(); } catch (Exception ex) { if (db.Database.Connection != null) { try { dbContextTransaction.Rollback(); } catch { } } ap.cardEIN = parm.CardEIN; ap.resultCode = "0"; if (ex.InnerException != null) { ap.message = ex.InnerException.Message; if (ex.InnerException.StackTrace != null) { ap.message += " + InnerException.StackTrace: " + ex.InnerException.StackTrace; } } if (ex.Message != null) { ap.message += "+" + ex.Message; if (ex.StackTrace != null) { ap.message += " + StackTrace: " + ex.StackTrace; } } if (ex.InnerException == null && ex.Message == null) { ap.message = "Error: SaveCard catch 2"; } ap.message += " (Step 2)"; //ap.message = ex.InnerException == null ? (ex.Message == null ? "Error: SaveCard catch 2" : ex.Message) : ex.InnerException.Message + " StackTrace:" + ex.StackTrace; } } } string json = new JavaScriptSerializer().Serialize(ap); context.Response.ContentType = "text/javascript"; context.Response.Write(json); } catch (Exception ex) { SaveCardResponse ap = new SaveCardResponse(); ap.cardEIN = cardEIN; ap.resultCode = "0"; if (ex.InnerException != null) { ap.message = ex.InnerException.Message; if (ex.InnerException.StackTrace != null) { ap.message += " + InnerException.StackTrace: " + ex.InnerException.StackTrace; } } if (ex.Message != null) { ap.message += "+" + ex.Message; if (ex.StackTrace != null) { ap.message += " + StackTrace: " + ex.StackTrace; } } if (ex.InnerException == null && ex.Message == null) { ap.message = "Error: SaveCard catch 1"; } ap.message += " (Step 1)"; string json = new JavaScriptSerializer().Serialize(ap); context.Response.ContentType = "text/javascript"; context.Response.Write(json); } }
public ActionResult Create([Bind(Include = "ID,CreateBy,CreateDate,TgID,Subject,Description,Picture,TpID,Status,WhID,CommendDescription")] Issue issue) { if (ModelState.IsValid) { issue.Status = "1"; //กำลังดำเนินการ db.Issues.Add(issue); db.SaveChanges(); int isid = issue.ID; if (issue.CommendDescription != null && issue.CommendDescription.ToString() != "") { Commend c = new Commend(); c.CreateBy = issue.CreateBy; //c.CreateDate = issue.CreateDate; c.Description = issue.CommendDescription; c.Status = issue.Status; c.IsID = isid; db.Commends.Add(c); db.SaveChanges(); } return(RedirectToAction("Index")); } ViewBag.CommendList = new SelectList(db.Commends, "ID", "Description"); ViewBag.TgList = new SelectList(db.TopicGroups, "ID", "Name"); ViewBag.WhList = db.Warehouses.ToList(); ViewBag.StList = db.Staffs.ToList(); var list = db.Topics.ToList(); foreach (var i in list) { i.Name = i.Subject; } ViewBag.TpList = list; return(View(issue)); }
public void ProcessRequest(HttpContext context) { try { GetCardInfoRequest parm = new GetCardInfoRequest(); using (StreamReader sr = new StreamReader(context.Request.InputStream)) { String data = sr.ReadToEnd(); parm = new JavaScriptSerializer().Deserialize <GetCardInfoRequest>(data); } GetCardInfoResponse ap = new GetCardInfoResponse(); using (DLSMEntities db = new DLSMEntities()) { db.Database.Connection.Open(); using (var dbContextTransaction = db.Database.BeginTransaction()) { try { var result = db.sp_ApiGetCardInfo(parm.WH_ID, parm.staffId, parm.cardEIN).ToList(); if (result.Count() > 0) { db.SaveChanges(); dbContextTransaction.Commit(); ap.addrNo = result[0].addrNo; ap.ampDesc = result[0].ampDesc; ap.ampDescEng = result[0].ampDescEng; ap.birthDateStr = result[0].birthDateStr; ap.birthFlag = result[0].birthFlag; ap.distDesc = result[0].distDesc; ap.distDescEng = result[0].distDescEng; ap.docNo = result[0].docNo; ap.docType = result[0].docType; ap.reqMasRef = result[0].reqMasRef; ap.expDateStr = result[0].expDateStr; ap.fname = result[0].fname; ap.fnameEng = result[0].fnameEng; ap.issDateStr = result[0].issDateStr; ap.issOffLocCode = result[0].issOffLocCode; ap.lane = result[0].lane; ap.lname = result[0].lname; ap.lnameEng = result[0].lnameEng; ap.locFullDesc = result[0].locFullDesc; ap.natDesc = result[0].natDesc; ap.offLocDesc = result[0].offLocDesc; ap.offLocEngDesc = result[0].offLocEngDesc; ap.offRegDesc = result[0].offRegDesc; ap.offRegEngDesc = result[0].offRegEngDesc; ap.pcNo = result[0].pcNo; ap.pltCode = result[0].pltCode; ap.pltDesc = result[0].pltDesc; ap.pltEngDesc = result[0].pltEngDesc; ap.pltNo = result[0].pltNo; ap.pltPrnDesc = result[0].pltPrnDesc; ap.prevExpDateStr = result[0].prevExpDateStr; ap.prevIssDateStr = result[0].prevIssDateStr; ap.prevOffLocDesc = result[0].prevOffLocDesc; ap.prevOffRegDesc = result[0].prevOffRegDesc; ap.prevOffRegEngDesc = result[0].prevOffRegEngDesc; ap.prevPltDesc = result[0].prevPltDesc; ap.prevPltNo = result[0].prevPltNo; ap.prvCode = result[0].prvCode; ap.prvDesc = result[0].prvDesc; ap.prvDescEng = result[0].prvDescEng; ap.rcpNo = result[0].rcpNo; ap.reqDateStr = result[0].reqDateStr; ap.reqNo = result[0].reqNo; ap.reqTrDesc = result[0].reqTrDesc; ap.sex = result[0].sex; ap.soi = result[0].soi; ap.street = result[0].street; ap.titleAbrev = result[0].titleAbrev; ap.titleDesc = result[0].titleDesc; ap.titleEngAbrev = result[0].titleEngAbrev; ap.villageNo = result[0].villageNo; ap.zipCode = result[0].zipCode; ap.alienFlag = result[0].alienFlag; ap.ccFlag = result[0].ccFlag; ap.DCICode = result[0].DCICode; ap.conditionDesc = result[0].conditionDesc; ap.organDonateFlag = result[0].organDonateFlag; ap.TRSFlag = result[0].TRSFlag; ap.firstIssueDateStr = result[0].firstIssueDateStr; ap.pltDescShort = result[0].pltDescShort; ap.pltNo1 = result[0].pltNo1; ap.pltNo2 = result[0].pltNo2; ap.prevPltDescShort = result[0].prevPltDescShort; ap.prevPltNo1 = result[0].prevPltNo1; ap.prevPltNo2 = result[0].prevPltNo2; ap.pltNoEng = result[0].pltNoEng; ap.workstationId = result[0].workstationId; ap.productType = result[0].productType; ap.CardEIN = result[0].CardEIN; ap.qrCode = result[0].qrCode; ap.cardStatus = result[0].cardStatus; // 1: ดี , 2: เสีย, 3: ไม่พิมพ์ ap.startPrintDttmStr = result[0].startPrintDttmStr; ap.finishPrintDttmStr = result[0].finishPrintDttmStr; ap.person_image = result[0].PartData; ap.message = "OK"; ap.resultCode = "1"; } else { dbContextTransaction.Rollback(); ap.resultCode = "0"; ap.message = "not found"; } } catch (Exception ex) { dbContextTransaction.Rollback(); ap.resultCode = "0"; ap.message = ex.InnerException == null ? (ex.Message == null ? "Error: GetCardInfo catch 2" : ex.Message) : ex.InnerException.Message + " StackTrace:" + ex.StackTrace; } } } string json = new JavaScriptSerializer().Serialize(ap); context.Response.ContentType = "text/javascript"; context.Response.Write(json); } catch (Exception ex) { GetCardInfoResponse ap = new GetCardInfoResponse(); ap.resultCode = "0"; ap.message = ex.InnerException == null ? (ex.Message == null ? "Error: GetCardInfo catch 1" : ex.Message) : ex.InnerException.Message + " StackTrace:" + ex.StackTrace; string json = new JavaScriptSerializer().Serialize(ap); context.Response.ContentType = "text/javascript"; context.Response.Write(json); } }
public ActionResult InsertFailCard(StockSerial model) { var context = new DLSMEntities(); var UserID = Session["UserID"].ToString(); model.CardList.RemoveAt(0); foreach (var a in model.CardList) { StockSerial SS = new StockSerial(); SS.ID = a.ID; SS.WhID = a.WhID; SS.SerialBegin = a.CardSerial; SS.Name = a.CardDate; SS.IpProperty = a.Remark; SaveCardResponse ap = new SaveCardResponse(); using (DLSMEntities db = new DLSMEntities()) { db.Database.Connection.Open(); using (var dbContextTransaction = db.Database.BeginTransaction()) { try { var result = context.sp_SaveCardManual("", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", Convert.ToString(SS.WhID), UserID, "", "", SS.SerialBegin, "", Convert.ToDateTime(SS.Name), SS.IpProperty).ToList(); if (result[0].seqno > 0) { db.SaveChanges(); dbContextTransaction.Commit(); ap.resultCode = "1"; ap.cardEIN = SS.SerialBegin; ap.message = "OK"; } else { if (db.Database.Connection != null) { try { dbContextTransaction.Rollback(); } catch { } } ap.cardEIN = SS.SerialBegin; ap.resultCode = "0"; ap.message = "not found"; } //dbContextTransaction.Rollback(); } catch (Exception ex) { if (db.Database.Connection != null) { try { dbContextTransaction.Rollback(); return(Json("ERROR : " + ex.ToString())); } catch { } } ap.cardEIN = SS.SerialBegin; ap.resultCode = "0"; if (ex.InnerException != null) { ap.message = ex.InnerException.Message; if (ex.InnerException.StackTrace != null) { ap.message += " + InnerException.StackTrace: " + ex.InnerException.StackTrace; } } if (ex.Message != null) { ap.message += "+" + ex.Message; if (ex.StackTrace != null) { ap.message += " + StackTrace: " + ex.StackTrace; } } if (ex.InnerException == null && ex.Message == null) { ap.message = "Error: SaveCard catch 2"; } ap.message += " (Step 2)"; //ap.message = ex.InnerException == null ? (ex.Message == null ? "Error: SaveCard catch 2" : ex.Message) : ex.InnerException.Message + " StackTrace:" + ex.StackTrace; } } } //string json = new JavaScriptSerializer().Serialize(ap); //context.Response.ContentType = "text/javascript"; //context.Response.Write(json); } return(Json("success")); }
public ActionResult ReceiveStock(Document model) { var oldstatus = model.Status; using (DLSMEntities context = new DLSMEntities()) { using (var dbContextTransaction = context.Database.BeginTransaction()) { try { //Update Status var upd = (from d in context.Documents where d.ID == model.ID select d).ToList().SingleOrDefault(); upd.Status = model.Status; upd.Remark = model.Remark; context.SaveChanges(); dbContextTransaction.Commit(); if (model.Status.ToString() == "8") //ถ็า Reject มา Status ก่อนหน้าเป็น 7 ต้องรับของคืน Status จะเป็น 8 และแก้ไข Stock { string avbError = CheckAvailable(model); string snError = CheckSerialIn(model); if (avbError == "Y" && snError == "Y") { // Execute store procudure var docid = model.ID; var userid = int.Parse(Session["UserID"].ToString()); var result = context.sp_ProcessDocument(docid, userid).ToList(); if (result[0].ID == 1) { context.SaveChanges(); dbContextTransaction.Commit(); } else { dbContextTransaction.Rollback(); } } else { //return Json(); throw new Exception(avbError != "Y" ? avbError : "" + snError != "Y" ? snError : ""); } } } catch (Exception ex) { dbContextTransaction.Rollback(); //Update Status var upd = (from d in context.Documents where d.ID == model.ID select d).ToList().SingleOrDefault(); upd.Status = oldstatus; return(Json(ex.InnerException.Message)); } } } return(Json("success")); }