public static bool SetMEPanelData(Com_PartOperation comPartOperation, string cus, string partNo, string cusVer, string opVer, string op1, ref GridPanel MEPanel)
        {
            try
            {
                Com_MEMain            comMEMain1        = new Com_MEMain();
                IList <Com_Dimension> listComDimension1 = new List <Com_Dimension>();
                CaxSQL.GetCom_MEMain(comPartOperation, out comMEMain1);
                CaxSQL.GetListCom_Dimension(comMEMain1, out listComDimension1);

                //Com_MEMain comMEMain = session.QueryOver<Com_MEMain>()
                //                              .Where(x => x.comPartOperation == comPartOperation).SingleOrDefault<Com_MEMain>();

                //IList<Com_Dimension> listComDimension = session.QueryOver<Com_Dimension>()
                //                              .Where(x => x.comMEMain == comMEMain).List<Com_Dimension>();

                int MECount = -1;
                foreach (Com_Dimension i in listComDimension1)
                {
                    //2017.02.14判斷是否已經有插入過
                    bool IsExist = false;
                    for (int y = 0; y < MEPanel.Rows.Count; y++)
                    {
                        if (i.excelType == MEPanel.GetCell(y, 1).Value.ToString())
                        {
                            IsExist = true;
                        }
                    }
                    if (IsExist)
                    {
                        continue;
                    }

                    MECount++;
                    //由excelType取得廠區專用的Excel路徑
                    List <string> ExcelData = new List <string>();
                    status = GetExcelForm.GetMEExcelForm(i.excelType, out ExcelData);
                    if (!status)
                    {
                        return(false);
                    }

                    object[] o = new object[] { false, i.excelType, i.draftingVer, ""
                                                , string.Format("{0}_{1}_{2}資料夾"
                                                                , partNo
                                                                , cusVer
                                                                , opVer) };
                    MEPanel.Rows.Add(new GridRow(o));
                    MEPanel.GetCell(MECount, 0).Value      = false;
                    MEPanel.GetCell(MECount, 3).EditorType = typeof(GridComboBoxExEditControl);
                    GridComboBoxExEditControl singleCell = MEPanel.GetCell(MECount, 3).EditControl as GridComboBoxExEditControl;
                    //singleCell.Items.Add("");
                    foreach (string tempStr in ExcelData)
                    {
                        singleCell.Items.Add(tempStr);
                    }


                    if (singleCell.Items.Count == 1)
                    {
                        MEPanel.GetCell(MECount, 3).Value = singleCell.Items[0].ToString();
                    }
                    else
                    {
                        MEPanel.GetCell(MECount, 3).Value = "(雙擊)選擇表單";
                    }
                }

                #region 找OIS資料夾,並插入Panel
                string OISFolderPath = string.Format(@"{0}\{1}\{2}\{3}\{4}\{5}\{6}", OutputForm.EnvVariables.env_Task, cus, partNo, cusVer, opVer, "OP" + op1, "OIS");
                //string OISFolderPath = string.Format(@"{0}\{1}\{2}\{3}\{4}\{5}\{6}", CaxEnv.GetGlobaltekEnvDir() + "\\Task", cus, partNo, cusVer, opVer, "OP" + op1, "OIS");
                string[] OISFolder = Directory.GetFileSystemEntries(OISFolderPath, "*.pdf");
                foreach (string item in OISFolder)
                {
                    if (!item.Contains(".pdf"))
                    {
                        continue;
                    }
                    MECount++;
                    object[] o = new object[] { false, "PDF", Path.GetFileNameWithoutExtension(item), "", string.Format("{0}_{1}_{2}資料夾", partNo, cusVer, opVer) };
                    MEPanel.Rows.Add(new GridRow(o));
                }
                #endregion
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return(false);
            }
            return(true);
        }
        public static bool SetTEPanelData(Com_PartOperation comPartOperation, string cus, string partNo, string cusVer, string opVer, string op1, ref GridPanel TEPanel)
        {
            try
            {
                List <string>             ExcelData = new List <string>();
                GridComboBoxExEditControl singleCell;
                IList <Com_TEMain>        comTEMain = session.QueryOver <Com_TEMain>()
                                                      .Where(x => x.comPartOperation == comPartOperation).List <Com_TEMain>();
                int TECount = -1;
                foreach (Com_TEMain i in comTEMain)
                {
                    #region 由teExcelSrNo取得對應的ExcelType
                    Sys_TEExcel sysTEExcel = session.QueryOver <Sys_TEExcel>()
                                             .Where(x => x.teExcelSrNo == i.sysTEExcel.teExcelSrNo).SingleOrDefault <Sys_TEExcel>();
                    ExcelData = new List <string>();
                    status    = GetExcelForm.GetTEExcelForm(sysTEExcel.teExcelType, out ExcelData);
                    if (!status)
                    {
                        return(false);
                    }
                    #endregion

                    #region 插入Panel
                    TECount++;
                    object[] o = new object[] { false, sysTEExcel.teExcelType, i.ncGroupName, ""
                                                , string.Format("{0}_{1}_{2}資料夾"
                                                                , partNo
                                                                , cusVer
                                                                , opVer) };
                    TEPanel.Rows.Add(new GridRow(o));
                    TEPanel.GetCell(TECount, 0).Value      = false;
                    TEPanel.GetCell(TECount, 3).EditorType = typeof(GridComboBoxExEditControl);
                    singleCell = TEPanel.GetCell(TECount, 3).EditControl as GridComboBoxExEditControl;
                    //singleCell.Items.Add("");
                    foreach (string tempStr in ExcelData)
                    {
                        singleCell.Items.Add(tempStr);
                    }

                    if (singleCell.Items.Count == 1)
                    {
                        TEPanel.GetCell(TECount, 3).Value = singleCell.Items[0].ToString();
                    }
                    else
                    {
                        TEPanel.GetCell(TECount, 3).Value = "(雙擊)選擇表單";
                    }
                    #endregion
                }

                #region 取得ToolList的表單格式
                ExcelData = new List <string>();
                status    = GetExcelForm.GetTEExcelForm("ToolList", out ExcelData);
                if (!status)
                {
                    return(false);
                }
                #endregion

                foreach (Com_TEMain i in comTEMain)
                {
                    #region 找ToolList資料,並插入Panel
                    IList <Com_ToolList> comToolList = session.QueryOver <Com_ToolList>().Where(x => x.comTEMain == i).List();
                    if (comToolList.Count == 0)
                    {
                        continue;
                    }
                    else
                    {
                        TECount++;
                        object[] o = new object[] { false, "ToolList", i.ncGroupName, ""
                                                    , string.Format("{0}_{1}_{2}資料夾"
                                                                    , partNo
                                                                    , cusVer
                                                                    , opVer) };
                        TEPanel.Rows.Add(new GridRow(o));
                        TEPanel.GetCell(TECount, 0).Value      = false;
                        TEPanel.GetCell(TECount, 3).EditorType = typeof(GridComboBoxExEditControl);
                        singleCell = TEPanel.GetCell(TECount, 3).EditControl as GridComboBoxExEditControl;
                        //singleCell.Items.Add("");
                        foreach (string tempStr in ExcelData)
                        {
                            singleCell.Items.Add(tempStr);
                        }

                        if (singleCell.Items.Count == 1)
                        {
                            TEPanel.GetCell(TECount, 3).Value = singleCell.Items[0].ToString();
                        }
                        else
                        {
                            TEPanel.GetCell(TECount, 3).Value = "(雙擊)選擇表單";
                        }
                    }
                    #endregion
                }


                #region 找NC資料夾,並插入Panel
                string CAMFolderPath = string.Format(@"{0}\{1}\{2}\{3}\{4}\{5}\{6}", OutputForm.EnvVariables.env_Task, cus, partNo, cusVer, opVer, "OP" + op1, "CAM");
                //string CAMFolderPath = string.Format(@"{0}\{1}\{2}\{3}\{4}\{5}\{6}", CaxEnv.GetGlobaltekEnvDir() + "\\Task", cus, partNo, cusVer, opVer, "OP" + op1, "CAM");
                string[] NCFolder = Directory.GetDirectories(CAMFolderPath);
                foreach (string item in NCFolder)
                {
                    if (!item.Contains("NC"))
                    {
                        continue;
                    }
                    TECount++;
                    object[] o = new object[] { false, "NC程式", Path.GetFileNameWithoutExtension(item), ""
                                                , string.Format("{0}_{1}_{2}資料夾"
                                                                , partNo
                                                                , cusVer
                                                                , opVer) };
                    TEPanel.Rows.Add(new GridRow(o));
                }
                #endregion
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return(false);
            }
            return(true);
        }
        private void OK_Click(object sender, EventArgs e)
        {
            CaxLoading.RunDlg();
            string ExcelFolder = string.Format(@"{0}\{1}_{2}_{3}", Environment.GetFolderPath(Environment.SpecialFolder.Desktop), PartNoCombobox.Text, CusVerCombobox.Text, OpVerCombobox.Text);

            #region ME表單
            if (SuperTabControl.SelectedTab.Text == "ME")
            {
                //ME_檢查是否有選取表單格式
                status = CheckFun.CheckAll("ME", MEPanel);
                if (!status)
                {
                    CaxLoading.CloseDlg();
                    return;
                }

                //ME_建立桌面資料夾存放產生的Excel
                if (!Directory.Exists(ExcelFolder))
                {
                    Directory.CreateDirectory(ExcelFolder);
                }

                foreach (GridRow i in MEPanel.Rows)
                {
                    if (i.GetCell(1).Value.ToString() == "PDF" && ((bool)i.GetCell(0).Value) == true)
                    {
                        CopyNC.CopyOISPDFToDesktop(CusComboBox.Text, PartNoCombobox.Text, CusVerCombobox.Text, OpVerCombobox.Text, Op1Combobox.Text, i.GetCell(2).Value.ToString());
                    }
                }

                //ME_由選取的Op1與Excel表單,查出資料庫的Com_Dimension
                status = GetDataFromDatabase.GetDimensionData(Op1Combobox, out DicDimensionData);
                if (!status)
                {
                    CaxLoading.CloseDlg();
                    MessageBox.Show("由Panel資料查DicDimensionData時發生錯誤,請聯繫開發工程師");
                    this.Close();
                }
                //ME_開始輸出ME的Excel
                status = GetExcelForm.InsertDataToMEExcel(DicDimensionData, CusComboBox.Text, PartNoCombobox.Text, CusVerCombobox.Text, OpVerCombobox.Text, Op1Combobox.Text);
                if (!status)
                {
                    CaxLoading.CloseDlg();
                    MessageBox.Show("輸出ME的Excel時發生錯誤,請聯繫開發工程師");
                    this.Close();
                }
            }
            #endregion
            #region TE表單
            else if (SuperTabControl.SelectedTab.Text == "TE")
            {
                //TE_檢查是否有選取表單格式
                status = CheckFun.CheckAll("TE", TEPanel);
                if (!status)
                {
                    return;
                }
                //TE_建立桌面資料夾存放產生的Excel
                if (!Directory.Exists(ExcelFolder))
                {
                    Directory.CreateDirectory(ExcelFolder);
                }

                foreach (GridRow i in TEPanel.Rows)
                {
                    if (i.GetCell(1).Value.ToString() == "ShopDoc" && ((bool)i.GetCell(0).Value) == true)
                    {
                        #region ShopDoc
                        //TE_由選取的Op1與Excel表單,查出資料庫的Com_ShopDoc
                        status = GetDataFromDatabase.GetShopDocData(Op1Combobox, out DicShopDocData);
                        if (!status)
                        {
                            CaxLoading.CloseDlg();
                            MessageBox.Show("由Panel資料查DicShopDocData時發生錯誤,請聯繫開發工程師");
                            this.Close();
                        }
                        //TE_開始輸出TE的ShopDoc
                        status = GetExcelForm.InsertDataToShopDocExcel(DicShopDocData, CusComboBox.Text, PartNoCombobox.Text, CusVerCombobox.Text, OpVerCombobox.Text, Op1Combobox.Text);
                        if (!status)
                        {
                            CaxLoading.CloseDlg();
                            MessageBox.Show("輸出TE的ShopDoc時發生錯誤,請聯繫開發工程師");
                            this.Close();
                        }
                        #endregion
                    }
                    else if (i.GetCell(1).Value.ToString() == "ToolList" && ((bool)i.GetCell(0).Value) == true)
                    {
                        #region ToolList
                        //TE_由選取的Op1與Excel表單,查出資料庫的Com_ToolList
                        status = GetDataFromDatabase.GetToolListData(Op1Combobox, out DicToolListData);
                        if (!status)
                        {
                            CaxLoading.CloseDlg();
                            MessageBox.Show("由Panel資料查DicToolListData時發生錯誤,請聯繫開發工程師");
                            this.Close();
                        }
                        //TE_開始輸出TE的ToolList
                        status = GetExcelForm.InsertDataToTLExcel(DicToolListData, CusComboBox.Text, PartNoCombobox.Text, CusVerCombobox.Text, OpVerCombobox.Text, Op1Combobox.Text);
                        if (!status)
                        {
                            CaxLoading.CloseDlg();
                            MessageBox.Show("輸出TE的ToolList時發生錯誤,請聯繫開發工程師");
                            this.Close();
                        }
                        #endregion
                    }
                    else if (i.GetCell(1).Value.ToString() == "NC程式" && ((bool)i.GetCell(0).Value) == true)
                    {
                        #region NC程式
                        status = CopyNC.CopyNCToDesktop(CusComboBox.Text, PartNoCombobox.Text, CusVerCombobox.Text, OpVerCombobox.Text, Op1Combobox.Text, i.GetCell(2).Value.ToString());
                        if (!status)
                        {
                            MessageBox.Show("下載NC資料夾時發生錯誤,請聯繫開發工程師");
                            this.Close();
                        }
                        #endregion
                    }
                }
            }
            #endregion
            #region PE表單
            else if (SuperTabControl.SelectedTab.Text == "PE")
            {
                //PE_檢查是否有選取表單格式
                status = CheckFun.CheckAll("PE", PEPanel);
                if (!status)
                {
                    return;
                }
                //PE_建立桌面資料夾存放產生的Excel
                if (!Directory.Exists(ExcelFolder))
                {
                    Directory.CreateDirectory(ExcelFolder);
                }

                foreach (GridRow i in PEPanel.Rows)
                {
                    if (i.GetCell(1).Value.ToString() == "PFD" && ((bool)i.GetCell(0).Value) == true)
                    {
                        //PE_由選取的Row查出PFD資料
                        status = GetDataFromDatabase.GetPFDData(comPEMain, out DicPFDData);
                        if (!status)
                        {
                            CaxLoading.CloseDlg();
                            MessageBox.Show("由Panel資料查PFD Data時發生錯誤,請聯繫開發工程師");
                            this.Close();
                        }

                        //PE_開始輸出PFD的Excel
                        status = GetExcelForm.InsertDataToPFDExcel(PartNoCombobox.Text, DicPFDData);
                        if (!status)
                        {
                            CaxLoading.CloseDlg();
                            MessageBox.Show("輸出PFD的Excel時發生錯誤,請聯繫開發工程師");
                            this.Close();
                        }
                    }
                    else if (i.GetCell(1).Value.ToString() == "Control Plan" && ((bool)i.GetCell(0).Value) == true)
                    {
                        //PE_由選取的Row查出Control Plan資料
                        status = GetDataFromDatabase.GetControlPlanData(comPEMain, out DicCPData);
                        if (!status)
                        {
                            CaxLoading.CloseDlg();
                            MessageBox.Show("由Panel資料查Control Plan Data時發生錯誤,請聯繫開發工程師");
                            this.Close();
                        }

                        //PE_開始輸出Control Plan的Excel
                        status = GetExcelForm.InsertDataToCPExcel(DicCPData);
                        if (!status)
                        {
                            CaxLoading.CloseDlg();
                            MessageBox.Show("輸出Control Plan的Excel時發生錯誤,請聯繫開發工程師");
                            this.Close();
                        }
                    }
                }
            }
            #endregion
            #region 模.檢.治
            else if (SuperTabControl.SelectedTab.Text == "模.檢.治")
            {
                //模.檢.治_檢查是否有選取表單格式
                status = CheckFun.CheckAll("模.檢.治", FixInsPanel);
                if (!status)
                {
                    return;
                }
                //建立桌面資料夾存放產生的Excel
                if (!Directory.Exists(ExcelFolder))
                {
                    Directory.CreateDirectory(ExcelFolder);
                }
                foreach (GridRow i in OutputForm.FixInsPanel.Rows)
                {
                    if (i.GetCell(1).Value.ToString().Contains(".pdf") && (bool)i.GetCell(0).Value)
                    {
                        CopyNC.CopyFixOISPDFToDesktop(this.CusComboBox.Text, this.PartNoCombobox.Text, this.CusVerCombobox.Text, this.OpVerCombobox.Text, this.Op1Combobox.Text, i.GetCell(1).Value.ToString());
                    }
                }
                foreach (GridRow i in FixInsPanel.Rows)
                {
                    if (((bool)i.GetCell(0).Value) != true || i.GetCell(1).Value.ToString().Contains(".pdf") /*|| i.GetCell(1).Value.ToString() == "PDF"*/)
                    {
                        continue;
                    }
                    status = GetDataFromDatabase.GetFixInsData(Op1Combobox, i.GetCell(1).Value.ToString(), out DicFixDimensionData);
                    if (!status)
                    {
                        CaxLoading.CloseDlg();
                        MessageBox.Show("由Panel資料查DicFixDimensionData時發生錯誤");
                        this.Close();
                    }

                    status = GetExcelForm.InsertDataToFixInsExcel(DicFixDimensionData, CusComboBox.Text, PartNoCombobox.Text, CusVerCombobox.Text, OpVerCombobox.Text, Op1Combobox.Text);
                    if (!status)
                    {
                        CaxLoading.CloseDlg();
                        MessageBox.Show("輸出模.檢.治的Excel時發生錯誤,請聯繫開發工程師");
                        this.Close();
                    }
                }
            }
            #endregion
            CaxLoading.CloseDlg();
            MessageBox.Show("表單輸出完成!");
            //this.Close();
        }