コード例 #1
0
        /// <summary>
        /// 二级机构读取
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 读取ToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            FilterInstitute form = (FilterInstitute)GetForm(typeof(FilterInstitute));

            openFileDialog.Filter = "Text File(*.csv)|*.csv";
            if (DialogResult.OK == openFileDialog.ShowDialog())
            {
                #region 委托
                Func <DataGridView, DataTable> getDataTableFromGridView = (dgvInstituteDataTable) =>
                {
                    return(form.GetDataTableFromGridView(dgvInstituteDataTable));
                };
                Action <DataTable> bingDataGridViewDataSource = (normtable) =>
                {
                    form.BindInstituteDataTable(normtable);
                };
                Action showResult = () =>
                {
                    form.ShowResult();
                };
                Action <string> addLog = (content) =>
                {
                    form.AddLog(content);
                };
                Func <DataTable, DataTable, DataTable> merge = (maintable, updatetable) =>
                {
                    return(form.Merge(maintable, updatetable));
                };
                #endregion
                Task task = new Task(() =>
                {
                    DataTable NormTable = NormalizeTable.Import(openFileDialog.FileName);
                    this.BeginInvoke(addLog, "加载规范表数据:" + NormTable.Rows.Count.ToString() + "条");
                    if (NormTable.Rows.Count > 0)
                    {
                        if (form.dgvInstituteDataTable.Rows.Count > 0)
                        {
                            DataTable dgvTable = (DataTable)this.Invoke(getDataTableFromGridView, form.dgvInstituteDataTable);
                            // NormTable.Merge(dgvTable);
                            NormTable = (DataTable)this.Invoke(merge, dgvTable, NormTable);
                        }
                        form.tempInstituteDataTable = NormTable.Copy();
                        this.BeginInvoke(bingDataGridViewDataSource, NormTable);
                    }
                });

                form.isOpen        = true;
                form.UseWaitCursor = true;
                task.Start();
                task.ContinueWith(task1 =>
                {
                    this.Invoke(showResult);
                });
            }
        }
コード例 #2
0
        //private void btnSaveNormTable_Click_1(object sender, EventArgs e)
        //{
        //    if (dgvInstituteDataTable == null || dgvInstituteDataTable.Rows.Count == 0)
        //    {
        //        MessageBox.Show("没有要保存的规范数据");
        //        return;
        //    }
        //    saveFileDialog1.Filter = "Text File(*.csv)|*.csv";
        //    DialogResult dialogresult = saveFileDialog1.ShowDialog();

        //    if (dialogresult == DialogResult.OK)
        //    {
        //        Tuple<string, int> result = NormalizeTable.Import(dgvInstituteDataTable);
        //        using (StreamWriter writer = new StreamWriter(saveFileDialog1.FileName, false, Encoding.UTF8))
        //        {
        //            writer.Write(result.Item1);
        //            writer.Flush();
        //            writer.Close();
        //        }
        //        AddLog("保存规范表数据:" + result.Item2.ToString());
        //        MessageBox.Show("规范表保存成功!");
        //    }
        //}
        #endregion
        private void btnReadNormTable_Click(object sender, EventArgs e)
        {
            openFileDialog_NormTable.Filter = "Text File(*.csv)|*.csv";
            DialogResult dialogresult = openFileDialog_NormTable.ShowDialog();

            if (dialogresult == DialogResult.OK && !string.IsNullOrEmpty(openFileDialog_NormTable.FileName))
            {
                #region 委托
                Func <DataGridView, DataTable> getDataTableFromGridView = (dgvInstituteDataTable) =>
                {
                    return(GetDataTableFromGridView(dgvInstituteDataTable));
                };
                Action <DataTable> bingDataGridViewDataSource = (normtable) =>
                {
                    BindInstituteDataTable(normtable);
                };
                Action showResult = () =>
                {
                    ShowResult();
                };
                Action <string> addLog = (content) =>
                {
                    AddLog(content);
                };
                Func <DataTable, DataTable, DataTable> merge = (maintable, updatetable) =>
                {
                    return(Merge(maintable, updatetable));
                };
                #endregion
                Task task = new Task(() =>
                {
                    DataTable NormTable = NormalizeTable.Import(openFileDialog_NormTable.FileName);
                    this.BeginInvoke(addLog, "加载规范表数据:" + NormTable.Rows.Count.ToString() + "条");
                    if (NormTable.Rows.Count > 0)
                    {
                        if (dgvInstituteDataTable.Rows.Count > 0)
                        {
                            DataTable dgvTable = (DataTable)this.Invoke(getDataTableFromGridView, dgvInstituteDataTable);
                            // NormTable.Merge(dgvTable);
                            NormTable = (DataTable)this.Invoke(merge, dgvTable, NormTable);
                        }
                        this.BeginInvoke(bingDataGridViewDataSource, NormTable);
                    }
                });

                isOpen        = true;
                UseWaitCursor = true;
                task.Start();
                task.ContinueWith(task1 =>
                {
                    this.Invoke(showResult);
                });
            }
        }