private void InitCommand() { DirectorySelectBaseCommand = new DelegateCommand((obj) => { // 导出目录选择 System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog(); if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { HostConfig.HostValue = fbd.SelectedPath; var result = CommonService.SaveHostConfig(HostConfig); if (result) { HostConfig = CommonService.GetHostConfig(Menu.ID, HostName, User.ID); } } }); ExportBaseCommand = new DelegateCommand((obj) => { if (Directory.Exists(HostConfig.HostValue)) { ExportView view = new ExportView(Menu.ID, 3);// Menu.ID-SJExportViewTypedColumn中的ViewGroupId; 3 - 第几个radioButton被默认选中从1开始 //Export((type - 导出1 取消0, outputEntity 界面选中的radiobuttion 同上, checkBoxValue 选择分类导出的情况下,选择的类别和, orderedColumns 选择分类导出的情况下,选择类别的顺序列表) (view.DataContext as ExportViewModel).Export((type, outputEntity, checkBoxValue, orderedColumns) => { view.Close(); if (type == 1) { if (outputEntity == 3) { DataTable datatable = _service.GetSJBatchBomRequestDeliveryExportData(GeneralParameter.ParamBeginDate.Value, string.Join(",", orderedColumns)); if (datatable.Rows.Count > 0) { ExportHelper.ExportDeliveryDataToExcel(GeneralParameter.ParamBeginDate.Value, datatable, HostConfig.HostValue, HostConfig.TypeDesciption + CommonService.GetQueryParameterValueString(GeneralParameter) , outputEntity, orderedColumns, true, "$$$发料单", true); MessageBox.Show("导出成功"); } else { MessageBox.Show($"【{GeneralParameter.ParamBeginDate.Value}】 没有可导出的数据"); } } else { DataTable datatable = _service.GeSJBatchBOMSummaryExportData(GeneralParameter.ParamBeginDate.Value); if (datatable.Rows.Count > 0) { ExportHelper.ExportDataTableToExcel(datatable, HostConfig.HostValue, "物料需求" + CommonService.GetQueryParameterValueString(GeneralParameter), outputEntity, null, false, "物料需求", false); MessageBox.Show("导出成功"); } else { MessageBox.Show($"【{GeneralParameter.ParamBeginDate.Value}】 没有可导出的数据"); } } } }); view.ShowDialog(); } else { MessageBox.Show("目录不存在,请先选择导出的目录"); DirectorySelectBaseCommand.Execute(null); } CommonService.WriteActionLog(new ActionOperationLogModel { ActionName = "ExportBaseCommand", ActionDesc = HostConfig.TypeDesciption + HostConfig.TypeId.ToString(), UserId = User.ID, MainMenuId = Menu.ID, PKId = -1, HostName = HostName }); }); MaterialRequestGenerateCommand = new DelegateCommand((obj) => { _service.SplitBatchBomRequest(GeneralParameter.ParamBeginDate.Value); QueryBaseCommand.Execute(null); CommonService.WriteActionLog(new ActionOperationLogModel { ActionName = "MaterialRequestGenerateCommand", ActionDesc = "生成物料需求", UserId = User.ID, MainMenuId = Menu.ID, PKId = -1, HostName = HostName }); }); WorkshopInventoryRefreshCommand = new DelegateCommand((obj) => { BatchBomRequestSummaryLists.Clear(); _service.RefreshWorkshopInventoryQty(CommonService.GetSqlWhereString(Filter)); QueryBaseCommand.Execute(null); CommonService.WriteActionLog(new ActionOperationLogModel { ActionName = "WorkshopInventoryRefreshCommand", ActionDesc = "获取现场库存", UserId = User.ID, MainMenuId = Menu.ID, PKId = -1, HostName = HostName }); }); QueryBaseCommand = new DelegateCommand((obj) => { BatchBomRequestSummaryLists.Clear(); InventoryLists.Clear(); DeliverTransferLists.Clear(); _service.GetBatchBomRequestDetailSummaryLists(CommonService.GetSqlWhereString(Filter)).ForEach(x => BatchBomRequestSummaryLists.Add(x)); }); DeliverCommand = new DelegateCommand((obj) => { if (BatchBomRequestSummarySelectedItem != null) { if (InventorySelectedItem != null && InventorySelectedItem.TransferingWeight > 0 && InventorySelectedItem.TransferingWeight <= InventorySelectedItem.TotalWeight) { if (_service.InsertDeliverTransfer(InventorySelectedItem)) { DeliverTransferLists.Clear(); _service.GetDeliverTransferLists(BatchBomRequestSummarySelectedItem).ForEach(x => DeliverTransferLists.Add(x)); BatchBomRequestSummarySelectedItem.QtyTransfering = DeliverTransferLists.Where(x => string.IsNullOrEmpty(x.TransferedBillNo)).Sum(x => x.TransferingWeight).Value; } } else { MessageBox.Show("发料数量必须大于0且小于总重量"); } } else { MessageBox.Show("先选择主表行数据"); } CommonService.WriteActionLog(new ActionOperationLogModel { ActionName = "DeliverCommand", ActionDesc = "发料", UserId = User.ID, MainMenuId = Menu.ID, PKId = -1, HostName = HostName }); }); DeliveryDeleteCommand = new DelegateCommand((obj) => { int id = -1; if (BatchBomRequestSummarySelectedItem != null) { var selectedLists = ((obj as DataGrid).SelectedItems).Cast <MaterialTimelyInventoryModel>().ToList(); if (selectedLists.Count == 1) { var model = selectedLists.First(); if (_service.DeleteDeliverTransfer(model.Id)) { id = model.Id; DeliverTransferLists.Clear(); _service.GetDeliverTransferLists(BatchBomRequestSummarySelectedItem).ForEach(x => DeliverTransferLists.Add(x)); BatchBomRequestSummarySelectedItem.QtyTransfering = DeliverTransferLists.Sum(x => x.TransferingWeight).Value; } } else { MessageBox.Show("每次必须选中且删除一行记录"); } } else { MessageBox.Show("先选择主表行数据"); } CommonService.WriteActionLog(new ActionOperationLogModel { ActionName = "DeliveryDeleteCommand", ActionDesc = "删除发料", UserId = User.ID, MainMenuId = Menu.ID, PKId = id, HostName = HostName }); }); TransferDeleteCommand = new DelegateCommand((obj) => { if (BatchBomRequestSummarySelectedItem != null) { var selectedLists = ((obj as DataGrid).SelectedItems).Cast <MaterialTimelyInventoryModel>().ToList(); if (selectedLists.Count == 1) { var model = selectedLists.First(); if (!_service.ExistsK3Bill(model.TransferedBillNo)) { if (_service.DeleteDeliverTransfer(model.TransferedBillNo)) { //重新加载主表格 QueryBaseCommand.Execute(null); } } else { MessageBox.Show("请先将选择的调拨单号,在K3里面删除"); } } else { MessageBox.Show("每次必须选中且删除一行记录"); } } else { MessageBox.Show("先选择主表行数据"); } CommonService.WriteActionLog(new ActionOperationLogModel { ActionName = "TransferDeleteCommand", ActionDesc = "删除调拨单", UserId = User.ID, MainMenuId = Menu.ID, PKId = -1, HostName = HostName }); }); SelectionChangedCommand = new DelegateCommand((obj) => { if (BatchBomRequestSummarySelectedItem == null) { return; } InventoryLists.Clear(); _service.GetGetMaterialTimelyInventoryLists(BatchBomRequestSummarySelectedItem.MaterialId, BatchBomRequestSummarySelectedItem.ProductionDate, BatchBomRequestSummarySelectedItem.BatchTypeId, BatchBomRequestSummarySelectedItem.StockId).ForEach(x => InventoryLists.Add(x)); DeliverTransferLists.Clear(); _service.GetDeliverTransferLists(BatchBomRequestSummarySelectedItem).ForEach(x => DeliverTransferLists.Add(x)); }); BatchNoQtyK3InsertCommand = new DelegateCommand((obj) => { // 获取当天所有已发料未调拨数据 var selectedLists = ((obj as DataGrid).SelectedItems).Cast<MaterialTimelyInventoryModel>().ToList(); var selectedLists = _service.GetK3InsertData(GeneralParameter.ParamBeginDate.Value); if (selectedLists.Count > 0) { var emp = K3ApiFKService.GetEmployeeByUserName(User.UserName); if (emp != null) { TransferMainModel main = new TransferMainModel { FBillerID = new BaseNumberNameModelX { FNumber = emp.FName, FName = emp.FName }, FFManagerID = emp, // BaseNumberNameModelX { FNumber = "111", FName = "吴强" }, FSManagerID = emp, // new BaseNumberNameModelX { FNumber = "111", FName = "吴强" }, FRefType = new BaseNumberNameModelX { FNumber = "01", FName = "成本调拨" }, FClassTypeID = 41, FDate = DateTime.Now.Date.ToString("yyyy-MM-dd") }; List <TransferSonModel> sons = new List <TransferSonModel>(); foreach (MaterialTimelyInventoryModel item in selectedLists) { sons.Add(new TransferSonModel { FItemID = new BaseNumberNameModelX { FNumber = item.MaterialNumber, FName = item.MaterialName }, // K3ApiFKService.GetMaterialById FChkPassItem = new BaseNumberNameModelX { FNumber = "Y", FName = "是" }, FPlanMode = new BaseNumberNameModelX { FNumber = "MTS", FName = "MTS计划模式" }, FDCStockID1 = new BaseNumberNameModelX { FNumber = item.ParentStockNumber, FName = item.ParentStockName }, //K3ApiFKService.GetStockById(item.ParentStockId), FSCStockID1 = new BaseNumberNameModelX { FNumber = item.StockNumber, FName = item.StockName }, FUnitID = new BaseNumberNameModelX { FNumber = "kg", FName = "kg" }, FAuxQty = item.TransferingWeight.Value, FQty = item.TransferingWeight.Value, FBatchNo = item.BatchNo, }); } var requestModel = new K3ApiInsertRequestModel <TransferMainModel, TransferSonModel>() { Data = new K3ApiInsertDataRequestModel <TransferMainModel, TransferSonModel>() { Page1 = new List <TransferMainModel> { main }, Page2 = sons } }; string postJson = JsonHelper.ObjectToJson(requestModel); K3ApiInsertResponseModel response = K3ApiService.Insert("Transfer", postJson); if (response.StatusCode == 200) { //double totalQty = selectedLists.Sum(x => x.TransferingWeight).Value; string ids = string.Join(",", selectedLists.Select(x => x.Id)); if (_service.UpdateBillNo(ids, response.Data.BillNo)) { QueryBaseCommand.Execute(null); } else { MessageBox.Show($"插入K3调拨单,更新发料表失败,请联系管理员"); } } else { MessageBox.Show($"{response.Message}"); } } else { MessageBox.Show($"【{User.UserName}】 在K3里面不存在,或不一致"); } } else { MessageBox.Show($"【{GeneralParameter.ParamBeginDate.Value}】 没有已发料且未调拨的数据"); } CommonService.WriteActionLog(new ActionOperationLogModel { ActionName = "BatchNoQtyK3InsertCommand", ActionDesc = "生成调拨单", UserId = User.ID, MainMenuId = Menu.ID, PKId = -1, HostName = HostName }); }); }
private void InitCommand() { AllCheckCommand = new DelegateCommand((obj) => { if (IsCheckedAll) { foreach (var item in MaterialPlanSeorderLists) { if (!item.IsLocked) { item.IsChecked = true; } } } else { foreach (var item in MaterialPlanSeorderLists) { if (!item.IsLocked) { item.IsChecked = false; } } } }); QueryCommand = new DelegateCommand((obj) => { MaterialPlanSeOrderFullLists.Clear(); MaterialPlanSeOrderFullLists = _materialPlanInventoryService.GetMaterialPlanSeorderFullLists(Filter.ParamBeginDate, Filter.ParamEndDate); MaterialPlanSeorderLists.Clear(); MaterialPlanSeOrderFullLists.GroupBy(x => new { x.FCustName, x.FEmpName, x.FDeptName, x.FDate, x.FInterID, x.FBillNo }) .Select(x => new MaterialPlanSeOrderShowModel { FCustName = x.Key.FCustName, FEmpName = x.Key.FEmpName, FDeptName = x.Key.FDeptName, FDate = x.Key.FDate, FInterID = x.Key.FInterID, FBillNo = x.Key.FBillNo }) .ToList().ForEach(m => MaterialPlanSeorderLists.Add(m)); MaterialPlanSeOrderEntryLists.Clear(); _materialPlanInventoryService.DeleteMaterialPlanInventory(); MaterialPlanInventoryLists.Clear(); }); UnLockCommand = new DelegateCommand((obj) => { // 将列表的锁定状态归0并且清空原料锁定总数 MaterialPlanSeOrderEntryLists.Clear(); foreach (var item in MaterialPlanSeorderLists) { item.IsChecked = false; item.IsLocked = false; } _materialPlanInventoryService.DeleteMaterialPlanInventory(); MaterialPlanInventoryLists.Clear(); }); CalculateCommand = new DelegateCommand((obj) => { //var data = MaterialPlanSeorderLists.Where(x => !x.IsLocked && x.IsChecked).Select(x => x.FDetailId); if (MaterialPlanSeOrderEntryLists.Count() > 0) { // 将选定计算行,锁定数据 string ids = string.Join(",", MaterialPlanSeOrderEntryLists.Select(x => x.FDetailId)); MaterialPlanInventoryLists.Clear(); _materialPlanInventoryService.GetMaterialPlanInventoryLists(ids).OrderByDescending(x => x.IsVisible).ToList().ForEach(x => MaterialPlanInventoryLists.Add(x)); MaterialPlanSeOrderEntryLists.Clear(); foreach (var item in MaterialPlanSeorderLists) { if (!item.IsLocked && item.IsChecked) { item.IsLocked = true; } } } else { MessageBox.Show("没有选择最新的数据"); } }); MouseLeftClickCommand = new DelegateCommand((obj) => { MaterialPlanSeOrderShowModel dr = (obj as DataGridRow).Item as MaterialPlanSeOrderShowModel; if (!dr.IsLocked) { dr.IsChecked = !dr.IsChecked; var cz = MaterialPlanSeOrderEntryLists.Any(x => x.FBillNo == dr.FBillNo); if (cz) { for (int i = 0; i < MaterialPlanSeOrderEntryLists.Count; i++) { if (MaterialPlanSeOrderEntryLists[i].FBillNo == dr.FBillNo) { MaterialPlanSeOrderEntryLists.RemoveAt(i); i--; } } } else { var entries = MaterialPlanSeOrderFullLists.Where(x => x.FBillNo == dr.FBillNo).Select(x => new MaterialPlanSeOrderEntryShowModel { FBillNo = x.FBillNo, FInterID = x.FInterID, FEntryID = x.FEntryID, FDetailId = x.FDetailId, DeliveryDate = x.DeliveryDate, FitemId = x.FitemId, FName = x.FName, FQty = x.FQty }); foreach (var item in entries) { MaterialPlanSeOrderEntryLists.Add(item); } } } }); MouseLeftClickCommand1 = new DelegateCommand((obj) => { //MaterialBomModel dr = (obj as DataGridRow).Item as MaterialBomModel; //dr.IsChecked = !dr.IsChecked; }); ImportCommand = new DelegateCommand((obj) => { StringBuilder sb = new StringBuilder(); //文件选择窗口 System.Windows.Forms.OpenFileDialog opd = new System.Windows.Forms.OpenFileDialog(); opd.Title = "选择文件"; //第一个参数是名称,随意取,第二个是模式匹配, 多个也是用“|”分割 opd.Filter = "EXCEL文件|*.xls*"; if (opd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ImportFileFullName = opd.FileName; DataTable dataTable1 = new FileHelper().ConvertExcelToDataTable(opd.FileName, true); DataTable dataTable2 = _materialPlanInventoryService.GetMaterialBomLists(); var query1 = from a in dataTable1.AsEnumerable() join b in dataTable2.AsEnumerable() on a.Field <string>("物料代码") equals b.Field <string>("Number") into temp from tt in temp.DefaultIfEmpty() select new MaterialBomModel { Seq = Convert.ToInt32(a.Field <string>("Seq")), Number = a.Field <string>("物料代码"), ItemName = tt == null ? "" : tt.Field <string>("ItemName"), BomCount = tt == null ? 0 : tt.Field <int>("BomCount"), ItemId = tt == null ? 0 : tt.Field <int>("ItemId") }; MaterialBomLists.Clear(); MaterialBomLists = new ObservableCollection <MaterialBomModel>(query1); } opd.Dispose(); }); PurchaseRequisitionImportCommand = new DelegateCommand((obj) => { StringBuilder sb = new StringBuilder(); //文件选择窗口 System.Windows.Forms.OpenFileDialog opd = new System.Windows.Forms.OpenFileDialog(); opd.Title = "选择文件"; //第一个参数是名称,随意取,第二个是模式匹配, 多个也是用“|”分割 opd.Filter = "EXCEL文件|*.xls*"; if (opd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ImportFileFullName1 = opd.FileName; // 读取Excel内容到导入Model DataTable dataTable1 = new FileHelper().ConvertExcelToDataTable(opd.FileName, true); // 读取数据库底表,跟上述excel数据做左连接来验证哪些是有合法的 DataTable dataTable2 = CommonService.GetAllItems(); var query1 = from a in dataTable1.AsEnumerable() join b in dataTable2.AsEnumerable() on a.Field <string>("物料代码") equals b.Field <string>("FNumber") into temp from tt in temp.DefaultIfEmpty() select new PurchaseRequisitionImportVerificationModel { Seq = Convert.ToInt32(a.Field <string>("Seq")), FNumber = a.Field <string>("物料代码"), Quantity = Convert.ToDouble(a.Field <string>("数量")), FName = tt == null ? "" : tt.Field <string>("FName"), SystemId = tt == null ? 0 : Convert.ToInt32(tt["FItemID"]), IsPassed = tt == null || string.IsNullOrEmpty(a.Field <string>("物料代码")) || Convert.ToDouble(a.Field <string>("数量")) <= 0 ? false : true }; CheckedPurchaseRequisitionMaterialLists.Clear(); CheckedPurchaseRequisitionMaterialLists = new ObservableCollection <PurchaseRequisitionImportVerificationModel>(query1); } opd.Dispose(); }); PurchaseRequisitionInsertK3Command = new DelegateCommand((obj) => { MessageBoxResult result = System.Windows.MessageBox.Show("验证失败的数据将会被过滤,是否继续?", "【温馨提示】", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { var sons = new List <PurchaseRequisitionSonModel>(); var ss = CheckedPurchaseRequisitionMaterialLists.AsQueryable().Where(x => x.IsPassed); var emp = _employeeLists.Where(m => m.FName == User.UserName).FirstOrDefault(); foreach (var item in ss) { var refSource = _purchaseRequisitionICItemLists.Where(m => m.FNumber == item.FNumber).FirstOrDefault(); if (refSource == null) { MessageBox.Show($" 此物料{item.FNumber}在t_icitem中不存在,请联系管理员"); return; } var son = new PurchaseRequisitionSonModel() { FItemID = new BaseNumberNameModel() { FNumber = refSource.FNumber, FName = refSource.FName }, FLeadTime = refSource.FFixLeadTime, //这个字段是根据FNumber带出来的,本身表里面没有是不是不用传递参数? FAPurchTime = DateTime.Now.Date.ToString("yyyy-MM-dd"), FFetchTime = DateTime.Now.Date.AddDays(refSource.FFixLeadTime).ToString("yyyy-MM-dd"), FAuxPropID = new BaseNumberNameModel() { FNumber = "", FName = "" }, FUnitID = _measureUnitLists.Where(m => m.FId == refSource.FUnitID).FirstOrDefault(), // FUnitID = new BaseNumberNameModel() { FNumber = "kg", FName = "kg" }, FBomInterID = new BaseNumberNameModel() { FNumber = "", FName = "" }, FSupplyID = new BaseNumberNameModel() { FNumber = "", FName = "" }, FPlanMode = new BaseNumberNameModel() { FNumber = "MTS", FName = "MTS计划模式" }, //FItemID = new BaseNumberNameModel() { FNumber = "YL.SC.RJ.00825", FName = "110" }, //FAuxPropID = new BaseNumberNameModel() { FNumber = "", FName = "" }, //FUnitID = new BaseNumberNameModel() { FNumber = "kg", FName = "kg" }, //FBomInterID = new BaseNumberNameModel() { FNumber = "", FName = "" }, //FSupplyID = new BaseNumberNameModel() { FNumber = "", FName = "" }, //FPlanMode = new BaseNumberNameModel() { FNumber = "MTS", FName = "MTS计划模式" }, FQty = item.Quantity, Fauxqty = item.Quantity, FOrderQty = 0, Fuse = "", FNumber = "", FIsInquiry = 0, FMTONo = "", FMrpLockFlag = 0, FSourceEntryID = 0, FSourceInterId = 0, FSourceTranType = 0, FSourceBillNo = "", FPlanOrderInterID = 0, FSecQty = 0, FSecCoefficient = 0, FSecUnitID = null, FAuxPropCls = null }; sons.Add(son); } PurchaseRequisitionMainModel main = new PurchaseRequisitionMainModel() { //FHeadSelfP0131 = new BaseNumberNameModel() { FNumber = "10.01", FName = "销售部" }, FHeadSelfP0131 = new BaseNumberNameModel() { FNumber = "FSQLX02", FName = "生产部" }, FPlanCategory = new BaseNumberNameModel() { FNumber = "STD", FName = "标准" }, FBizType = new BaseNumberNameModel() { FNumber = "FPLX01", FName = "外购入库" }, FDeptID = new BaseNumberNameModel() { FNumber = "05.04.02", FName = "生产制造组" }, //FCheckerID = new BaseNumberNameModel(), FSelTranType = new BaseNumberNameModel() { FNumber = "81", FName = "销售订单" }, FRequesterID = new BaseNumberNameModel() { FNumber = emp.FNumber, FName = emp.FName }, Fdate = DateTime.Now.Date.ToString("yyyy-MM-dd"), FMRP = 0, FTranType = 70, FGeneratePurBudQty = 0, Fnote = "", FNumber = "", FBillerID = new BaseNumberNameModel { FNumber = emp.FNumber, FName = emp.FName } }; var requestModel = new K3ApiInsertRequestModel <PurchaseRequisitionMainModel, PurchaseRequisitionSonModel>() { Data = new K3ApiInsertDataRequestModel <PurchaseRequisitionMainModel, PurchaseRequisitionSonModel>() { Page1 = new List <PurchaseRequisitionMainModel> { main }, Page2 = sons } }; string postJson = JsonHelper.ObjectToJson(requestModel); K3ApiInsertResponseModel response = new K3ApiService("Purchase_Requisition").Insert(postJson); K3InsertResponseData = response.Data; MessageBox.Show($"{response.Message}"); } }); PurchaseRequisitionCheckBill1K3Command = new DelegateCommand((obj) => { //var check = new K3ApiCheckBillRequestMode() //{ // Data = new K3ApiCheckBillDataRequestMode() // { // FBillNo = "POREQ005735", // FChecker = "Administrator", // FCheckDirection = 1,// 1 开启多级审核,预审 // FDealComment = "" // } //}; //string json = JsonHelper.ObjectToJson(check); //var checkRes = new K3ApiService("Purchase_Requisition").CheckBill(json); }); PurchaseRequisitionCheckBill2K3Command = new DelegateCommand((obj) => { if (string.IsNullOrEmpty(K3InsertResponseData.BillNo)) { MessageBox.Show("请生成或者输入单据号"); return; } var check = new K3ApiCheckBillRequestMode() { Data = new K3ApiCheckBillDataRequestMode() { FBillNo = K3InsertResponseData.BillNo, FChecker = User.UserName, FCheckDirection = 2,// 1 开启多级审核,预审 FDealComment = "" } }; string json = JsonHelper.ObjectToJson(check); var checkRes = new K3ApiService("Purchase_Requisition").CheckBill(json); MessageBox.Show(checkRes.Message); }); }
private void InitCommand() { ICStockBill29ImportCommand = new DelegateCommand((obj) => { System.Windows.Forms.OpenFileDialog opd = new System.Windows.Forms.OpenFileDialog(); opd.Title = "选择文件"; opd.Filter = "EXCEL文件|*.xls*"; if (opd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { CommonService.ImportExcelToDatabaseTable(opd.FileName, "SJICStockBill29ExcelTemplate"); ImportFileFullName = opd.FileName; // 数据验证后加载验证模型列表到表格 CheckedICStockBill29VerificationLists.Clear(); _stockService.GetICStockBill29ImportVerificationLists().ForEach(x => CheckedICStockBill29VerificationLists.Add(x)); } opd.Dispose(); }); ICStockBill1ImportCommand = new DelegateCommand((obj) => { System.Windows.Forms.OpenFileDialog opd = new System.Windows.Forms.OpenFileDialog(); opd.Title = "选择文件"; opd.Filter = "EXCEL文件|*.xls*"; if (opd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { CommonService.ImportExcelToDatabaseTable(opd.FileName, "SJICStockBill1ExcelTemplate"); ImportFileFullName1 = opd.FileName; // 数据验证后加载验证模型列表到表格 CheckedICStockBill1VerificationLists.Clear(); _stockService.GetICStockBill1ImportVerificationLists().ForEach(x => CheckedICStockBill1VerificationLists.Add(x)); } opd.Dispose(); }); ICStockBill29InsertK3Command = new DelegateCommand((obj) => { if (CheckedICStockBill29VerificationLists.Count == 0) { MessageBox.Show("请先导入Excel模板数据"); } else if (CheckedICStockBill29VerificationLists.Where(m => !m.IsPassed).Count() > 0) { MessageBox.Show("必须全部数据验证成功才允许导入,请修改Excel数据"); } else { var billnos = CheckedICStockBill29VerificationLists.GroupBy(m => m.BillNo); foreach (var item in billnos) { var data = CheckedICStockBill29VerificationLists.Where(m => m.BillNo == item.Key); var first = data.First(); var main = new MiscellaneousDeliveryMainModel() { Fuse = "研发领料", FHeadSelfB0939 = first.BillNo, FDate = DateTime.Now.Date.ToShortDateString(), FDeptID = new BaseNumberNameModelX() { FNumber = first.DeptFNumber, FName = first.DeptFName }, FBillerID = new BaseNumberNameModelX() { FNumber = "何科威", FName = "何科威" }, // FFManagerID = new BaseNumberNameModel() { FNumber = "1033", FName = "付志刚" }, 领料人 FFManagerID = new BaseNumberNameModelX() { FNumber = first.FFManagerFNumber, FName = first.FFManagerName }, FSManagerID = new BaseNumberNameModelX() { FNumber = "1033", FName = "付志刚" } }; var sons = new List <MiscellaneousDeliverySonModel>(); foreach (ICStockBill29ImportVerificationModel entry in data) { var son = new MiscellaneousDeliverySonModel() { FItemID = new BaseNumberNameModelX() { FNumber = entry.MaterialFNumber, FName = entry.MaterialFName }, FUnitID = new BaseNumberNameModelX() { FNumber = "kg", FName = "kg" }, FDCStockID1 = new BaseNumberNameModelX() { FNumber = entry.StockFNumber, FName = entry.StockFName }, FDCSPID = new BaseNumberNameModelX() { FNumber = entry.StockPlaceFNumber, FName = entry.StockPlaceFName }, FPlanMode = new BaseNumberNameModelX() { FNumber = "MTS", FName = "MTS计划模式" }, FQty = entry.Quantity, FScanQty = entry.Quantity, Fauxqty = entry.Quantity, FEntrySelfB0947 = entry.BrandName, //"品牌", FEntrySelfB0948 = entry.CaseName, //"案子", FBatchNo = entry.BatchNo, FNote = entry.FNote }; sons.Add(son); } var requestModel = new K3ApiInsertRequestModel <MiscellaneousDeliveryMainModel, MiscellaneousDeliverySonModel>() { Data = new K3ApiInsertDataRequestModel <MiscellaneousDeliveryMainModel, MiscellaneousDeliverySonModel>() { Page1 = new List <MiscellaneousDeliveryMainModel> { main }, Page2 = sons } }; string postJson = JsonHelper.ObjectToJson(requestModel); K3ApiInsertResponseModel response = new K3ApiService("Miscellaneous_Delivery").Insert(postJson); if (response.StatusCode == 200) { K3InsertResponseData.BillNo += response.Data.BillNo + "\t"; K3InsertResponseData.BillInterID += response.Data.BillInterID + "\t"; } else { MessageBox.Show($"{response.Message}"); return; } } MessageBox.Show($"导入成功"); } }); ICStockBill1InsertK3Command = new DelegateCommand((obj) => { if (CheckedICStockBill1VerificationLists.Count == 0) { MessageBox.Show("请先导入Excel模板数据"); } else if (CheckedICStockBill1VerificationLists.Where(m => !m.IsPassed).Count() > 0) { MessageBox.Show("必须全部数据验证成功才允许导入,请修改Excel数据"); } else { } }); }
private void BtnNewExport_Click(object sender, RoutedEventArgs e) { var data = new ProductiveTaskService().GetSrOrderData(Convert.ToDateTime(this.DP2.Text)); if (data.Count() > 0) { var firstOrder = data.FirstOrDefault(); var fbillno = firstOrder.FBillNo; var main = new SrSoMainModel { FTranType = 81, FAreaPS = new BaseNumberNameModelX { FNumber = "1", FName = "购销" }, FCurrencyID = new BaseNumberNameModelX { FNumber = "CNY", FName = "人民币" }, FExchangeRateType = new BaseNumberNameModelX { FNumber = "01", FName = "公司汇率" }, FSelTranType = new BaseNumberNameModelX { FNumber = "81", FName = "销售订单" }, FPlanCategory = new BaseNumberNameModelX { FNumber = "STD", FName = "标准" }, FBillerID = new BaseNumberNameModelX { FNumber = "丁惠兰", FName = "丁惠兰" }, FDeptID = new BaseNumberNameModelX { FNumber = "10.01", FName = "销售部" }, Fdate = firstOrder.FProductionDate.ToString("yyyy-MM-dd"), FCustID = new BaseNumberNameModelX { FNumber = firstOrder.OrgNumber, FName = firstOrder.OrgName }, FEmpID = new BaseNumberNameModelX { FNumber = firstOrder.EmpNumber, FName = firstOrder.EmpName }, FExchangeRate = 1, }; var sons = new List <SrSoSonModel>(); foreach (var item in data) { // 单据号相等,增加明细 if (item.FBillNo == fbillno) { sons.Add(new SrSoSonModel { FAdviceConsignDate = item.DeliveryDate.ToString("yyyy-MM-dd"), FDate1 = item.DeliveryDate.ToString("yyyy-MM-dd"), FOrderBillNo = item.FOrgBillNo, FItemID = new BaseNumberNameModelX { FNumber = item.MaterialNumber, FName = item.MaterialName }, FItemName = item.MaterialName, FBaseUnit = "kg", FUnitID = new BaseNumberNameModelX { FNumber = "kg", FName = "kg" }, FPlanMode = new BaseNumberNameModelX { FNumber = "MTS", FName = "MTS计划模式" }, FEntrySelfS0179 = item.FBillNo, FEntrySelfS0178 = item.FProductionName, FEntrySelfS0177 = item.FBucketCount, FEntrySelfS0176 = new BaseNumberNameModelX { FNumber = item.SpecNumber, FName = item.SpecName }, FCESS = item.FCESS, FQty = item.OrderQty, Fauxqty = item.OrderQty, //Fauxprice = item.Price, //Famount = item.OrderQty * item.Price, //FAuxTaxPrice = item.Price * (decimal)(1.13), //FAuxPriceDiscount = item.Price * (decimal)1.13, //FTaxAmt = item.OrderQty * item.Price * (decimal)0.13, //FAllAmount = item.OrderQty * item.Price * (decimal)1.13 , Fauxprice = item.Fauxprice, Famount = item.Famount, FAuxTaxPrice = item.FAuxTaxPrice, FAuxPriceDiscount = item.FAuxPriceDiscount, FTaxAmt = item.FTaxAmt, FAllAmount = item.FAllAmount, Fnote = item.OrderEntryNote, FMapName = item.FLabel, FEntrySelfS0180 = string.IsNullOrEmpty(item.FOrgCode) ? "." : item.FOrgCode, FEntrySelfS0181 = item.FBatchNo, }); } else //插入K3 { var requestModel = new K3ApiInsertRequestModel <SrSoMainModel, SrSoSonModel>() { Data = new K3ApiInsertDataRequestModel <SrSoMainModel, SrSoSonModel>() { Page1 = new List <SrSoMainModel> { main }, Page2 = sons } }; string postJson = JsonHelper.ObjectToJson(requestModel); K3ApiInsertResponseModel response = new SrK3ApiService().Insert("SO", postJson); if (response.StatusCode == 200) { fbillno = item.FBillNo; main.Fdate = item.FProductionDate.ToString("yyyy-MM-dd"); main.FCustID = new BaseNumberNameModelX { FNumber = item.OrgNumber, FName = item.OrgName }; main.FEmpID = new BaseNumberNameModelX { FNumber = item.EmpNumber, FName = item.EmpName }; sons.Clear(); sons.Add(new SrSoSonModel { FAdviceConsignDate = item.DeliveryDate.ToString("yyyy-MM-dd"), FDate1 = item.DeliveryDate.ToString("yyyy-MM-dd"), FOrderBillNo = item.FOrgBillNo, FItemID = new BaseNumberNameModelX { FNumber = item.MaterialNumber, FName = item.MaterialName }, FItemName = item.MaterialName, FBaseUnit = "kg", FUnitID = new BaseNumberNameModelX { FNumber = "kg", FName = "kg" }, FPlanMode = new BaseNumberNameModelX { FNumber = "MTS", FName = "MTS计划模式" }, FEntrySelfS0179 = item.FBillNo, FEntrySelfS0178 = item.FProductionName, FEntrySelfS0177 = item.FBucketCount, FEntrySelfS0176 = new BaseNumberNameModelX { FNumber = item.SpecNumber, FName = item.SpecName }, FCESS = item.FCESS, FQty = item.OrderQty, Fauxqty = item.OrderQty, Fauxprice = item.Fauxprice, Famount = item.Famount, FAuxTaxPrice = item.FAuxTaxPrice, FAuxPriceDiscount = item.FAuxPriceDiscount, FTaxAmt = item.FTaxAmt, FAllAmount = item.FAllAmount, Fnote = item.OrderEntryNote, FMapName = item.FLabel, FEntrySelfS0180 = string.IsNullOrEmpty(item.FOrgCode) ? "." : item.FOrgCode, FEntrySelfS0181 = item.FBatchNo, }); } else { MessageBox.Show($"{response.Message}"); } } } // 最后一行执行一次插入 if (sons.Count > 0) { var requestModel = new K3ApiInsertRequestModel <SrSoMainModel, SrSoSonModel>() { Data = new K3ApiInsertDataRequestModel <SrSoMainModel, SrSoSonModel>() { Page1 = new List <SrSoMainModel> { main }, Page2 = sons } }; string postJson = JsonHelper.ObjectToJson(requestModel); K3ApiInsertResponseModel response = new SrK3ApiService().Insert("SO", postJson); MessageBox.Show($"执行完毕: {response.Message}"); } } else { MessageBox.Show("没有最新的8319数据"); } }
private void InitCommand() { QueryBaseCommand = new DelegateCommand((obj) => { SalesRebateSummaryLists.Clear(); ListsCount = 0; ListsSum = 0; SalesRebateLists.Clear(); RebatePctValueString = string.Empty; _salesRebateService.GetSalesRebateSummaryLists(UserDataId, CommonService.GetSqlWhereString(QueryParameter)).ForEach(x => { SalesRebateSummaryLists.Add(x); ListsSum += x.OrgAmount; ListsCount++; }); }); DirectorySelectBaseCommand = new DelegateCommand((obj) => { // 导出目录选择 System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog(); if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { HostConfig.HostValue = fbd.SelectedPath; var result = CommonService.SaveHostConfig(HostConfig); if (result) { HostConfig = CommonService.GetHostConfig(DataGridId, HostName, User.ID); } } }); ExportBaseCommand = new DelegateCommand((obj) => { if (Directory.Exists(HostConfig.HostValue)) { ExportView view = new ExportView(DataGridId, 1); (view.DataContext as ExportViewModel).Export((type, outputEntity, checkBoxValue, orderedColumns) => { view.Close(); if (type == 1) { DataTable datatable = new DataTable(); if (outputEntity == 1) { // 获取导出数据名称 string viewName = CommonService.GetExportViewName(DataGridId, 1); if (!string.IsNullOrEmpty(viewName)) { datatable = viewName.EndsWith("Proc")? _salesRebateService.GetExportDataProc(viewName, ReportQueryParameter): CommonService.GetExportDataView(viewName, CommonService.GetSqlWhereString(ReportQueryParameter)); ExportHelper.ExportDataTableToExcel(datatable, HostConfig.HostValue, HostConfig.TypeDesciption + CommonService.GetQueryParameterValueString(ReportQueryParameter)); MessageBox.Show("导出成功"); } } else if (outputEntity == 2) { // 获取导出数据名称 string viewName = CommonService.GetExportViewName(DataGridId, 2); if (!string.IsNullOrEmpty(viewName)) { datatable = viewName.EndsWith("Proc") ? _salesRebateService.GetExportDataProc(viewName, ReportQueryParameter) : CommonService.GetExportDataView(viewName, CommonService.GetSqlWhereString(ReportQueryParameter)); ExportHelper.ExportDataTableToExcel(datatable, HostConfig.HostValue, HostConfig.TypeDesciption + CommonService.GetQueryParameterValueString(ReportQueryParameter)); MessageBox.Show("导出成功"); } } else if (outputEntity == 3) { // 获取导出数据名称 string procName = CommonService.GetExportViewName(DataGridId, 3); if (!string.IsNullOrEmpty(procName)) { datatable = CommonService.GetExportDataProcedure(procName, UserDataId, string.Join(",", orderedColumns), CommonService.GetSqlWhereString(ReportQueryParameter)); ExportHelper.ExportDataTableToExcel(datatable, HostConfig.HostValue, HostConfig.TypeDesciption + CommonService.GetQueryParameterValueString(ReportQueryParameter), checkBoxValue, orderedColumns, false, "", false); MessageBox.Show("导出成功"); } } } }); view.ShowDialog(); } else { MessageBox.Show("目录不存在,请先选择导出的目录"); DirectorySelectBaseCommand.Execute(null); } CommonService.WriteActionLog(new ActionOperationLogModel { ActionName = "ExportBaseCommand", ActionDesc = HostConfig.TypeDesciption + CommonService.GetQueryParameterValueString(QueryParameter), UserId = User.ID, MainMenuId = Menu.ID, PKId = -1, HostName = HostName }); }); SalesRebateRecentParameterConfigCommand = new DelegateCommand((obj) => { if (BatchParameter.OrganizationSearchedItem != null && BatchParameter.RebateClassSeletedItem != null) { if (BatchParameterVerification(out DateTime maxDate)) { if (_salesRebateService.IfExistsOrgICSaleBill(BatchParameter)) { SalesRebateRecentParameterView view = new SalesRebateRecentParameterView(BatchParameter); (view.DataContext as SalesRebateRecentParameterViewModel).WithParam(null, (type, outputEntity, isChanged) => { view.Close(); if (isChanged) { // 计算刚才配置的参数 _salesRebateService.CalculateAmount(BatchParameter, User.ID, true); // 查询出刚生成的数据 QueryBaseCommand.Execute(null); } }); view.Show(); CommonService.WriteActionLog(new ActionOperationLogModel { ActionName = "SalesRebateRecentParameterConfigCommand", ActionDesc = CommonService.GetSqlWhereString(BatchParameter), UserId = User.ID, MainMenuId = Menu.ID, PKId = -1, HostName = HostName }); } else { MessageBox.Show($"【{BatchParameter.SettleDateBegin}】至【{BatchParameter.SettleDateEnd}】 ,客户【{BatchParameter.OrganizationSearchedItem.Name}】 没有K3销售单据"); } } else { MessageBox.Show($"【{maxDate}】 该类型【{BatchParameter.RebateClassSeletedItem.ItemValue} 】已经返利,同时间点不能多次返利"); } } else { MessageBox.Show("请先输入客户和返利类别"); } }); SalesRebateK3ApiInsertCommand = new DelegateCommand((obj) => { StringBuilder stringBuilder = new StringBuilder(); if (SalesRebateSummarySelectedItem != null && string.IsNullOrEmpty(SalesRebateSummarySelectedItem.K3BillNo) && SalesRebateLists.Count > 0) { var maxDate = _salesRebateService.GetMaxSettleDateByOrgId(BatchParameter.OrganizationSearchedItem.Id, BatchParameter.RebateClassSeletedItem.ItemSeq); if (SalesRebateSummarySelectedItem.SettleDateBegin > maxDate && SalesRebateSummarySelectedItem.SettleDateEnd > maxDate) { SalesInvoiceVATMainModel main = new SalesInvoiceVATMainModel { Fdate = SalesRebateSummarySelectedItem.SettleDateEnd.AddDays(5).ToString("yyyy-MM-dd"), FCustID = K3ApiFKService.GetOrganizationById(SalesRebateSummarySelectedItem.OrgId), FBillerID = new BaseNumberNameModelX { FNumber = User.UserName, FName = User.UserName }, FNote = "结算日期:" + SalesRebateSummarySelectedItem.SettleDateBegin.Date.ToString("yyyy-MM-dd") + "至" + SalesRebateSummarySelectedItem.SettleDateEnd.Date.ToString("yyyy-MM-dd") }; var son = new SalesInvoiceVATSonModel { Fauxprice = SalesRebateSummarySelectedItem.OrgAmount, Famount = SalesRebateSummarySelectedItem.OrgAmount * main.FROB, FStdAmount = SalesRebateSummarySelectedItem.OrgAmount * main.FROB, FTaxRate = SalesRebateSummarySelectedItem.OrgAmount * 0.13, FTaxAmount = SalesRebateSummarySelectedItem.OrgAmount * 0.13 * main.FROB, FStdTaxAmount = SalesRebateSummarySelectedItem.OrgAmount * 0.13 * main.FROB, FAllAmount = SalesRebateSummarySelectedItem.OrgAmount * (1 + 0.13), FAuxTaxPrice = SalesRebateSummarySelectedItem.OrgAmount * (1 + 0.13), FAuxPriceDiscount = SalesRebateSummarySelectedItem.OrgAmount * (1 + 0.13), FAmountincludetax = SalesRebateSummarySelectedItem.OrgAmount * (1 + 0.13) * main.FROB, FStdAmountincludetax = SalesRebateSummarySelectedItem.OrgAmount * (1 + 0.13) * main.FROB, FRemainAmount = SalesRebateSummarySelectedItem.OrgAmount * (1 + 0.13) * main.FROB, FRemainAmountFor = SalesRebateSummarySelectedItem.OrgAmount * (1 + 0.13) * main.FROB, }; var requestModel = new K3ApiInsertRequestModel <SalesInvoiceVATMainModel, SalesInvoiceVATSonModel>() { Data = new K3ApiInsertDataRequestModel <SalesInvoiceVATMainModel, SalesInvoiceVATSonModel>() { Page1 = new List <SalesInvoiceVATMainModel> { main }, Page2 = new List <SalesInvoiceVATSonModel> { son } } }; string postJson = JsonHelper.ObjectToJson(requestModel); K3ApiInsertResponseModel response = K3ApiXService.Insert(Token, "Sales_Invoice_VAT", postJson); if (response.StatusCode == 200) { // 更新后台数据 _salesRebateService.UpdateK3BillNo(SalesRebateSummarySelectedItem.Id, response.Data.BillNo, SalesRebateSummarySelectedItem.SettleDateEnd.AddDays(5)); stringBuilder.Append($"成功 BillNo:{response.Data.BillNo}, SettleDateBegin:{SalesRebateSummarySelectedItem.SettleDateBegin}, SettleDateEnd:{SalesRebateSummarySelectedItem.SettleDateEnd},OrgId: {SalesRebateSummarySelectedItem.OrgId}, RebateClass:{SalesRebateSummarySelectedItem.RebateClass}"); } else { MessageBox.Show(response.Message); stringBuilder.Append($"{response.Message}"); CommonService.WriteActionLog(new ActionOperationLogModel { ActionName = "SalesRebateRecentParameterConfigCommand", ActionDesc = stringBuilder.ToString(), UserId = User.ID, MainMenuId = Menu.ID, PKId = -1, HostName = HostName }); return; } } else { MessageBox.Show($"【{maxDate}】 该类型【{BatchParameter.RebateClassSeletedItem.ItemValue} 】已经返利,同时间点不能多次返利"); } } //重新加载数据 QueryBaseCommand.Execute(null); CommonService.WriteActionLog(new ActionOperationLogModel { ActionName = "SalesRebateK3ApiInsertCommand", ActionDesc = stringBuilder.ToString(), UserId = User.ID, MainMenuId = Menu.ID, PKId = -1, HostName = HostName }); }); SalesRebateK3ApiRemoveCommand = new DelegateCommand((obj) => { // 弹出删除提示 if (MessageBox.Show($"此操作会将K3单据和本条记录同时删除", "温馨提示", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { if (SalesRebateSummarySelectedItem != null && !string.IsNullOrEmpty(SalesRebateSummarySelectedItem.K3BillNo)) { string k3BillNo = SalesRebateSummarySelectedItem.K3BillNo; // 可选参数FInterID,当FBillNo重复时传入,【只删除明细行】 string postJson = @"{""Data"": {""FBillNo"":""" + k3BillNo + @"""}}"; var response = K3ApiXService.Delete(Token, "Sales_Invoice_VAT", postJson); // 如果Token过期则重新加载 if (response.StatusCode == 200) { if (_salesRebateService.SummaryDelete(SalesRebateSummarySelectedItem.Id, SalesRebateSummarySelectedItem.Guid)) { MessageBox.Show("删除K3单据成功"); } else { MessageBox.Show("后台删除失败,单据不存在"); } } else if (response.Message.IndexOf("token", StringComparison.OrdinalIgnoreCase) > 0) { Token = K3ApiXService.GetToken(); response = K3ApiXService.Delete(Token, "Sales_Invoice_VAT", postJson); MessageBox.Show(response.Message); } else { MessageBox.Show(response.Message); } CommonService.WriteActionLog(new ActionOperationLogModel { ActionName = "SalesRebateK3ApiRemoveCommand", ActionDesc = k3BillNo, UserId = User.ID, MainMenuId = Menu.ID, PKId = -1, HostName = HostName }); QueryBaseCommand.Execute(null); } else { MessageBox.Show("一次只能选择一个K3单据且已经生成过K3单据"); } } }); DetailSelectionChangedCommand = new DelegateCommand((obj) => { if (SalesRebateSelectedItem != null) { var lists = _salesRebateAmountRangeService.GetSalesRebateAmountRangeRecentParameterLists(SalesRebateSelectedItem.PGuid); if (lists.Count > 0) { StringBuilder result = new StringBuilder(); foreach (var item in lists) { result.Append($"金额区间:{item.AmountLower}-{item.AmountUpper} 万元 比例:{item.SalesRebatePctValue}% \t\t"); } RebatePctValueString = result.ToString(); } else { RebatePctValueString = string.Empty; } } }); SummarySelectionChangedCommand = new DelegateCommand((obj) => { if (SalesRebateSummarySelectedItem != null) { RebatePctValueString = string.Empty; SalesRebateLists.Clear(); _salesRebateService.GetSalesRebateListsByGuid(SalesRebateSummarySelectedItem.Guid).ForEach(x => SalesRebateLists.Add(x)); } }); SalesRebateSummaryDeleteCommand = new DelegateCommand((obj) => { if (SalesRebateSummarySelectedItem != null && string.IsNullOrEmpty(SalesRebateSummarySelectedItem.K3BillNo)) { _salesRebateService.SummaryDelete(SalesRebateSummarySelectedItem.Id, SalesRebateSummarySelectedItem.Guid); QueryBaseCommand.Execute(null); } }); ReportQueryCommand = new DelegateCommand((obj) => { ReportLists.Clear(); _salesRebateService.GetCaseAmountReport(ReportQueryParameter).ForEach(x => ReportLists.Add(x)); }); AmountCalculateCommand = new DelegateCommand((obj) => { if (BatchParameterVerification(out DateTime maxDate)) { // 计算刚才配置的参数 _salesRebateService.CalculateAmount(BatchParameter, User.ID, false); // 查询出刚生成的数据 QueryBaseCommand.Execute(null); } else { MessageBox.Show($"【{maxDate}】 该类型【{BatchParameter.RebateClassSeletedItem.ItemValue} 】已经返利,同时间点不能多次返利"); } }); }