public RPTLotMateriallistParameter GetQueryConditionP(LotMaterialList1ViewModel model) { RPTLotMateriallistParameter p = new RPTLotMateriallistParameter() { LotNumber = model.LotNumber, PageNo = model.PageNo, //PageNo = 2, PageSize = model.PageSize }; return(p); }
public ActionResult QueryLotProcessingHistory(LotMaterialList1ViewModel model) { string strErrorMessage = string.Empty; MethodReturnResult <DataSet> result = new MethodReturnResult <DataSet>(); try { RPTLotMateriallistParameter param = GetQueryConditionP(model); using (LotQueryServiceClient client = new LotQueryServiceClient()) { //RPTLotMateriallistParameter param = new RPTLotMateriallistParameter(); //param.LotNumber = model.LotNumber; MethodReturnResult <DataSet> ds = client.GetRPTLotProcessingHistory(ref param); ViewBag.ListData = ds.Data.Tables[0]; ViewBag.PagingConfig = new PagingConfig() { PageNo = model.PageNo, PageSize = model.PageSize, Records = param.TotalRecords }; model.TotalRecords = param.TotalRecords; } } catch (Exception ex) { result.Code = 1000; result.Message = ex.Message; result.Detail = ex.ToString(); } if (Request.IsAjaxRequest()) { return(PartialView("_LotProcessingHistoryListPartial", model)); } else { return(View("IndexLotProcessingHistory", model)); } }
public string GetQueryCondition(LotMaterialListViewModel model) { RPTLotMateriallistParameter p = new RPTLotMateriallistParameter() { LotNumber = model.LotNumber, PageNo = model.PageNo, PageSize = model.PageSize }; StringBuilder where = new StringBuilder(); if (model != null) { if (!string.IsNullOrEmpty(model.LotNumber)) { char[] splitChars = new char[] { ',', '$' }; string[] LotNumbers = model.LotNumber.TrimEnd(splitChars).Split(splitChars); if (LotNumbers.Length <= 1) { where.AppendFormat(" {0} Key.LotNumber = '{1}'" , where.Length > 0 ? "AND" : string.Empty , LotNumbers[0]); } else { where.AppendFormat(" {0} Key.LotNumber IN (" , where.Length > 0 ? "AND" : string.Empty); foreach (string package in LotNumbers) { where.AppendFormat("'{0}',", package); } where.Remove(where.Length - 1, 1); where.Append(")"); } } } return(where.ToString()); }
public async Task <ActionResult> ExportToExcelLotProcessingHistory(LotMaterialList1ViewModel model) { DataTable dt = new DataTable(); MethodReturnResult <DataSet> result = new MethodReturnResult <DataSet>(); using (LotQueryServiceClient client = new LotQueryServiceClient()) { //RPTLotMateriallistParameter param = GetQueryCondition(model); RPTLotMateriallistParameter param = new RPTLotMateriallistParameter(); param.LotNumber = model.LotNumber; param.PageSize = model.PageSize; param.PageNo = -1; await Task.Run(() => { PagingConfig cfg = new PagingConfig() { OrderBy = "Key.LotNumber,ItemNo", Where = GetQueryConditionP(model).ToString() //Where = GetQueryConditionP(model).ToString() }; MethodReturnResult <DataSet> ds = client.GetRPTLotProcessingHistory(ref param); dt = ds.Data.Tables[0]; }); } //创建工作薄。 IWorkbook wb = new HSSFWorkbook(); //设置EXCEL格式 ICellStyle style = wb.CreateCellStyle(); style.FillForegroundColor = 10; //有边框 style.BorderBottom = BorderStyle.Thin; style.BorderLeft = BorderStyle.Thin; style.BorderRight = BorderStyle.Thin; style.BorderTop = BorderStyle.Thin; IFont font = wb.CreateFont(); font.Boldweight = 10; style.SetFont(font); ISheet ws = null; for (int j = 0; j < dt.Rows.Count; j++) { if (j % 65535 == 0) { ws = wb.CreateSheet(); IRow row = ws.CreateRow(0); ICell cell = null; #region //列名 foreach (DataColumn dc in dt.Columns) { cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(dc.Caption); } #endregion font.Boldweight = 5; } IRow rowData = ws.CreateRow(j + 1); #region //数据 ICell cellData = null; foreach (DataColumn dc in dt.Columns) { cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; if (dc.DataType == typeof(double) || dc.DataType == typeof(float)) { cellData.SetCellValue(Convert.ToDouble(dt.Rows[j][dc])); } else if (dc.DataType == typeof(int)) { cellData.SetCellValue(Convert.ToInt32(dt.Rows[j][dc])); } else { cellData.SetCellValue(Convert.ToString(dt.Rows[j][dc])); } } #endregion } MemoryStream ms = new MemoryStream(); wb.Write(ms); ms.Flush(); ms.Position = 0; return(File(ms, "application/vnd.ms-excel", "LotProcessingHistoryData.xls")); }
public async Task <ActionResult> ExportToExcelWl(LotMaterialListViewModel model) { DataTable dt = new DataTable(); MethodReturnResult <DataSet> result = new MethodReturnResult <DataSet>(); using (LotQueryServiceClient client = new LotQueryServiceClient()) { RPTLotMateriallistParameter param = new RPTLotMateriallistParameter(); param.LotNumber = model.LotNumber; param.PageSize = model.PageSize; param.PageNo = -1; await Task.Run(() => { PagingConfig cfg = new PagingConfig() { OrderBy = "Key.LotNumber,ItemNo", Where = GetQueryCondition(model) }; MethodReturnResult <DataSet> ds = client.GetRPTLotMaterialList(ref param); dt = ds.Data.Tables[0]; }); } //创建工作薄。 IWorkbook wb = new HSSFWorkbook(); //设置EXCEL格式 ICellStyle style = wb.CreateCellStyle(); style.FillForegroundColor = 10; //有边框 style.BorderBottom = BorderStyle.Thin; style.BorderLeft = BorderStyle.Thin; style.BorderRight = BorderStyle.Thin; style.BorderTop = BorderStyle.Thin; IFont font = wb.CreateFont(); font.Boldweight = 10; style.SetFont(font); ISheet ws = null; for (int j = 0; j < dt.Rows.Count; j++) { if (j % 65535 == 0) { ws = wb.CreateSheet(); IRow row = ws.CreateRow(0); ICell cell = null; #region //列名 foreach (DataColumn dc in dt.Columns) { cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(dc.Caption); } #endregion font.Boldweight = 5; } IRow rowData = ws.CreateRow(j + 1); #region //数据 ICell cellData = null; foreach (DataColumn dc in dt.Columns) { System.Data.DataRow obj = dt.Rows[j]; Manufacturer mf = null; using (SupplierToManufacturerServiceClient clients = new SupplierToManufacturerServiceClient()) { PagingConfig cfg0 = new PagingConfig() { Where = string.Format(@"Key.MaterialCode='{0}' AND Key.SupplierCode='{1}'" , obj["MATERIAL_CODE"] , obj["SUPPLIER_CODE"]) }; MethodReturnResult <IList <SupplierToManufacturer> > results = clients.Gets(ref cfg0); if (results.Code <= 0 && results.Data.Count > 0) { if (results.Data[0].Key.OrderNumber == "*") { using (ManufacturerServiceClient clientss = new ManufacturerServiceClient()) { MethodReturnResult <Manufacturer> rsts = clientss.Get(results.Data[0].ManufacturerCode); if (rsts.Data != null) { mf = rsts.Data; } } } else { PagingConfig cfg1 = new PagingConfig() { Where = string.Format(@"Key.MaterialCode='{0}' AND Key.OrderNumber='{1}' AND Key.SupplierCode='{2}'" , obj["MATERIAL_CODE"] , obj["ORDER_NUMBER"] , obj["SUPPLIER_CODE"]) }; MethodReturnResult <IList <SupplierToManufacturer> > resultss = clients.Gets(ref cfg1); if (resultss.Code <= 0 && resultss.Data.Count > 0) { using (ManufacturerServiceClient clientss = new ManufacturerServiceClient()) { MethodReturnResult <Manufacturer> rsts = clientss.Get(resultss.Data[0].ManufacturerCode); if (rsts.Data != null) { mf = rsts.Data; } } } } } } cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; if (dc.DataType == typeof(double) || dc.DataType == typeof(float)) { if (dc.ColumnName == "SUPPLIER_CODE") { cellData.SetCellValue(mf == null ? Convert.ToString(dt.Rows[j][dc]) : mf.Key); } else if (dc.ColumnName == "SUPPLIER_NAME") { cellData.SetCellValue(mf == null ? Convert.ToString(dt.Rows[j][dc]) : mf.Name); } else { cellData.SetCellValue(Convert.ToDouble(dt.Rows[j][dc])); } } else if (dc.DataType == typeof(int)) { if (dc.ColumnName == "SUPPLIER_CODE") { cellData.SetCellValue(mf == null ? Convert.ToString(dt.Rows[j][dc]) : mf.Key); } else if (dc.ColumnName == "SUPPLIER_NAME") { cellData.SetCellValue(mf == null ? Convert.ToString(dt.Rows[j][dc]) : mf.Name); } else { cellData.SetCellValue(Convert.ToInt32(dt.Rows[j][dc])); } } else { if (dc.ColumnName == "SUPPLIER_CODE") { cellData.SetCellValue(mf == null ? Convert.ToString(dt.Rows[j][dc]) : mf.Key); } else if (dc.ColumnName == "SUPPLIER_NAME") { cellData.SetCellValue(mf == null ? Convert.ToString(dt.Rows[j][dc]) : mf.Name); } else { cellData.SetCellValue(Convert.ToString(dt.Rows[j][dc])); } } } #endregion } MemoryStream ms = new MemoryStream(); wb.Write(ms); ms.Flush(); ms.Position = 0; return(File(ms, "application/vnd.ms-excel", "LotMaterialData.xls")); }