#region Exel导出方法
[MaxuniAuthAttribute(Roles = "sysroles")]
public void OrderExport(string id)
{
string strWhere = " from VOutProceExel where OProcessRequisitionId='" + id + "'";
var obj = objBaseRepository.GetOneRecord(id);//数据库,表里的信息
var objlist = objVOutProceExelRepository.GetAll(strWhere);//要导出的视图信息
string path = Server.MapPath("~/exceltemplate/XX合同.xls");//模板
FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read);//用模板导出 string suppliercontactperson1 = "";
string supplierName = "";
string supplierpaymentType = "";
string suppliertel = "";
string supplierfax = "";
string supplierOrderNo = "";
GetSupplierinfo(id, out suppliercontactperson1, out supplierName, out supplierpaymentType, out suppliertel, out supplierfax, out supplierOrderNo); string CompayName = "";
string address = "";
string tel = "";
string fax = "";
string homepage = "";
string email = "";
GetCompanyAddres(out CompayName, out address, out tel, out fax, out homepage, out email); IWorkbook hssfworkbook = WorkbookFactory.Create(file);//创建Execl
ICellStyle style = hssfworkbook.CreateCellStyle();
ISheet sheetk3 = hssfworkbook.GetSheet("inquiry");//导出的Execl里的工作表名称,一定要一致 sheetk3.DefaultColumnWidth = * ;
sheetk3.DefaultRowHeightInPoints = ;
sheetk3.DisplayGridlines = true; style.BorderBottom = BorderStyle.THIN;
style.BorderLeft = BorderStyle.THIN;
style.BorderRight = BorderStyle.THIN;
style.BorderTop = BorderStyle.THIN;
int count = objlist.Count; //
IRow row1 = sheetk3.GetRow();//.GetRow(2)代表Execl模板里的行数,2代表第二行
row1.GetCell().SetCellValue("甲方(委托方):XX有限公司");//.GetCell(0)代表Execl模板里的列数,0代表第一列
row1.GetCell().SetCellValue(obj.contractNO);//.GetCell(5)代表Execl模板里的列数,5代表第五列 IRow row2 = sheetk3.GetRow();//代表Execl模板里的行数,3代表第三行
row2.CreateCell().SetCellValue("乙方(加工方):");
row2.CreateCell().SetCellValue(obj.supplierName);// IRow row3 = sheetk3.GetRow();//.GetRow(6)代表Execl模板里的行数,6代表第6行
row3.CreateCell().SetCellValue("一、内容:"); for (int i = ; i < count; i++)
{
IRow row = sheetk3.CreateRow( + i);//添加序列号,从第7行开始加,加到i行
row.CreateCell().SetCellValue(i + );
row.CreateCell().SetCellValue(objlist[i].mouldNo);
row.CreateCell().SetCellValue(objlist[i].partName);
row.CreateCell().SetCellValue(objlist[i].drawingNo);
row.CreateCell().SetCellValue(objlist[i].OutTypeName);
row.CreateCell().SetCellValue(objlist[i].qty);
row.CreateCell().SetCellValue(objlist[i].processRemark);
row.CreateCell().SetCellValue(objlist[i].Price);
row.CreateCell().SetCellValue(objlist[i].TotaPricel);
row.CreateCell().SetCellValue(objlist[i].oendDate == null ? "" : objlist[i].oendDate.Value.ToString("yyyy-MM-dd")); row.Cells[].CellStyle = style;
row.Cells[].CellStyle = style;
row.Cells[].CellStyle = style;
row.Cells[].CellStyle = style;
row.Cells[].CellStyle = style;
row.Cells[].CellStyle = style;
row.Cells[].CellStyle = style;
row.Cells[].CellStyle = style;
row.Cells[].CellStyle = style;
row.Cells[].CellStyle = style; } IRow row4 = sheetk3.GetRow();
string strdiscount = "";
if (obj.discount == )
strdiscount = "";
else
strdiscount = "折扣:" + obj.discount + "%";
row4.GetCell().SetCellValue(obj.discountPrice.ToString());
row4.GetCell().SetCellValue(strdiscount); IRow row5 = sheetk3.GetRow();
row5.GetCell().SetCellValue("付款方式:" + supplierpaymentType); IRow row6 = sheetk3.GetRow();
row6.GetCell().SetCellValue(obj.outUserName); MemoryStream ms = new MemoryStream();
hssfworkbook.Write(ms);//
Response.ContentType = "application/vnd.ms-excel";
if (obj.contractNO == null)
{
Response.AddHeader("Content-Disposition", string.Format("attachment;filename=inquiry.xls"));
}
else
{
Response.AddHeader("Content-Disposition", string.Format("attachment;filename=" + obj.contractNO + ".xls"));
}
Response.BinaryWrite(ms.ToArray());
Response.End();
hssfworkbook = null;
ms.Close();
ms.Dispose(); }
#endregion #region 公司地址及详细信息
private void GetCompanyAddres(out string CompayName, out string address, out string tel, out string fax, out string homepage, out string email)
{
var model = objCompayRepositoryRepository.GetAll();
CompayName = "";
address = "";
tel = "";
fax = "";
homepage = "";
email = "";
if (model.Count > )
{
CompayName = model[].CompayName;
address = model[].address;
tel = model[].tel;
fax = model[].fax;
homepage = model[].homepage;
email = model[].email;
//ViewData["companyname"] = model[0].CompayName;
//ViewData["address"] = model[0].address;
//ViewData["tel"] = model[0].tel;
//ViewData["fax"] = model[0].fax;
//ViewData["homepage"] = model[0].homepage;
//ViewData["email"] = model[0].email;
}
}
#endregion #region 供应商地址级详细信息 合同条约 private void GetSupplierinfo(string id, out string suppliercontactperson1, out string supplierName, out string supplierpaymentType, out string suppliertel, out string supplierfax, out string supplierOrderNo)
{
OProcessRequisition objOrderApply = objBaseRepository.GetOneRecord(id);
string strSupplierid = objOrderApply.supplierID;
Supplier objsupplier = new Supplier();
if (!string.IsNullOrEmpty(strSupplierid))
objsupplier = objSupplierRepository.GetOneRecord(strSupplierid); suppliercontactperson1 = objsupplier.contactperson1;
supplierName = objsupplier.supplierName;
supplierpaymentType = objsupplier.paymentType + ";税率:" + objsupplier.taxRate;
suppliertel = objsupplier.tel;
supplierfax = objsupplier.fax;
supplierOrderNo = objOrderApply.contractNO; IList<OrderCond> objordercond = objOrderCondRepository.GetAll("from OrderCond where TypeNo=1").OrderBy(o => o.SortId).ToList();
//var objplaymenthod = objordercond.FirstOrDefault(o => o.SortId ==6);
//var obj = objplaymenthod;
//objordercond.Remove(objplaymenthod);
//obj.CondContent = objplaymenthod.CondContent.Replace(":", "").Replace(":", "") + ":" + objsupplier.paymentType + ";税率:" + objsupplier.taxRate;
//objordercond.Insert(11, obj);
ViewData["allcond"] = objordercond;
}
#endregion