public string AddCostContract(decimal pid, string name, string bidno, DateTime date, DateTime sdate,
            DateTime edate, decimal price, string usecount, string audit, string fco, string sco, string remark)
        {
            var user = GetCookieUser();
            if (user == null)
            {
                return JsonConvert.SerializeObject(new
                {
                    Message = "notlogin"
                });
            }
            try
            {
                var proj = projBll.GetModel(pid);

                //取出该工程下所有分包合同
                var list = costContractBll.GetModelList("Cc_PID = " + proj.P_ID);
                //遍历获取最大分享编号
                var maxNo = list.Count == 0 ? 0 : list.Max(li => CommonMethod.ConvertToInt(li.Cc_No.Split('-').LastOrDefault()));
                //附件
                var file = Request.Files["fl_CostContract"];
                var save_path = "/filecache/";
                if (!Directory.Exists(Server.MapPath(save_path)))
                {
                    Directory.CreateDirectory(Server.MapPath(save_path));
                }
                if (file != null)
                {
                    var ext = System.IO.Path.GetExtension(file.FileName).ToLower();
                    if (ext != ".zip")
                    {
                        return JsonConvert.SerializeObject(new
                        {
                            Message = "false",
                            Content = "仅支持ZIP文件导入!"
                        });
                    }
                }
                var fileId = SaveZipFiles(file, save_path);

                var model = new Mo.CostContractInfo
                {
                    Cc_PID = Convert.ToDecimal(proj.P_ID),
                    Cc_No = proj.P_No + "-" + (maxNo + 1),
                    Cc_Name = HttpUtility.UrlDecode(name),
                    Cc_Fco = HttpUtility.UrlDecode(fco),
                    Cc_Sco = HttpUtility.UrlDecode(sco),
                    Cc_Date = date,
                    Cc_Price = price,
                    Cc_Pi = 0,
                    Cc_NoPi = price,
                    Cc_Pm = 0,
                    Cc_NoPm = price,
                    Cc_SDate = sdate,
                    Cc_EDate = edate,
                    Cc_BidNo = bidno,
                    Cc_Type = Convert.ToInt32(Request["type"]),
                    Cc_State = 0,
                    Cc_Remark = HttpUtility.UrlDecode(remark),
                    Cc_Audit = audit,
                    Cc_File = fileId,
                    Cc_UseCount = HttpUtility.UrlDecode(usecount),
                    Cc_Inputer = user.Id,
                    Cc_InputDate = DateTime.Now
                };
                if (costContractBll.Add(model))
                {
                    Dal.Log.Add("添加成本合同", "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"
                });
            }
        }
        //将文件数据放入DataSet对象中
        public string ImportXlsToData(string fileName)
        {
            var user = GetCookieUser();
            var result = string.Empty;
            try
            {

                //生成工程编号和ID的键值对
                var sql = "SELECT P_ID, P_No FROM tbl_ProjectInfo WHERE P_Flag in (0,1)";
                var ds = Dal.SqlHelper.Query(sql);
                var projDic = new Dictionary<string, decimal>();
                ds.Tables[0].AsEnumerable().ToList().ForEach(li => projDic.Add(li["P_No"].ToString(), CommonMethod.ConvertToDecimal(li["P_ID"])));

                ds = CommonMethod.ImportXlsToDataSet(fileName);
                var typeXml = GetTypeByXml();

                var costContractList = new List<Mo.CostContractInfo>();
                var list = ds.Tables[0].AsEnumerable().ToList();
                list.ForEach(li =>
                {
                    var msg = string.Empty;
                    //空行跳过
                    if (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() == "" &&
                        li["备注"].ToString().Trim() == "")
                    {
                        return;
                    }
                    //筛选错误类型
                    var node = typeXml.SelectSingleNode("/root/ContractType/Value[text()='" + li["合同类别"].ToString() + "']");

                    if (li["工程编号"].ToString().Trim() == "")
                    {
                        msg += ",工程编号不得为空";
                    }
                    else if (!projDic.ContainsKey(li["工程编号"].ToString().Trim()))
                    {
                        msg += ",工程编号不正确";
                    }

                    if (li["合同名称"].ToString().Trim() == "")
                    {
                        msg += ",合同名称不得为空";
                    }
                    if (li["合同类别"].ToString().Trim() == "")
                    {
                        msg += ",合同类别不得为空";
                    }
                    else if (node == null)
                    {
                        msg += ",合同类别填写有误";
                    }
                    if (li["乙方单位名称"].ToString().Trim() == "")
                    {
                        msg += ",乙方单位名称不得为空";
                    }
                    if (li["签订日期"].ToString().Trim() == "")
                    {
                        msg += ",签订日期不得为空";
                    }
                    decimal price = 0;
                    if (li["合同价款"].ToString().Trim() == "")
                    {
                        msg += ",合同价款不得为空";
                    }
                    else if (!decimal.TryParse(li["合同价款"].ToString(), out price))
                    {
                        msg += ",合同价款格式错误";
                    }

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

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

                    var pid = projDic[li["工程编号"].ToString()];

                    var model = new Mo.CostContractInfo()
                    {
                        Cc_PID = pid,
                        Cc_No = li["工程编号"] + "-",
                        Cc_Name = li["合同名称"].ToString(),
                        Cc_Type = CommonMethod.ConvertToInt((node.ParentNode).ChildNodes[0].InnerText),
                        Cc_Fco = "天津市光达电力有限公司",
                        Cc_Sco = li["乙方单位名称"].ToString(),
                        Cc_Date = CommonMethod.ConvertToDateTimeOrNull(li["签订日期"].ToString()),

                        Cc_Price = price,
                        Cc_Pi = 0,
                        Cc_NoPi = price,
                        Cc_Pm = 0,
                        Cc_NoPm = price,
                        Cc_SDate = CommonMethod.ConvertToDateTimeOrNull(li["开工日期"].ToString()),
                        Cc_EDate = CommonMethod.ConvertToDateTimeOrNull(li["竣工日期"].ToString()),
                        Cc_BidNo = li["标书号"].ToString(),
                        Cc_Audit = li["审计单位"].ToString(),
                        Cc_UseCount = li["料款实际使用单位"].ToString(),
                        Cc_Remark = li["备注"].ToString(),
                        Cc_State = 0,
                        Cc_Inputer = user.Id,
                        Cc_InputDate = DateTime.Now
                    };
                    costContractList.Add(model);
                });

                if (result == "")
                {
                    costContractList.ForEach(li =>
                    {
                        //遍历获取最大分享编号
                        var nolist = costContractBll.GetModelList("Cc_PID = " + li.Cc_PID);
                        var maxNo = nolist.Count == 0 ? 0 : nolist.Max(l => CommonMethod.ConvertToInt(l.Cc_No.Split('-').LastOrDefault()));
                        li.Cc_No += maxNo + 1;
                        costContractBll.Add(li);
                    });
                }
            }
            catch (Exception ex)
            {
                Dal.LogError.Add(ex, user.Id);
                result = "数据格式有误,导入失败";
            }
            return result;
        }