private async void btnBrowse_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            grvData.Columns.Clear();
            txtRate.Text        = "";
            cboSheet.DataSource = null;
            OpenFileDialog ofd = new OpenFileDialog();

            if (chkAutoCheck.Checked)
            {
                OpenFileDialog openFileDialog1 = new OpenFileDialog();
                var            result          = openFileDialog1.ShowDialog();
                if (result == DialogResult.OK)
                {
                    btnBrowse.Text = openFileDialog1.FileName;
                }
                else if (result == DialogResult.Cancel)
                {
                    return;
                }

                try
                {
                    using (WaitDialogForm wait = new WaitDialogForm("", ""))
                    {
                        Task <DataSet> tasks = new Task <DataSet>(ReadData);                        // Load method vao Task
                        tasks.Start();                                                              // Cho Task chay
                        //frmSonLoading.ShowSplashScreen();
                        txtRate.Text = "Dang xu ly...";
                        DataSet ds         = await tasks;                                           // Lay data tra ve tu task
                        var     tablenames = GetTablenames(ds.Tables);

                        cboSheet.DataSource = tablenames;
                        //frmSonLoading.CloseForm();
                        //this.Focus(); this.Show();
                        if (tablenames.Count > 0)
                        {
                            cboSheet.SelectedIndex = 0;
                        }
                        txtRate.Text    = "Da xong!";
                        btnSave.Enabled = true;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    btnBrowse.Text      = ofd.FileName;
                    cboSheet.DataSource = null;
                    cboSheet.DataSource = TextUtils.ListSheetInExcel(ofd.FileName);
                    btnSave.Enabled     = true;
                }
            }
        }
Exemple #2
0
        private void btnBrowse_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                btnBrowse.Text       = ofd.FileName;
                cboStatus.DataSource = null;
                cboStatus.DataSource = TextUtils.ListSheetInExcel(ofd.FileName);
            }
        }
Exemple #3
0
        void ChangeModuleName()
        {
            using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang lấy mã mới"))
            {
                string        tableCodeFilePath = @"\\server\data2\Thietke\ISO\ISO.Thietke\TAI LIEU DAO TAO\TAI LIEU HO TRO PHONG THIET KE\TK09- Huong dan doi ma san pham TK\TK09-BM01 - Bang thay doi ma TK.xlsx";
                List <string> listSheet         = TextUtils.ListSheetInExcel(tableCodeFilePath);
                foreach (string sheetName in listSheet)
                {
                    if (!sheetName.ToUpper().StartsWith("TPAD."))
                    {
                        continue;
                    }

                    DataTable dt = TextUtils.ExcelToDatatableNoHeader(tableCodeFilePath, sheetName);
                    foreach (DataRow item in dt.Rows)
                    {
                        string newCode = item["F3"] == null ? "" : item["F3"].ToString();
                        if (newCode == "")
                        {
                            continue;
                        }

                        ModulesModel model = null;
                        try
                        {
                            model = (ModulesModel)ModulesBO.Instance.FindByCode(newCode);
                        }
                        catch (Exception)
                        {
                        }
                        if (model != null)
                        {
                            string oldName = item["F5"] == null ? "" : item["F5"].ToString();
                            string newName = item["F6"] == null ? "" : item["F6"].ToString();
                            string name    = (newName == "" ? oldName : newName);

                            model.Name = name;
                            ModulesBO.Instance.Update(model);
                        }
                    }
                }
            }
        }
Exemple #4
0
        private void btnBrowse_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                if (ofd.FileName.Contains("xls"))
                {
                    btnBrowse.Text       = ofd.FileName;
                    NgayLap              = File.GetCreationTime(ofd.FileName).ToString();
                    cboStatus.DataSource = null;
                    cboStatus.DataSource = TextUtils.ListSheetInExcel(ofd.FileName);
                }
                else
                {
                    MessageBox.Show("Không phải là file Excel");
                    return;
                }
            }
        }
Exemple #5
0
        private void btnBrowser_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();

            fbd.SelectedPath = @"D:\Thietke.Ck\TPAD.D";
            if (fbd.ShowDialog() == DialogResult.OK)
            {
                _modulePath       = fbd.SelectedPath;
                txtOldModule.Text = Path.GetFileNameWithoutExtension(_modulePath);

                using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang lấy mã mới"))
                {
                    string        tableCodeFilePath = @"\\server\data2\Thietke\ISO\ISO.Thietke\TAI LIEU DAO TAO\TAI LIEU HO TRO PHONG THIET KE\TK09- Huong dan doi ma san pham TK\TK09-BM01 - Bang thay doi ma TK.xlsx";
                    List <string> listSheet         = TextUtils.ListSheetInExcel(tableCodeFilePath);
                    foreach (string sheetName in listSheet)
                    {
                        DataTable dt = TextUtils.ExcelToDatatableNoHeader(tableCodeFilePath, sheetName);
                        try
                        {
                            DataRow[] drs = dt.Select("F4 = '" + txtOldModule.Text + "'");
                            if (drs.Length > 0)
                            {
                                string oldName = drs[0]["F5"] == null ? "" : drs[0]["F5"].ToString();
                                string newName = drs[0]["F6"] == null ? "" : drs[0]["F6"].ToString();
                                _newModuleName    = newName == "" ? oldName : newName;
                                txtNewModule.Text = drs[0]["F3"].ToString();
                                break;
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }
        }
        private void btnBrowse_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            grvData.Columns.Clear();
            OpenFileDialog ofd = new OpenFileDialog();

            if (chkAutoCheck.Checked)
            {
                OpenFileDialog openFileDialog1 = new OpenFileDialog();
                var            result          = openFileDialog1.ShowDialog();
                if (result == DialogResult.OK)
                {
                    btnBrowse.Text = openFileDialog1.FileName;
                }
                else if (result == DialogResult.Cancel)
                {
                    return;
                }

                try
                {
                    var stream = new FileStream(btnBrowse.Text, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

                    var sw = new Stopwatch();
                    sw.Start();

                    IExcelDataReader reader = ExcelReaderFactory.CreateReader(stream);

                    var openTiming = sw.ElapsedMilliseconds;

                    ds = reader.AsDataSet(new ExcelDataSetConfiguration()
                    {
                        UseColumnDataType  = false,
                        ConfigureDataTable = (tableReader) => new ExcelDataTableConfiguration()
                        {
                            UseHeaderRow = false
                        }
                    });
                    //toolStripStatusLabel1.Text = "Elapsed: " + sw.ElapsedMilliseconds.ToString() + " ms (" + openTiming.ToString() + " ms to open)";

                    var tablenames = GetTablenames(ds.Tables);

                    cboSheet.DataSource = tablenames;

                    if (tablenames.Count > 0)
                    {
                        cboSheet.SelectedIndex = 0;
                    }
                    btnSave.Enabled = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    btnBrowse.Text      = ofd.FileName;
                    cboSheet.DataSource = null;
                    cboSheet.DataSource = TextUtils.ListSheetInExcel(ofd.FileName);
                    btnSave.Enabled     = true;
                }
            }
        }