Пример #1
0
        private void sbCheckInvmb_Click(object sender, EventArgs e)
        {
            string[] tmpString = new string[3];
            tmpString[0] = "123";
            tmpString[1] = "1231";
            tmpString[2] = "1234";

            bool result = MvDbDao.checkData_hasIllegalItemInInvmb(tmpString);

            MessageBox.Show("resut is " + result);
        }
Пример #2
0
        private void sbParserRdDiffBomExcel_Click(object sender, EventArgs e)
        {
            gridControl1.DataSource = null;
            gridControl1.DataBindings.Clear();
            gridControl1.RefreshDataSource();
            gridView1.Columns.Clear();
            gridView1.RefreshData();

            Workbook workbook = new Workbook();
            bool     isLoad   = false;
            //isLoad = workbook.LoadDocument(@"D:\\1.xlsx", DocumentFormat.Xlsx);
            //Console.WriteLine("result = " + isLoad);

            ArrayList itemList = new ArrayList();


            DataTable dt = new DataTable();

            using (FileStream stream = new FileStream(@"D:\99_TempForProgram\\差異料清單表_OK_AOI4.0 R167.xlsx", FileMode.Open))
            {
                isLoad = workbook.LoadDocument(stream, DocumentFormat.Xlsx);
                if (isLoad == false)
                {
                    MessageBox.Show("請確認EXCEL檔案是否已解密");
                    return;
                }

                // 判斷Sheet只能有一個, 等要release再打開
                //if(workbook.Sheets.Count != 1)
                //{
                //    MessageBox.Show(string.Format("請確認EXCEL檔案內只有一個sheet{0}該檔現有個sheets : {1}", Environment.NewLine, workbook.Sheets.Count));
                //    return;
                //}

                // 定義column
                dt = new DataTable();
                dt.Columns.Add("Item");
                dt.Columns.Add("Add");
                dt.Columns.Add("Delete");
                dt.Columns.Add("Change");
                dt.Columns.Add("OrgA8");
                dt.Columns.Add("NewA8");
                dt.Columns.Add("A8Name");
                dt.Columns.Add("OrgCount");
                dt.Columns.Add("NewCount");
                dt.Columns.Add("IsNew");
                dt.Columns.Add("IsRDConfirm");
                dt.Columns.Add("Owner");
                dt.Columns.Add("Module");
                dt.Columns.Add("Remark");
                // 取得sheet 內容
                Worksheet sheet = workbook.Worksheets[workbook.Sheets.Count - 1];


                Range range = sheet.GetUsedRange();
                Console.WriteLine("column count = " + range.ColumnCount);
                Console.WriteLine("row count = " + range.RowCount);

                // 取得欄位標題資訊
                int j = 1;
                textBox1.Text = sheet.GetCellValue(1, 1).ToString();
                textBox2.Text = sheet.GetCellValue(1, 2).ToString();
                textBox3.Text = sheet.GetCellValue(j, 3).ToString();
                textBox4.Text = sheet.GetCellValue(j, 4).ToString();
                textBox5.Text = sheet.GetCellValue(j, 5).ToString();
                textBox6.Text = sheet.GetCellValue(j, 6).ToString();

                // 取得欄位修改內容
                j = 2;
                for (int i = 9; i <= range.RowCount; i++)
                {
                    if (sheet.GetCellValue(j, i).IsEmpty == true)
                    {
                        break;
                    }
                    j = 1;
                    DataRow dr = dt.NewRow();
                    dr["Item"]   = sheet.GetCellValue(j, i);
                    dr["Add"]    = sheet.GetCellValue(++j, i);
                    dr["Delete"] = sheet.GetCellValue(++j, i);
                    dr["Change"] = sheet.GetCellValue(++j, i);
                    dr["OrgA8"]  = sheet.GetCellValue(++j, i);

                    if (dr["OrgA8"].ToString().Equals("N/A") == false)
                    {
                        itemList.Add(dr["OrgA8"].ToString());
                    }

                    dr["NewA8"] = sheet.GetCellValue(++j, i);
                    if (dr["NewA8"].ToString().Equals("N/A") == false)
                    {
                        itemList.Add(dr["NewA8"].ToString());
                    }

                    dr["A8Name"]      = sheet.GetCellValue(++j, i);
                    dr["OrgCount"]    = sheet.GetCellValue(++j, i);
                    dr["NewCount"]    = sheet.GetCellValue(++j, i);
                    dr["IsNew"]       = sheet.GetCellValue(++j, i);
                    dr["IsRDConfirm"] = sheet.GetCellValue(++j, i);
                    dr["Owner"]       = sheet.GetCellValue(++j, i);
                    dr["Module"]      = sheet.GetCellValue(++j, i);
                    dr["Remark"]      = sheet.GetCellValue(++j, i);
                    dt.Rows.Add(dr);
                }
            }


            gridControl1.DataSource            = dt;
            gridView1.OptionsBehavior.Editable = false;
            gridView1.OptionsBehavior.ReadOnly = true;
            gridView1.RefreshData();


            // 判斷品號是否有不存在DB的資料, 如果有, 直接跳出訊息說明
            bool result = MvDbDao.checkData_hasIllegalItemInInvmb((string[])itemList.ToArray(typeof(string)));

            MessageBox.Show("resut is " + result);
        }