예제 #1
0
        /////////////////////////////材料详细信息////////////////////////////////
        public string AddMaterialDetail(decimal pcid, string name, string brand, int count, decimal price,
            decimal total, string size, string seller, string contact, string tel, DateTime? date, string remark)
        {
            var user = GetCookieUser();
            if (user == null)
            {
                return JsonConvert.SerializeObject(new
                {
                    Message = "notlogin"
                });
            }
            try
            {
                var model = new Mo.MaterialDetail()
                {
                    Md_PcID = pcid,
                    Md_Name = name,
                    Md_Brand = brand,
                    Md_Count = count,
                    Md_Price = price,
                    Md_Total = total,
                    Md_Size = size,
                    Md_Seller = seller,
                    Md_Contact = contact,
                    Md_ContactTel = tel,
                    Md_Date = date,
                    Md_Remark = remark,
                    Md_State = 0,
                    Md_Inputer = user.Id,
                    Md_InputDate = DateTime.Now,
                };
                var id = materialBll.Add(model);
                if (id != 0)
                {
                    var purchase = purchaseBll.GetModel(Convert.ToDecimal(model.Md_PcID));
                    purchase.Pc_Total += model.Md_Total;
                    purchase.Pc_Editer = user.Id;
                    purchase.Pc_EditDate = DateTime.Now;
                    purchaseBll.Update(purchase);

                    Dal.Log.Add("添加材料详细信息,编号为:" + id, "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"
                });
            }
        }
예제 #2
0
        //将文件数据放入DataSet对象中
        public string ImportXlsToData(string fileName)
        {
            var user = GetCookieUser();
            var result = string.Empty;
            try
            {
                var ds = CommonMethod.ImportXlsToDataSet(fileName);

                var list = ds.Tables[0].AsEnumerable().Where(li => !(li["工程编号"].ToString().Trim() == ""
                    && li["材料名称"].ToString().Trim() == "" && li["数量"].ToString().Trim() == ""
                    && li["单价"].ToString().Trim() == "" && li["规格型号"].ToString().Trim() == ""
                    && li["生产厂家"].ToString().Trim() == "" && li["联系人"].ToString().Trim() == ""
                    && li["联系电话"].ToString().Trim() == "" && li["供货日期"].ToString().Trim() == ""
                    && li["备注"].ToString().Trim() == "" && li["品牌"].ToString().Trim() == "")).ToList();

                if (!list.Any())
                {
                    result = "数据为空,导入失败";
                    return result;
                }

                var projNo = list.FirstOrDefault()["工程编号"].ToString();
                if (string.IsNullOrEmpty(projNo))
                {
                    result = "首行数据中工程编号不能为空,导入失败";
                    return result;
                }

                var proj = projBll.GetModelByNo(projNo);
                if (proj == null)
                {
                    result = "工程编号填写有误,导入失败";
                    return result;
                }

                var construction = constructionBll.GetModelList("Ct_State = 0 AND Ct_PID = " + proj.P_ID).FirstOrDefault();
                if (construction == null)
                {
                    result = "该工程无施工信息,导入失败";
                    return result;
                }

                var total = list.Sum(li => CommonMethod.ConvertToDecimal(li["单价"]) * CommonMethod.ConvertToInt(li["数量"]));

                var materialList = new List<Mo.MaterialDetail>();
                list.ForEach(li =>
                {
                    var msg = string.Empty;

                    //筛选错误类型

                    if (li["材料名称"].ToString().Trim() == "")
                    {
                        msg += ",材料名称不得为空";
                    }
                    if (li["数量"].ToString().Trim() == "")
                    {
                        msg += ",数量不得为空";
                    }
                    if (li["单价"].ToString().Trim() == "")
                    {
                        msg += ",单价不得为空";
                    }

                    //本条数据含有错误信息,则放弃导入,记录错误信息
                    if (msg != "")
                    {
                        result += "第" + (list.IndexOf(li) + 2) + "行数据有误" + msg + "<br/>";
                        return;
                    }

                    //总体错误信息不为空则放弃导入,只记录错误信息
                    if (result != "") return;

                    var model = new Mo.MaterialDetail
                    {
                        Md_Name = li["材料名称"].ToString(),
                        Md_Brand = li["品牌"].ToString(),
                        Md_Price = CommonMethod.ConvertToDecimal(li["单价"]),
                        Md_Count = CommonMethod.ConvertToInt(li["数量"]),
                        Md_Total = CommonMethod.ConvertToDecimal(li["单价"]) * CommonMethod.ConvertToInt(li["数量"]),
                        Md_Size = li["规格型号"].ToString(),
                        Md_Seller = li["生产厂家"].ToString(),
                        Md_Contact = li["联系人"].ToString(),
                        Md_ContactTel = li["联系电话"].ToString(),
                        Md_Date = CommonMethod.ConvertToDateTimeOrNull(li["供货日期"]),
                        Md_Remark = li["备注"].ToString(),
                        Md_State = 0,
                        Md_Inputer = user.Id,
                        Md_InputDate = DateTime.Now
                    };
                    materialList.Add(model);
                });
                //错误信息为空 则导入数据
                if (result == string.Empty)
                {
                    var pcid = purchaseBll.Add(new Mo.Purchase
                    {
                        Pc_CtID = construction.Ct_ID,
                        Pc_Total = total,
                        Pc_Date = DateTime.Now,
                        Pc_State = 0,
                        Pc_Inputer = user.Id,
                        Pc_InputDate = DateTime.Now,
                    });
                    if (pcid != 0)
                    {
                        Dal.Log.Add("添加材料采购信息,编号为:" + pcid, "ADD", user.Id);
                    }
                    materialList.ForEach(li =>
                    {
                        li.Md_PcID = pcid;
                        var mdId = materialBll.Add(li);
                        Dal.Log.Add("添加材料详细信息,编号为:" + mdId, "ADD", user.Id);
                    });
                }
            }
            catch (Exception ex)
            {
                result = "数据格式有误,导入失败";
            }
            return result;
        }