コード例 #1
0
 /// <summary>
 /// 删除物料
 /// </summary>
 private void DeleteMaterial(HttpContext context)
 {
     //需要一个实体对象参数
     //1,创建要删除的对象
     Model.base_Material m = new Model.base_Material()
     {
         ID = int.Parse(context.Request["ID"] + ""),//仓库ID
     };
     //2,将对象添加到EF管理容器中
     db.base_Material.Attach(m);
     //3,修改对象的包装类对象标识为删除状态
     db.base_Material.Remove(m);
     //4,更新到数据库
     int num = db.SaveChanges();
     if (num > 0)
     {
         string ModelNumber = context.Request["ModelNumber"] + "";
         string MaterialName = context.Request["MaterialName"] + "";
         //删除物料库存表的记录
         foreach (var item in
                       db.domain_Material_WareHouse.Where(w => w.MaterialModelNumber == ModelNumber && w.MaterialName == MaterialName))
         {
             //2,将对象添加到EF管理容器中
             db.domain_Material_WareHouse.Attach(item);
             //3,修改对象的包装类对象标识为删除状态
             db.domain_Material_WareHouse.Remove(item);
         }
     }
     db.SaveChanges();
     context.Response.Write("{\"d\":" + num + "}");
 }
コード例 #2
0
        /// <summary>
        /// 编辑物料
        /// </summary>
        private void EditMaterial(HttpContext context)
        {
            int ID = NCore.DataConvert.ToInt(context.Request["ID"],0);
            string ModelNumber = context.Request["ModelNumber"] + "";
            string ModelNumber_old = context.Request["ModelNumber_old"] + "";
            //新输入的型号和原来的型号不一致,才执行。
            if(!ModelNumber.Equals(ModelNumber_old))
            {
            //判断型号是否已经存在
            List<int> listM = db.base_Material.Where(w => w.ModelNumber == ModelNumber).Select(s => s.ID).ToList();
            if (listM.Count > 0)
            {
                context.Response.Write("{\"d\":-1,\"msg\":\"型号【" + ModelNumber + "】已存在!\"}");
                return;
            }
            }
            string MaterialName = context.Request["MaterialName"] + "";
            string MaterialName_old = context.Request["MaterialName_old"] + "";
            int CategoryID = NCore.DataConvert.ToInt(context.Request["CategoryID"]+"", 0);
            string CategoryName = context.Request["CategoryName"] + "";
            int AttributeID = NCore.DataConvert.ToInt(context.Request["AttributeID"] + "", 0);
            string AttributeName = context.Request["AttributeName"] + "";
            int UnitID = NCore.DataConvert.ToInt(context.Request["UnitID"] + "", 0);
            string UnitName = context.Request["UnitName"] + "";
            int UpperLimit = NCore.DataConvert.ToInt(context.Request["UpperLimit"] + "", 0);
            int LowerLimit = NCore.DataConvert.ToInt(context.Request["LowerLimit"] + "", 0);
            string TechnicalParameter = context.Request["TechnicalParameter"] + "";
            int Status = NCore.DataConvert.ToInt(context.Request["Status"] + "", 0);

            Model.base_Material m = new Model.base_Material()
            {
                ID =ID,
                MaterialName = MaterialName,
                ModelNumber = ModelNumber,
                CategoryID = CategoryID,
                CategoryName = CategoryName,
                AttributeID = AttributeID,
                AttributeName = AttributeName,
                UnitID = UnitID,
                UnitName = UnitName,
                UpperLimit = UpperLimit,
                LowerLimit = LowerLimit,
                TechnicalParameter = TechnicalParameter,
                Status = Status,
                LastUpdateBy = UserInfo.UserName,//添加人
                LastUpdateTime = DateTime.Now//添加时间
            };

            //先将实体附加到实体上下文中
            db.base_Material.Attach(m);
            //手动修改实体的状态
            db.Entry(m).State = EntityState.Modified;
            int num = db.SaveChanges();
            //删除物料库存表的记录
            foreach (var item in
                          db.domain_Material_WareHouse.Where(w => w.MaterialModelNumber == ModelNumber_old && w.MaterialName==MaterialName_old))
            {
                 //2,将对象添加到EF管理容器中
                db.domain_Material_WareHouse.Attach(item);
                //3,修改对象的包装类对象标识为删除状态
                db.domain_Material_WareHouse.Remove(item);
            }
            db.SaveChanges();
            if (num > 0)
            {
                string Material_WareHouse = context.Request["Material_WareHouse"] ?? "";
                if (!string.IsNullOrEmpty(Material_WareHouse))
                {
                    //把json字符串转换成对象
                    List<Model.domain_Material_WareHouse> listMW = NCore.Json.JsonToListOnDCJS<Model.domain_Material_WareHouse>(Material_WareHouse);
                    if (listMW != null && listMW.Count > 0)
                    {
                        foreach (Model.domain_Material_WareHouse mw in listMW)
                        {
                            mw.MaterialModelNumber = ModelNumber;
                            mw.MaterialName = MaterialName;
                            db.domain_Material_WareHouse.Add(mw);
                        }

                        db.SaveChanges();
                    }
                }
                context.Response.Write("{\"d\":1}");
            }
            else
            {
                context.Response.Write("{\"d\":0,\"msg\":\"保存失败!\"}");
            }
        }
