Esempio n. 1
0
        public static bool loadBosaReport()
        {
            if (GlobalData.initSetting.BOSAREPORT.Trim().Length == 0)
            {
                return(false);
            }
            Thread t = new Thread(new ThreadStart(() => {
                //Load data from excel to dataGrid
                DataTable dt = new DataTable();
                dt           = BosaReport.readData();

                //Import data from dataGrid to Sql Server (using Sql Bulk)
                int counter             = 0;
                GlobalData.listBosaInfo = new List <bosainfo>();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string _bosaSN = "", _Ith = "", _Vbr = "";
                    _bosaSN        = dt.Rows[i].ItemArray[0].ToString().Trim();
                    if (_bosaSN.Length > 0 && BaseFunctions.bosa_SerialNumber_Is_Correct(_bosaSN) == true)
                    {
                        _Ith = dt.Rows[i].ItemArray[1].ToString().Trim();
                        _Vbr = dt.Rows[i].ItemArray[5].ToString().Trim();

                        bosainfo _bs = new bosainfo()
                        {
                            BosaSN = _bosaSN, Ith = _Ith, Vbr = _Vbr
                        };
                        GlobalData.listBosaInfo.Add(_bs);
                        counter++;
                    }
                }
            }));

            t.IsBackground = true;
            t.Start();
            return(true);
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Button b    = sender as Button;
            string _txt = b.Content.ToString();

            b.Content = "Please wait...";

            Thread t = new Thread(new ThreadStart(() => {
                //***************************************************SQL SERVER
                ////Load data from excel to dataGrid
                //DataTable dt = new DataTable();
                //importInfo.STATUS = "Loading data from excel to datagrid...";
                //dt = BosaReport.readData();

                ////Display data to dataGrid
                //Dispatcher.Invoke(new Action(() => {
                //    this.datagrid.ItemsSource = dt.DefaultView;
                //    importInfo.PROGRESSMAX = dt.Rows.Count - 1;
                //    b.Content = _txt;
                //}));

                ////Import data from dataGrid to Sql Server (using Sql Bulk)
                //importInfo.STATUS = "Importing data from datagrid to Sql Server...";
                //int counter = 0;
                //for (int i = 0; i < dt.Rows.Count; i++) {
                //    string _bosaSN = "", _Ith = "", _Vbr = "";
                //    _bosaSN = dt.Rows[i].ItemArray[0].ToString().Trim();
                //    if (_bosaSN.Length > 0 && BaseFunctions.bosa_SerialNumber_Is_Correct(_bosaSN) == true) {
                //        _Ith = dt.Rows[i].ItemArray[1].ToString().Trim();
                //        _Vbr = dt.Rows[i].ItemArray[18].ToString().Trim();

                //        bosainfo _bs = new bosainfo() { BosaSN = _bosaSN, Ith = _Ith, Vbr = _Vbr };
                //        if (GlobalData.sqlServer.insertData(_bs)) counter++;
                //        importInfo.PROGRESSVALUE += 1;
                //    }
                //}
                //importInfo.PROGRESSVALUE = importInfo.PROGRESSMAX;
                //importInfo.STATUS = string.Format("Finished.The Bosa SN already imported {0}/{1}.", counter, dt.Rows.Count);

                //***************************************************NO SQL SERVER

                //Load data from excel to dataGrid
                DataTable dt      = new DataTable();
                importInfo.STATUS = "Loading data from excel to datagrid...";
                dt = BosaReport.readData();

                //Display data to dataGrid
                Dispatcher.Invoke(new Action(() => {
                    this.datagrid.ItemsSource = dt.DefaultView;
                    importInfo.PROGRESSMAX    = dt.Rows.Count - 1;
                    b.Content = _txt;
                }));

                //Import data from dataGrid to Sql Server (using Sql Bulk)
                importInfo.STATUS       = "Importing data from datagrid to Sql Server...";
                int counter             = 0;
                GlobalData.listBosaInfo = new List <bosainfo>();

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string _bosaSN = "", _Ith = "", _Vbr = "";
                    _bosaSN        = dt.Rows[i].ItemArray[0].ToString().Trim();
                    if (_bosaSN.Length > 0 && BaseFunctions.bosa_SerialNumber_Is_Correct(_bosaSN) == true)
                    {
                        _Ith = dt.Rows[i].ItemArray[1].ToString().Trim();
                        _Vbr = dt.Rows[i].ItemArray[5].ToString().Trim();

                        bosainfo _bs = new bosainfo()
                        {
                            BosaSN = _bosaSN, Ith = _Ith, Vbr = _Vbr
                        };
                        GlobalData.listBosaInfo.Add(_bs);
                        counter++;
                        importInfo.PROGRESSVALUE += 1;
                    }
                }
                importInfo.PROGRESSVALUE = importInfo.PROGRESSMAX;
                importInfo.STATUS        = string.Format("Finished.The Bosa SN already imported {0}/{1}.", counter, dt.Rows.Count - 1);
            }));

            t.IsBackground = true;
            t.Start();
        }