219 lines
11 KiB
C#
219 lines
11 KiB
C#
using FineUIPro;
|
|
using MiniExcelLibs;
|
|
using Model;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
|
|
namespace BLL
|
|
{
|
|
public static class PHTGL_BidProjectQuantityService
|
|
{
|
|
public static PHTGL_BidProjectQuantity GetPHTGL_BidProjectQuantityById(string bidProjectQuantityId)
|
|
{
|
|
return Funs.DB.PHTGL_BidProjectQuantity.FirstOrDefault(x => x.BidProjectQuantityId == bidProjectQuantityId);
|
|
}
|
|
|
|
public static void AddPHTGL_BidProjectQuantity(PHTGL_BidProjectQuantity newtable)
|
|
{
|
|
var table = new PHTGL_BidProjectQuantity
|
|
{
|
|
BidProjectQuantityId = newtable.BidProjectQuantityId,
|
|
LotNumber = newtable.LotNumber,
|
|
BidProjectCode = newtable.BidProjectCode,
|
|
IsMainProject = newtable.IsMainProject,
|
|
ProjectId = newtable.ProjectId,
|
|
CreatorId = newtable.CreatorId,
|
|
CreateDate = newtable.CreateDate
|
|
};
|
|
Funs.DB.PHTGL_BidProjectQuantity.InsertOnSubmit(table);
|
|
Funs.DB.SubmitChanges();
|
|
}
|
|
|
|
|
|
public static void UpdatePHTGL_BidProjectQuantity(PHTGL_BidProjectQuantity newtable)
|
|
{
|
|
var table = Funs.DB.PHTGL_BidProjectQuantity.FirstOrDefault(x =>
|
|
x.BidProjectQuantityId == newtable.BidProjectQuantityId);
|
|
if (table != null)
|
|
{
|
|
table.BidProjectQuantityId = newtable.BidProjectQuantityId;
|
|
table.LotNumber = newtable.LotNumber;
|
|
table.BidProjectCode = newtable.BidProjectCode;
|
|
table.IsMainProject = newtable.IsMainProject;
|
|
table.ProjectId = newtable.ProjectId;
|
|
table.CreatorId = newtable.CreatorId;
|
|
table.CreateDate = newtable.CreateDate;
|
|
Funs.DB.SubmitChanges();
|
|
}
|
|
}
|
|
|
|
public static void DeletePHTGL_BidProjectQuantityById(string BidProjectQuantityId)
|
|
{
|
|
var table = Funs.DB.PHTGL_BidProjectQuantity.FirstOrDefault(x =>
|
|
x.BidProjectQuantityId == BidProjectQuantityId);
|
|
if (table != null)
|
|
{
|
|
Funs.DB.PHTGL_BidProjectQuantity.DeleteOnSubmit(table);
|
|
Funs.DB.SubmitChanges();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 导出招标工作量清单
|
|
/// </summary>
|
|
/// <param name="bidProjectQuantityId">招标工作量清单主键id</param>
|
|
public static void ExportById(string bidProjectQuantityId)
|
|
{
|
|
var bidProjectQuantity = GetPHTGL_BidProjectQuantityById(bidProjectQuantityId);
|
|
var sheets = new Dictionary<string, object>();
|
|
var mainProjectQuantity = new PHTGL_MainProjectQuantity();
|
|
mainProjectQuantity.QuantityId = bidProjectQuantityId;
|
|
var mainProjectList = PHTGL_MainProjectQuantityService.GetPHTGL_MainProjectQuantityByModle(mainProjectQuantity);//获取主项
|
|
foreach (var item in mainProjectList)
|
|
{
|
|
var querytable = new PHTGL_Quantity();
|
|
querytable.IsTemplate = false;
|
|
querytable.ParentId = item.MainProjectQuantityId;
|
|
var tb = PHTGL_QuantityService.GetPHTGL_QuantityByModle(querytable);
|
|
var exportmodel = (from x in tb
|
|
select new
|
|
{
|
|
专业 = x.Major,
|
|
分部工程 = x.SubProject,
|
|
分项工程 = x.SubItemProject,
|
|
项目编码 = x.ProjectCode,
|
|
项目名称 = x.ProjectName,
|
|
项目特征描述 = x.ProjectDescription,
|
|
计量单位 = x.UnitOfMeasurement,
|
|
工程量 = x.Quantity,
|
|
全费用固定综合单价 = x.TotalCostFixedComprehensiveUnitPrice,
|
|
主材费 = x.MainMaterialCost,
|
|
合价 = x.TotalPrice,
|
|
计算规则 = x.CalculationRule,
|
|
工作内容 = x.WorkContent,
|
|
备注 = x.Remarks,
|
|
}).ToList();
|
|
sheets.Add(item.MainProjectQuantityName, exportmodel);
|
|
}
|
|
string path = Funs.RootPath + @"File\Excel\Temp\招标工作清单-" + bidProjectQuantity.BidProjectCode + ".xlsx";
|
|
path = path.Replace(".xlsx", string.Format("{0:yyyy-MM-dd-HH-mm}", DateTime.Now) + ".xlsx");
|
|
MiniExcel.SaveAs(path, sheets);
|
|
string fileName = "招标工作清单-" + bidProjectQuantity.BidProjectCode + ".xlsx";
|
|
FileInfo info = new FileInfo(path);
|
|
long fileSize = info.Length;
|
|
System.Web.HttpContext.Current.Response.Clear();
|
|
System.Web.HttpContext.Current.Response.ContentType = "application/x-zip-compressed";
|
|
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
|
|
System.Web.HttpContext.Current.Response.AddHeader("Content-Length", fileSize.ToString());
|
|
System.Web.HttpContext.Current.Response.TransmitFile(path, 0, fileSize);
|
|
System.Web.HttpContext.Current.Response.Flush();
|
|
System.Web.HttpContext.Current.Response.Close();
|
|
File.Delete(path);
|
|
}
|
|
public static void ExportByMainProjectQuantityId(string mainProjectQuantityId)
|
|
{
|
|
var sheets = new Dictionary<string, object>();
|
|
var mainProjectList = PHTGL_MainProjectQuantityService.GetPHTGL_MainProjectQuantityById(mainProjectQuantityId);//获取主项
|
|
if (mainProjectList == null)
|
|
{
|
|
return;
|
|
}
|
|
var querytable = new PHTGL_Quantity();
|
|
querytable.IsTemplate = false;
|
|
querytable.ParentId = mainProjectQuantityId;
|
|
var tb = PHTGL_QuantityService.GetPHTGL_QuantityByModle(querytable);
|
|
var exportmodel = (from x in tb
|
|
select new
|
|
{
|
|
专业 = x.Major,
|
|
分部工程 = x.SubProject,
|
|
分项工程 = x.SubItemProject,
|
|
项目编码 = x.ProjectCode,
|
|
项目名称 = x.ProjectName,
|
|
项目特征描述 = x.ProjectDescription,
|
|
计量单位 = x.UnitOfMeasurement,
|
|
工程量 = x.Quantity,
|
|
全费用固定综合单价 = x.TotalCostFixedComprehensiveUnitPrice,
|
|
主材费 = x.MainMaterialCost,
|
|
合价 = x.TotalPrice,
|
|
计算规则 = x.CalculationRule,
|
|
工作内容 = x.WorkContent,
|
|
备注 = x.Remarks,
|
|
}).ToList();
|
|
sheets.Add(mainProjectList.MainProjectQuantityName, exportmodel);
|
|
|
|
string path = Funs.RootPath + @"File\Excel\Temp\招标工作清单-" + mainProjectList.MainProjectQuantityCode + ".xlsx";
|
|
path = path.Replace(".xlsx", string.Format("{0:yyyy-MM-dd-HH-mm}", DateTime.Now) + ".xlsx");
|
|
MiniExcel.SaveAs(path, sheets);
|
|
string fileName = "招标工作清单-" + mainProjectList.MainProjectQuantityCode + ".xlsx";
|
|
FileInfo info = new FileInfo(path);
|
|
long fileSize = info.Length;
|
|
System.Web.HttpContext.Current.Response.Clear();
|
|
System.Web.HttpContext.Current.Response.ContentType = "application/x-zip-compressed";
|
|
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
|
|
System.Web.HttpContext.Current.Response.AddHeader("Content-Length", fileSize.ToString());
|
|
System.Web.HttpContext.Current.Response.TransmitFile(path, 0, fileSize);
|
|
System.Web.HttpContext.Current.Response.Flush();
|
|
System.Web.HttpContext.Current.Response.Close();
|
|
File.Delete(path);
|
|
}
|
|
|
|
|
|
#region 获取列表
|
|
|
|
/// <summary>
|
|
/// 记录数
|
|
/// </summary>
|
|
public static int count { get; set; }
|
|
|
|
public static List<PHTGL_BidProjectQuantity> GetPHTGL_BidProjectQuantityByModle(PHTGL_BidProjectQuantity table)
|
|
{
|
|
var q = from x in Funs.DB.PHTGL_BidProjectQuantity
|
|
where
|
|
(string.IsNullOrEmpty(table.BidProjectQuantityId) ||
|
|
x.BidProjectQuantityId.Contains(table.BidProjectQuantityId)) &&
|
|
(string.IsNullOrEmpty(table.LotNumber) || x.LotNumber.Contains(table.LotNumber)) &&
|
|
(string.IsNullOrEmpty(table.BidProjectCode) ||
|
|
x.BidProjectCode.Contains(table.BidProjectCode)) &&
|
|
(string.IsNullOrEmpty(table.ProjectId) ||
|
|
x.ProjectId.Contains(table.ProjectId))
|
|
&&
|
|
(string.IsNullOrEmpty(table.CreatorId) ||
|
|
x.CreatorId.Contains(table.CreatorId))
|
|
select x
|
|
;
|
|
|
|
return q.ToList();
|
|
}
|
|
|
|
/// 获取分页列表
|
|
/// </summary>
|
|
/// <param name="PageIndex">页码</param>
|
|
/// <param name="PageSize">每页数量</param>
|
|
/// <returns></returns>
|
|
public static IEnumerable getListData(PHTGL_BidProjectQuantity table, Grid Grid1)
|
|
{
|
|
var q = GetPHTGL_BidProjectQuantityByModle(table);
|
|
count = q.Count();
|
|
if (count == 0) return null;
|
|
q = q.Skip(Grid1.PageSize * Grid1.PageIndex).Take(Grid1.PageSize).ToList();
|
|
// q = SortConditionHelper.SortingAndPaging(q, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize);
|
|
return from x in q
|
|
select new
|
|
{
|
|
x.BidProjectQuantityId,
|
|
x.LotNumber,
|
|
x.BidProjectCode,
|
|
x.IsMainProject,
|
|
x.ProjectId,
|
|
x.CreatorId,
|
|
x.CreateDate
|
|
};
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |