public ActionResult AddScheduler(int orderId, int orderServiceId, int serviceNatureId, string serviceWorkDate, string serviceWorkTime, string serviceWorkPlace, string tugId, string isCaptainConfirm, string informCaptainTime, string captainConfirmTime, string ropeUsed, int ropeNum, string remark) { this.Internationalization(); try { TugDataEntities db = new TugDataEntities(); { //插入多个调度到数据库 { List<string> lstTugIds = tugId.Split(',').ToList(); if (lstTugIds != null && lstTugIds.Count > 0) { List<Scheduler> lstSchedulers = new List<Scheduler>(); foreach (string item in lstTugIds) { TugDataModel.Scheduler aScheduler = new Scheduler(); //aScheduler.OrderID = orderId; //aScheduler.ServiceNatureID = serviceNatureId; aScheduler.OrderServiceID = orderServiceId; aScheduler.TugID = Util.toint(item); aScheduler.RopeUsed = ropeUsed; aScheduler.RopeNum = ropeNum; aScheduler.Remark = remark; aScheduler.IsCaptainConfirm = isCaptainConfirm; aScheduler.InformCaptainTime = informCaptainTime; aScheduler.CaptainConfirmTime = captainConfirmTime; aScheduler.JobStateID = 32; aScheduler.OwnerID = -1; aScheduler.UserID = Session.GetDataFromSession<int>("userid"); aScheduler.CreateDate = aScheduler.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); aScheduler.UserDefinedCol1 = ""; aScheduler.UserDefinedCol2 = ""; aScheduler.UserDefinedCol3 = ""; aScheduler.UserDefinedCol4 = ""; //if (Request.Form["UserDefinedCol5"].Trim() != "") // aScheduler.UserDefinedCol5 = Convert.ToDouble(Request.Form["UserDefinedCol5"].Trim()); //if (Request.Form["UserDefinedCol6"].Trim() != "") // aScheduler.UserDefinedCol6 = Util.toint(Request.Form["UserDefinedCol6"].Trim()); //if (Request.Form["UserDefinedCol7"].Trim() != "") // aScheduler.UserDefinedCol7 = Util.toint(Request.Form["UserDefinedCol7"].Trim()); //if (Request.Form["UserDefinedCol8"].Trim() != "") // aScheduler.UserDefinedCol8 = Util.toint(Request.Form["UserDefinedCol8"].Trim()); aScheduler.UserDefinedCol9 = ""; aScheduler.UserDefinedCol10 = ""; lstSchedulers.Add(aScheduler); } db.Scheduler.AddRange(lstSchedulers); db.SaveChanges(); } } { //更新订单状态 //OrderInfor tmpOrder = db.OrderInfor.Where(u => u.IDX == orderId).FirstOrDefault(); //if (tmpOrder != null) //{ // tmpOrder.WorkStateID = 3; //已排船 // db.Entry(tmpOrder).State = System.Data.Entity.EntityState.Modified; // db.SaveChanges(); //} } //更新服务状态 { OrderService os = db.OrderService.Where(u => u.IDX == orderServiceId).FirstOrDefault(); if (os == null) { os = new OrderService(); os.CreateDate = os.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); os.OrderID = orderId; os.OwnerID = -1; os.ServiceNatureID = serviceNatureId; os.ServiceWorkDate = serviceWorkDate; os.ServiceWorkTime = serviceWorkTime; os.ServiceWorkPlace = serviceWorkPlace; os.JobStateID = 115; os.UserID = Session.GetDataFromSession<int>("userid"); os = db.OrderService.Add(os); db.SaveChanges(); } else { os.ServiceWorkDate = serviceWorkDate; os.ServiceWorkTime = serviceWorkTime; os.ServiceWorkPlace = serviceWorkPlace; os.JobStateID = 115; os.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); db.Entry(os).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } var ret = new { code = Resources.Common.SUCCESS_CODE, message = Resources.Common.SUCCESS_MESSAGE }; //Response.Write(@Resources.Common.SUCCESS_MESSAGE); return Json(ret); } } catch (Exception) { var ret = new { code = Resources.Common.EXCEPTION_CODE, message = Resources.Common.EXCEPTION_MESSAGE }; //Response.Write(@Resources.Common.EXCEPTION_MESSAGE); return Json(ret); } }
public ActionResult Add_EditOrder(string oper,string ordermark,int customerId, string customerName, string ordDate, int shipId, string shipName, string linkMan, string linkPhone, string linkEmail, string remark,List<string[]> dataListFromTable) { //customerName中&符 customerName = customerName.Replace("~*~", "&"); TugDataModel.OrderInfor aOrder=null; this.Internationalization(); using (System.Transactions.TransactionScope trans = new System.Transactions.TransactionScope()) { try { TugDataEntities db = new TugDataEntities(); { //判断客户名称是否存在 System.Linq.Expressions.Expression<Func<Customer, bool>> expctm = u => u.Name1 == customerName; Customer objctm = db.Customer.Where(expctm).FirstOrDefault(); if (objctm == null) { throw new Exception("客戶名稱不存在!"); } //判断客户船名称是否存在 System.Linq.Expressions.Expression<Func<CustomerShip, bool>> expcts = u => u.Name1 == shipName; CustomerShip objcts = db.CustomerShip.Where(expcts).FirstOrDefault(); if (objcts == null) { throw new Exception("客戶船名稱不存在!"); } //获取服务项 System.Linq.Expressions.Expression<Func<OrderService, bool>> exp = u => u.UserDefinedCol1 == ordermark; List<OrderService> entityos = db.OrderService.Where(exp).ToList(); //先刪除該訂單下的排船信息 for (int i = 0; i < entityos.Count(); i++) { int ordsrvid = Util.toint(entityos[i].IDX); System.Linq.Expressions.Expression<Func<Scheduler, bool>> exp0 = u => u.OrderServiceID == ordsrvid; var entitysch = db.Scheduler.Where(exp0); entitysch.ToList().ForEach(entity => db.Entry(entity).State = System.Data.Entity.EntityState.Deleted); //不加这句也可以 db.Scheduler.RemoveRange(entitysch); db.SaveChanges(); } //先删除订单下的所有服务项 entityos.ForEach(entity => db.Entry(entity).State = System.Data.Entity.EntityState.Deleted); //不加这句也可以 db.OrderService.RemoveRange(entityos); db.SaveChanges(); //删除订单 System.Linq.Expressions.Expression<Func<OrderInfor, bool>> exp2 = u => u.UserDefinedCol1 == ordermark; var entityord = db.OrderInfor.Where(exp2); entityord.ToList().ForEach(entity => db.Entry(entity).State = System.Data.Entity.EntityState.Deleted); //不加这句也可以 db.OrderInfor.RemoveRange(entityord); db.SaveChanges(); //保存 //获取服务项 List<CustomField> listServ; listServ = TugBusinessLogic.Utils.GetServices(); string mcode = TugBusinessLogic.Utils.AutoGenerateOrderSequenceNo(); for (int i = 0; i < dataListFromTable.Count - 1; i++)//最后一行空行 { //保存订单 aOrder = new OrderInfor(); aOrder.Code = mcode;//TugBusinessLogic.Utils.AutoGenerateOrderSequenceNo(); aOrder.CreateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); aOrder.HasInvoice = "否"; //没有账单 aOrder.HasInFlow = "否"; //没有在流程中 aOrder.IsGuest = "否"; //if (oper == "add") //{ // aOrder = new OrderInfor(); // aOrder.Code = TugBusinessLogic.Utils.AutoGenerateOrderSequenceNo(); // aOrder.CreateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); // aOrder.HasInvoice = "否"; //没有账单 // aOrder.HasInFlow = "否"; //没有在流程中 // aOrder.IsGuest = "否"; //} //else if (oper == "edit") //{ // aOrder = db.OrderInfor.Where(u => u.IDX == orderId).FirstOrDefault(); //} aOrder.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //aOrder.CustomerID = customerId; aOrder.CustomerID = CustomerLogic.AutoAddCustomer("", customerName, "", "", linkMan, linkPhone, "", linkEmail, "", "", "", Session.GetDataFromSession<int>("userid")); aOrder.CustomerName = customerName; aOrder.OrdDate = ordDate; aOrder.LinkMan = linkMan; aOrder.LinkPhone = linkPhone; aOrder.LinkEmail = linkEmail; aOrder.OwnerID = -1; aOrder.Remark = remark; //aOrder.ShipID = shipId; aOrder.ShipID = CustomerLogic.AutoAddCustomerShip((int)aOrder.CustomerID, shipName, "", "", "", "", "", "", "", "", Session.GetDataFromSession<int>("userid")); aOrder.ShipName = shipName; aOrder.UserID = Session.GetDataFromSession<int>("userid"); aOrder.WorkStateID = 2; //CustomField表里面的OrderInfor.WorkStateID的IDX 订单修改后订单改为未排船 aOrder.UserDefinedCol1 = mcode; aOrder.UserDefinedCol2 = i.ToString(); aOrder.UserDefinedCol3 = dataListFromTable[i][0]; aOrder.UserDefinedCol4 = ""; //if (Request.Form["UserDefinedCol5"].Trim() != "") // aOrder.UserDefinedCol5 = Convert.ToDouble(Request.Form["UserDefinedCol5"].Trim()); //if (Request.Form["UserDefinedCol6"].Trim() != "") // aOrder.UserDefinedCol6 = Util.toint(Request.Form["UserDefinedCol6"].Trim()); //if (Request.Form["UserDefinedCol7"].Trim() != "") // aOrder.UserDefinedCol7 = Util.toint(Request.Form["UserDefinedCol7"].Trim()); //if (Request.Form["UserDefinedCol8"].Trim() != "") // aOrder.UserDefinedCol8 = Util.toint(Request.Form["UserDefinedCol8"].Trim()); aOrder.UserDefinedCol9 = ""; aOrder.UserDefinedCol10 = ""; aOrder = db.OrderInfor.Add(aOrder); //if (oper == "add") //{ // aOrder = db.OrderInfor.Add(aOrder); //} //else if (oper == "edit") //{ // db.Entry(aOrder).State = System.Data.Entity.EntityState.Modified; //} db.SaveChanges(); //保存服务项 TugDataModel.OrderService obj = new OrderService(); obj.OrderID = aOrder.IDX; string serName = dataListFromTable[i][0]; CustomField sv = listServ.Where(u => u.CustomLabel == serName).FirstOrDefault(); obj.ServiceNatureID = sv.IDX; obj.ServiceWorkDate = TugBusinessLogic.Utils.CNDateTimeToDateTime(dataListFromTable[i][1]).ToString("yyyy-MM-dd"); obj.ServiceWorkTime = dataListFromTable[i][2]; //obj.EstimatedCompletionTime= obj.ServiceWorkPlace = dataListFromTable[i][6]; obj.BigTugNum = Util.toint(dataListFromTable[i][3]); obj.MiddleTugNum = Util.toint(dataListFromTable[i][4]); obj.SmallTugNum = Util.toint(dataListFromTable[i][5]); //obj.Remark = ""; obj.JobStateID = 114; obj.HasBilling = "否"; obj.HasBillingInFlow = "否"; obj.OwnerID = -1; obj.CreateDate = aOrder.CreateDate; obj.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); ; obj.UserID = Session.GetDataFromSession<int>("userid"); obj.UserDefinedCol1 = mcode; //obj.UserDefinedCol2 = ""; //obj.UserDefinedCol3 = ""; //obj.UserDefinedCol4 = ""; //if (Request.Form["UserDefinedCol5"] != "") // obj.UserDefinedCol5 = Util.toint(Request.Form["UserDefinedCol5"]); //obj.UserDefinedCol6 =; //obj.UserDefinedCol7 =; //obj.UserDefinedCol8 =; //obj.UserDefinedCol9 = ""; //obj.UserDefinedCol10 = ""; obj = db.OrderService.Add(obj); db.SaveChanges(); } trans.Complete(); var ret = new { code = Resources.Common.SUCCESS_CODE, message = Resources.Common.SUCCESS_MESSAGE }; //Response.Write(@Resources.Common.SUCCESS_MESSAGE); return Json(ret); } } catch (Exception ex) { trans.Dispose(); throw ex; //var ret = new { code = Resources.Common.EXCEPTION_CODE, message = Resources.Common.EXCEPTION_MESSAGE }; ////Response.Write(@Resources.Common.EXCEPTION_MESSAGE); //return Json(ret); } } }