Пример #1
0
        public void DoTest2()
        {
            var gdt   = new GenerateDataTable();
            var table = gdt.GetNewTable(1000000);

            Stopwatch sw = new Stopwatch();

            sw.Start();
            var filename = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".xlsx");

            LargeExport(filename, table);
            sw.Stop();
            Console.WriteLine($"Save used {sw.ElapsedMilliseconds} ms");
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
        }
        public void DoTest()
        {
            var gdt = new GenerateDataTable();
            var dt  = gdt.GetNewTable();

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            var filename = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".xlsx");

            //创建文件
            FileStream file = new FileStream(filename, FileMode.CreateNew, FileAccess.Write);

            //以指定的字符编码向指定的流写入字符
            StreamWriter sw = new StreamWriter(file, Encoding.UTF8);

            //写入标题
            for (int i = 0; i < dt.Columns.Count; i++)
            {
                sw.Write(dt.Columns[i].ColumnName.ToString() + "\t");
            }
            //加入换行字符串
            sw.Write(Environment.NewLine);

            //写入内容
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    sw.Write(dt.Rows[i][j].ToString() + "\t");
                }
                sw.Write(Environment.NewLine);
            }

            sw.Flush();
            file.Flush();

            sw.Close();
            sw.Dispose();

            file.Close();
            file.Dispose();

            stopwatch.Stop();
            Console.WriteLine($"Save used {stopwatch.ElapsedMilliseconds} ms");
        }
        public void DoTest_GenerateThenAttach()
        {
            var gdt   = new GenerateDataTable();
            var table = gdt.GetNewTable(1);

            Stopwatch sw = new Stopwatch();

            sw.Start();
            var filePath    = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".xlsx");
            int looRowCount = 8000;

            using (var workbook = new XLWorkbook())
            {
                workbook.Worksheets.Add(gdt.GetTableWithNRows(table, looRowCount), table.TableName);
                workbook.SaveAs(filePath);
            }

            int i    = 2;
            int loop = 300000 / looRowCount;

            while (i <= loop)
            {
                using (var workbook = new XLWorkbook(filePath))
                {
                    IXLWorksheet Worksheet       = workbook.Worksheet(table.TableName);
                    int          NumberOfLastRow = Worksheet.LastRowUsed().RowNumber();
                    IXLCell      CellForNewData  = Worksheet.Cell(NumberOfLastRow + 1, 1);
                    CellForNewData.InsertTable(gdt.GetTableWithNRows(table, looRowCount));
                    if (i == loop)
                    {
                        Worksheet.Columns().AdjustToContents();
                    }
                    workbook.Save();
                    Console.WriteLine($"Loop {i} work done...");
                    i++;
                }

                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
            }

            sw.Stop();
            Console.WriteLine($"Save all rows used {sw.ElapsedMilliseconds} ms");
        }
        public void DoTest_GenerateDirectly()
        {
            var gdt   = new GenerateDataTable();
            var table = gdt.GetNewTable();

            Stopwatch sw = new Stopwatch();

            sw.Start();
            using (var workbook = new XLWorkbook())
            {
                var filePath  = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".xlsx");
                var worksheet = workbook.Worksheets.Add(table, table.TableName);
                sw.Stop();
                Console.WriteLine($"Add workbook used {sw.ElapsedMilliseconds} ms");
                sw.Restart();
                workbook.SaveAs(filePath);
            }
            sw.Stop();
            Console.WriteLine($"Save used {sw.ElapsedMilliseconds} ms");
        }
        protected override void OnTextChanged(EventArgs e) //Doesn't call the base so no wiring up this event for you.
        {
            try
            {
                //Run a few checks to make sure there should be any "suggesting" going on.
                if (m_bTextChangedInternal)         //If the text is being changed by another member of this class do nothing
                {
                    m_bTextChangedInternal = false; //It will only be getting changed once internally, next time do something.
                    return;
                }

                if (!Suggest)
                {
                    return;
                }
                if (SelectionStart < this.Text.Length)
                {
                    return;
                }
                if (string.IsNullOrWhiteSpace(this.Text))
                {
                    if (DataInter.Rows.Count != DataSourceSettig.Rows.Count)
                    {
                        this.DataSourceSettig = DataInter;
                    }
                    this.DroppedDown = false;
                    return;
                }

                int iOffset = 0;
                if ((m_kcLastKey == Keys.Back) || (m_kcLastKey == Keys.Delete))//Obviously we aren't going to find anything when they push Backspace or Delete
                {
                    UpdateIndex();
                    return;
                }
                if (m_slSuggestions == null || this.Text.Length < 1)
                {
                    return;
                }

                //Put the current text into temp storage
                string sText;
                sText = this.Text;
                string sOriginal = sText;
                sText = sText.ToUpper();
                int    iLength = sText.Length;
                string sFound  = null;
                int    index   = 0;

                // start the filter
                if (this.Text.Length > 2 && string.IsNullOrWhiteSpace(Strings.Right(this.Text, 1)))
                {
                    if (ExisInCurrentList(this.Text))
                    {
                        return;
                    }
                    string ColumnViewName = this.Columns[m_iViewColumn].Name;
                    //generate new data table
                    DataTable dtTemp = new GenerateDataTable(m_dtData.Columns);
                    DataTable dt1    = new GenerateDataTable(m_dtData.Columns);
                    DataTable dt2    = new GenerateDataTable(m_dtData.Columns);
                    DataTable dt3    = new GenerateDataTable(m_dtData.Columns);

                    var spliter = GetSpliter.GenerateSpliter(this.Text);
                    if (spliter.IsSucces)
                    {
                        switch (spliter.Spliter.Count())
                        {
                        case 1:
                            var datafilter = DataInter.Select(string.Format("{0} Like '%{1}%'", ColumnViewName, spliter.Spliter[0]));
                            if (datafilter != null)
                            {
                                foreach (var item in datafilter)
                                {
                                    dtTemp.ImportRow(item);
                                }
                            }
                            break;

                        case 2:
                            var datafilter1 = DataInter.Select(string.Format("{0} Like '%{1}%'", ColumnViewName, spliter.Spliter[0]));
                            if (datafilter1 != null)
                            {
                                foreach (var item in datafilter1)
                                {
                                    dt1.ImportRow(item);
                                }
                            }
                            var datafilter2 = dt1.Select(string.Format("{0} Like '%{1}%'", ColumnViewName, spliter.Spliter[1]));
                            if (datafilter2 != null)
                            {
                                foreach (var item in datafilter2)
                                {
                                    dtTemp.ImportRow(item);
                                }
                            }
                            break;

                        case 3:

                            break;

                        default:

                            break;
                        }
                    }
                    m_bTextChangedInternal = true;
                    isController           = true;
                    this.DroppedDown       = false;
                    this.DataSourceSettig  = dtTemp;
                    UpdateIndex();
                    m_iSelectedIndex       = -1;
                    SelectedIndex          = -1;
                    isController           = false;
                    Text                   = sOriginal;
                    m_bTextChangedInternal = false;
                    base.OnSelectedIndexChanged(new EventArgs());
                    this.SelectionStart  = sOriginal.Length;
                    this.SelectionLength = 0;
                    this.DroppedDown     = true;

                    return;
                }

                if (DataInter.Rows.Count != DataSourceSettig.Rows.Count)
                {
                    this.DataSourceSettig = DataInter;
                    UpdateIndex();
                }
                //see if what is currently in the text box matches anything in the string list
                for (index = 0; index < m_slSuggestions.Count; index++)
                {
                    string sTemp = m_slSuggestions[index].ToUpper();
                    if (sTemp.Length >= sText.Length)
                    {
                        if (sTemp.IndexOf(sText, 0, sText.Length) > -1)
                        {
                            sFound = m_slSuggestions[index];
                            break;
                        }
                    }
                }
                //see if what is currently in the text box matches anything in the string list
                if (sFound != null)
                {
                    m_bTextChangedInternal = true;
                    if (DropDownOnSuggestion && !DroppedDown)
                    {
                        m_bTextChangedInternal = true;
                        string sTempText = Text;
                        this.DroppedDown       = true;
                        Text                   = sTempText;
                        m_bTextChangedInternal = false;
                    }
                    if (this.Text != sFound)
                    {
                        this.Text           += sFound.Substring(iLength);
                        this.SelectionStart  = iLength + iOffset;
                        this.SelectionLength = this.Text.Length - iLength + iOffset;
                        m_iSelectedIndex     = index;
                        SelectedIndex        = index;
                        base.OnSelectedIndexChanged(new EventArgs());
                    }
                    else
                    {
                        UpdateIndex();
                        this.SelectionStart  = iLength;
                        this.SelectionLength = 0;
                    }
                }
                else
                {
                    m_bTextChangedInternal = true;
                    m_iSelectedIndex       = -1;
                    SelectedIndex          = -1;
                    Text = sOriginal;
                    m_bTextChangedInternal = false;
                    base.OnSelectedIndexChanged(new EventArgs());
                    this.SelectionStart  = sOriginal.Length;
                    this.SelectionLength = 0;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message + "\r\nIn ColumnComboBox.OnTextChanged(EventArgs).");
            }
        }