public string GetFiles() { var list = new List<Mo.Projectfile>(); var ids = ""; if (!string.IsNullOrEmpty(Request["id"])) { var id = decimal.Parse(Request["id"]); if (Request["type"] == "proj") { var proj = new Mo.ProjectInfo(); if (!string.IsNullOrEmpty(Request["pid"])) { proj = projBll.GetModel(CommonMethod.ConvertToDecimal(Request["pid"])); } else { proj = projBll.GetModel(id); } if (proj == null) { return JsonConvert.SerializeObject(new { Message = "false", Content = list }); } //判断查找文件属于招标文件还是立项文件等类型 if (!string.IsNullOrEmpty(Request["projtype"])) { switch (Request["projtype"]) { case "bid": ids = proj.P_BidFile; break; case "pro": ids = proj.P_ProFile; break; default: ids = proj.P_ProFile + proj.P_BidFile; break; } } else { ids = proj.P_ProFile + proj.P_BidFile; } } else if (Request["type"] == "construction") { var model = constructionBll.GetModel(id); if (model == null) { return JsonConvert.SerializeObject(new { Message = "false", Content = list }); } ids = model.Ct_File; } else if (Request["type"] == "contract") { var contract = contractBll.GetModel(id); if (contract == null) { return JsonConvert.SerializeObject(new { Message = "false", Content = list }); } ids = contract.C_File; } else if (Request["type"] == "costcontract") { var model = costContractBll.GetModel(id); if (model == null) { return JsonConvert.SerializeObject(new { Message = "false", Content = list }); } ids = model.Cc_File; } else if (Request["type"] == "balance") { var model = balanceBll.GetModel(id); if (model == null) { return JsonConvert.SerializeObject(new { Message = "false", Content = list }); } ids = model.Bl_File; } else if (Request["type"] == "completion") { var model = completionBll.GetModel(id); if (model == null) { return JsonConvert.SerializeObject(new { Message = "false", Content = list }); } ids = model.Cp_File; } if (string.IsNullOrEmpty(ids)) { return JsonConvert.SerializeObject(new { Message = "false", Content = list }); } if (ids.EndsWith(",")) { ids = ids.Substring(0, ids.Length - 1); } } var wherePart = new StringBuilder(); var parameters = new List<SqlParameter> { new SqlParameter("@PageSize", string.IsNullOrEmpty(Request["rows"]) ? 999 : CommonMethod.ConvertToInt(Request["rows"])), new SqlParameter("@PageNum", string.IsNullOrEmpty(Request["page"]) ? 1 : CommonMethod.ConvertToInt(Request["page"])) }; if (!string.IsNullOrEmpty(Request["id"])) { wherePart.Append(" AND F_ID IN(" + ids + ")"); } if (!string.IsNullOrEmpty(Request["filetype"]) && Request["filetype"] != "-1") { wherePart.Append(" AND F_Limit = @F_Limit"); parameters.Add(new SqlParameter("@F_Limit", Request["filetype"])); } if (!string.IsNullOrEmpty(Request["name"])) { wherePart.Append(" AND F_Name like @F_Name"); parameters.Add(new SqlParameter("@F_Name", "%" + Request["name"] + "%")); } if (!string.IsNullOrEmpty(Request["sdate"])) { wherePart.Append(" AND F_Inputdate >= @SDate"); parameters.Add(new SqlParameter("@SDate", Convert.ToDateTime(Request["sdate"]))); } if (!string.IsNullOrEmpty(Request["edate"])) { wherePart.Append(" AND F_Inputdate <= @EDate"); parameters.Add(new SqlParameter("@EDate", Convert.ToDateTime(Request["edate"] + " 23:59:59"))); } var sql = @" SELECT * FROM ( SELECT ROW_NUMBER() OVER(ORDER BY f.F_Inputdate desc) RowNum, f.*,u.U_RealName RealName FROM dbo.tbl_Projectfile f JOIN tbl_User u ON u.U_ID = f.F_Inputer WHERE 1=1 " + wherePart + @" )T WHERE RowNum BETWEEN (@PageNum - 1) * @PageSize + 1 AND @PageSize * @PageNum"; if (!string.IsNullOrEmpty(Request["sidx"])) { sql += " ORDER BY " + Request["sidx"] + " " + Request["sord"]; } list = fileBll.GetModelListBySql(sql, parameters.ToArray()); var projTypeXml = GetTypeByXml(); list.ForEach(li => { li.Limit = (projTypeXml.SelectSingleNode("/root/FileLimit/Key[text()='" + li.F_Limit + "']").ParentNode) .ChildNodes[1].InnerText; li.F_Path = "UploadFile/" + li.F_Path.Replace("\\", "/"); }); sql = @" SELECT COUNT(*) TotalCount FROM tbl_Projectfile WHERE 1=1 " + wherePart; var ds = Dal.SqlHelper.Query(sql, parameters.ToArray()); var totalCount = CommonMethod.ConvertToInt(ds.Tables[0].Rows[0][0].ToString()); return JsonConvert.SerializeObject(new { Message = "success", Content = list }); }
//将文件数据放入DataSet对象中 public string ImportXlsToData(string fileName) { var user = GetCookieUser(); var result = string.Empty; try { var ds = CommonMethod.ImportXlsToDataSet(fileName); var typeXml = GetTypeByXml(); 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() == "" && li["中标日期"].ToString().Trim() == "" && li["中标金额"].ToString().Trim() == "" && li["电压等级"].ToString().Trim() == "")).ToList(); if (!list.Any()) { result = "数据为空,导入失败"; return result; } if (list.GroupBy(li => li["工程编号"]).Count() < list.Count()) { result = "数据中含有重复工程编号"; return result; } var projList = new List<Mo.ProjectInfo>(); list.ForEach(li => { var msg = string.Empty; //筛选错误类型 var node = typeXml.SelectSingleNode("/root/ProjectType/Value[text()='" + li["工程类别"].ToString().Trim() + "']"); 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 += ",国网工程编号不得为空"; } if (li["项目负责人"].ToString().Trim() == "") { msg += ",项目负责人不得为空"; } if (projBll.GetModelByNo(li["工程编号"].ToString()) != null) { msg += ",已含有相同工程编号"; } //本条数据含有错误信息,则放弃导入,记录错误信息 if (msg != "") { result += "第" + (list.IndexOf(li) + 2) + "行数据有误" + msg + "<br/>"; return; } //总体错误信息不为空则放弃导入,只记录错误信息 if (result != "") return; var model = new Mo.ProjectInfo { P_Name = li["工程名称"].ToString(), P_No = li["工程编号"].ToString(), P_Type = CommonMethod.ConvertToInt((node.ParentNode).ChildNodes[0].InnerText), P_Tag = !li["电网内外标志"].ToString().Contains("内"), P_SGNo = li["国网工程编号"].ToString(), P_Header = li["项目负责人"].ToString(), P_Number = li["立项编号"].ToString(), P_CDate = CommonMethod.ConvertToDateTimeOrNull(li["立项日期"]), P_BidBatch = CommonMethod.ConvertToInt(li["招标批次"]), P_BlockPrice = CommonMethod.ConvertToDecimal(li["拦标价"]), P_BidSDate = CommonMethod.ConvertToDateTimeOrNull(li["投标日期"]), P_BidEDate = CommonMethod.ConvertToDateTimeOrNull(li["中标日期"]), P_BidPrice = CommonMethod.ConvertToDecimal(li["中标金额"]), P_VC = CommonMethod.ConvertToInt(li["电压等级"]), P_Flag = 0, P_Inputer = user.Id, P_InputDate = DateTime.Now }; projList.Add(model); }); //错误信息为空 则导入数据 if (result == string.Empty) { projList.ForEach(li => projBll.Add(li)); } } catch (Exception ex) { Dal.LogError.Add(ex, user.Id); //result = "数据格式有误,导入失败"; result = ex.Message; } return result; }
public string AddProject() { var user = GetCookieUser(); if (user == null) { return JsonConvert.SerializeObject(new { Message = "notlogin" }); } try { if (projBll.GetModelByNo(Request["ProjNum"]) != null) { return JsonConvert.SerializeObject(new { Message = "exists" }); } //上传文件 var file_ZB = Request.Files["fl_ZB"]; var file_LX = Request.Files["fl_LX"]; var save_path = "/filecache/"; if (!Directory.Exists(Server.MapPath(save_path))) { Directory.CreateDirectory(Server.MapPath(save_path)); } if (file_ZB != null) { var ext_ZB = System.IO.Path.GetExtension(file_ZB.FileName).ToLower(); if (ext_ZB != ".zip") { return JsonConvert.SerializeObject(new { Message = "false", Content = "仅支持ZIP文件导入!" }); } } if (file_LX != null) { var ext_LX = System.IO.Path.GetExtension(file_LX.FileName).ToLower(); if (ext_LX != ".zip") { return JsonConvert.SerializeObject(new { Message = "false", Content = "仅支持ZIP文件导入!" }); } } var zbId = SaveZipFiles(file_ZB, save_path); var lxId = SaveZipFiles(file_LX, save_path); var project = new Mo.ProjectInfo { P_Name = HttpUtility.UrlDecode(Request["ProjName"]), P_Type = Convert.ToInt32(Request["ProjType"]), P_No = Request["ProjNum"], P_SGNo = Request["ProjNumGW"], P_Header = Request["Hearder"], P_Tag = Request["Tag"] != "in", P_BidBatch = string.IsNullOrEmpty(Request["BidBatch"]) ? 1 : CommonMethod.ConvertToInt(Request["BidBatch"]), P_VC = CommonMethod.ConvertToInt(Request["VC"]), P_BlockPrice = CommonMethod.ConvertToDecimal(Request["BlockPrice"]), P_BidSDate = CommonMethod.ConvertToDateTimeOrNull(Request["BidSDate"]), P_BidEDate = CommonMethod.ConvertToDateTimeOrNull(Request["BidEDate"]), P_BidPrice = CommonMethod.ConvertToDecimal(Request["BidPrice"]), P_BidFile = zbId, P_Number = Request["ProNum"], P_Flag = 0, P_CDate = CommonMethod.ConvertToDateTimeOrNull(Request["ProDate"]), P_ProFile = lxId, P_Inputer = user.Id, P_InputDate = DateTime.Now }; var pid = projBll.Add(project); if (pid != 0) { Dal.LogOperation.Add("新建工程: " + project.P_Name, "Project", pid, JsonConvert.SerializeObject(project), user.Id); Dal.Log.Add("添加工程", "ADD", user.Id); return JsonConvert.SerializeObject(new { Message = "success" }); } else { return JsonConvert.SerializeObject(new { Message = "false" }); } } catch (Exception ex) { Dal.LogError.Add(ex, user.Id); return JsonConvert.SerializeObject(new { Message = "error" }); } }