Beispiel #1
0
        public ActionResult AddEdit()
        {
            this.Internationalization();

            #region Add

            if (Request.Form["oper"].Equals("add"))
            {
                try
                {
                    TugDataEntities db = new TugDataEntities();
                    {
                        TugDataModel.OrderInfor aOrder = new OrderInfor();

                        aOrder.Code = TugBusinessLogic.Utils.AutoGenerateOrderSequenceNo();

                        aOrder.CreateDate = aOrder.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        aOrder.CustomerID = Util.toint(Request.Form["CustomerID"]);
                        aOrder.CustomerName = Request.Form["CustomerName"].Trim();
                        aOrder.OrdDate = Request.Form["OrdDate"].Trim();
                        //aOrder.WorkDate = Request.Form["WorkDate"].Trim();
                        //aOrder.WorkTime = Request.Form["WorkTime"].Trim();
                        //aOrder.EstimatedCompletionTime = Request.Form["EstimatedCompletionTime"].Trim();

                        aOrder.IsGuest = "否"; // Request.Form["IsGuest"].Trim();
                        aOrder.LinkMan = Request.Form["LinkMan"].Trim();
                        aOrder.LinkPhone = Request.Form["LinkPhone"].Trim();
                        aOrder.LinkEmail = Request.Form["LinkEmail"].Trim();

                        //if (Request.Form["BigTugNum"].Trim() != "")
                        //    aOrder.BigTugNum = Util.toint(Request.Form["BigTugNum"].Trim());
                        //if (Request.Form["MiddleTugNum"].Trim() != "")
                        //    aOrder.MiddleTugNum = Util.toint(Request.Form["MiddleTugNum"].Trim());
                        //if (Request.Form["SmallTugNum"].Trim() != "")
                        //    aOrder.SmallTugNum = Util.toint(Request.Form["SmallTugNum"].Trim());

                        aOrder.OwnerID = -1;
                        aOrder.Remark = Request.Form["Remark"].Trim();
                        aOrder.ShipID = Util.toint(Request.Form["ShipID"].Trim());
                        aOrder.ShipName = Request.Form["ShipName"].Trim();
                        aOrder.UserID = Session.GetDataFromSession<int>("userid");
                        //aOrder.WorkPlace = Request.Form["WorkPlace"].Trim();

                        //Dictionary<string, string> dic = TugBusinessLogic.Utils.ResolveServices(Request.Form["ServiceNatureNames"].Trim());
                        //aOrder.ServiceNatureIDS = dic["ids"];
                        //aOrder.ServiceNatureNames = dic["labels"];

                        //aOrder.WorkStateID = Util.toint(Request.Form["WorkStateID"].Trim());
                        aOrder.WorkStateID = 2; //CustomField表里面的OrderInfor.WorkStateID的IDX

                        aOrder.UserDefinedCol1 = Request.Form["UserDefinedCol1"].Trim();
                        aOrder.UserDefinedCol2 = Request.Form["UserDefinedCol2"].Trim();
                        aOrder.UserDefinedCol3 = Request.Form["UserDefinedCol3"].Trim();
                        aOrder.UserDefinedCol4 = Request.Form["UserDefinedCol4"].Trim();

                        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 = Request.Form["UserDefinedCol9"].Trim();
                        aOrder.UserDefinedCol10 = Request.Form["UserDefinedCol10"].Trim();

                        aOrder = db.OrderInfor.Add(aOrder);
                        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);
                }
            }

            #endregion Add

            #region Edit

            if (Request.Form["oper"].Equals("edit"))
            {
                try
                {
                    TugDataEntities db = new TugDataEntities();

                    int idx = Util.toint(Request.Form["IDX"].Trim());
                    OrderInfor aOrder = db.OrderInfor.Where(u => u.IDX == idx).FirstOrDefault();

                    if (aOrder == null)
                    {
                        return Json(new { code = Resources.Common.ERROR_CODE, message = Resources.Common.ERROR_MESSAGE });
                    }
                    else
                    {
                        aOrder.CustomerID = Util.toint(Request.Form["CustomerID"].Trim());
                        aOrder.CustomerName = Request.Form["CustomerName"].Trim();
                        aOrder.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                        //aOrder.IsGuest = Request.Form["IsGuest"].Trim();
                        aOrder.LinkMan = Request.Form["LinkMan"].Trim();
                        aOrder.LinkPhone = Request.Form["LinkPhone"].Trim();
                        aOrder.LinkEmail = Request.Form["LinkEmail"].Trim();

                        aOrder.OrdDate = Request.Form["OrdDate"].Trim();
                        //aOrder.WorkDate = Request.Form["WorkDate"].Trim();
                        //aOrder.WorkTime = Request.Form["WorkTime"].Trim();
                        //aOrder.EstimatedCompletionTime = Request.Form["EstimatedCompletionTime"].Trim();

                        aOrder.ShipID = Util.toint(Request.Form["ShipID"].Trim());
                        aOrder.ShipName = Request.Form["ShipName"].Trim();
                        //if (Request.Form["BigTugNum"].Trim() != "")
                        //    aOrder.BigTugNum = Util.toint(Request.Form["BigTugNum"].Trim());
                        //if (Request.Form["MiddleTugNum"].Trim() != "")
                        //    aOrder.MiddleTugNum = Util.toint(Request.Form["MiddleTugNum"].Trim());
                        //if (Request.Form["SmallTugNum"].Trim() != "")
                        //    aOrder.SmallTugNum = Util.toint(Request.Form["SmallTugNum"].Trim());
                        //aOrder.WorkPlace = Request.Form["WorkPlace"].Trim();

                        //Dictionary<string, string> dic = TugBusinessLogic.Utils.ResolveServices(Request.Form["ServiceNatureNames"].Trim());
                        //aOrder.ServiceNatureIDS = dic["ids"];
                        //aOrder.ServiceNatureNames = dic["labels"];

                        //aOrder.WorkStateID = Util.toint(Request.Form["WorkStateID"].Trim());

                        aOrder.Remark = Request.Form["Remark"].Trim();

                        aOrder.UserDefinedCol1 = Request.Form["UserDefinedCol1"].Trim();
                        aOrder.UserDefinedCol2 = Request.Form["UserDefinedCol2"].Trim();
                        aOrder.UserDefinedCol3 = Request.Form["UserDefinedCol3"].Trim();
                        aOrder.UserDefinedCol4 = Request.Form["UserDefinedCol4"].Trim();

                        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 = Request.Form["UserDefinedCol9"].Trim();
                        aOrder.UserDefinedCol10 = Request.Form["UserDefinedCol10"].Trim();

                        db.Entry(aOrder).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();

                        return Json(new { code = Resources.Common.SUCCESS_CODE, message = Resources.Common.SUCCESS_MESSAGE });
                    }
                }
                catch (Exception exp)
                {
                    return Json(new { code = Resources.Common.EXCEPTION_CODE, message = Resources.Common.EXCEPTION_MESSAGE });
                }
            }

            #endregion Edit

            return Json(new { code = Resources.Common.ERROR_CODE, message = Resources.Common.ERROR_MESSAGE });
        }
Beispiel #2
0
        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);
                }
            }
        }