public string CheckFlowChart(FlowChartExcelImportParas parasItem) { string isValid = string.Empty; var budItem = systemBUDRepository.GetMany(m => m.BU_D_Name == parasItem.BU_D_Name).FirstOrDefault(); //如果budItem没有,说明不存在这个客户 if (budItem != null) { if (parasItem.isEdit) { var masterItem = flowChartMasterRepository.GetById(parasItem.FlowChart_Master_UID); if (masterItem.System_Project.Project_Name == parasItem.Project_Name && masterItem.System_Project.System_BU_D.BU_D_Name == parasItem.BU_D_Name && masterItem.System_Project.Product_Phase == parasItem.Product_Phase && masterItem.Part_Types == parasItem.Part_Types) { isValid = string.Format("{0}_{1}_{2}_{3}", masterItem.FlowChart_Master_UID, masterItem.Project_UID, masterItem.FlowChart_Version, masterItem.System_Project.Organization_UID); } else { isValid = string.Format("客户{0},专案名称{1},部件{2},阶段{3}不匹配,不能更新", parasItem.BU_D_Name, parasItem.Project_Name, parasItem.Part_Types, parasItem.Product_Phase); } } else { var projetItem = systemProjectRepository.GetMany(m => m.BU_D_UID == budItem.BU_D_UID && m.Project_Name == parasItem.Project_Name && m.Product_Phase == parasItem.Product_Phase && parasItem.Organization_UIDList.Contains(m.Organization_UID)).FirstOrDefault(); //如果projectUIDList没有,说明该数据不存在 if (projetItem != null) { //如果flItem为空,说明可以新导入这条数据 var flItem = flowChartMasterRepository.GetMany(m => m.Project_UID == projetItem.Project_UID && m.Part_Types == parasItem.Part_Types).FirstOrDefault(); if (flItem == null) { isValid = string.Format("{0}_{1}", projetItem.Project_UID.ToString(), projetItem.Organization_UID); } else { isValid = string.Format("导入的专案{0}已经存在,不能新增专案", parasItem.Project_Name); } } else { isValid = string.Format("客户{0}或专案名称{1}或阶段{2}不存在,或者用户没有该专案的权限,不能导入", parasItem.BU_D_Name, parasItem.Project_Name, parasItem.Product_Phase); } } } else { isValid = string.Format("客户名称{0}不存在", parasItem.BU_D_Name); } return(isValid); }
public string CheckExeclValid(ExcelWorksheet worksheet, int iRow, int FlowChart_Master_UID, FlowChartExcelImportParas paraItem, out string Part_Types) { Part_Types = string.Empty; string errorInfo = string.Empty; if (worksheet == null) { errorInfo = "没有worksheet内容"; return(errorInfo); } //头样式设置 var propertiesHead = FlowchartImportCommon.GetHeadColumn(); bool allColumnsAreEmpty = true; for (var i = 1; i <= propertiesHead.Length; i++) { if (worksheet.Cells[iRow, i].Value != null && !String.IsNullOrEmpty(worksheet.Cells[iRow, i].Value.ToString())) { allColumnsAreEmpty = false; break; } } if (allColumnsAreEmpty) { errorInfo = "Excel格式不正确"; return(errorInfo); } string BU_D_Name = ExcelHelper.ConvertColumnToString(worksheet.Cells[iRow, ExcelHelper.GetColumnIndex(propertiesHead, "客户")].Value); string Project_Name = ExcelHelper.ConvertColumnToString(worksheet.Cells[iRow, ExcelHelper.GetColumnIndex(propertiesHead, "专案名称")].Value); Part_Types = ExcelHelper.ConvertColumnToString(worksheet.Cells[iRow, ExcelHelper.GetColumnIndex(propertiesHead, "部件")].Value); string Product_Phase = ExcelHelper.ConvertColumnToString(worksheet.Cells[iRow, ExcelHelper.GetColumnIndex(propertiesHead, "阶段")].Value); if (string.IsNullOrWhiteSpace(BU_D_Name) || string.IsNullOrWhiteSpace(Project_Name) || string.IsNullOrWhiteSpace(Part_Types) || string.IsNullOrWhiteSpace(Product_Phase)) { errorInfo = "客户,专案名称,部件,阶段不能为空Excel格式不正确"; return(errorInfo); } paraItem.BU_D_Name = BU_D_Name.Trim(); paraItem.Project_Name = Project_Name.Trim(); paraItem.Part_Types = Part_Types.Trim(); paraItem.Product_Phase = Product_Phase.Trim(); paraItem.FlowChart_Master_UID = FlowChart_Master_UID; return(errorInfo); }
public override string AddOrUpdateExcel(HttpPostedFileBase uploadName, int FlowChart_Master_UID, string FlowChart_Version_Comment, bool isEdit, FlowChartImport importItem) { string apiUrl = string.Empty; string errorInfo = string.Empty; FlowChartMasterDTO newMaster = new FlowChartMasterDTO(); List <FlowChartImportDetailDTO> detailDTOList = new List <FlowChartImportDetailDTO>(); importItem.FlowChartMasterDTO = newMaster; importItem.FlowChartImportDetailDTOList = detailDTOList; var userInfo = HttpContext.Current.Session[SessionConstants.CurrentUserInfo] as CustomUserInfoVM; if (userInfo == null || userInfo.OrgInfo.Count() == 0 || userInfo.Plant_OrganizationUIDList.Count() == 0) { return("用户没有配置对应的SITE"); } try { using (var xlPackage = new ExcelPackage(uploadName.InputStream)) { FlowChartExcelImportParas paraItem = new FlowChartExcelImportParas(); int iRow = 2; var worksheet = xlPackage.Workbook.Worksheets.FirstOrDefault(); int totalRows = worksheet.Dimension.End.Row; string Part_Types; #region 判断Excel是否合法 errorInfo = CheckExeclValid(worksheet, iRow, FlowChart_Master_UID, paraItem, out Part_Types); if (!string.IsNullOrEmpty(errorInfo)) { return(errorInfo); } #endregion #region 判断新增和编辑都检查客户,专案名称,部件,阶段是否匹配 string projectUIDOrFLMasterUID; errorInfo = CheckFlowchartIsMatch(paraItem, newMaster, isEdit, FlowChart_Version_Comment, Part_Types, userInfo, out projectUIDOrFLMasterUID); if (!string.IsNullOrEmpty(errorInfo)) { return(errorInfo); } #endregion #region 读取Excel内容,判断单元格是否为空并赋值,判断绑定序号,制程序号是否重复 errorInfo = SetAndCheckExcelContent(detailDTOList, isEdit, worksheet, iRow, totalRows, newMaster, FlowChart_Version_Comment, userInfo); if (!string.IsNullOrEmpty(errorInfo)) { return(errorInfo); } #endregion #region Flowchart升版,把WIP,生产计划,绑定物料员都带出来 if (isEdit) { List <int> detailUIDList = new List <int>(); SetFlowchartWipAndPlan(userInfo, detailDTOList, newMaster, out detailUIDList); importItem.FlowchartDetailUIDList = detailUIDList; } #endregion } } catch (Exception exc) { errorInfo = "上传的文件类型不正确 " + exc.ToString(); } return(errorInfo); }
public string CheckFlowchartIsMatch(FlowChartExcelImportParas paraItem, FlowChartMasterDTO newMaster, bool isEdit, string FlowChart_Version_Comment, string Part_Types, CustomUserInfoVM userInfo, out string projectUIDOrFLMasterUID) { string errorInfo = string.Empty; var orgList = userInfo.OrgInfo.Select(m => m.OPType_OrganizationUID.Value).ToList(); paraItem.Organization_UIDList = orgList; if (isEdit) { paraItem.isEdit = true; } else { paraItem.isEdit = false; } var apiUrl = string.Format("FlowChart/CheckFlowChartAPI"); HttpResponseMessage responMessage = APIHelper.APIPostAsync(paraItem, apiUrl); projectUIDOrFLMasterUID = responMessage.Content.ReadAsStringAsync().Result; projectUIDOrFLMasterUID = projectUIDOrFLMasterUID.Replace("\"", ""); //正确返回id字符串,错误则返回出错字符串 if (!FlowchartImportCommon.ValidIsInt(projectUIDOrFLMasterUID, isEdit)) { errorInfo = projectUIDOrFLMasterUID; return(errorInfo); } if (isEdit) { var idList = projectUIDOrFLMasterUID.Split('_').ToList(); newMaster.FlowChart_Master_UID = Convert.ToInt32(idList[0]); newMaster.Project_UID = Convert.ToInt32(idList[1]); newMaster.FlowChart_Version = Convert.ToInt32(idList[2]); newMaster.Organization_UID = Convert.ToInt32(idList[3]); newMaster.Modified_UID = userInfo.Account_UID; newMaster.Modified_Date = DateTime.Now; //检查当前时间段是否包含有ProductInput的制程信息 string productapiUrl = string.Format("ProductInput/CheckHasExistProcessAPI?MasterUID={0}&Version={1}", newMaster.FlowChart_Master_UID, newMaster.FlowChart_Version); HttpResponseMessage productResponMessage = APIHelper.APIGetAsync(productapiUrl); var hasProcess = productResponMessage.Content.ReadAsStringAsync().Result; if (hasProcess == "true") { errorInfo = "当前Flowchart的相关制程还未完全录入,不能导入新版本"; return(errorInfo); } } else { int tag = projectUIDOrFLMasterUID.IndexOf('_'); newMaster.Project_UID = Convert.ToInt32(projectUIDOrFLMasterUID.Substring(0, tag)); newMaster.Organization_UID = Convert.ToInt32(projectUIDOrFLMasterUID.Substring(tag + 1)); newMaster.FlowChart_Version = 1; newMaster.Created_UID = userInfo.Account_UID; } newMaster.Part_Types = Part_Types.Trim(); newMaster.FlowChart_Version_Comment = FlowChart_Version_Comment; newMaster.Is_Latest = true; newMaster.Is_Closed = false; newMaster.Modified_UID = userInfo.Account_UID; newMaster.Modified_Date = DateTime.Now; return(errorInfo); }
public string CheckFlowChartAPI(FlowChartExcelImportParas parasItem) { var result = flowChartService.CheckFlowChart(parasItem); return(result); }
public override string AddOrUpdateExcel(HttpPostedFileBase uploadName, int FlowChart_Master_UID, string FlowChart_Version_Comment, bool isEdit, FlowChartImport importItem) { string apiUrl = string.Empty; string errorInfo = string.Empty; FlowChartMasterDTO newMaster = new FlowChartMasterDTO(); List <FlowChartImportDetailDTO> detailDTOList = new List <FlowChartImportDetailDTO>(); importItem = new FlowChartImport(); importItem.FlowChartMasterDTO = newMaster; importItem.FlowChartImportDetailDTOList = detailDTOList; var userInfo = HttpContext.Current.Session[SessionConstants.CurrentUserInfo] as CustomUserInfoVM; if (userInfo == null) { return("Session is Null"); } try { using (var xlPackage = new ExcelPackage(uploadName.InputStream)) { var worksheet = xlPackage.Workbook.Worksheets.FirstOrDefault(); int totalRows = worksheet.Dimension.End.Row; if (worksheet == null) { errorInfo = "没有worksheet内容"; return(errorInfo); } //头样式设置 var propertiesHead = FlowchartImportCommon.GetHeadColumn(); //内容样式设置 var propertiesContent = FlowchartImportCommon.GetEtransferContentColumn(); int iRow = 2; bool allColumnsAreEmpty = true; for (var i = 1; i <= propertiesHead.Length; i++) { if (worksheet.Cells[iRow, i].Value != null && !String.IsNullOrEmpty(worksheet.Cells[iRow, i].Value.ToString())) { allColumnsAreEmpty = false; break; } } if (allColumnsAreEmpty) { errorInfo = "Excel格式不正确"; return(errorInfo); } string BU_D_Name = ExcelHelper.ConvertColumnToString(worksheet.Cells[iRow, ExcelHelper.GetColumnIndex(propertiesHead, "客户")].Value); string Project_Name = ExcelHelper.ConvertColumnToString(worksheet.Cells[iRow, ExcelHelper.GetColumnIndex(propertiesHead, "专案名称")].Value); string Part_Types = ExcelHelper.ConvertColumnToString(worksheet.Cells[iRow, ExcelHelper.GetColumnIndex(propertiesHead, "部件")].Value); string Product_Phase = ExcelHelper.ConvertColumnToString(worksheet.Cells[iRow, ExcelHelper.GetColumnIndex(propertiesHead, "阶段")].Value); if (string.IsNullOrWhiteSpace(BU_D_Name) || string.IsNullOrWhiteSpace(Project_Name) || string.IsNullOrWhiteSpace(Part_Types) || string.IsNullOrWhiteSpace(Product_Phase)) { errorInfo = "客户,专案名称,部件,阶段不能为空Excel格式不正确"; return(errorInfo); } FlowChartExcelImportParas paraItem = new FlowChartExcelImportParas(); paraItem.BU_D_Name = BU_D_Name.Trim(); paraItem.Project_Name = Project_Name.Trim(); paraItem.Part_Types = Part_Types.Trim(); paraItem.Product_Phase = Product_Phase.Trim(); paraItem.FlowChart_Master_UID = FlowChart_Master_UID; if (isEdit) { paraItem.isEdit = true; } else { paraItem.isEdit = false; } apiUrl = string.Format("FlowChart/CheckFlowChartAPI"); HttpResponseMessage responMessage = APIHelper.APIPostAsync(paraItem, apiUrl); var projectUIDOrFLMasterUID = responMessage.Content.ReadAsStringAsync().Result; projectUIDOrFLMasterUID = projectUIDOrFLMasterUID.Replace("\"", ""); if (!FlowchartImportCommon.ValidIsInt(projectUIDOrFLMasterUID, isEdit)) { errorInfo = projectUIDOrFLMasterUID; return(errorInfo); } if (isEdit) { var idList = projectUIDOrFLMasterUID.Split('_').ToList(); newMaster.FlowChart_Master_UID = Convert.ToInt32(idList[0]); newMaster.Project_UID = Convert.ToInt32(idList[1]); newMaster.FlowChart_Version = Convert.ToInt32(idList[2]); //检查当前时间段是否包含有ProductInput的制程信息 string productapiUrl = string.Format("ProductInput/CheckHasExistProcessAPI?MasterUID={0}&Version={1}", newMaster.FlowChart_Master_UID, newMaster.FlowChart_Version); HttpResponseMessage productResponMessage = APIHelper.APIGetAsync(productapiUrl); var hasProcess = productResponMessage.Content.ReadAsStringAsync().Result; if (hasProcess == "true") { errorInfo = "当前Flowchart的相关制程还未完全录入,不能导入新版本"; return(errorInfo); } } else { newMaster.Project_UID = Convert.ToInt32(projectUIDOrFLMasterUID); newMaster.FlowChart_Version = 1; } newMaster.Part_Types = Part_Types.Trim(); newMaster.FlowChart_Version_Comment = FlowChart_Version_Comment; newMaster.Is_Latest = true; newMaster.Is_Closed = false; newMaster.Modified_UID = userInfo.Account_UID; newMaster.Modified_Date = DateTime.Now; //获取所有厂别 //不考虑跨厂区的权限,跨厂区不会操作flowchart导入,默认取第一个optypes var plantAPI = "FlowChart/QueryAllFunctionPlantsAPI?optype=" + userInfo.OrgInfo.First().OPType; HttpResponseMessage message = APIHelper.APIGetAsync(plantAPI); var jsonPlants = message.Content.ReadAsStringAsync().Result; var functionPlants = JsonConvert.DeserializeObject <List <SystemFunctionPlantDTO> >(jsonPlants); //从第四行开始读取 iRow = iRow + 2; //制程序号 string ItemNo = string.Empty; int Process_Seq = 0; //DRI string DRI; //场地 string Place; //工站名稱 string Process; //厂别 int System_FunPlant_UID = 20; string plantName; //阶层 int Product_Stage = 0; //颜色 string Color; //工站說明 string Process_Desc; //返工设定 string Rework_Setting; //检测设定 string Check_Setting = string.Empty; ///eTransfer所需属性---Robert 2016、10、31 string FromWHS = string.Empty; string ToWHSOK = string.Empty; string ToWHSNG = string.Empty; //返修站点数量,每个FlowChart只能允许1个站点是返工站点 int Repair_Count = 0; int Process_Sign = 0; for (var i = iRow; i <= totalRows; i++) { //列名,列名序号是0 var value = worksheet.Cells[i, ExcelHelper.GetColumnIndex(propertiesContent, "制程序号")].Value; if (value == null) { break; } ItemNo = ExcelHelper.ConvertColumnToString(value); //循环结束,防止有空行 DRI = ExcelHelper.ConvertColumnToString(worksheet.Cells[i, ExcelHelper.GetColumnIndex(propertiesContent, "DRI")].Value); if (string.IsNullOrWhiteSpace(DRI)) { //跳出循环 errorInfo = string.Format("第[{0}]行DRI不能为空", i); return(errorInfo); } Place = ExcelHelper.ConvertColumnToString(worksheet.Cells[i, ExcelHelper.GetColumnIndex(propertiesContent, "场地")].Value); if (string.IsNullOrWhiteSpace(Place)) { //跳出循环 errorInfo = string.Format("第[{0}]行场地不能为空", i); return(errorInfo); } Process = ExcelHelper.ConvertColumnToString(worksheet.Cells[i, ExcelHelper.GetColumnIndex(propertiesContent, "工站名稱")].Value); if (string.IsNullOrWhiteSpace(Process)) { //跳出循环 errorInfo = string.Format("第[{0}]行工站名稱不能为空", i); return(errorInfo); } plantName = ExcelHelper.ConvertColumnToString(worksheet.Cells[i, ExcelHelper.GetColumnIndex(propertiesContent, "厂别")].Value) ?? string.Empty; if (string.IsNullOrWhiteSpace(plantName)) { //跳出循环 errorInfo = string.Format("第[{0}]行厂别不能为空", i); return(errorInfo); } //获取到当前的OP类型 //var nowOpTypes = this.CurrentUser.DataPermissions.Op_Types.FirstOrDefault(); //获取到当前账号所在的功能厂 //var nowFuncPlant = this.CurrentUser.DataPermissions.UserOrgInfo.Org_FuncPlant; //var nowFuncPlant = userInfo.OrgInfo.Org_FuncPlant; var hasItem = functionPlants.FirstOrDefault(m => m.FunPlant.ToLower() == plantName.ToLower().Trim()); if (hasItem != null) { System_FunPlant_UID = hasItem.System_FunPlant_UID; } //else //{ // //跳出循环 // errorInfo = string.Format("厂别[{0}", plantName); // return errorInfo; //} Product_Stage = Convert.ToInt32(worksheet.Cells[i, ExcelHelper.GetColumnIndex(propertiesContent, "阶层")].Value); Color = ExcelHelper.ConvertColumnToString(worksheet.Cells[i, ExcelHelper.GetColumnIndex(propertiesContent, "颜色")].Value) ?? string.Empty; Process_Desc = ExcelHelper.ConvertColumnToString(worksheet.Cells[i, ExcelHelper.GetColumnIndex(propertiesContent, "工站說明")].Value); Rework_Setting = ExcelHelper.ConvertColumnToString(worksheet.Cells[i, ExcelHelper.GetColumnIndex(propertiesContent, "返工设定")].Value); if (Process_Sign != Process_Seq && Rework_Setting == "Repair") { Repair_Count++; } if (Repair_Count > 1) { //跳出循环 errorInfo = string.Format("第[{0}]行出现重复的修复站点!", i); return(errorInfo); } Process_Sign = Process_Seq; //检测站点赋值 var CheckTemp = ExcelHelper.ConvertColumnToString(worksheet.Cells[i, ExcelHelper.GetColumnIndex(propertiesContent, "检测设定")].Value); if (!string.IsNullOrWhiteSpace(CheckTemp)) { CheckTemp = CheckTemp.Trim(); } switch (CheckTemp) { case StructConstants.IsQAProcessType.InspectText: //IPQC全检 Check_Setting = StructConstants.IsQAProcessType.InspectKey; break; case StructConstants.IsQAProcessType.PollingText: //IPQC巡检 Check_Setting = StructConstants.IsQAProcessType.PollingKey; break; case StructConstants.IsQAProcessType.InspectOQCText: //OQC检测 Check_Setting = StructConstants.IsQAProcessType.InspectOQCKey; break; case StructConstants.IsQAProcessType.InspectAssembleText: //组装检测 Check_Setting = StructConstants.IsQAProcessType.InspectAssembleKey; break; case StructConstants.IsQAProcessType.AssembleOQCText: //组装&OQC检测 Check_Setting = StructConstants.IsQAProcessType.AssembleOQCKey; break; default: Check_Setting = string.Empty; break; } //eTransfer部分获取值 FromWHS = ExcelHelper.ConvertColumnToString(worksheet.Cells[i, ExcelHelper.GetColumnIndex(propertiesContent, "FromWHS")].Value); ToWHSNG = ExcelHelper.ConvertColumnToString(worksheet.Cells[i, ExcelHelper.GetColumnIndex(propertiesContent, "ToWHSNG")].Value); ToWHSOK = ExcelHelper.ConvertColumnToString(worksheet.Cells[i, ExcelHelper.GetColumnIndex(propertiesContent, "ToWHSOK")].Value); var listColor = Color.Split('/').ToList(); foreach (var itemColor in listColor) { FlowChartImportDetailDTO detailDTOItem = new FlowChartImportDetailDTO(); FlowChartDetailDTO newDetailDtoItem = new FlowChartDetailDTO(); newDetailDtoItem.FlowChart_Master_UID = newMaster.FlowChart_Master_UID; newDetailDtoItem.System_FunPlant_UID = System_FunPlant_UID; newDetailDtoItem.Process_Seq = Process_Seq.ToString(); newDetailDtoItem.ItemNo = ItemNo; newDetailDtoItem.DRI = DRI; newDetailDtoItem.Place = Place; newDetailDtoItem.Process = Process; newDetailDtoItem.Product_Stage = Product_Stage; newDetailDtoItem.Color = itemColor; newDetailDtoItem.Process_Desc = Process_Desc; newDetailDtoItem.FlowChart_Version_Comment = FlowChart_Version_Comment; newDetailDtoItem.Rework_Flag = Rework_Setting; //新增QA字段 newDetailDtoItem.IsQAProcess = Check_Setting; newDetailDtoItem.Modified_UID = newMaster.Modified_UID; newDetailDtoItem.Modified_Date = newMaster.Modified_Date; newDetailDtoItem.FromWHS = FromWHS; newDetailDtoItem.ToWHSNG = ToWHSNG; newDetailDtoItem.ToWHSOK = ToWHSOK; if (isEdit) { //存到临时表里面的数据所以要加1 newDetailDtoItem.FlowChart_Version = newMaster.FlowChart_Version + 1; } else { //存到正式表里面的数据不用加1 newDetailDtoItem.FlowChart_Version = newMaster.FlowChart_Version; } detailDTOItem.FlowChartDetailDTO = newDetailDtoItem; //detailDTOItem.FlowChartMgDataDTO = newMgDataDtoItem; detailDTOList.Add(detailDTOItem); } } } } catch (Exception exc) { errorInfo = "上传的文件类型不正确 " + exc.ToString(); } return(errorInfo); }