public string AddPurchase(decimal ctid, decimal? sumprice, DateTime? date, string remark)
        {
            var user = GetCookieUser();
            if (user == null)
            {
                return JsonConvert.SerializeObject(new
                {
                    Message = "notlogin"
                });
            }
            try
            {
                var sql = "SELECT 1 FROM tbl_Purchase WHERE Pc_State = 0 AND Pc_CtID = " + ctid;

                var ds = Dal.SqlHelper.Query(sql);

                if (ds.Tables[0].Rows.Count > 0)
                {
                    return JsonConvert.SerializeObject(new
                    {
                        Message = "exist",
                        Content = "该施工信息已存在采购计划"
                    });
                }

                var model = new Mo.Purchase
                {
                    Pc_CtID = ctid,
                    Pc_Total = sumprice,
                    Pc_Date = date,
                    Pc_State = 0,
                    Pc_Remark = HttpUtility.UrlDecode(remark),
                    Pc_Inputer = user.Id,
                    Pc_InputDate = DateTime.Now,
                };
                var pcid = purchaseBll.Add(model);
                if (pcid != 0)
                {
                    Dal.Log.Add("添加材料采购信息,编号为:" + pcid, "ADD", user.Id);
                    return JsonConvert.SerializeObject(new
                    {
                        Message = "success",
                        Content = pcid
                    });
                }
                else
                {
                    return JsonConvert.SerializeObject(new
                    {
                        Message = "false",
                        Content = "保存失败"
                    });
                }
            }
            catch (Exception ex)
            {
                Dal.LogError.Add(ex, user.Id);

                return JsonConvert.SerializeObject(new
                {
                    Message = "error"
                });
            }
        }
        public string AddPurchase(decimal ctid, decimal sumprice, DateTime? date, string remark)
        {
            var user = GetCookieUser();
            if (user == null)
            {
                return JsonConvert.SerializeObject(new
                {
                    Message = "notlogin"
                });
            }
            try
            {
                var model = new Mo.Purchase
                {
                    Pc_CtID = ctid,
                    Pc_Total = sumprice,
                    Pc_Date = date,
                    Pc_State = 0,
                    Pc_Remark = HttpUtility.UrlDecode(remark),
                    Pc_Inputer = user.Id,
                    Pc_InputDate = DateTime.Now,
                };
                var pcid = purchaseBll.Add(model);
                if (pcid != 0)
                {
                    Dal.Log.Add("添加材料采购信息,编号为:" + pcid, "ADD", user.Id);
                    return JsonConvert.SerializeObject(new
                    {
                        Message = "success"
                    });
                }
                else
                {
                    return JsonConvert.SerializeObject(new
                    {
                        Message = "false",
                        Content = "保存失败"
                    });
                }
            }
            catch (Exception ex)
            {
                Dal.LogError.Add(ex, user.Id);

                return JsonConvert.SerializeObject(new
                {
                    Message = "error"
                });
            }
        }
Beispiel #3
0
 /// <summary>
 /// 获得数据列表
 /// </summary>
 public List<PCMLib.Model.Purchase> DataTableToList(DataTable dt)
 {
     var modelList = new List<PCMLib.Model.Purchase>();
     int rowsCount = dt.Rows.Count;
     if (rowsCount > 0)
     {
         PCMLib.Model.Purchase model;
         for (int n = 0; n < rowsCount; n++)
         {
             model = new PCMLib.Model.Purchase();
             if (dt.Rows[n]["Pc_ID"] != null && dt.Rows[n]["Pc_ID"].ToString() != "")
             {
                 model.Pc_ID = decimal.Parse(dt.Rows[n]["Pc_ID"].ToString());
             }
             if (dt.Rows[n]["Pc_CtID"] != null && dt.Rows[n]["Pc_CtID"].ToString() != "")
             {
                 model.Pc_CtID = decimal.Parse(dt.Rows[n]["Pc_CtID"].ToString());
             }
             if (dt.Rows[n]["Pc_Date"] != null && dt.Rows[n]["Pc_Date"].ToString() != "")
             {
                 model.Pc_Date = DateTime.Parse(dt.Rows[n]["Pc_Date"].ToString());
                 model.Date = Convert.ToDateTime(dt.Rows[n]["Pc_Date"].ToString()).ToShortDateString();
             }
             if (dt.Rows[n]["Pc_Total"] != null && dt.Rows[n]["Pc_Total"].ToString() != "")
             {
                 model.Pc_Total = decimal.Parse(dt.Rows[n]["Pc_Total"].ToString());
             }
             if (dt.Rows[n]["Pc_Remark"] != null && dt.Rows[n]["Pc_Remark"].ToString() != "")
             {
                 model.Pc_Remark = dt.Rows[n]["Pc_Remark"].ToString();
             }
             if (dt.Rows[n]["Pc_State"] != null && dt.Rows[n]["Pc_State"].ToString() != "")
             {
                 model.Pc_State = int.Parse(dt.Rows[n]["Pc_State"].ToString());
             }
             if (dt.Rows[n]["Pc_Inputer"] != null && dt.Rows[n]["Pc_Inputer"].ToString() != "")
             {
                 model.Pc_Inputer = decimal.Parse(dt.Rows[n]["Pc_Inputer"].ToString());
             }
             if (dt.Rows[n]["Pc_InputDate"] != null && dt.Rows[n]["Pc_InputDate"].ToString() != "")
             {
                 model.Pc_InputDate = DateTime.Parse(dt.Rows[n]["Pc_InputDate"].ToString());
                 model.InputDate = Convert.ToDateTime(dt.Rows[n]["Pc_InputDate"].ToString()).ToShortDateString();
             }
             if (dt.Rows[n]["Pc_Editer"] != null && dt.Rows[n]["Pc_Editer"].ToString() != "")
             {
                 model.Pc_Editer = decimal.Parse(dt.Rows[n]["Pc_Editer"].ToString());
             }
             if (dt.Rows[n]["Pc_EditDate"] != null && dt.Rows[n]["Pc_EditDate"].ToString() != "")
             {
                 model.Pc_EditDate = DateTime.Parse(dt.Rows[n]["Pc_EditDate"].ToString());
                 model.EditDate = Convert.ToDateTime(dt.Rows[n]["Pc_EditDate"].ToString()).ToShortDateString();
             }
             if (dt.Rows[n]["P_Name"] != null && dt.Rows[n]["P_Name"].ToString() != "")
             {
                 model.P_Name = dt.Rows[n]["P_Name"].ToString();
             }
             if (dt.Rows[n]["U_RealName"] != null && dt.Rows[n]["U_RealName"].ToString() != "")
             {
                 model.U_RealName = dt.Rows[n]["U_RealName"].ToString();
             }
             if (dt.Rows[n]["P_No"] != null && dt.Rows[n]["P_No"].ToString() != "")
             {
                 model.P_No = dt.Rows[n]["P_No"].ToString();
             }
             if (dt.Rows[n]["Ct_Type"] != null && dt.Rows[n]["Ct_Type"].ToString() != "")
             {
                 model.Ct_Type = int.Parse(dt.Rows[n]["Ct_Type"].ToString());
             }
             if (dt.Rows[n]["Ct_Company"] != null && dt.Rows[n]["Ct_Company"].ToString() != "")
             {
                 model.Ct_Company = dt.Rows[n]["Ct_Company"].ToString();
             }
             modelList.Add(model);
         }
     }
     return modelList;
 }