using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Data.Entity.Migrations; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using CK.SCP.Models; using CK.SCP.Models.Enums; using CK.SCP.Models.ScpEntity; using CK.SCP.Models.ScpEntity.ExcelExportEnttity; using CK.SCP.Models.ScpEntity.ExcelImportEntity; using CK.SCP.Utils; namespace CK.SCP.Controller { public class SCP_EXCEL_CONTROLLER { public static DataSet GET_PO_EXECEL(List p_lst,bool p_IsDetail=false) { DataSet _ds = new DataSet(); using (ScpEntities db = EntitiesFactory.CreateScpInstance()) { if (p_IsDetail == false) { var _ls = db.V_TB_PO.Where(p => p_lst.Contains(p.PoBillNum)).ToList(); var _exportList = new List(); _ls.ForEach(itm => { SCP_PO_EXPORT _export = new SCP_PO_EXPORT(); _export.状态 = itm.State_DESC; _export.订单类型 = itm.ModType_DESC; _export.订单编号 = itm.PoBillNum; _export.Erp订单编号 = itm.ErpBillNum; _export.供应商编码 = itm.VendId; _export.供应商名称 = itm.VendName; _export.订货日期 = itm.BeginTime == null ? string.Empty : ((DateTime)itm.BeginTime).ToString("yyyyMMdd"); _export.收货地点 = itm.Site; _export.收货人 = itm.Buyer; _export.收货人电话 = itm.BuyerPhone; _export.备注 = itm.Remark; _exportList.Add(_export); }); var _dt = ConvertHelper.ToDataTable(_exportList); _ds.Tables.Add(_dt); } var _detailList = db.V_TB_PO_DETAIL.Where(p => p_lst.Contains(p.PoBillNum)).ToList(); _detailList = SCP_PO_CONTROLLER.LOAD_PO_DETAIL_SUM(_detailList); var _exportDetailList = new List(); _detailList.ForEach(itm => { var po_detail = new SCP_PO_DETAIL_EXPORT(); po_detail.订单编号 = itm.PoBillNum; po_detail.状态 = itm.State_DESC; po_detail.行号 = itm.PoLine.ToString(); po_detail.零件名 = itm.PartDesc1; po_detail.零件编 = itm.PartCode; po_detail.订单数 = itm.PlanQty.ToString(); po_detail.已要数 = itm.TempQty == null ? string.Empty : itm.TempQty.ToString(); po_detail.发货数 = itm.ShippedQty.ToString(); po_detail.收货数 = itm.ReceivedQty.ToString(); po_detail.退货数 = itm.RejectQty; po_detail.到货日期 = itm.EndTime == null ? string.Empty : ((DateTime)itm.BeginTime).ToString("yyyyMMdd"); ; po_detail.单位 = itm.PoUnit; _exportDetailList.Add(po_detail); }); var _list_dt = ConvertHelper.ToDataTable(_exportDetailList); _ds.Tables.Add(_list_dt); } return _ds; } public static List GET_PO_EXECEL_Model(List p_lst, bool p_IsDetail = false) { DataSet _ds = new DataSet(); var _exportDetailList = new List(); using (ScpEntities db = EntitiesFactory.CreateScpInstance()) { var _detailList = db.V_TB_PO_DETAIL.Where(p => p_lst.Contains(p.UID.ToString())).ToList(); var polist=_detailList.Select(p => p.PoBillNum); var _po = db.V_TB_PO.Where(p =>polist.Contains(p.PoBillNum)).FirstOrDefault(); _detailList.ForEach(itm => { var po_detail = new SCP_PO_DETAIL_EXPORT_MODEL(); po_detail.订单编号 = itm.PoBillNum; po_detail.行号 = itm.PoLine.ToString(); po_detail.零件名 = itm.PartDesc1; if (!string.IsNullOrEmpty(itm.PartDesc2)) { po_detail.零件名 += itm.PartDesc2; } po_detail.零件编码 = itm.PartCode; po_detail.订单数 = "0"; po_detail.供应商 = itm.VendName; po_detail.供应商编码 = itm.VendId; po_detail.订货日期 =DateTime.Now.ToShortDateString(); po_detail.到货日期 = DateTime.Now.ToShortDateString(); po_detail.单位 = itm.PoUnit; po_detail.域名 = _po.Site; po_detail.站点 = _po.Remark; po_detail.计划员 = _po.Buyer; po_detail.计划员电话 = _po.BuyerPhone; po_detail.价格 = itm.Price.ToString(); po_detail.币种 = itm.Currency; po_detail.收货口 = itm.DockCode; po_detail.项目编号 = itm.ProjectId; po_detail.备注 = string.Empty; po_detail.预测一 = "0"; po_detail.预测二 = "0"; po_detail.预测三 = "0"; _exportDetailList.Add(po_detail); }); //var _list_dt = ConvertHelper.ToDataTable(_exportDetailList); //_ds.Tables.Add(_list_dt);/ } return _exportDetailList; } public static DataSet GET_PALLET_EXECEL(List p_lst) { DataSet _ds = new DataSet(); using (ScpEntities db = EntitiesFactory.CreateScpInstance()) { var _ls = db.V_TB_PALLET_DETAIL.Where(p => p_lst.Contains(p.AsnBillNum)).ToList(); var _exportList = new List(); _ls.ForEach(itm => { SCP_PALLET_EXPORT _entity = new SCP_PALLET_EXPORT(); _entity.订单号 = itm.PoBillNum; _entity.发货单号 = itm.AsnBillNum; _entity.托盘号 = itm.PalletNum; _entity.托盘名 = itm.PlateNumber; _entity.零件编号 = itm.PartCode; _entity.零件名称 = itm.PartDesc1 + itm.PartDesc2; _entity.数量 = itm.Qty.ToString(); _entity.包装数量 = itm.PackQty.ToString(); _entity.供应商 = itm.VendName; _exportList.Add(_entity); }); var _dt = ConvertHelper.ToDataTable(_exportList); _ds.Tables.Add(_dt); } return _ds; } public static DataSet GET_ASK_EXECEL(List p_lst) { DataSet _ds = new DataSet(); using (ScpEntities db = EntitiesFactory.CreateScpInstance()) { var _ls = db.V_TB_ASK.Where(p => p_lst.Contains(p.AskBillNum)).ToList(); var _exportList = new List(); _ls.ForEach(itm => { SCP_ASK_EXPORT _entity = new SCP_ASK_EXPORT(); _entity.状态 = itm.State_DESC; _entity.单据类型 = itm.ModType_DESC; _entity.要货单号 = itm.AskBillNum; _entity.订单号 = itm.PoBillNum; _entity.项目编号 = itm.ErpBillNum; _entity.供应商 = itm.VendName; _entity.订货日期 = itm.BeginTime == null ? string.Empty : itm.BeginTime.Value.ToString("yyyyMMdd"); _entity.地点 = itm.Site_Desc; _entity.到货日期 = itm.EndTime == null ? string.Empty : itm.EndTime.Value.ToString("yyyyMMdd"); _entity.收货人 = itm.Buyer; _entity.收货电话 = itm.BuyerPhone; _exportList.Add(_entity); }); var _dt = ConvertHelper.ToDataTable(_exportList); _ds.Tables.Add(_dt); var _detailList = db.V_TB_ASK_DETAIL.Where(p => p_lst.Contains(p.AskBillNum)).ToList(); var _exportDetailList = new List(); _detailList.ForEach(itm => { SCP_ASK_DETAIL_EXPORT _entity = new SCP_ASK_DETAIL_EXPORT(); _entity.要货单号 = itm.AskBillNum; _entity.行号 = itm.PoLine.ToString(); _entity.零件名称 = itm.PartDesc1; _entity.零件号 = itm.PartCode; _entity.单位 = itm.PoUnit; _entity.标包数量 = itm.PackQty.ToString(); // _entity.币种 = itm.CurrencyDesc; //_entity.价格 = itm.Price.ToString(); _entity.要货数量 = itm.AskQty.ToString(); _entity.说明 = string.IsNullOrEmpty(itm.Remark)?string.Empty:itm.Remark.ToString(); _entity.到货日期 = itm.EndTime == null ? string.Empty : itm.EndTime.Value.ToString("yyyyMMdd"); _entity.预测一 = itm.Extend1.ToString(); _entity.预测二= itm.Extend2.ToString(); _entity.预测三 = itm.Extend3.ToString(); _exportDetailList.Add(_entity); }); var _list_dt = ConvertHelper.ToDataTable(_exportDetailList); _ds.Tables.Add(_list_dt); } return _ds; } public static DataSet GET_ASN_EXECEL(List p_lst) { DataSet _ds = new DataSet(); using (ScpEntities db = EntitiesFactory.CreateScpInstance()) { var _ls = db.V_TB_ASN.Where(p => p_lst.Contains(p.AsnBillNum)).ToList(); var _exportList = new List(); _ls.ForEach(itm => { var _entity = new SCP_ASN_EXPORT(); _entity.状态 = itm.State_DESC; _entity.发货单号 = itm.AsnBillNum; _entity.车牌号 = itm.PlateNumber; _entity.供应商 = itm.VendName; _entity.订单号 = itm.PoBillNum; _entity.发货时间 = itm.ShipTime == null ? string.Empty : itm.ShipTime.Value.ToString("yyyyMMdd"); _entity.发货人 = itm.ShipUser; _entity.收货时间 = itm.ReceiveTime == null ? string.Empty : itm.ReceiveTime.Value.ToString("yyyyMMdd"); _entity.收货人 = itm.ReceiveUser; _entity.发往地点 = itm.Site_Desc; _entity.备注 = itm.Remark; _exportList.Add(_entity); }); var _dt = ConvertHelper.ToDataTable(_exportList); _ds.Tables.Add(_dt); var _exportDetailList = new List(); var _detailList = db.V_TB_ASN_DETAIL.Where(p => p_lst.Contains(p.AsnBillNum)).ToList(); _detailList.ForEach(itm =>{ var _entity = new SCP_ASN_DETAIL_EXPORT(); _entity.发货单号 = itm.AsnBillNum; _entity.标包数量 = itm.PackQty.ToString(); _entity.供应商零件编号 = itm.VendPartCode; _entity.发货数量 = itm.Qty.ToString(); _entity.零件编号 = itm.PartCode; _entity.零件名称 = itm.PartDesc1; _entity.币种 = itm.CurrencyDesc; _entity.批次 = itm.Batch; _entity.供应商批次 = itm.VendBatch; _entity.生产日期 = itm.ProduceDate==null?string.Empty: itm.ProduceDate.Value.ToString("yyyyMMdd"); _entity.单位 = itm.PoUnit; _entity.价格 = itm.Price.ToString(); _exportDetailList.Add(_entity); }); var _list_dt = ConvertHelper.ToDataTable(_exportDetailList); _ds.Tables.Add(_list_dt); } return _ds; } public static DataSet GET_INVOICE_EXECEL(List p_lst) { DataSet _ds = new DataSet(); using (ScpEntities db = EntitiesFactory.CreateScpInstance()) { var _ls = db.V_TB_INVOICE.Where(p => p_lst.Contains(p.InvcBillNum)).ToList(); var _exportList = new List(); _ls.ForEach(itm => { var _entity = new SCP_INVOICE_EXPORT(); _entity.状态 = itm.State_DESC; _entity.发票编号 = itm.InvcBillNum; _entity.金税票号 = itm.InvoiceNum; _entity.供应商 = itm.VendName; _entity.金额 = itm.Amount.ToString(); _entity.税率 = itm.Tax.ToString(); _entity.税额 = itm.TaxAmount.ToString(); _entity.折扣金额 = itm.ContractPrice.ToString(); _entity.税额调整 = itm.BlancePrice.ToString(); _entity.开票金额 = itm.Total.ToString(); _entity.创建时间 = itm.CreateTime == null ? string.Empty : itm.CreateTime.Value.ToString("yyyyMMdd"); _entity.快递单号 = itm.ExpressNum; _entity.备注 = itm.Remark; _exportList.Add(_entity); }); var _dt = ConvertHelper.ToDataTable(_exportList); _ds.Tables.Add(_dt); var _exportDetailList = new List(); var _detailList = db.V_TB_INVOICE_DETAIL.Where(p => p_lst.Contains(p.InvcBillNum)).ToList(); _detailList.ForEach(itm => { var _entity = new SCP_INVOICE_DETAIL_EXPORT(); _entity.发票编号 = itm.InvcBillNum; _entity.金税票号 = itm.InvoiceNum; _entity.ERP收货单号 = itm.ErpRecvBillNum; _entity.WMS收货单号 = itm.RecvBillNum; _entity.项目编号 = !string.IsNullOrEmpty(itm.ProjectId)?itm.ProjectId:string.Empty; _entity.订单号 = itm.PoBillNum; _entity.订单行 = itm.PoLineNum.ToString(); _entity.发货单 = itm.AsnBillNum; _entity.零件名称 = itm.PartDesc1; _entity.零件号 = itm.PartCode; _entity.币种 = itm.Currency; _entity.单价 = itm.Price.ToString(); _entity.采购价 = itm.PurCost==null?"0":itm.PurCost.Value.ToString(); _entity.成本价= itm.StdCost == null ? "0" : itm.StdCost.Value.ToString(); // _entity.要货日期 = itm.BeginTime == null ? string.Empty : itm.BeginTime.Value.ToString("yyyyMMdd"); //_entity.折扣价格 = itm.DiscountPrice.ToString(); //_entity.折扣备注 = itm.DiscountRemark; _entity.开票数量 = itm.Qty.ToString(); _entity.备注 = itm.Remark; _exportDetailList.Add(_entity); }); var _list_dt = ConvertHelper.ToDataTable(_exportDetailList); _ds.Tables.Add(_list_dt); } return _ds; } public static DataSet GET_OTD_REPORT_EXECEL(List p_lst) { DataSet _ds = new DataSet(); var _exportList = new List(); using (ScpEntities db = EntitiesFactory.CreateScpInstance()) { p_lst.ForEach(itm => { SCP_OTD_REPORT_EXPORT _entity = new SCP_OTD_REPORT_EXPORT(); _entity.供应商编号 = itm.VendId; _entity.供应商名称 = itm.VendName; _entity.要货看板号 = itm.AskBillNum; _entity.零件号 = itm.PartCode; _entity.零件名称 = itm.PartName; _entity.要求到货时间 = Convert.ToDateTime(itm.EndTime).ToString("yyyy/MM/dd"); _entity.订单要货数量 = itm.AskQty.ToString(); _entity.到货数量 = itm.ArriveQty.ToString(); _entity.差额 = itm.Qty.ToString(); _entity.及时数量 = itm.NntimelyQty.ToString(); _entity.及时率 = itm.OTD.ToString(); _entity.到货率 = itm.ArriveOTD.ToString(); _exportList.Add(_entity); }); var _dt = ConvertHelper.ToDataTable(_exportList); _ds.Tables.Add(_dt); } return _ds; } } }