/// <summary>
 /// 添加单价
 /// </summary>
 /// <param name="context"></param>
 private void addMaterialPrice(HttpContext context)
 {
     int SuppliersID = Convert.ToInt32(context.Request["SuppliersID"]);//供应商
     string CompanyName = context.Request["CompanyName"] + "",  //供应商名称
         ModelNumber = context.Request["ModelNumber"] + "";
     var data = db.domain_MaterialPrice.Where(w => w.SuppliersID == SuppliersID && w.ModelNumber == ModelNumber);
     if (data.Count() > 0)//已存在此单价记录
     {
         context.Response.Write("{\"d\":111}");
     }
     else
     {
         Model.domain_MaterialPrice mp = new domain_MaterialPrice()
       {
           SuppliersID = SuppliersID,
           CompanyName = CompanyName,                //供应商名称
           ModelNumber = ModelNumber,                //物料型号
           MaterialName = context.Request["MaterialName"] + "",              //物料名称
           UnitPrice = Convert.ToInt32(context.Request["UnitPrice"] + ""),   //单价
           Remark = context.Request["Remark"] + "",                          //备注
           AddBy = UserInfo.UserName,                                        //添加人
           AddTime = DateTime.Now
       };
         db.domain_MaterialPrice.Add(mp);
         int num = db.SaveChanges();
         if (num == 1)
         {
             num = 1;
             Model.domain_Log log = new Model.domain_Log()
             {
                 DoID = Convert.ToInt32(ModelNumber),
                 DoType = 1,
                 DoContent = "添加单价 " + mp.CompanyName + "  " + mp.UnitPrice,
                 DoBy = UserInfo.UserName,
                 DoTime = DateTime.Now
             };
             db.domain_Log.Add(log);
             db.SaveChanges();
         }
         context.Response.Write("{\"d\":" + num + "}");
     }
 }
 /// <summary>
 /// 编辑单价
 /// </summary>
 /// <param name="context"></param>
 private void editMaterialPrice(HttpContext context)
 {
     int ID = Convert.ToInt32(context.Request["ID"]);
     decimal UnitPrice = Convert.ToDecimal(context.Request["UnitPrice"] + "");
     Model.domain_MaterialPrice mp = db.domain_MaterialPrice.Where(w => w.ID == ID).First();
     mp.SuppliersID = Convert.ToInt32(context.Request["SuppliersID"]);//供应商
     mp.CompanyName = context.Request["CompanyName"] + "";                //供应商名称
     mp.ModelNumber = context.Request["ModelNumber"] + "";                //物料型号
     mp.MaterialName = context.Request["MaterialName"] + "";              //物料名称
     mp.UnitPrice = UnitPrice;   //单价
     mp.Remark = context.Request["Remark"] + "";                          //备注
     mp.LastUpdateBy = UserInfo.UserName;
     mp.LastUpdateTime = DateTime.Now;
     int num = db.SaveChanges();
     if (num == 1)
     {
         num = 1;
         Model.domain_Log log = new Model.domain_Log()
         {
             DoID = Convert.ToInt32(mp.ModelNumber),
             DoType = 1,
             DoContent = "编辑单价 " + mp.CompanyName + "  " + mp.UnitPrice,
             DoBy = UserInfo.UserName,
             DoTime = DateTime.Now
         };
         db.domain_Log.Add(log);
         db.SaveChanges();
     }
     context.Response.Write("{\"d\":" + num + "}");
 }
 /// <summary>
 /// 删除单价
 /// </summary>
 /// <param name="context"></param>
 private void delMaterialPrice(HttpContext context)
 {
     int ID = Convert.ToInt32(context.Request["ID"]);
     Model.domain_MaterialPrice mp = db.domain_MaterialPrice.Where(w => w.ID == ID).First();
     db.domain_MaterialPrice.Remove(mp);
     int num = db.SaveChanges();
     if (num == 1)
     {
         num = 1;
         Model.domain_Log log = new Model.domain_Log()
         {
             DoID = Convert.ToInt32(mp.ModelNumber),
             DoType = 1,
             DoContent = "删除单价 " + mp.CompanyName + "  " + mp.UnitPrice,
             DoBy = UserInfo.UserName,
             DoTime = DateTime.Now
         };
         db.domain_Log.Add(log);
         db.SaveChanges();
     }
     context.Response.Write("{\"d\":" + num + "}");
 }
 /// <summary>
 /// 添加评级信息
 /// </summary>
 /// <param name="context"></param>
 private void addLevel(HttpContext context)
 {
     int SuppliersID = Convert.ToInt32(context.Request["SuppliersID"]);
     var data = db.domain_EvaluationLevel.Where(w => w.SuppliersID == SuppliersID);
     if (data.Count() > 0)
     {
         context.Response.Write("{\"d\":111}");//此评级信息已存在
     }
     else
     {
         Model.domain_EvaluationLevel el = new Model.domain_EvaluationLevel()
        {
            SuppliersID = SuppliersID,
            CompanyName = context.Request["CompanyName"] + "",
            Level = context.Request["Level"] + "",
            AddBy = UserInfo.UserName,
            AddTime = DateTime.Now
        };
         db.domain_EvaluationLevel.Add(el);
         Model.base_Suppliers sup = db.base_Suppliers.Where(w => w.ID == SuppliersID).First();
         sup.AssessmentLevel = el.Level;
         int num = db.SaveChanges();
         if (num == 2)
         {
             num = 1;
             Model.domain_Log log = new Model.domain_Log()
                           {
                               DoID = SuppliersID,
                               DoType = 2,
                               DoContent = "添加 " + el.Level,
                               DoBy = UserInfo.UserName,
                               DoTime = DateTime.Now
                           };
             db.domain_Log.Add(log);
             db.SaveChanges();
         }
         context.Response.Write("{\"d\":" + num + "}");
     }
 }
 /// <summary>
 /// 编辑评级信息
 /// </summary>
 /// <param name="context"></param>
 private void editLevel(HttpContext context)
 {
     int num;
     int ID = Convert.ToInt32(context.Request["ID"]);
     int SuppliersID = Convert.ToInt32(context.Request["SuppliersID"]);
     string Level = context.Request["Level"] + "";
     Model.domain_EvaluationLevel el = db.domain_EvaluationLevel.Where(w => w.ID == ID).First();
     if (SuppliersID == el.SuppliersID && Level == el.Level)//信息未更改
     {
         num = 1;
     }
     else
     {
         el.SuppliersID = SuppliersID;
         el.CompanyName = context.Request["CompanyName"] + "";
         el.Level = Level;
         el.LastUpdateBy = UserInfo.UserName;
         el.LastUpdateTime = DateTime.Now;
         Model.base_Suppliers sup = db.base_Suppliers.Where(w => w.ID == el.SuppliersID).First();
         sup.AssessmentLevel = el.Level;
         num = db.SaveChanges();
         if (num == 2)
         {
             num = 1;
             Model.domain_Log log = new Model.domain_Log()
             {
                 DoID = (int)el.SuppliersID,
                 DoType = 2,
                 DoContent = "编辑 " + el.Level,
                 DoBy = UserInfo.UserName,
                 DoTime = DateTime.Now
             };
             db.domain_Log.Add(log);
             db.SaveChanges();
         }
     }
     context.Response.Write("{\"d\":" + num + "}");
 }
 /// <summary>
 /// 删除评级信息
 /// </summary>
 /// <param name="context"></param>
 private void delLevel(HttpContext context)
 {
     int ID = Convert.ToInt32(context.Request["ID"]);
     Model.domain_EvaluationLevel el = db.domain_EvaluationLevel.Where(w => w.ID == ID).First();
     db.domain_EvaluationLevel.Remove(el);
     Model.base_Suppliers sup = db.base_Suppliers.Where(w => w.ID == el.SuppliersID).First();
     sup.AssessmentLevel = "";
     int num = db.SaveChanges();
     if (num == 2)
     {
         num = 1;
         Model.domain_Log log = new Model.domain_Log()
        {
            DoID = (int)el.SuppliersID,
            DoType = 2,
            DoContent = "删除 " + el.Level,
            DoBy = UserInfo.UserName,
            DoTime = DateTime.Now
        };
         db.domain_Log.Add(log);
         db.SaveChanges();
     }
     context.Response.Write("{\"d\":" + num + "}");
 }