コード例 #1
0
        private void Upload_Click(object sender, EventArgs e)
        {
            try
            {
                int          SheetCount  = 0;
                NXOpen.Tag[] SheetTagAry = null;
                theUfSession.Draw.AskDrawings(out SheetCount, out SheetTagAry);
                //判斷是否需要出PDF
                List <DrawingSheet> drawingSheets = new List <DrawingSheet>();
                for (int j = 0; j < SheetCount; j++)
                {
                    drawingSheets.Add((DrawingSheet)NXObjectManager.Get(SheetTagAry[j]));
                }
                if (this.ExportPDF.Checked)
                {
                    if (!Directory.Exists(this.L_Folder))
                    {
                        Directory.CreateDirectory(this.L_Folder);
                    }
                    string str1 = string.Format(@"{0}\{1}.pdf", this.L_Folder, Path.GetFileNameWithoutExtension(FixInsUploadDlg.displayPart.FullPath));
                    CaxME.CreateOISPDF(drawingSheets, str1);

                    //傳OIS圖到SERVER
                    if (!Directory.Exists(S_Folder))
                    {
                        System.IO.Directory.CreateDirectory(S_Folder);
                    }
                    CaxPublic.DirectoryCopy(this.L_Folder, S_Folder, true);
                }
                //取得WorkPart資訊並檢查資料是否完整
                DadDimension.WorkPartAttribute sWorkPartAttribute = new DadDimension.WorkPartAttribute();
                status = DadDimension.GetWorkPartAttribute(workPart, out sWorkPartAttribute);
                if (!status)
                {
                    if (this.ExportPDF.Checked)
                    {
                        MessageBox.Show("量測資訊不足,僅上傳PDF檔案,上傳完成!");
                    }
                    else
                    {
                        MessageBox.Show("量測資訊不足,無法上傳資料!");
                    }
                    this.Close();
                    return;
                }
                //if (sWorkPartAttribute.draftingVer == "" || sWorkPartAttribute.draftingDate == "" ||
                //    sWorkPartAttribute.partDescription == "" || sWorkPartAttribute.material == "")
                //{
                //    MessageBox.Show("量測資訊不足");
                //    this.Close();
                //    return;
                //}

                //取得所有量測尺寸資料

                List <DadDimension> listDimensionData = new List <DadDimension>();
                for (int i = 0; i < SheetCount; i++)
                {
                    //打開Sheet並記錄所有OBJ
                    NXOpen.Drawings.DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]);
                    CurrentSheet.Open();
                    CurrentSheet.View.UpdateDisplay();
                    DisplayableObject[] SheetObj = CurrentSheet.View.AskVisibleObjects();
                    status = Com_FixDimension.RecordFixDimension(SheetObj, sWorkPartAttribute, ref listDimensionData);
                    if (!status)
                    {
                        this.Close();
                        return;
                    }
                }

                //將圖片存到本機Globaltek內
                for (int i = 0; i < PicNameStr.Length; i++)
                {
                    string destFileName = string.Format(@"{0}\{1}", this.L_Folder, PicNameStr[i]);
                    File.Copy(PicPathStr[i], destFileName, true);
                }



                //由料號查Com_PEMain
                Com_PEMain cCom_PEMain = new Com_PEMain();
                status = CaxSQL.GetCom_PEMain(cCaxUpLoad.CusName, cCaxUpLoad.PartName, cCaxUpLoad.CusRev, cCaxUpLoad.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, cCaxUpLoad.OpNum, out cCom_PartOperation);
                if (!status)
                {
                    return;
                }

                #region 比對資料庫FixInspection是否有同筆數據
                bool Is_Exit = true;
                Com_FixInspection cCom_FixInspection = new Com_FixInspection();
                CaxSQL.GetCom_FixInspection(cCom_PartOperation, Path.GetFileNameWithoutExtension(workPart.FullPath), out cCom_FixInspection);
                if (cCom_FixInspection == null)
                {
                    Is_Exit = false;
                }

                if (Is_Exit && eTaskDialogResult.Yes == CaxPublic.ShowMsgYesNo("此檢、治具已存在上一筆資料,是否更新?"))
                {
                    #region 刪除Com_FixDimension
                    IList <Com_FixDimension> listComFixDimension = new List <Com_FixDimension>();
                    CaxSQL.GetListCom_FixDimension(cCom_FixInspection, out listComFixDimension);
                    foreach (Com_FixDimension i in listComFixDimension)
                    {
                        CaxSQL.Delete <Com_FixDimension>(i);
                    }
                    #endregion
                    #region 刪除Com_FixInspection
                    CaxSQL.Delete <Com_FixInspection>(cCom_FixInspection);
                    #endregion
                    Is_Exit = false;
                }

                if (!Is_Exit)
                {
                    cCom_FixInspection = new Com_FixInspection()
                    {
                        comPartOperation  = cCom_PartOperation,
                        fixinsDescription = this.Desc.Text,
                        fixinsERP         = this.ERPNo.Text,
                        fixinsNo          = this.FixInsNo.Text,
                        fixPicPath        = this.S_PicPath,
                        fixPartName       = Path.GetFileNameWithoutExtension(FixInsUploadDlg.workPart.FullPath)
                    };

                    IList <Com_FixDimension> listCom_FixDimension = new List <Com_FixDimension>();
                    foreach (DadDimension i in listDimensionData)
                    {
                        //Com_FixDimension cCom_FixDimension = new Com_FixDimension()
                        //{
                        //    comFixInspection = comFixInspection
                        //};
                        ////cCom_FixDimension.comFixInspection = comFixInspection;

                        //CaxME.MappingData(i, ref cCom_FixDimension);
                        //listCom_FixDimension.Add(cCom_FixDimension);
                        Com_FixDimension cCom_FixDimension = new Com_FixDimension();
                        cCom_FixDimension.MappingData(i);
                        cCom_FixDimension.comFixInspection = cCom_FixInspection;
                        listCom_FixDimension.Add(cCom_FixDimension);
                    }
                    cCom_FixInspection.comFixDimension = listCom_FixDimension;

                    CaxSQL.Save <Com_FixInspection>(cCom_FixInspection);

                    //傳OIS圖到SERVER
                    if (!Directory.Exists(S_Folder))
                    {
                        System.IO.Directory.CreateDirectory(S_Folder);
                    }
                    CaxPublic.DirectoryCopy(this.L_Folder, S_Folder, true);
                }

                #endregion

                MessageBox.Show("上傳完成");
                base.Close();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
コード例 #2
0
        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();
        }