void PlanListWindow_Closed(object sender, EventArgs e) { PlanListEditWindow planListWindow = sender as PlanListEditWindow; if (planListWindow.DialogResult == true) { SaveFileDialog sDialog = new SaveFileDialog(); sDialog.Filter = "Excel Files(*.xls)|*.xls"; if (sDialog.ShowDialog() == true) { try { string versionId = "文件编号:"; if (null != planListWindow.planExtraEntity && null != planListWindow.planExtraEntity.FileId) { versionId += planListWindow.planExtraEntity.FileId; } versionId += " 计划版本:"; versionId += SelectProjectEntity.PlanVersionID; string projectNameKey = SelectProjectEntity.ProjectName + " "; string manufactureNumber = "生产令号:" + SelectProjectEntity.ManufactureNumber; Workbook workbook = new Workbook(); ColumnModel columnModel = new ColumnModel(); foreach (PlanListViewModel item in planListWindow.planListViewModelList) { string projectNameName = projectNameKey + item.Title; Worksheet worksheet = new Worksheet(item.Title); Int16 RowCount = 0; worksheet.Cells[RowCount++, 0] = new Cell(versionId); worksheet.Cells[RowCount++, 0] = new Cell(projectNameName); worksheet.Cells[RowCount++, 0] = new Cell(manufactureNumber); int columnCount = 0; foreach (string itemColumn in columnModel.List[item.ColumnModelIndex]) { worksheet.Cells[RowCount, columnCount++] = new Cell(itemColumn); } ++RowCount; foreach (PlanEntity planEntity in item.PlanList) { columnCount = 0; string value = Convert.ToString(planEntity.SequenceId); worksheet.Cells[RowCount, columnCount++] = new Cell(value); worksheet.Cells[RowCount, columnCount++] = new Cell(planEntity.ComponentName); worksheet.Cells[RowCount, columnCount++] = new Cell(planEntity.TaskDescription); value = Convert.ToString(planEntity.Weight); worksheet.Cells[RowCount, columnCount++] = new Cell(value); if (planEntity.Score.HasValue) { value = Convert.ToString(planEntity.Score.Value); worksheet.Cells[RowCount, columnCount] = new Cell(value); } ++columnCount; if (1 == item.ColumnModelIndex) { if (planEntity.OrderDate.HasValue) { value = Convert.ToString(planEntity.OrderDate.Value); worksheet.Cells[RowCount, columnCount] = new Cell(value); } ++columnCount; } value = Convert.ToString(planEntity.TargetDate); worksheet.Cells[RowCount, columnCount++] = new Cell(value); if (planEntity.TargetDateAdjustment1.HasValue) { value = Convert.ToString(planEntity.TargetDateAdjustment1.Value); worksheet.Cells[RowCount, columnCount] = new Cell(value); } ++columnCount; if (planEntity.TargetDateAdjustment2.HasValue) { value = Convert.ToString(planEntity.TargetDateAdjustment2.Value); worksheet.Cells[RowCount, columnCount] = new Cell(value); } ++columnCount; if (planEntity.AccomplishDate.HasValue) { value = Convert.ToString(planEntity.AccomplishDate.Value); worksheet.Cells[RowCount, columnCount] = new Cell(value); } ++columnCount; if (null != planEntity.DepartmentName && string.Empty != planEntity.DepartmentName) { worksheet.Cells[RowCount, columnCount] = new Cell(planEntity.DepartmentName); } ++columnCount; if (null != planEntity.Remark && string.Empty != planEntity.Remark) { worksheet.Cells[RowCount, columnCount] = new Cell(planEntity.Remark); } ++columnCount; ++RowCount; } workbook.Worksheets.Add(worksheet); } Stream sFile = sDialog.OpenFile(); workbook.Save(sFile); Message.InfoMessage("导出成功"); } catch (Exception outputE) { string errorMessage = "导出文件失败:" + outputE.Message; Message.ErrorMessage(errorMessage); } } } (OnExportPlan as DelegateCommand).RaiseCanExecuteChanged(); }
private void OnExportPlanCommand() { IsBusy = true; if (null == SelectProjectEntity.PlanVersionID || null == SelectProjectEntity.ManufactureNumber || string.Empty == SelectProjectEntity.PlanVersionID || string.Empty == SelectProjectEntity.ManufactureNumber) { Message.ErrorMessage("生产令号或版本号无效"); } else { IEnumerable <string> sheetNames = from c in planManagerDomainContext.plans where c.manufacture_number == SelectProjectEntity.ManufactureNumber.TrimEnd() && c.version_id == SelectProjectEntity.PlanVersionID select c.sheet_name; if (sheetNames.Count() > 0) { ObservableCollection <PlanListViewModel> planListViewModelList = new ObservableCollection <PlanListViewModel>(); ObservableCollection <string> differentSheets = new ObservableCollection <string>(); foreach (string value in sheetNames) { if (null == value || differentSheets.Contains(value)) { continue; } differentSheets.Add(value); IEnumerable <plan> selectedPlans = from c in planManagerDomainContext.plans where c.manufacture_number == SelectProjectEntity.ManufactureNumber.TrimEnd() && c.version_id == SelectProjectEntity.PlanVersionID && c.sheet_name == value select c; ObservableCollection <PlanEntity> planList = new ObservableCollection <PlanEntity>(); bool hasOrderDate = false; foreach (plan item in selectedPlans) { PlanEntity planEntity = new PlanEntity(); planEntity.Plan = item; if (item.order_date.HasValue) { hasOrderDate = true; } string getDepartmentName = string.Empty; planEntity.Update(); planEntity.ProjectName = SelectProjectEntity.ProjectName; if (departmentIdNameDictionary.TryGetValue(planEntity.DepartmentId, out getDepartmentName)) { planEntity.DepartmentName = getDepartmentName; } planList.Add(planEntity); } if (planList.Count > 0) { int modelIndex = -1; if ("采购节点" == planList[0].SheetName) { if (hasOrderDate) { modelIndex = 1; } else { modelIndex = 2; } } else { modelIndex = 0; } PlanListViewModel planListViewModel = new PlanListViewModel(value, planList, modelIndex, departmentIdNameDictionary); planListViewModel.IsReadOnly = true; planListViewModelList.Add(planListViewModel); } } if (planListViewModelList.Count > 0) { PlanExtraEntity planExtraEntity = null; IEnumerable <plan_extra> plan_extras = from c in planManagerDomainContext.plan_extras where c.version_id == SelectProjectEntity.PlanVersionID && c.manufacture_number == SelectProjectEntity.ManufactureNumber.TrimEnd() select c; if (0 != plan_extras.Count()) { planExtraEntity = new PlanExtraEntity(); planExtraEntity.PlanExtra = plan_extras.First <plan_extra>(); planExtraEntity.Update(); planExtraEntity.PlanExtra = null; } PlanListEditWindow planListWindow = new PlanListEditWindow("计划导出", "导出", SelectProjectEntity.PlanVersionID, planListViewModelList, planExtraEntity); planListWindow.ManufactureNumber = SelectProjectEntity.ManufactureNumber; planListWindow.Closed += new EventHandler(PlanListWindow_Closed); planListWindow.Show(); } } else { string errorMessage = "无相关数据(生产令号:" + SelectProjectEntity.ManufactureNumber.TrimEnd() + ",版本号" + SelectProjectEntity.PlanVersionID + ")"; Message.ErrorMessage(errorMessage); } } IsBusy = false; }
private void OnSmallChangeCommand() { IsBusy = true; if (null == SelectProjectEntity.PlanVersionID || null == SelectProjectEntity.ManufactureNumber || string.Empty == SelectProjectEntity.PlanVersionID || string.Empty == SelectProjectEntity.ManufactureNumber) { Message.ErrorMessage("生产令号或版本号无效"); } else { string newVersionId = SelectProjectEntity.PlanVersionID; // if (!GetNewVersionId(SelectProjectEntity.ManufactureNumber, ref newVersionId)) // { // Message.ErrorMessage("生成新版本号失败"); // IsBusy = false; // return; // } IEnumerable<string> sheetNames = from c in planManagerDomainContext.plans where c.manufacture_number == SelectProjectEntity.ManufactureNumber.TrimEnd() && c.version_id == SelectProjectEntity.PlanVersionID select c.sheet_name; if (sheetNames.Count() > 0) { ObservableCollection<PlanListViewModel> planListViewModelList = new ObservableCollection<PlanListViewModel>(); ObservableCollection<string> differentSheets = new ObservableCollection<string>(); foreach (string originalValue in sheetNames) { if (null == originalValue) { continue; } string value = originalValue; if ("设计完成节点" == value) { value = "设计节点"; } else if ("采购完成节点" == value) { value = "采购节点"; } else if ("生产完成节点" == value) { value = "生产节点"; } if (differentSheets.Contains(value)) { continue; } differentSheets.Add(value); IEnumerable<plan> selectedPlans = from c in planManagerDomainContext.plans where c.manufacture_number == SelectProjectEntity.ManufactureNumber.TrimEnd() && c.version_id == SelectProjectEntity.PlanVersionID && c.sheet_name == originalValue orderby c.sequence_id select c; ObservableCollection<PlanEntity> planList = new ObservableCollection<PlanEntity>(); bool hasOrderDate = false; for (int pos = 0; pos < selectedPlans.Count<plan>(); ++pos) { plan item = selectedPlans.ElementAt(pos); ; PlanEntity planEntity = new PlanEntity(); planEntity.Plan = item; if (item.order_date.HasValue) { hasOrderDate = true; } string getDepartmentName = string.Empty; planEntity.Update(); // planEntity.Plan = null; // planEntity.VersionId = newVersionId; planEntity.ProjectName = SelectProjectEntity.ProjectName; if (departmentIdNameDictionary.TryGetValue(planEntity.DepartmentId, out getDepartmentName)) { planEntity.DepartmentName = getDepartmentName; } planList.Add(planEntity); } if (planList.Count > 0) { int modelIndex = -1; if ("采购节点" == planList[0].SheetName) { if (hasOrderDate) { modelIndex = 1; } else { modelIndex = 2; } } else { modelIndex = 0; } PlanListViewModel planListViewModel = new PlanListViewModel(value, planList, modelIndex, departmentIdNameDictionary); planListViewModel.IsChanged = false; planListViewModel.IsReadOnly = false; planListViewModelList.Add(planListViewModel); } } if (planListViewModelList.Count > 0) { string title = "少量修改("; title += SelectProjectEntity.ProjectName; title += " "; title += SelectProjectEntity.ManufactureNumber.TrimEnd(); title += " "; title += newVersionId; title += ")"; PlanExtraEntity planExtraEntity = null; IEnumerable<plan_extra> plan_extras = from c in planManagerDomainContext.plan_extras where c.version_id == SelectProjectEntity.PlanVersionID && c.manufacture_number == SelectProjectEntity.ManufactureNumber.TrimEnd() select c; if (0 != plan_extras.Count()) { planExtraEntity = new PlanExtraEntity(); planExtraEntity.PlanExtra = plan_extras.First<plan_extra>(); planExtraEntity.Update(); // planExtraEntity.VersionId = newVersionId; // planExtraEntity.PlanExtra = null; } PlanListEditWindow planListWindow = new PlanListEditWindow(title, "修改", newVersionId, planListViewModelList, planExtraEntity); planListWindow.ManufactureNumber = SelectProjectEntity.ManufactureNumber; planListWindow.Closed += new EventHandler(PlanListWindow_Closed); planListWindow.Show(); } } else { string errorMessage = "无相关数据(生产令号:" + SelectProjectEntity.ManufactureNumber.TrimEnd() + ",版本号" + SelectProjectEntity.PlanVersionID + ")" + "\r\n"; ; Message.ErrorMessage(errorMessage); } } IsBusy = false; }
private void OnExportPlanCommand() { IsBusy = true; if (null == SelectProjectEntity.PlanVersionID || null == SelectProjectEntity.ManufactureNumber || string.Empty == SelectProjectEntity.PlanVersionID || string.Empty == SelectProjectEntity.ManufactureNumber) { Message.ErrorMessage("生产令号或版本号无效"); } else { IEnumerable<string> sheetNames = from c in planManagerDomainContext.plans where c.manufacture_number == SelectProjectEntity.ManufactureNumber.TrimEnd() && c.version_id == SelectProjectEntity.PlanVersionID select c.sheet_name; if (sheetNames.Count() > 0) { ObservableCollection<PlanListViewModel> planListViewModelList = new ObservableCollection<PlanListViewModel>(); ObservableCollection<string> differentSheets = new ObservableCollection<string>(); foreach (string value in sheetNames) { if (null == value || differentSheets.Contains(value)) { continue; } differentSheets.Add(value); IEnumerable<plan> selectedPlans = from c in planManagerDomainContext.plans where c.manufacture_number == SelectProjectEntity.ManufactureNumber.TrimEnd() && c.version_id == SelectProjectEntity.PlanVersionID && c.sheet_name == value select c; ObservableCollection<PlanEntity> planList = new ObservableCollection<PlanEntity>(); bool hasOrderDate = false; foreach (plan item in selectedPlans) { PlanEntity planEntity = new PlanEntity(); planEntity.Plan = item; if (item.order_date.HasValue) { hasOrderDate = true; } string getDepartmentName = string.Empty; planEntity.Update(); planEntity.ProjectName = SelectProjectEntity.ProjectName; if (departmentIdNameDictionary.TryGetValue(planEntity.DepartmentId, out getDepartmentName)) { planEntity.DepartmentName = getDepartmentName; } planList.Add(planEntity); } if (planList.Count > 0) { int modelIndex = -1; if ("采购节点" == planList[0].SheetName) { if (hasOrderDate) { modelIndex = 1; } else { modelIndex = 2; } } else { modelIndex = 0; } PlanListViewModel planListViewModel = new PlanListViewModel(value, planList, modelIndex, departmentIdNameDictionary); planListViewModel.IsReadOnly = true; planListViewModelList.Add(planListViewModel); } } if (planListViewModelList.Count > 0) { PlanExtraEntity planExtraEntity = null; IEnumerable<plan_extra> plan_extras = from c in planManagerDomainContext.plan_extras where c.version_id == SelectProjectEntity.PlanVersionID && c.manufacture_number == SelectProjectEntity.ManufactureNumber.TrimEnd() select c; if (0 != plan_extras.Count()) { planExtraEntity = new PlanExtraEntity(); planExtraEntity.PlanExtra = plan_extras.First<plan_extra>(); planExtraEntity.Update(); planExtraEntity.PlanExtra = null; } PlanListEditWindow planListWindow = new PlanListEditWindow("计划导出", "导出", SelectProjectEntity.PlanVersionID, planListViewModelList, planExtraEntity); planListWindow.ManufactureNumber = SelectProjectEntity.ManufactureNumber; planListWindow.Closed += new EventHandler(PlanListWindow_Closed); planListWindow.Show(); } } else { string errorMessage = "无相关数据(生产令号:" + SelectProjectEntity.ManufactureNumber.TrimEnd() + ",版本号" + SelectProjectEntity.PlanVersionID + ")"; Message.ErrorMessage(errorMessage); } } IsBusy = false; }
private void OnImportAndChangeCommand() { IsBusy = true; // string newVersionId = SelectProjectEntity.PlanVersionID; // if (!GetNewVersionId(SelectProjectEntity.ManufactureNumber, ref newVersionId)) // { // Message.ErrorMessage("生成新版本号失败"); // IsBusy = false; // return; // } OpenFileDialog oFile = new OpenFileDialog(); // .xls filter specified to select only .xls file. oFile.Filter = "Excel (*.xls)|*.xls"; if (oFile.ShowDialog() == true) { ObservableCollection<PlanListViewModel> planListViewModelList = new ObservableCollection<PlanListViewModel>(); string excelVersionId = string.Empty; string errorMessage = string.Empty; string lastVersionId = string.Empty; string getFileId = string.Empty; string getRequirement = string.Empty; PlanExtraEntity planExtraEntity = null; importErrorList.Clear(); try { FileStream fs = oFile.File.OpenRead(); Workbook book = Workbook.Open(fs); for (int loop = 0; loop < book.Worksheets.Count; ++loop) { if ("设计完成节点" == book.Worksheets[loop].Name) { book.Worksheets[loop].Name = "设计节点"; } else if ("采购完成节点" == book.Worksheets[loop].Name) { book.Worksheets[loop].Name = "采购节点"; } else if ("生产完成节点" == book.Worksheets[loop].Name) { book.Worksheets[loop].Name = "生产节点"; } int firstValueRow = -1; string getManufactureName = string.Empty; int modelIndex = -1; Dictionary<string, int> matchedColumnDictionary = new Dictionary<string, int>(); if (-1 == (modelIndex = ExcelSheetValidation(book.Worksheets[loop], ref firstValueRow, ref getManufactureName, ref excelVersionId, ref getFileId, ref getRequirement, ref matchedColumnDictionary))) { errorMessage += book.Worksheets[loop].Name; errorMessage += "格式与模板不匹配;\r\n"; continue; } if (string.Empty == excelVersionId) { errorMessage += book.Worksheets[loop].Name; errorMessage += "解析版本号失败;\r\n"; continue; } if (string.Empty != lastVersionId && excelVersionId != lastVersionId) { errorMessage += book.Worksheets[loop].Name; errorMessage += "版本号与上页不一致;\r\n"; continue; } if (SelectProjectEntity.ManufactureNumber.TrimEnd() != getManufactureName) { errorMessage += book.Worksheets[loop].Name; errorMessage += "生产令号不正确;\r\n"; continue; } var lResult = from c in planManagerDomainContext.plans where c.version_id == excelVersionId && c.manufacture_number == getManufactureName select c; if (0 != lResult.Count()) { errorMessage += book.Worksheets[loop].Name; errorMessage += "版本号重复;\r\n"; continue; } lastVersionId = excelVersionId; ObservableCollection<int> sequenceIdList = new ObservableCollection<int>(); ObservableCollection<PlanEntity> planList = new ObservableCollection<PlanEntity>(); string lastComponentName = string.Empty; foreach (KeyValuePair<int, Row> rowPair in book.Worksheets[loop].Cells.Rows) { try { if (rowPair.Key < firstValueRow || CellToPlanExtraEntity(rowPair.Value, getManufactureName, getFileId, getRequirement, ref planExtraEntity) || rowPair.Value.LastColIndex < 1) { //不允许穿插 continue; } } catch (Exception e) { //empty line continue; } PlanEntity planEntity = ExcelRowToPlanEntity(book.Worksheets[loop].Name, rowPair.Key, rowPair.Value, matchedColumnDictionary, ref lastComponentName); if (null != planEntity) { while (sequenceIdList.Contains(planEntity.SequenceId)) { planEntity.SequenceId++; } sequenceIdList.Add(planEntity.SequenceId); planEntity.VersionId = excelVersionId; planEntity.ManufactureNumber = getManufactureName; planEntity.SheetName = book.Worksheets[loop].Name; planList.Add(planEntity); } } if (planList.Count > 0) { PlanListViewModel planListViewModel = new PlanListViewModel(book.Worksheets[loop].Name, planList, modelIndex, departmentIdNameDictionary); planListViewModel.IsReadOnly = false; planListViewModelList.Add(planListViewModel); } } if (string.Empty == errorMessage && 0 == planListViewModelList.Count) { errorMessage = "无效文件 " + oFile.File.Name + "\r\n"; } else { foreach (string value in importErrorList) { errorMessage += (value + "\r\n"); } importErrorList.Clear(); } } catch (Exception e) { errorMessage = e.Message; } if (planListViewModelList.Count > 0) { string title = "大量修改("; title += SelectProjectEntity.ProjectName; title += " "; title += SelectProjectEntity.ManufactureNumber; title += " "; title += excelVersionId; title += ")"; if (null != planExtraEntity) { planExtraEntity.VersionId = excelVersionId; } PlanListEditWindow planListWindow = new PlanListEditWindow(title, "修改", excelVersionId, planListViewModelList, planExtraEntity); planListWindow.ManufactureNumber = SelectProjectEntity.ManufactureNumber; planListWindow.Closed += new EventHandler(PlanListWindow_Closed); planListWindow.Show(); if (string.Empty != errorMessage) { Message.InfoMessage(errorMessage); } } else { Message.ErrorMessage(errorMessage); } } IsBusy = false; }