private void OK_Click(object sender, EventArgs e) { CaxPart.SaveAll(); #region Part上傳 List <string> ListPartName = new List <string>(); status = CaxUpLoad.UploadPart(DicPartDirData, out ListPartName); if (!status) { this.Close(); return; } System.IO.File.WriteAllLines(string.Format(@"{0}\{1}\{2}", sDownUpLoadDat.Server_ShareStr, "OP" + cCaxTEUpLoad.OpNum, "PartNameText_CAM.txt"), ListPartName.ToArray()); #endregion //CAM資料夾上傳 status = CaxPublic.DirectoryCopy(sDownUpLoadDat.Local_Folder_CAM, sDownUpLoadDat.Server_Folder_CAM, true); if (!status) { MessageBox.Show("CAM資料夾複製失敗,請聯繫開發工程師"); this.Close(); } #region (註解中)Excel上傳 /* * if (File.Exists(sExcelDirData.ExcelShopDocLocalDir)) * { * try * { * File.Copy(sExcelDirData.ExcelShopDocLocalDir, sExcelDirData.ExcelShopDocServerDir, true); * } * catch (System.Exception ex) * { * CaxLog.ShowListingWindow("ShopDoc.xls上傳失敗"); * this.Close(); * } * } */ #endregion #region (註解)NC上傳 /* * if (Directory.Exists(sNCProgramDirData.NCProgramLocalDir)) * { * try * { * CaxPublic.DirectoryCopy(sNCProgramDirData.NCProgramLocalDir, sNCProgramDirData.NCProgramServerDir, true); * } * catch (System.Exception ex) * { * CaxLog.ShowListingWindow("NC上傳失敗"); * this.Close(); * } * } */ #endregion #region (註解)上傳至資料庫 /* * NCGroup[] NCGroupAry = displayPart.CAMSetup.CAMGroupCollection.ToArray(); * Dictionary<string, Function.OperData> DicNCData = new Dictionary<string, Function.OperData>(); * status = Function.GetNCProgramData(NCGroupAry, out DicNCData); * if (!status) * { * MessageBox.Show("取得NC資料失敗,無法上傳至數據庫,僅上傳NX檔案"); * goto finish; * } * * Com_PEMain comPEMain = new Com_PEMain(); * status = Function.GetCom_PEMain(sPartInfo, out comPEMain); * if (!status) * { * MessageBox.Show("資料庫無此筆料號,僅上傳NX檔案"); * goto finish; * } * * Com_PartOperation comPartOperation = new Com_PartOperation(); * status = Function.GetCom_PartOperation(sPartInfo, comPEMain, out comPartOperation); * if (!status) * { * MessageBox.Show("資料庫無此筆料號,僅上傳NX檔案"); * goto finish; * } * * foreach (KeyValuePair<string,Function.OperData> kvp in DicNCData) * { * Com_TEMain ComTEMain = session.QueryOver<Com_TEMain>() * .Where(x => x.comPartOperation == comPartOperation) * .And(x => x.ncGroupName == kvp.Key) * .SingleOrDefault(); * if (ComTEMain == null) * { * //表示未插入過此NC資料,直接插入 * * } * } */ #endregion //finish: MessageBox.Show("上傳完成!"); this.Close(); }
private void OK_Click(object sender, EventArgs e) { CaxPart.SaveAll(); //Part上傳 List <string> ListPartName = new List <string>(); status = CaxMEUpLoad.UploadPart(DicPartDirData, out ListPartName); //status = Function.UploadPart(DicPartDirData, out ListPartName); if (!status) { this.Close(); return; } System.IO.File.WriteAllLines(string.Format(@"{0}\{1}\{2}", sDownUpLoadDat.Server_ShareStr, "OP" + cCaxMEUpLoad.OpNum, "PartNameText_OIS.txt"), ListPartName.ToArray()); //新增TE的下載文件 if (TEDownloadText.Count > 0) { string PartNameText_CAM = string.Format(@"{0}\{1}\{2}", sDownUpLoadDat.Server_ShareStr, "OP" + cCaxMEUpLoad.OpNum, "PartNameText_CAM.txt"); foreach (string i in TEDownloadText) { using (StreamWriter sw = File.AppendText(PartNameText_CAM)) { sw.WriteLine(i); } } } #region (註解)Excel上傳 /* * //Excel上傳 * if (File.Exists(sExcelDirData.ExcelIPQCLocalDir)) * { * try * { * File.Copy(sExcelDirData.ExcelIPQCLocalDir, sExcelDirData.ExcelIPQCServerDir, true); * } * catch (System.Exception ex) * { * CaxLog.ShowListingWindow("IPQC.xls上傳失敗"); * this.Close(); * } * } * * if (File.Exists(sExcelDirData.ExcelSelfCheckLocalDir)) * { * try * { * File.Copy(sExcelDirData.ExcelSelfCheckLocalDir, sExcelDirData.ExcelSelfCheckServerDir, true); * } * catch (System.Exception ex) * { * CaxLog.ShowListingWindow("SelfCheck.xls上傳失敗"); * this.Close(); * } * } * * if (File.Exists(sExcelDirData.ExcelIQCLocalDir)) * { * try * { * File.Copy(sExcelDirData.ExcelIQCLocalDir, sExcelDirData.ExcelIQCServerDir, true); * } * catch (System.Exception ex) * { * CaxLog.ShowListingWindow("IQC.xls上傳失敗"); * this.Close(); * } * } * * if (File.Exists(sExcelDirData.ExcelFAILocalDir)) * { * try * { * File.Copy(sExcelDirData.ExcelFAILocalDir, sExcelDirData.ExcelFAIServerDir, true); * } * catch (System.Exception ex) * { * CaxLog.ShowListingWindow("FAI.xls上傳失敗"); * this.Close(); * } * } * * if (File.Exists(sExcelDirData.ExcelFQCLocalDir)) * { * try * { * File.Copy(sExcelDirData.ExcelFQCLocalDir, sExcelDirData.ExcelFQCServerDir, true); * } * catch (System.Exception ex) * { * CaxLog.ShowListingWindow("FQC.xls上傳失敗"); * this.Close(); * } * } */ #endregion int SheetCount = 0; NXOpen.Tag[] SheetTagAry = null; theUfSession.Draw.AskDrawings(out SheetCount, out SheetTagAry); List <NXOpen.Drawings.DrawingSheet> listDrawingSheet = new List <NXOpen.Drawings.DrawingSheet>(); for (int i = 0; i < SheetCount; i++) { //打開Sheet並記錄所有OBJ NXOpen.Drawings.DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]); listDrawingSheet.Add(CurrentSheet); } #region 輸出OIS //輸出PDF if (ExportPFD.Checked == true) { //建立PFD資料夾 string PFDFullPath = string.Format(@"{0}\{1}", sDownUpLoadDat.Local_Folder_OIS, cCaxMEUpLoad.PartName + "_OIS" + cCaxMEUpLoad.OpNum + ".pdf"); CaxME.CreateOISPDF(listDrawingSheet, PFDFullPath); //OIS資料夾上傳 status = CaxPublic.DirectoryCopy(sDownUpLoadDat.Local_Folder_OIS, sDownUpLoadDat.Server_Folder_OIS, true); if (!status) { MessageBox.Show("OIS資料夾複製失敗,請聯繫開發工程師"); this.Close(); } } #endregion #region 資料上傳至Database //取得WorkPart資訊並檢查資料是否完整 DadDimension.WorkPartAttribute sWorkPartAttribute = new DadDimension.WorkPartAttribute(); //status = Function.GetWorkPartAttribute(workPart, out sWorkPartAttribute); status = DadDimension.GetWorkPartAttribute(workPart, out sWorkPartAttribute); if (!status) { MessageBox.Show("量測資訊不足,僅上傳CAD檔案,上傳完成!"); this.Close(); return; } #region 取得所有量測尺寸資料 /* * //取得泡泡特徵,並記錄總共有幾個泡泡,後續比對數量用 * IdSymbolCollection BallonCollection = workPart.Annotations.IdSymbols; * IdSymbol[] BallonAry = BallonCollection.ToArray(); * int balloonCount = 0; * foreach (IdSymbol i in BallonAry) * { * try * { * i.GetStringAttribute("BalloonAtt"); * balloonCount++; * } * catch (System.Exception ex) * { * continue; * } * } * * List<CaxME.DimensionData> listDimensionData = new List<CaxME.DimensionData>(); * List<int> listBalloonCount = new List<int>(); * NXOpen.Drawings.DrawingSheet FirstSheet = null; * while (listBalloonCount.Count != balloonCount) * { * for (int i = 0; i < SheetCount; i++) * { * //打開Sheet並記錄所有OBJ * NXOpen.Drawings.DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]); * if (CurrentSheet.Name == "S1") * { * FirstSheet = CurrentSheet; * } * CurrentSheet.Open(); * CurrentSheet.View.UpdateDisplay(); * DisplayableObject[] SheetObj = CurrentSheet.View.AskVisibleObjects(); * status = CaxME.RecordDimension(SheetObj, sWorkPartAttribute, ref listDimensionData); * if (!status) * { * this.Close(); * return; * } * } * foreach (CaxME.DimensionData i in listDimensionData) * { * if (!listBalloonCount.Contains(i.ballonNum)) * { * listBalloonCount.Add(i.ballonNum); * } * } * * } */ //List<CaxME.DimensionData> listDimensionData = new List<CaxME.DimensionData>(); List <DadDimension> listDimensionData = new List <DadDimension>(); NXOpen.Drawings.DrawingSheet FirstSheet = null; for (int i = 0; i < SheetCount; i++) { //打開Sheet並記錄所有OBJ NXOpen.Drawings.DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]); if (CurrentSheet.Name == "S1") { FirstSheet = CurrentSheet; } CurrentSheet.Open(); CurrentSheet.View.UpdateDisplay(); DisplayableObject[] SheetObj = CurrentSheet.View.AskVisibleObjects(); status = Com_Dimension.RecordDimension(SheetObj, sWorkPartAttribute, ref listDimensionData); if (!status) { this.Close(); return; } } #endregion //切回首頁 if (FirstSheet != null) { FirstSheet.Open(); } //由料號查Com_PEMain Com_PEMain cCom_PEMain = new Com_PEMain(); status = CaxSQL.GetCom_PEMain(cCaxMEUpLoad.CusName, cCaxMEUpLoad.PartName, cCaxMEUpLoad.CusRev, cCaxMEUpLoad.OpRev, out cCom_PEMain); if (!status) { return; } //由Com_PEMain和Op查Com_PartOperation Com_PartOperation cCom_PartOperation = new Com_PartOperation(); status = CaxSQL.GetCom_PartOperation(cCom_PEMain, cCaxMEUpLoad.OpNum, out cCom_PartOperation); if (!status) { return; } #region (註解)由excelType查meExcelSrNo //Sys_MEExcel sysMEExcel = new Sys_MEExcel(); //try //{ // sysMEExcel = session.QueryOver<Sys_MEExcel>().Where(x => x.meExcelType == meExcelType).SingleOrDefault<Sys_MEExcel>(); //} //catch (System.Exception ex) //{ // MessageBox.Show("資料庫中沒有此料號的紀錄,故無法上傳量測尺寸,僅成功上傳實體檔案"); // return; //} #endregion #region 比對資料庫MEMain是否有同筆數據 IList <Com_MEMain> ListCom_MEMain = new List <Com_MEMain>(); CaxSQL.GetListCom_MEMain(out ListCom_MEMain); bool Is_Exist = false; Com_MEMain currentComMEMain = new Com_MEMain(); foreach (Com_MEMain i in ListCom_MEMain) { if (i.comPartOperation == cCom_PartOperation) { Is_Exist = true; currentComMEMain = i; break; } } #endregion #region 如果本次上傳的資料不存在於資料庫,則開始上傳資料;如果已存在資料庫,則詢問是否要更新尺寸 bool Is_Update = true; if (Is_Exist) { if (eTaskDialogResult.Yes == CaxPublic.ShowMsgYesNo("此料號已存在上一次的標註尺寸資料,是否更新?")) { #region 刪除Com_Dimension資料表 IList <Com_Dimension> ListCom_Dimension = new List <Com_Dimension>(); CaxSQL.GetListCom_Dimension(currentComMEMain, out ListCom_Dimension); foreach (Com_Dimension i in ListCom_Dimension) { CaxSQL.Delete <Com_Dimension>(i); } #endregion #region 刪除Com_MEMain資料表 Com_MEMain cCom_MEMain = new Com_MEMain(); CaxSQL.GetCom_MEMain(cCom_PartOperation, out cCom_MEMain); CaxSQL.Delete <Com_MEMain>(cCom_MEMain); #endregion } else { Is_Update = false; } } if (Is_Update) { #region 整理資料並上傳 try { Com_MEMain cCom_MEMain = new Com_MEMain(); cCom_MEMain.comPartOperation = cCom_PartOperation; //cCom_MEMain.sysMEExcel = sysMEExcel; cCom_MEMain.partDescription = sWorkPartAttribute.partDescription; cCom_MEMain.createDate = sWorkPartAttribute.createDate; cCom_MEMain.material = sWorkPartAttribute.material; cCom_MEMain.draftingVer = sWorkPartAttribute.draftingVer; IList <Com_Dimension> listCom_Dimension = new List <Com_Dimension>(); foreach (DadDimension i in listDimensionData) { Com_Dimension cCom_Dimension = new Com_Dimension(); cCom_Dimension.MappingData(i); cCom_Dimension.comMEMain = cCom_MEMain; listCom_Dimension.Add(cCom_Dimension); //Com_Dimension cCom_Dimension = new Com_Dimension(); //cCom_Dimension.comMEMain = cCom_MEMain; //CaxME.MappingData(i, ref cCom_Dimension); //listCom_Dimension.Add(cCom_Dimension); } cCom_MEMain.comDimension = listCom_Dimension; CaxSQL.Save <Com_MEMain>(cCom_MEMain); } catch (System.Exception ex) { MessageBox.Show("上傳資料庫時發生錯誤,僅上傳實體檔案"); } #endregion } #endregion #endregion CaxPart.Save(); MessageBox.Show("上傳完成!"); this.Close(); }