/// <summary> ///上传时候保存Excel /// </summary> /// <param name="files"></param> /// <returns></returns> public string Save(string[] files) { if (files == null || files.Length == 0) { return("未选择文件!"); } string billCodes = ""; //try //{ foreach (var item in files) { DataTable dt = ExcelHelp.ExcelToDT(item); string typeTemp = dt.Rows[0][0].ToString(); //首行首列 string ColumnName = dt.Columns[0].ColumnName; //第一个列名 //如果是批量导入交货单 if (ColumnName == "交货") { billCodes = AddManyGiveBills(dt); } else { //单张单据 dt.Rows.RemoveAt(0); //删除标题行 switch (typeTemp) { case "转仓单号": AddTransferBill(dt); break; case "退仓单号": AddBackInput(dt); break; case "交货单号": AddGiveBill(dt); break; case "退货单号": AddBackOutput(dt); break; } } //删除文件 File.Delete(item); } return(billCodes == "" ? "导入成功" : "导入异常:" + billCodes); //} //catch(Exception e) //{ // return e.ToString(); //} }
/// <summary> /// 导出交货单 /// </summary> /// <param name="billId"></param> /// <returns></returns> private MemoryStream ExportGiveBill(Guid billId, string TemplateUrl) { GiveBill bill = CurrentDBSession.GiveBillDal.LoadEntities(a => a.Id == billId).FirstOrDefault(); if (bill == null) { return(null); } //根据模板创建Datatable DataTable dt = ExcelHelp.ExcelToDT(TemplateUrl); foreach (var record in bill.Record) { DataRow dr = dt.NewRow(); dr["LBBillCode"] = bill.LBBillCode; dr["LBBillDate"] = bill.LBBillDate; dr["LBTaskBillCode"] = bill.LBTaskBillCode; dr["LBLine"] = bill.LBLine; dr["LBContacts"] = bill.LBContacts; dr["LBPhone"] = bill.LBPhone; dr["LBMailCode"] = bill.LBMailCode; dr["LBCustomerCode"] = bill.LBCustomerCode; dr["LBCustomerName"] = bill.LBCustomerName; dr["LBSendAddress"] = bill.LBSendAddress; dr["LBRemark"] = bill.LBRemark; dr["CreateDate"] = bill.CreateDate; dr["ChargePerson"] = bill.ChargePerson; dr["MakePerson"] = bill.MakePerson; dr["Warehouse"] = bill.Warehouse; dr["WarehouseId"] = bill.WarehouseId; dr["LoadGoodsType"] = bill.LoadGoodsType; dr["OutputType"] = bill.OutputType; dr["OutputTypeId"] = bill.OutputTypeId; dr["BusinessType"] = bill.BusinessType; dr["LineWay"] = bill.LineWay; dr["Remark"] = bill.Remark; dr["Department"] = bill.Department; dr["DepartmentId"] = bill.DepartmentId; dr["Company"] = bill.Company; dr["CompanyId"] = bill.CompanyId; //子表 dr["ItemCode"] = record.ItemCode; dr["ItemLocationId"] = record.ItemLocationId; dr["ItemBatch"] = record.ItemBatch; dr["Count"] = record.Count; dt.Rows.Add(dr); } return(NPIOHelper.RenderToMemory(dt, "sheet1")); }
/// <summary> /// 导出入库单 /// </summary> /// <param name="billId"></param> /// <param name="TemplateUrl"></param> /// <returns></returns> private MemoryStream ExportTransferBill(Guid billId, string TemplateUrl) { TransferBill bill = CurrentDBSession.TransferBillDal.LoadEntities(a => a.Id == billId).FirstOrDefault(); if (bill == null) { return(null); } DataTable dt = ExcelHelp.ExcelToDT(TemplateUrl); foreach (var record in bill.Record) { DataRow dr = dt.NewRow(); dr["LBBillCode"] = bill.LBBillCode; dr["LBBillDate"] = bill.LBBillDate; dr["LBFrom"] = bill.LBFrom; dr["LBMoveType"] = bill.LBMoveType; dr["LBRemark"] = bill.LBRemark; dr["MakePerson"] = bill.MakePerson; dr["CreateDate"] = bill.CreateDate; dr["ChargePerson"] = bill.ChargePerson; dr["Warehouse"] = bill.Warehouse; dr["WarehouseId"] = bill.WarehouseId; dr["LoadGoodsType"] = bill.LoadGoodsType; dr["InputType"] = bill.InputType; dr["InputTypeId"] = bill.InputTypeId; dr["BusinessType"] = bill.BusinessType; dr["Remark"] = bill.Remark; dr["Department"] = bill.Department; dr["DepartmentId"] = bill.DepartmentId; dr["Company"] = bill.Company; dr["CompanyId"] = bill.CompanyId; //子表 dr["ItemCode"] = record.ItemCode; dr["ItemLocationId"] = record.ItemLocationId; dr["ItemBatch"] = record.ItemBatch; dr["Count"] = record.Count; dt.Rows.Add(dr); } return(NPIOHelper.RenderToMemory(dt, "sheet1")); }