Esempio n. 1
0
        public ActionResult GetOrder(string id)
        {
            SalesOrder order = null;
            Guid       ID    = Guid.Empty;


            if (!string.IsNullOrEmpty(id))
            {
                if (Guid.TryParse(id, out ID))
                {
                    order = oc.BLLSession.ISalesOrderBLL.Entities.FirstOrDefault(s => s.ID.Equals(ID));
                }
                else
                {
                    return(PackagingAjaxmsg(new AjaxMsgModel(AjaxStatu.err, "传入的参数有误!")));
                }
            }
            else
            {
                order = Model_SalesOrder.CreateOrder();
            }
            var obj = new
            {
                ID         = order.ID,
                BillCode   = order.BillCode,
                OrderDate  = order.OrderDate,
                CustomerID = oc.BLLSession.ICustomerBLL.Entities.Where(c => c.ID == order.CustomerID).Select(c => new { ID = c.ID, Code = c.Code, Name = c.Name }).FirstOrDefault(),
                Remark     = order.Remark
            };

            return(Json(obj, JsonRequestBehavior.AllowGet));
        }
Esempio n. 2
0
        /// <summary>
        /// 保存订单
        /// </summary>
        /// <returns></returns>
        public ActionResult Save(string id)
        {
            var           sr     = new StreamReader(Request.InputStream);
            var           str    = sr.ReadToEnd();
            var           objs   = DataHelper.JsonToObject(str) as Dictionary <string, object>;
            List <object> detail = new List <object>();
            Guid          ID     = Guid.Empty;

            Guid.TryParse(id, out ID);
            SalesOrder order = oc.BLLSession.ISalesOrderBLL.Entities.FirstOrDefault(s => s.ID.Equals(ID));
            List <SalesOrderDetail> details = oc.BLLSession.ISalesOrderDetailBLL.Entities.Where(s => s.MainID.Equals(ID)).ToList() ?? new List <SalesOrderDetail>();

            order = order ?? Model_SalesOrder.CreateOrder();
            var props           = typeof(SalesOrder).GetProperties();
            var detailPropertys = typeof(SalesOrderDetail).GetProperties();

            foreach (var obj in objs)
            {
                if (obj.Value is object[])
                {
                    detail.AddRange(obj.Value as object[]);
                    continue;
                }
                // Console.WriteLine("列:{0}--值:{1}", obj.Key, obj.Value);
                var p = props.FirstOrDefault(o => o.Name == obj.Key);
                if (p != null)
                {
                    p.SetValue(order, p.PropertyType.ChangeType(obj.Value), null);
                    //p.SetValue(order, obj.Value, null);
                }
            }
            if (detail.Count > 0)
            {
                details = new List <SalesOrderDetail>();
            }
            foreach (var o in detail)
            {
                var  columns  = o as Dictionary <string, object>;
                Guid detailID = Guid.Empty;
                if (columns.ContainsKey("ID"))
                {
                    Guid.TryParse(columns["ID"].ToString(), out detailID);
                }
                if (detailID.Equals(Guid.Empty))
                {
                    detailID = Guid.NewGuid();
                }
                SalesOrderDetail salesOrderDetail = details.FirstOrDefault(d => d.Equals(detailID));
                if (salesOrderDetail == null)
                {
                    salesOrderDetail = new SalesOrderDetail()
                    {
                        ID = detailID
                    };
                    details.Add(salesOrderDetail);
                }

                salesOrderDetail.MainID = ID;
                foreach (var c in columns)
                {
                    Console.WriteLine("列:{0}--值:{1}", c.Key, c.Value);
                    var p = detailPropertys.FirstOrDefault(ps => ps.Name == c.Key);
                    if (p != null)
                    {
                        p.SetValue(salesOrderDetail, p.PropertyType.ChangeType(c.Value), null);
                    }
                }
            }
            oc.BLLSession.ISalesOrderBLL.Modify(order);
            return(PackagingAjaxmsg(new AjaxMsgModel(AjaxStatu.ok, "保存成功!")));
        }