Beispiel #1
0
        /// <summary>
        /// 采购订单-新增
        /// </summary>
        /// <param name="tpurorder"></param>
        /// <param name="tpurorderdtl"></param>
        /// <param name="tpurorderatt"></param>
        /// <returns></returns>
        public int AddPurOrderDtl(tpurorder tpurodr, List <tpurorderdtl> tpurodrdtl, List <tpurorderatt> tpurodratt)
        {
            int ret = 0;

            using (var tran = erpsEntities.Database.BeginTransaction())
            {
                try
                {
                    erpsEntities.tpurorder.Add(tpurodr);
                    erpsEntities.tpurorderdtl.AddRange(tpurodrdtl);
                    erpsEntities.tpurorderatt.AddRange(tpurodratt);

                    ret = erpsEntities.SaveChanges();
                    tran.Commit();
                    if (ret > 0)
                    {
                        ret = 1;
                    }
                    return(ret);
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    ret = -1;
                    throw ex;
                }
            }
        }
Beispiel #2
0
        public int EditPurOrderDtl(string purOrderNo, tpurorder tpurorder, List <tpurorderdtl> tpurodrdtl, List <tpurorderatt> tpurodratt)
        {
            int ret = 0;

            using (var tran = erpsEntities.Database.BeginTransaction())
            {
                try
                {
                    var tpodr = erpsEntities.tpurorder.Attach(tpurorder);
                    erpsEntities.Entry(tpurorder).Property("TotalNum").IsModified    = true;
                    erpsEntities.Entry(tpurorder).Property("TotalAmount").IsModified = true;
                    erpsEntities.Entry(tpurorder).Property("Remark").IsModified      = true;
                    erpsEntities.Entry(tpurorder).Property("AppointDate").IsModified = true;
                    erpsEntities.Entry(tpurorder).Property("UpdateID").IsModified    = true;
                    erpsEntities.Entry(tpurorder).Property("UpdateDate").IsModified  = true;
                    var vm = erpsEntities.tpurorderdtl.Where(m => m.PurOrderNO == purOrderNo);
                    vm.ToList().ForEach(t => erpsEntities.Entry(t).State = EntityState.Deleted);
                    erpsEntities.tpurorderdtl.RemoveRange(vm);

                    erpsEntities.tpurorderdtl.AddRange(tpurodrdtl);
                    erpsEntities.tpurorderatt.AddRange(tpurodratt);

                    ret = erpsEntities.SaveChanges();
                    tran.Commit();
                    if (ret > 0)
                    {
                        ret = 1;
                    }
                    return(ret);
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    ret = -1;
                    throw ex;
                }
            }
        }
Beispiel #3
0
        public BaseDataPackage <string> EditPurOrderDtl()
        {
            var result = new BaseDataPackage <string>();

            try
            {
                HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"]; //获取传统context
                HttpRequestBase request = context.Request;                                       //定义传统request对象

                string PurOrderNO = request.Form["PurOrderNO"];
                string SupID      = request.Form["SupID"];
                string UserID     = request.Form["UserID"];
                string CreDate    = request.Form["CreDate"];

                tpurorder tpurorder = new tpurorder();
                tpurorder.PurOrderNO  = PurOrderNO;
                tpurorder.SupID       = request.Form["SupID"];
                tpurorder.CreDate     = Convert.ToDateTime(CreDate);
                tpurorder.TotalNum    = float.Parse(request.Form["TotalNum"]);
                tpurorder.TotalAmount = float.Parse(request.Form["TotalAmount"]);
                tpurorder.AppointDate = Convert.ToDateTime(request.Form["AppointDate"]);
                tpurorder.UpdateID    = UserID;
                tpurorder.UpdateDate  = DateTime.Now;

                JavaScriptSerializer js   = new JavaScriptSerializer();
                List <v_purorderdtl> list = js.Deserialize <List <v_purorderdtl> >(request.Params["list"]);
                list.RemoveAll(r => string.IsNullOrEmpty(r.PdtID));
                List <tpurorderdtl> tpurorderdtls = new List <tpurorderdtl>();

                for (int i = 0; i < list.Count; i++)
                {
                    tpurorderdtl tpurorderdtl = new tpurorderdtl();
                    tpurorderdtl.PurOrderNO  = PurOrderNO;
                    tpurorderdtl.SeqNo       = i + 1;
                    tpurorderdtl.SupID       = SupID;
                    tpurorderdtl.PdtID       = list[i].PdtID;
                    tpurorderdtl.DelDate     = list[i].DelDate;
                    tpurorderdtl.OrderNum    = Convert.ToSingle(list[i].OrderNum);
                    tpurorderdtl.LftNum      = Convert.ToSingle(list[i].LftNum);
                    tpurorderdtl.UnitPrice   = list[i].UnitPrice;
                    tpurorderdtl.TotalAmount = list[i].TotalAmount;
                    tpurorderdtl.State       = list[i].State == null ? "N" : list[i].State;
                    tpurorderdtl.Remark      = list[i].Remark;
                    tpurorderdtl.UpdateID    = UserID;
                    tpurorderdtl.UpdateDate  = DateTime.Now;

                    tpurorderdtls.Add(tpurorderdtl);
                }

                List <tpurorderatt> tpurorderatts = new List <tpurorderatt>();

                HttpFileCollection files = HttpContext.Current.Request.Files;

                string url      = "/upload/" + PurOrderNO + "/";
                string basePath = HttpContext.Current.Server.MapPath(url);

                List <string> tmpPath = new List <string>();
                if (files.Count > 0)
                {
                    //如果目录不存在,则创建目录
                    if (!Directory.Exists(basePath))
                    {
                        Directory.CreateDirectory(basePath);
                    }
                    for (int i = 0; i < files.Count; i++)
                    {
                        tpurorderatt tpurorderatt = new tpurorderatt();
                        string       path         = basePath + files[i].FileName;

                        tpurorderatt.PurOrderNO  = PurOrderNO;
                        tpurorderatt.AttFileName = url + files[i].FileName;
                        tpurorderatt.UpdateID    = UserID;
                        tpurorderatt.UpdateDate  = DateTime.Now;

                        tpurorderatts.Add(tpurorderatt);
                        tmpPath.Add(path);
                    }
                }

                int ret = purOrder.EditPurOrderDtl(PurOrderNO, tpurorder, tpurorderdtls, tpurorderatts);
                if (ret == 1)
                {
                    for (int i = 0; i < files.Count; i++)
                    {
                        files[i].SaveAs(tmpPath[i]);
                    }
                    result.Status  = ApiStatusCode.OK;
                    result.Message = "修改成功";
                    return(result);
                }
                else
                {
                    result.Status  = ApiStatusCode.FAIL;
                    result.Message = "修改失败";
                    return(result);
                }
            }
            catch (Exception ex)
            {
                result.Status  = ApiStatusCode.EXCEPTION;
                result.Message = "发生异常=>" + ex.Message;
                return(result);
            }
        }