private void buttonDownload_Click(object sender, EventArgs e) { //建立Local路徑資料 string Local_IP = cMETE_Download_Upload_Path.Local_IP; string Local_ShareStr = cMETE_Download_Upload_Path.Local_ShareStr; Local_Folder_MODEL = cMETE_Download_Upload_Path.Local_Folder_MODEL; Local_Folder_CAM = cMETE_Download_Upload_Path.Local_Folder_CAM; Local_Folder_OIS = cMETE_Download_Upload_Path.Local_Folder_OIS; //取代字串成正確路徑 Local_ShareStr = Local_ShareStr.Replace("[Local_IP]", Local_IP); Local_ShareStr = Local_ShareStr.Replace("[CusName]", CurrentCusName); Local_ShareStr = Local_ShareStr.Replace("[PartNo]", CurrentPartNo); Local_ShareStr = Local_ShareStr.Replace("[CusRev]", CurrentCusRev); Local_Folder_MODEL = Local_Folder_MODEL.Replace("[Local_ShareStr]", Local_ShareStr); Local_Folder_CAM = Local_Folder_CAM.Replace("[Local_ShareStr]", Local_ShareStr); Local_Folder_OIS = Local_Folder_OIS.Replace("[Local_ShareStr]", Local_ShareStr); #region 建立Local_Folder_MODEL資料夾 if (!File.Exists(Local_Folder_MODEL)) { try { System.IO.Directory.CreateDirectory(Local_Folder_MODEL); } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); return; } } #endregion #region 複製Server客戶檔案到Local_Folder_MODEL資料夾內 //判斷客戶檔案是否存在 status = System.IO.File.Exists(Server_MODEL); if (!status) { MessageBox.Show("指定的檔案不存在,請再次確認"); return; } //建立Local_Folder_MODEL資料夾內客戶檔案路徑 string Local_CusPartFullPath = string.Format(@"{0}\{1}", Local_Folder_MODEL, Path.GetFileName(Server_MODEL)); //判斷是否存在,不存在則開始複製 if (!File.Exists(Local_CusPartFullPath)) { File.Copy(Server_MODEL, Local_CusPartFullPath, true); } #endregion #region 建立Local_Folder_CAM、Local_Folder_OIS資料夾 //暫存一個tempLocal_Folder_CAM、Local_Folder_OIS,目的要讓程式每次都能有[Oper1]可取代 tempLocal_Folder_CAM = Local_Folder_CAM; tempLocal_Folder_OIS = Local_Folder_OIS; //DicSeleOper1(Key = 製程序,Value = ServerPartPath) foreach (KeyValuePair <string, string> kvp in DicSeleOper1) { Local_Folder_CAM = tempLocal_Folder_CAM; Local_Folder_OIS = tempLocal_Folder_OIS; Local_Folder_CAM = Local_Folder_CAM.Replace("[Oper1]", kvp.Key); Local_Folder_OIS = Local_Folder_OIS.Replace("[Oper1]", kvp.Key); if (!File.Exists(Local_Folder_CAM)) { try { System.IO.Directory.CreateDirectory(Local_Folder_CAM); } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); return; } } if (!File.Exists(Local_Folder_OIS)) { try { System.IO.Directory.CreateDirectory(Local_Folder_OIS); } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); return; } } } #endregion #region 複製Server製程序檔案到Local資料夾內 foreach (KeyValuePair <string, string> kvp in DicSeleOper1) { //判斷製程序檔案是否存在 Server_MEDownloadPart = tempServer_MEDownloadPart; Server_MEDownloadPart = Server_MEDownloadPart.Replace("[Oper1]", kvp.Key); status = System.IO.File.Exists(Server_MEDownloadPart); if (!status) { MessageBox.Show("製程序檔案" + Path.GetFileName(Server_MEDownloadPart) + "不存在,請再次確認"); return; } //建立Local_ShareStr資料夾內製程序檔案路徑 string Local_Oper1PartFullPath = string.Format(@"{0}\{1}", Local_ShareStr, Path.GetFileName(Server_MEDownloadPart)); //開始複製 File.Copy(Server_MEDownloadPart, Local_Oper1PartFullPath, true); } #endregion #region (註解中)自動開啟檔案組立架構 /* * //組件存在,直接開啟任務組立 * BasePart newAsmPart; * status = CaxPart.OpenBaseDisplay(Local_Oper1PartFullPath, out newAsmPart); * if (!status) * { * CaxLog.ShowListingWindow("組立開啟失敗!"); * return; * } * * //將客戶檔案組裝進來 * string NewCusPartName = string.Format(@"{0}\{1}", Local_ShareStr, Path.GetFileNameWithoutExtension(Server_MODEL) + "_" + CurrentOper1 + ".prt"); * * //複製客戶檔案並更名(料號+製程序.prt)後放到新路徑(本機Globaltek\Task\料號\版次\) * File.Copy(Local_CusPartFullPath, NewCusPartName, true); * ` * //開始組裝 * NXOpen.Assemblies.Component newComponent = null; * status = CaxAsm.AddComponentToAsmByDefault(NewCusPartName, out newComponent); * if (!status) * { * CaxLog.ShowListingWindow("ERROR,組裝失敗!"); * return; * } */ #endregion //CaxAsm.SetWorkComponent(null); MessageBox.Show("下載完成!"); this.Close(); //CaxPart.Save(); }
private void Oper1comboBox_SelectedIndexChanged(object sender, EventArgs e) { //清空ListView資訊 listView.Items.Clear(); //取得當前選取的製程序 CurrentOper1 = Oper1comboBox.Text; //建立Server路徑資料 string Server_IP = cMETE_Download_Upload_Path.Server_IP; string Server_ShareStr = cMETE_Download_Upload_Path.Server_ShareStr; Server_Folder_MODEL = cMETE_Download_Upload_Path.Server_Folder_MODEL; Server_MEDownloadPart = cMETE_Download_Upload_Path.Server_MEDownloadPart; Server_IPQC = cMETE_Download_Upload_Path.Server_IPQC; Server_SelfCheck = cMETE_Download_Upload_Path.Server_SelfCheck; Server_IQC = cMETE_Download_Upload_Path.Server_IQC; Server_FAI = cMETE_Download_Upload_Path.Server_FAI; //取代字串成正確路徑 Server_ShareStr = Server_ShareStr.Replace("[Server_IP]", Server_IP); Server_ShareStr = Server_ShareStr.Replace("[CusName]", CurrentCusName); Server_ShareStr = Server_ShareStr.Replace("[PartNo]", CurrentPartNo); Server_ShareStr = Server_ShareStr.Replace("[CusRev]", CurrentCusRev); Server_ShareStr = Server_ShareStr.Replace("[OpRev]", CurrentOpRev); Server_Folder_MODEL = Server_Folder_MODEL.Replace("[Server_ShareStr]", Server_ShareStr); Server_MEDownloadPart = Server_MEDownloadPart.Replace("[Server_ShareStr]", Server_ShareStr); Server_MEDownloadPart = Server_MEDownloadPart.Replace("[PartNo]", CurrentPartNo); Server_IPQC = Server_IPQC.Replace("[Server_IP]", Server_IP); Server_SelfCheck = Server_SelfCheck.Replace("[Server_IP]", Server_IP); Server_IQC = Server_IQC.Replace("[Server_IP]", Server_IP); Server_FAI = Server_FAI.Replace("[Server_IP]", Server_IP); #region (註解)判斷IPQC.xls是否存在 //if (!File.Exists(Server_IPQC)) //{ // listView.Items.Add("IPQC樣板(IPQC.xls)不存在,無法下載"); // return; //} //listView.Items.Add("IPQC樣板:" + Path.GetFileName(Server_IPQC)); #endregion #region (註解)判斷SelfCheck.xls是否存在 //if (!File.Exists(Server_SelfCheck)) //{ // listView.Items.Add("SelfCheck樣板(SelfCheck.xls)不存在,無法下載"); // return; //} //listView.Items.Add("SelfCheck樣板:" + Path.GetFileName(Server_SelfCheck)); #endregion #region (註解)判斷IQC.xls是否存在 //if (!File.Exists(Server_IQC)) //{ // listView.Items.Add("IQC樣板(IQC.xls)不存在,無法下載"); // return; //} //listView.Items.Add("IQC樣板:" + Path.GetFileName(Server_IQC)); #endregion #region (註解)判斷FAI.xls是否存在 //if (!File.Exists(Server_FAI)) //{ // listView.Items.Add("FAI樣板(FAI.xls)不存在,無法下載"); // return; //} //listView.Items.Add("FAI樣板:" + Path.GetFileName(Server_FAI)); #endregion #region (2016.12.29註解)判斷客戶檔案是否存在 //Server_Folder_MODEL = string.Format(@"{0}\{1}", Server_Folder_MODEL, CurrentPartNo + ".prt"); //if (!File.Exists(Server_Folder_MODEL)) //{ // listView.Items.Add("客戶檔案不存在,無法下載"); // buttonDownload.Enabled = false; // return; //} //listView.Items.Add("客戶檔案:" + Path.GetFileName(Server_Folder_MODEL)); #endregion //暫存一個Server_MEDownloadPart,目的要讓程式每次都能有[Oper1]可取代 tempServer_MEDownloadPart = Server_MEDownloadPart; #region 將選取到的Oper1紀錄成DicSeleOper1(Key = 製程序,Value = ServerPartPath) DicSeleOper1 = new Dictionary <string, string>(); ListDownloadPartPath = new List <string>(); if (CurrentOper1 == "全部下載") { for (int i = 0; i < Oper1comboBox.Items.Count; i++) { if (Oper1comboBox.Items[i].ToString() == "全部下載") { continue; } //判斷OP資料夾內是否有PartNameText_OIS.txt,如果有,表示有上傳過,則讀取裡面檔案資料進行下載 string PartNameText_OISPath = string.Format(@"{0}\{1}\{2}", Server_ShareStr, "OP" + Oper1comboBox.Items[i].ToString(), "PartNameText_OIS.txt"); if (File.Exists(PartNameText_OISPath)) { //取得已上傳過的檔案名稱 string[] PartNameText_OISData = System.IO.File.ReadAllLines(PartNameText_OISPath); //開始記錄每個零件的路徑 foreach (string ii in PartNameText_OISData) { Server_MEDownloadPart = string.Format(@"{0}\{1}", Server_ShareStr, ii); ListDownloadPartPath.Add(Server_MEDownloadPart); } } else { Server_MEDownloadPart = tempServer_MEDownloadPart; Server_MEDownloadPart = Server_MEDownloadPart.Replace("[Oper1]", Oper1comboBox.Items[i].ToString()); ListDownloadPartPath.Add(Server_MEDownloadPart); } } } else { //判斷OP資料夾內是否有PartNameText_OIS.txt,如果有,表示有上傳過,則讀取裡面檔案資料進行下載 string PartNameText_OISPath = string.Format(@"{0}\{1}\{2}", Server_ShareStr, "OP" + CurrentOper1, "PartNameText_OIS.txt"); if (File.Exists(PartNameText_OISPath)) { //取得已上傳過的檔案名稱 string[] PartNameText_OISData = System.IO.File.ReadAllLines(PartNameText_OISPath); //開始記錄每個零件的路徑 foreach (string i in PartNameText_OISData) { Server_MEDownloadPart = string.Format(@"{0}\{1}", Server_ShareStr, i); ListDownloadPartPath.Add(Server_MEDownloadPart); } } else { Server_MEDownloadPart = tempServer_MEDownloadPart; Server_MEDownloadPart = Server_MEDownloadPart.Replace("[Oper1]", CurrentOper1); ListDownloadPartPath.Add(Server_MEDownloadPart); } } #endregion #region 判斷製程檔案是否存在 foreach (string i in ListDownloadPartPath) { //判斷Part檔案是否存在 if (!File.Exists(i)) { listView.Items.Add("Part檔案:"); listView.Items.Add(Path.GetFileName(i) + "不存在,請再次確認"); buttonDownload.Enabled = false; return; } listView.Items.Add("Part檔案:" + Path.GetFileName(i)); } buttonDownload.Enabled = true; #endregion }
private void Oper1comboBox_SelectedIndexChanged(object sender, EventArgs e) { //清空ListView資訊 listView.Items.Clear(); //取得當前選取的製程序 CurrentOper1 = Oper1comboBox.Text; //建立Server路徑資料 string Server_IP = cMETE_Download_Upload_Path.Server_IP; string Server_ShareStr = cMETE_Download_Upload_Path.Server_ShareStr; Server_MODEL = cMETE_Download_Upload_Path.Server_MODEL; Server_MEDownloadPart = cMETE_Download_Upload_Path.Server_MEDownloadPart; //取代字串成正確路徑 Server_ShareStr = Server_ShareStr.Replace("[Server_IP]", Server_IP); Server_ShareStr = Server_ShareStr.Replace("[CusName]", CurrentCusName); Server_ShareStr = Server_ShareStr.Replace("[PartNo]", CurrentPartNo); Server_ShareStr = Server_ShareStr.Replace("[CusRev]", CurrentCusRev); Server_MODEL = Server_MODEL.Replace("[Server_ShareStr]", Server_ShareStr); Server_MODEL = Server_MODEL.Replace("[PartNo]", CurrentPartNo); Server_MEDownloadPart = Server_MEDownloadPart.Replace("[Server_ShareStr]", Server_ShareStr); Server_MEDownloadPart = Server_MEDownloadPart.Replace("[PartNo]", CurrentPartNo); //先判斷客戶檔案是否存在 if (!File.Exists(Server_MODEL)) { listView.Items.Add("客戶檔案不存在,無法下載"); return; } listView.Items.Add("客戶檔案:" + Path.GetFileName(Server_MODEL)); //暫存一個Server_MEDownloadPart,目的要讓程式每次都能有[Oper1]可取代 tempServer_MEDownloadPart = Server_MEDownloadPart; //將選取到的Oper1紀錄成DicSeleOper1(Key = 製程序,Value = ServerPartPath) DicSeleOper1 = new Dictionary <string, string>(); if (CurrentOper1 == "全部下載") { for (int i = 0; i < Oper1comboBox.Items.Count; i++) { if (Oper1comboBox.Items[i].ToString() == "全部下載") { continue; } Server_MEDownloadPart = tempServer_MEDownloadPart; Server_MEDownloadPart = Server_MEDownloadPart.Replace("[Oper1]", Oper1comboBox.Items[i].ToString()); string ServerPartPath = ""; status = DicSeleOper1.TryGetValue(Oper1comboBox.Items[i].ToString(), out ServerPartPath); if (!status) { DicSeleOper1.Add(Oper1comboBox.Items[i].ToString(), Server_MEDownloadPart); } } } else { Server_MEDownloadPart = tempServer_MEDownloadPart; Server_MEDownloadPart = Server_MEDownloadPart.Replace("[Oper1]", CurrentOper1); DicSeleOper1.Add(CurrentOper1, Server_MEDownloadPart); } //判斷製程檔案是否存在 foreach (KeyValuePair <string, string> kvp in DicSeleOper1) { if (!File.Exists(kvp.Value)) { listView.Items.Add("製程序" + kvp.Key + "檔案不存在,無法下載"); return; } listView.Items.Add("製程序檔案:" + Path.GetFileName(kvp.Value)); } }
private void Oper1comboBox_SelectedIndexChanged(object sender, EventArgs e) { //清空ListView資訊 listView.Items.Clear(); //取得當前選取的製程序 CurrentOper1 = Oper1comboBox.Text; //建立Server路徑資料 string Server_IP = cMETE_Download_Upload_Path.Server_IP; string Server_ShareStr = cMETE_Download_Upload_Path.Server_ShareStr; Server_MODEL = cMETE_Download_Upload_Path.Server_MODEL; Server_MEDownloadPart = cMETE_Download_Upload_Path.Server_MEDownloadPart; Server_IPQC = cMETE_Download_Upload_Path.Server_IPQC; Server_SelfCheck = cMETE_Download_Upload_Path.Server_SelfCheck; Server_IQC = cMETE_Download_Upload_Path.Server_IQC; Server_FAI = cMETE_Download_Upload_Path.Server_FAI; //取代字串成正確路徑 Server_ShareStr = Server_ShareStr.Replace("[Server_IP]", Server_IP); Server_ShareStr = Server_ShareStr.Replace("[CusName]", CurrentCusName); Server_ShareStr = Server_ShareStr.Replace("[PartNo]", CurrentPartNo); Server_ShareStr = Server_ShareStr.Replace("[CusRev]", CurrentCusRev); Server_MODEL = Server_MODEL.Replace("[Server_ShareStr]", Server_ShareStr); Server_MODEL = Server_MODEL.Replace("[PartNo]", CurrentPartNo); Server_MEDownloadPart = Server_MEDownloadPart.Replace("[Server_ShareStr]", Server_ShareStr); Server_MEDownloadPart = Server_MEDownloadPart.Replace("[PartNo]", CurrentPartNo); Server_IPQC = Server_IPQC.Replace("[Server_IP]", Server_IP); Server_SelfCheck = Server_SelfCheck.Replace("[Server_IP]", Server_IP); Server_IQC = Server_IQC.Replace("[Server_IP]", Server_IP); Server_FAI = Server_FAI.Replace("[Server_IP]", Server_IP); #region 判斷IPQC.xls是否存在 if (!File.Exists(Server_IPQC)) { listView.Items.Add("IPQC樣板(IPQC.xls)不存在,無法下載"); return; } listView.Items.Add("IPQC樣板:" + Path.GetFileName(Server_IPQC)); #endregion #region 判斷SelfCheck.xls是否存在 if (!File.Exists(Server_SelfCheck)) { listView.Items.Add("SelfCheck樣板(SelfCheck.xls)不存在,無法下載"); return; } listView.Items.Add("SelfCheck樣板:" + Path.GetFileName(Server_SelfCheck)); #endregion #region 判斷IQC.xls是否存在 if (!File.Exists(Server_IQC)) { listView.Items.Add("IQC樣板(IQC.xls)不存在,無法下載"); return; } listView.Items.Add("IQC樣板:" + Path.GetFileName(Server_IQC)); #endregion #region 判斷FAI.xls是否存在 if (!File.Exists(Server_FAI)) { listView.Items.Add("FAI樣板(FAI.xls)不存在,無法下載"); return; } listView.Items.Add("FAI樣板:" + Path.GetFileName(Server_FAI)); #endregion #region 判斷客戶檔案是否存在 if (!File.Exists(Server_MODEL)) { listView.Items.Add("客戶檔案不存在,無法下載"); return; } listView.Items.Add("客戶檔案:" + Path.GetFileName(Server_MODEL)); #endregion //暫存一個Server_MEDownloadPart,目的要讓程式每次都能有[Oper1]可取代 tempServer_MEDownloadPart = Server_MEDownloadPart; #region 將選取到的Oper1紀錄成DicSeleOper1(Key = 製程序,Value = ServerPartPath) DicSeleOper1 = new Dictionary <string, string>(); ListDownloadPartPath = new List <string>(); if (CurrentOper1 == "全部下載") { for (int i = 0; i < Oper1comboBox.Items.Count; i++) { if (Oper1comboBox.Items[i].ToString() == "全部下載") { continue; } //判斷OP資料夾內是否有PartNameText_OIS.txt,如果有,表示有上傳過,則讀取裡面檔案資料進行下載 string PartNameText_OISPath = string.Format(@"{0}\{1}\{2}", Server_ShareStr, "OP" + Oper1comboBox.Items[i].ToString(), "PartNameText_OIS.txt"); if (File.Exists(PartNameText_OISPath)) { //取得已上傳過的檔案名稱 string[] PartNameText_OISData = System.IO.File.ReadAllLines(PartNameText_OISPath); //開始記錄每個零件的路徑 foreach (string ii in PartNameText_OISData) { Server_MEDownloadPart = string.Format(@"{0}\{1}", Server_ShareStr, ii); ListDownloadPartPath.Add(Server_MEDownloadPart); } } else { Server_MEDownloadPart = tempServer_MEDownloadPart; Server_MEDownloadPart = Server_MEDownloadPart.Replace("[Oper1]", Oper1comboBox.Items[i].ToString()); ListDownloadPartPath.Add(Server_MEDownloadPart); } /* * Server_MEDownloadPart = tempServer_MEDownloadPart; * Server_MEDownloadPart = Server_MEDownloadPart.Replace("[Oper1]", Oper1comboBox.Items[i].ToString()); * * string ServerPartPath = ""; * status = DicSeleOper1.TryGetValue(Oper1comboBox.Items[i].ToString(), out ServerPartPath); * if (!status) * { * DicSeleOper1.Add(Oper1comboBox.Items[i].ToString(), Server_MEDownloadPart); * } */ } } else { //判斷OP資料夾內是否有PartNameText_OIS.txt,如果有,表示有上傳過,則讀取裡面檔案資料進行下載 string PartNameText_OISPath = string.Format(@"{0}\{1}\{2}", Server_ShareStr, "OP" + CurrentOper1, "PartNameText_OIS.txt"); if (File.Exists(PartNameText_OISPath)) { //取得已上傳過的檔案名稱 string[] PartNameText_OISData = System.IO.File.ReadAllLines(PartNameText_OISPath); //開始記錄每個零件的路徑 foreach (string i in PartNameText_OISData) { Server_MEDownloadPart = string.Format(@"{0}\{1}", Server_ShareStr, i); ListDownloadPartPath.Add(Server_MEDownloadPart); } } else { Server_MEDownloadPart = tempServer_MEDownloadPart; Server_MEDownloadPart = Server_MEDownloadPart.Replace("[Oper1]", CurrentOper1); ListDownloadPartPath.Add(Server_MEDownloadPart); } } /* * if (File.Exists(PartNameText_OISPath)) * { * //取得已上傳過的檔案名稱 * string[] PartNameText_OISData = System.IO.File.ReadAllLines(PartNameText_OISPath); * //開始記錄每個零件的路徑 * foreach (string i in PartNameText_OISData) * { * Server_MEDownloadPart = string.Format(@"{0}\{1}", Server_ShareStr, i); * ListDownloadPartPath.Add(Server_MEDownloadPart); * //DicSeleOper1.Add(CurrentOper1, Server_MEDownloadPart); * } * } * else * { * if (CurrentOper1 == "全部下載") * { * for (int i = 0; i < Oper1comboBox.Items.Count; i++) * { * if (Oper1comboBox.Items[i].ToString() == "全部下載") * { * continue; * } * Server_MEDownloadPart = tempServer_MEDownloadPart; * Server_MEDownloadPart = Server_MEDownloadPart.Replace("[Oper1]", Oper1comboBox.Items[i].ToString()); * * string ServerPartPath = ""; * status = DicSeleOper1.TryGetValue(Oper1comboBox.Items[i].ToString(), out ServerPartPath); * if (!status) * { * DicSeleOper1.Add(Oper1comboBox.Items[i].ToString(), Server_MEDownloadPart); * } * } * } * else * { * Server_MEDownloadPart = tempServer_MEDownloadPart; * Server_MEDownloadPart = Server_MEDownloadPart.Replace("[Oper1]", CurrentOper1); * DicSeleOper1.Add(CurrentOper1, Server_MEDownloadPart); * } * } */ #endregion #region 判斷製程檔案是否存在 foreach (string i in ListDownloadPartPath) { //判斷Part檔案是否存在 if (!File.Exists(i)) { listView.Items.Add("Part檔案" + Path.GetFileName(i) + "不存在,請再次確認"); return; } listView.Items.Add("Part檔案:" + Path.GetFileName(i)); } /* * foreach (KeyValuePair<string, string> kvp in DicSeleOper1) * { * if (!File.Exists(kvp.Value)) * { * listView.Items.Add("製程序" + kvp.Key + "檔案不存在,無法下載"); * return; * } * listView.Items.Add("製程序檔案:" + Path.GetFileName(kvp.Value)); * } */ #endregion }