public ActionResult Edit(StaffInfo staff) { if (ModelState.IsValid) { //db.Entry(staff).State = EntityState.Modified; db.StaffInfo.Attach(staff); var tempEntity = db.Entry(staff); tempEntity.Property(item => item.Phone).IsModified = true; tempEntity.Property(item => item.telPhone).IsModified = true; tempEntity.Property(item => item.Address).IsModified = true; tempEntity.Property(item => item.HomeAddress).IsModified = true; tempEntity.Property(item => item.BirthDate).IsModified = true; tempEntity.Property(item => item.JoinInDate).IsModified = true; tempEntity.Property(item => item.EmergencyName).IsModified = true; tempEntity.Property(item => item.Password).IsModified = true; tempEntity.Property(item => item.Remarks).IsModified = true; db.SaveChanges(); return(RedirectToAction("Detail", staff)); } return(Content("输入修改施工单数据无效"));; }
public ActionResult Create(Schedules schedules, int machine, int temporary = 0) { if (!(ModelState.IsValid && machine > 0)) { return(Content("输入创建施工单数据无效")); } int userId = Convert.ToInt32(Session["UserID"]); Orders orderInfo = null; using (var t = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted })) { orderInfo = db.Orders.Find(schedules.OrderId); if (temporary == 0 && orderInfo.ProductFreeCount < schedules.ProductCount) { this.modelSchOrder.Schedules = schedules; this.modelSchOrder.Orders = orderInfo; this.modelSchOrder.SelectMachine(machine); ViewData["error"] = "分派数量超过订单剩余总数"; return(View(this.modelSchOrder)); } Machines currentMachine = this.db.Machines.Find(machine); schedules.MachineId = machine; schedules.MachineName = currentMachine.Name; schedules.RoomId = currentMachine.RoomID; if (!roomControl.CheckUserInRoom(userId, schedules.RoomId)) { return(RedirectToAction("Login", "Account")); } schedules.OrderNumber = orderInfo.OrderNumber; schedules.ProductCode = orderInfo.ProductCode; schedules.ProductUnit = orderInfo.ProductUnit; schedules.ProductInfo = orderInfo.ProductInfo; schedules.RoomNumber = orderInfo.RoomNumber; schedules.DateCreate = DateTime.Now; schedules.DateLastUpdate = DateTime.Now; schedules.FinishCount = 0; schedules.CreatorID = userId; schedules.CreatorName = User.Identity.Name; schedules.LastUpdatePersonID = schedules.CreatorID; schedules.LastUpdatePersonName = User.Identity.Name; string strMaterial = string.Empty; foreach (string tempKey in Request.Form.AllKeys) { if (tempKey.StartsWith("cm") && Request.Form[tempKey].Contains("true")) { strMaterial += tempKey.Substring(2) + ";"; } } if (strMaterial.Length > 0) { schedules.MaterialInfo = strMaterial.Substring(0, strMaterial.Length - 1); string strMatDetail = string.Empty; this.modelSchOrder.GetOrderMaterial(schedules.MaterialInfo); foreach (KeyValuePair <int, string> tempItem in this.modelSchOrder.MaterialList) { strMatDetail += tempItem.Value + ";"; } schedules.MaterialDetail = strMatDetail; } string tempNumberStr = KeepLength_CutFillStart(orderInfo.AssignedCount + 1, 4, '0'); schedules.Number = string.Format("{0}-{1}", schedules.OrderNumber, tempNumberStr); schedules.Status = temporary > 0 ? enumStatus.Temporary : enumStatus.Unhandle; db.Schedules.Add(schedules); } if (temporary == 0) { orderInfo.ProductFreeCount -= schedules.ProductCount; orderInfo.ProductAssignedCount += schedules.ProductCount; orderInfo.AssignedCount += 1; db.Entry(orderInfo).State = EntityState.Modified; } db.SaveChanges(); return(RedirectToAction("Index", new { id = schedules.OrderId })); }