private ImportMessageModel BarcodeInfo_FormatRow(DataRow row, Mes_Tra_SourceBarcode itemObj, int rowIndex) { ImportMessageModel errorObj = null; try { itemObj.Barcode = TConvertHelper.FormatDBString(row["条码"]); if (string.IsNullOrEmpty(itemObj.Barcode)) { return(new ImportMessageModel() { RowData = string.Format(ReadErrorMessage, rowIndex), RowMessage = "条码不能为空" }); } } catch (Exception ex) { return(new ImportMessageModel() { RowData = string.Format(ReadErrorMessage, rowIndex), RowMessage = ex.Message }); } return(errorObj); }
private ImportMessageModel TecProcessBom_FormatRow(DataRow row, Mes_Tec_ProcessBomItem itemObj, int rowIndex) { ImportMessageModel errorObj = null; try { //导入样品 itemObj.MaterialProNo = TConvertHelper.FormatDBString(row["产品编码"]); itemObj.Version = TConvertHelper.FormatDBString(row["版本"]); itemObj.ProcessName = TConvertHelper.FormatDBString(row["工艺"]); itemObj.SubMaterialProNo = TConvertHelper.FormatDBString(row["物料编码"]); itemObj.Num = TConvertHelper.FormatDBInt(row["数量"]); itemObj.Memo = TConvertHelper.FormatDBString(row["备注"]); itemObj.CreatedTime = DateTime.Now; if (string.IsNullOrEmpty(itemObj.MaterialProNo) || string.IsNullOrEmpty(itemObj.Version)) { return(new ImportMessageModel() { RowData = string.Format(ReadErrorMessage, rowIndex), RowMessage = "产品编码、版本不能为空" }); } if (string.IsNullOrEmpty(itemObj.SubMaterialProNo)) { return(new ImportMessageModel() { RowData = string.Format(ReadErrorMessage, rowIndex), RowMessage = "物料编码不能为空" }); } if (string.IsNullOrEmpty(itemObj.ProcessName)) { return(new ImportMessageModel() { RowData = string.Format(ReadErrorMessage, rowIndex), RowMessage = "工艺不能为空" }); } if (itemObj.Num <= 0) { return(new ImportMessageModel() { RowData = string.Format(ReadErrorMessage, rowIndex), RowMessage = "数量不能为空" }); } } catch (Exception ex) { return(new ImportMessageModel() { RowData = string.Format(ReadErrorMessage, rowIndex), RowMessage = ex.Message }); } return(errorObj); }
private ImportMessageModel ProductInfo_FormatRow(DataRow row, Mes_Tec_ProductInfo itemObj, int rowIndex) { ImportMessageModel errorObj = null; try { //导入样品 string sTemp = ""; itemObj.MaterialProNo = TConvertHelper.FormatDBString(row["物料编码"]); itemObj.MaterialCode = TConvertHelper.FormatDBString(row["物料名称"]); sTemp = TConvertHelper.FormatDBString(row["物料分类"]); if (!string.IsNullOrEmpty(sTemp)) { itemObj.MaterialClass = StatusHelper.GetStatusByDescription <MaterialClassStatus>(sTemp); } sTemp = TConvertHelper.FormatDBString(row["批次属性"]); if (!string.IsNullOrEmpty(sTemp)) { itemObj.TraceProperty = TConvertHelper.FormatDBInt(StatusHelper.GetStatusByDescription <MaterialClassStatus>(sTemp)); } itemObj.MaterialSize = TConvertHelper.FormatDBString(row["规格尺寸"]); itemObj.Unit = TConvertHelper.FormatDBString(row["单位"]); itemObj.PackNumber = TConvertHelper.FormatDBInt(row["每箱数量"]); itemObj.Memo = TConvertHelper.FormatDBString(row["备注"]); //itemObj.CreatedTime = DateTime.Now; if (string.IsNullOrEmpty(itemObj.MaterialProNo) || string.IsNullOrEmpty(itemObj.MaterialCode)) { return(new ImportMessageModel() { RowData = string.Format(ReadErrorMessage, rowIndex), RowMessage = "物料编码、物料名称不能为空" }); } } catch (Exception ex) { return(new ImportMessageModel() { RowData = string.Format(ReadErrorMessage, rowIndex), RowMessage = ex.Message }); } return(errorObj); }
/// <summary> /// 通用导出 /// </summary> /// <param name="businessObj"></param> public static string Export <T>(ref BussinessModel businessObj, List <T> list) where T : class { string message = string.Empty; try { //1.生成文件(由模板生成新的文件) string templateName = "ExportTemplate.xls"; string templatePath = HttpContext.Current.Server.MapPath("~" + SysConfigHelper.TemplateFolder) + templateName; string tempPath = HttpContext.Current.Server.MapPath("~" + SysConfigHelper.TempFolder); string fileName = string.Format("{0}_{1}.xls", businessObj.BusinessType, DateTime.Now.ToString("yyMMddHHmmssffff")); businessObj.FilePath = tempPath + fileName; businessObj.FileName = fileName; message = FileHelper.CopyFile(templatePath, tempPath.Trim('/'), fileName); if (!string.IsNullOrEmpty(message)) { return(message); } //2.填写文件内容 CellDLL.Workbook workbook = new CellDLL.Workbook(businessObj.FilePath); CellDLL.Cells cells = workbook.Worksheets[0].Cells;//单元格 int index = 0; int colNum = 0; object value = null; IDictionary <string, PropertyInfo> colProperties = new Dictionary <string, PropertyInfo>(); PropertyInfo property = null; Type type = typeof(T); if (businessObj.ColList != null && businessObj.ColList.Count > 0) { //(1)先写列头 businessObj.ColList.ForEach(item => { cells[index, colNum++].Value = item.Value; if (!colProperties.ContainsKey(item.Key)) { property = type.GetProperty(item.Key); colProperties.Add(item.Key, property); } }); //(2)写内容 if (list != null && list.Count > 0) { index = 1; colNum = 0; foreach (var item in list) { foreach (KeyModel keyObj in businessObj.ColList) { property = colProperties[keyObj.Key]; if (property != null) { value = property.GetValue(item, null); cells[index, colNum].Value = TConvertHelper.FormatDBString(value); } colNum++; } colNum = 0; index++; } } }/*businessObj.ColList*/ //3.保存文件 workbook.Save(businessObj.FilePath); } catch (Exception ex) { return("导出文件时出错,文件可能正被打开!"); } finally { //xlApp.Quit(); GC.Collect();//强行销毁 } return(string.Empty); }