private void loadExcel() { this.dgvDirectoryFiles.AllowUserToAddRows = false; UpdateUIDelegate += UpdataUIStatus; //绑定更新任务状态的委托 TaskCallBack += Accomplish; //绑定完成任务要调用的委托 using (BackgroundWorker bw = new BackgroundWorker()) { bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted); bw.DoWork += new DoWorkEventHandler(bw_DoWork); bw.RunWorkerAsync(); } }
//完成任务时需要调用 private void Accomplish() { if (table != null) { this.dgvExcels.DataSource = table; changHeaderText(); Cursor = Cursors.Default; this.dgvExcels.AlternatingRowsDefaultCellStyle.BackColor = System.Drawing.ColorTranslator.FromHtml("#D3D3D3"); MessageBox.Show("加载完成"); } TaskCallBack -= Accomplish; //取消侦听注册事件,避免多次侦听 }
/// <summary> /// 系统环境的测试 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnStart_Click(object sender, EventArgs e) { int taskCount = 100; //任务量为10000 this.progressBar.Maximum = taskCount; this.progressBar.Value = 0; this.UpdateUIDelegate += UpdataUIStatus; //绑定更新任务状态的委托 this.TaskCallBack += Accomplish; //绑定完成任务要调用的委托 Thread thread = new Thread(new ParameterizedThreadStart(this.Write)); thread.IsBackground = true; thread.Start(taskCount); }
//完成任务时需要调用 private void Accomplish() { // Color controlColor = Control.DefaultBackColor; // SetControlColor(controlColor); //还可以进行其他的一些完任务完成之后的逻辑处理 // MessageBox.Show("接转完成OK"); if (table != null) { this.dgvExcels.DataSource = table; changHeaderText(); Cursor = Cursors.Default; this.dgvExcels.AlternatingRowsDefaultCellStyle.BackColor = System.Drawing.ColorTranslator.FromHtml("#D3D3D3"); MessageBox.Show("加载完成"); } TaskCallBack -= Accomplish; //取消侦听注册事件,避免多次侦听 }
private void loadExcel() { this.dgvExcels.DataSource = null; if (this.txtSelectedFilePath.Text.Length <= 0) { MessageBox.Show("请选择文件!"); Cursor = Cursors.Default; return; } if (this.cbSelectSheet.SelectedIndex == -1) { MessageBox.Show("请选择表名!"); this.cbSelectSheet.DroppedDown = true; Cursor = Cursors.Default; return; } string sheetname = this.cbSelectSheet.SelectedItem.ToString(); int headno = 0; Regex reg = new Regex("^[0-9]+$"); //正则表达式 检测是否数字 Match ma = reg.Match(txtSheetHead.Text.ToString()); if (!ma.Success) { headno = 0; txtSheetHead.Text = headno.ToString(); } if (Convert.ToInt32(txtSheetHead.Text) < 0 || txtSheetHead.Text == "") { headno = 0; } headno = Convert.ToInt32(txtSheetHead.Text); this.dgvExcels.ReadOnly = true; this.dgvExcels.AllowUserToAddRows = false; UpdateUIDelegate += UpdataUIStatus; //绑定更新任务状态的委托 TaskCallBack += Accomplish; //绑定完成任务要调用的委托 using (BackgroundWorker bw = new BackgroundWorker()) { bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted); bw.DoWork += new DoWorkEventHandler(bw_DoWork); bw.RunWorkerAsync(); } this.fileNameStr = filename; this.sheeTnameStr = sheetname; this.headNoStr = headno; }
//完成任务时需要调用 private void Accomplish() { if (this.dtFromWriteExcel != null) { if (this.dtFromLocalHost.Rows == null || this.dtFromLocalHost.Rows.Count <= 0) { return; } if (this.dtFormExcel.Rows == null || this.dtFormExcel.Rows.Count <= 0) { return; } if (this.dtnoEques.Rows == null || this.dtnoEques.Rows.Count <= 0) { return; } this.dgvExcels.DataSource = this.dtFromWriteExcel; this.dgvLocalHostDB.DataSource = this.dtFromLocalHost;; this.dgvCompareResult.DataSource = this.dtnoEques; this.dgvCompareResult.EnableHeadersVisualStyles = false; for (int i = 0; i < dgvCompareResult.Rows.Count; i++) { if (this.dgvCompareResult.Rows[i].Cells[8].Value.ToString() != "0") { //行背景色 // this.dgvCompareResult.Rows[i].DefaultCellStyle.BackColor = System.Drawing.ColorTranslator.FromHtml("#FF0000"); //单元格背景色 this.dgvCompareResult.Rows[i].Cells[8].Style.BackColor = System.Drawing.ColorTranslator.FromHtml("#FF0000"); } } this.dgvCompareResult.Refresh(); // changdgvExcelsHeaderText(); // changdgvLocalHostDBHeaderText(); // changdgvCompareResultHeaderText(); Cursor = Cursors.Default; this.dgvExcels.AlternatingRowsDefaultCellStyle.BackColor = System.Drawing.ColorTranslator.FromHtml("#D3D3D3"); this.dgvLocalHostDB.AlternatingRowsDefaultCellStyle.BackColor = System.Drawing.ColorTranslator.FromHtml("#D3D3D3"); // this.dgvCompareResult.AlternatingRowsDefaultCellStyle.BackColor = System.Drawing.ColorTranslator.FromHtml("#D3D3D3"); MessageBox.Show("加载完成"); } TaskCallBack -= Accomplish; //取消侦听注册事件,避免多次侦听 }
private void loadExcel() { this.dgvExcels.DataSource = null; this.dgvLocalHostDB.DataSource = null; this.dgvCompareResult.DataSource = null; if (this.txtSelectedFilePath.Text.Length <= 0) { MessageBox.Show("请选择文件!"); Cursor = Cursors.Default; return; } if (this.cbSelectSheet.SelectedIndex == -1) { MessageBox.Show("请选择表名!"); this.cbSelectSheet.DroppedDown = true; Cursor = Cursors.Default; return; } // DateTime current_day = this.dtpStarTime.Value; // DateTime first_day = current_day.AddDays( current_day.Day); // DateTime last_day = current_day.AddDays( current_day.Day); // this.dtpStarTime.Value = first_day; // this.dtpStopTime.Value = last_day; this.starTime = this.dtpStarTime.Value.ToString("yyyy-MM-dd"); this.stopTime = this.dtpStopTime.Value.ToString("yyyy-MM-dd"); string sheetname = this.cbSelectSheet.SelectedItem.ToString(); int headno = 0; /* * // if(textHeadno.Text) * Regex reg = new Regex("^[0-9]+$"); //正则表达式 检测是否数字 * Match ma = reg.Match(txtSheetHead.Text.ToString()); * if (!ma.Success) * { * // MessageBox.Show("部门编码不是数字!"); * // return; * headno = 0; * txtSheetHead.Text = headno.ToString(); * } * * if (Convert.ToInt32(txtSheetHead.Text) < 0 || txtSheetHead.Text == "") * { * headno = 0; * } * headno = Convert.ToInt32(txtSheetHead.Text); * */ this.dgvExcels.ReadOnly = true; this.dgvExcels.AllowUserToAddRows = false; UpdateUIDelegate += UpdataUIStatus; //绑定更新任务状态的委托 TaskCallBack += Accomplish; //绑定完成任务要调用的委托 using (BackgroundWorker bw = new BackgroundWorker()) { bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted); bw.DoWork += new DoWorkEventHandler(bw_DoWork); bw.RunWorkerAsync(); } this.fileNameStr = filename; this.sheeTnameStr = sheetname; this.headNoStr = headno; }
private void loadExcel() { if (this.org == "SAA") { this.rbOrgSAA.Checked = true; } else if (this.org == "TOP") { this.rbOrgTOP.Checked = true; } else { // this.gbLoad.Visible = true; this.btnLoadExcel.Enabled = true; MessageBox.Show("请先设置默认厂区或选择厂区"); return; } if (this.subinv == "") { //this.gbLoad.Visible = true; this.subinv = this.cbSubinv.Text.Trim().ToUpper(); } else { bool isSubinv = false; for (int i = 0; i < this.cbSubinv.Items.Count; i++) { if (this.subinv == this.cbSubinv.Items[i].ToString()) { isSubinv = true; this.btnLoadExcel.Enabled = true; break; } } if (!isSubinv) { MessageBox.Show("配置的仓库代号" + this.subinv + "不正确! 请修改后重新运行本程式"); return; } // this.cbSubinv.Items.Clear(); // this.cbSubinv.Items.Add(this.subinv); this.cbSubinv.SelectedItem = this.subinv; } this.dgvExcels.DataSource = null; if (!File.Exists(filename)) { this.gbLoad.Visible = true; if (this.txtSelectedFilePath.Text.Length <= 0) { MessageBox.Show("请选择文件!"); Cursor = Cursors.Default; this.btnLoadExcel.Enabled = true; this.txtSelectedFilePath.Enabled = true; this.txtSelectedFilePath.Text = ""; return; } } else { this.txtSelectedFilePath.Enabled = false; this.txtSelectedFilePath.Text = filename; } string[] sheetnames = xiaomingCommom.getExcelSheetSum(filename); for (int i = 0; i < sheetnames.Length; i++) { if (sheetnames[i] == this.sheetname) { // this.gbLoad.Visible = true; isSheet = true; this.cbSelectSheet.Enabled = false; this.cbSelectSheet.Text = this.sheetname; this.cbSelectSheet.Items.Clear(); this.cbSelectSheet.Items.Add(sheetnames[i]);//添加表名 this.cbSelectSheet.SelectedIndex = i; break; } } // string sheetname =""; if (!isSheet) { this.gbLoad.Visible = true; this.cbSelectSheet.Enabled = true; this.cbSelectSheet.Text = ""; this.cbSelectSheet.Items.Clear(); for (int i = 0; i < sheetnames.Length; i++) { this.cbSelectSheet.Items.Add(sheetnames[i]); //添加表名 } if (this.cbSelectSheet.SelectedIndex == -1) { MessageBox.Show("请选择表名!"); this.cbSelectSheet.DroppedDown = true; this.btnLoadExcel.Enabled = true; return; } } this.sheetname = this.cbSelectSheet.SelectedItem.ToString(); if (this.sheetname == "") { this.gbLoad.Visible = true; MessageBox.Show("请选择表名!"); this.cbSelectSheet.DroppedDown = true; this.btnLoadExcel.Enabled = true; isSheet = false; Cursor = Cursors.Default; return; } int headno = 0; Regex reg = new Regex("^[0-9]+$"); //正则表达式 检测是否数字 Match ma = reg.Match(txtSheetHead.Text.ToString()); if (!ma.Success) { this.gbLoad.Visible = true; headno = 0; txtSheetHead.Text = headno.ToString(); } if (Convert.ToInt32(txtSheetHead.Text) < 0 || txtSheetHead.Text == "") { headno = 0; } headno = Convert.ToInt32(txtSheetHead.Text); this.dgvExcels.ReadOnly = true; this.dgvExcels.AllowUserToAddRows = false; UpdateUIDelegate += UpdataUIStatus; //绑定更新任务状态的委托 TaskCallBack += Accomplish; //绑定完成任务要调用的委托 using (BackgroundWorker bw = new BackgroundWorker()) { bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted); bw.DoWork += new DoWorkEventHandler(bw_DoWork); bw.RunWorkerAsync(); } this.fileNameStr = filename; this.sheeTnameStr = this.sheetname; this.headNoStr = headno; }
private void loadExcel() { this.dgvExcels.DataSource = null; if (this.txtSelectedFilePath.Text.Length <= 0) { MessageBox.Show("请选择文件!"); Cursor = Cursors.Default; return; } if (this.cbSelectSheet.SelectedIndex == -1) { MessageBox.Show("请选择表名!"); this.cbSelectSheet.DroppedDown = true; Cursor = Cursors.Default; return; } string sheetname = this.cbSelectSheet.SelectedItem.ToString(); // bool yesno = false;//第一行是否数据列名 //// if (radYES.Checked) // { // yesno = true; // } // else if (radNO.Checked) // { // yesno = false; // } int headno = 0; // if(textHeadno.Text) Regex reg = new Regex("^[0-9]+$"); //正则表达式 检测是否数字 Match ma = reg.Match(txtSheetHead.Text.ToString()); if (!ma.Success) { // MessageBox.Show("部门编码不是数字!"); // return; headno = 0; txtSheetHead.Text = headno.ToString(); } if (Convert.ToInt32(txtSheetHead.Text) < 0 || txtSheetHead.Text == "") { headno = 0; } headno = Convert.ToInt32(txtSheetHead.Text); this.dgvExcels.ReadOnly = true; this.dgvExcels.AllowUserToAddRows = false; UpdateUIDelegate += UpdataUIStatus; //绑定更新任务状态的委托 TaskCallBack += Accomplish; //绑定完成任务要调用的委托 using (BackgroundWorker bw = new BackgroundWorker()) { bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted); bw.DoWork += new DoWorkEventHandler(bw_DoWork); bw.RunWorkerAsync(); } this.fileNameStr = filename; this.sheeTnameStr = sheetname; this.headNoStr = headno; /* * table = BgtnPO.ExcelRead(filename, sheetname, headno); * * if (table != null) * { * this.dgvExcels.DataSource = table; * changHeaderText(); * Cursor = Cursors.Default; * this.dgvExcels.AlternatingRowsDefaultCellStyle.BackColor = System.Drawing.ColorTranslator.FromHtml("#D3D3D3"); * MessageBox.Show("加载完成"); * } */ }