コード例 #3
0
        /// <summary>
        /// 添加物料信息
        /// </summary>
        private void AddMaterial(HttpContext context)
        {
            string ModelNumber = context.Request["ModelNumber"] + "";
            //判断型号是否已经存在
            List<int> listM = db.base_Material.Where(w => w.ModelNumber == ModelNumber).Select(s => s.ID).ToList();
            if (listM.Count > 0)
            {
                context.Response.Write("{\"d\":-1,\"msg\":\"型号【" + ModelNumber + "】已存在!\"}");
                return;
            }
            string MaterialName = context.Request["MaterialName"] + "";
            int CategoryID = NCore.DataConvert.ToInt(context.Request["CategoryID"]+"", 0);
            string CategoryName = context.Request["CategoryName"] + "";
            int AttributeID = NCore.DataConvert.ToInt(context.Request["AttributeID"] + "", 0);
            string AttributeName = context.Request["AttributeName"] + "";
            int UnitID = NCore.DataConvert.ToInt(context.Request["UnitID"] + "", 0);
            string UnitName = context.Request["UnitName"] + "";
            int UpperLimit = NCore.DataConvert.ToInt(context.Request["UpperLimit"] + "", 0);
            int LowerLimit = NCore.DataConvert.ToInt(context.Request["LowerLimit"] + "", 0);
            string TechnicalParameter = context.Request["TechnicalParameter"] + "";
            int Status = NCore.DataConvert.ToInt(context.Request["Status"] + "", 0);

            Model.base_Material m = new Model.base_Material()
            {
                MaterialName = MaterialName,
                ModelNumber = ModelNumber,
                CategoryID = CategoryID,
                CategoryName = CategoryName,
                AttributeID = AttributeID,
                AttributeName = AttributeName,
                UnitID = UnitID,
                UnitName = UnitName,
                UpperLimit = UpperLimit,
                LowerLimit = LowerLimit,
                TechnicalParameter = TechnicalParameter,
                Status = Status,
                AddBy = UserInfo.UserName,//添加人
                AddTime = DateTime.Now//添加时间
            };

            db.base_Material.Add(m);
            int num = db.SaveChanges();
            //如果>0保存成功
            if (num > 0)
            {
                string Material_WareHouse = context.Request["Material_WareHouse"] ?? "";
                if (!string.IsNullOrEmpty(Material_WareHouse))
                {
                    //把json字符串转换成对象
                    List<Model.domain_Material_WareHouse> listMW = NCore.Json.JsonToListOnDCJS<Model.domain_Material_WareHouse>(Material_WareHouse);
                    if (listMW != null && listMW.Count > 0)
                    {
                        foreach (Model.domain_Material_WareHouse mw in listMW)
                        {
                            mw.MaterialModelNumber = ModelNumber;
                            mw.MaterialName = MaterialName;
                            db.domain_Material_WareHouse.Add(mw);
                        }

                        db.SaveChanges();
                    }
                }
                context.Response.Write("{\"d\":1}");
            }
            else
            {
                context.Response.Write("{\"d\":0,\"msg\":\"保存失败!\"}");
            }
        }