示例#1
0
        private void btn_excel_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();

            //return;
            if (!is3d)
            {
                dt = ToDataTable(lotterys);
                Lottery.BulkCopy("Lottery_Data", dt);
            }
            else
            {
                dt = ToDataTable(l3ds);
                Lottery.BulkCopy("[3D]", dt);
            }
            string filetime = DateTime.Now.ToString("yyyyMMddmm");
            string _webpath = AppDomain.CurrentDomain.BaseDirectory + "\\Excel\\Lottery";

            if (!Directory.Exists(_webpath))
            {
                Directory.CreateDirectory(_webpath);
            }
            string filename = "Lottery_" + filetime + ".xls";
            string path     = _webpath + "\\" + filename;

            try
            {
                MemoryStream ms       = new MemoryStream();
                IWorkbook    workbook = new HSSFWorkbook();
                ISheet       sheet    = workbook.CreateSheet("数据1");
                //CellRangeAddress四个参数为:起始行,结束行,起始列,结束列
                IRow row1 = sheet.CreateRow(0);

                row1.CreateCell(0).SetCellValue("AA");
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        IRow row2 = sheet.CreateRow(i);
                        for (int j = 0; j < dt.Columns.Count; j++)
                        {
                            row2.CreateCell(j).SetCellValue(dt.Rows[i][j].ToString());
                        }
                    }
                }
                workbook.Write(ms);
                ms.Position = 0;
                ms.Close();
                ms.Flush();
                MusicPlayer.SaveToFile(ms, path);
                MessageBox.Show("导出完成!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#2
0
        private void ContentProc()
        {
            string str  = "";
            string str1 = "";

            switch (com_lot.SelectedIndex)
            {
            case 1:
                try
                {
                    foreach (string sourcestr in all)
                    {
                        try
                        {
                            Lottery lot = new Lottery();
                            str      = sourcestr;
                            str1     = HandTD(str);
                            lot.unit = Convert.ToInt32(HandOutTD(str1, false));        //期数
                            str      = str.Replace(str1, "");
                            str1     = HandTD(str);
                            lot.red1 = Convert.ToInt32(HandOutTD(str1));
                            str      = str.Replace(str1, "");
                            str1     = HandTD(str);
                            lot.red2 = Convert.ToInt32(HandOutTD(str1));
                            str      = str.Replace(str1, "");
                            str1     = HandTD(str);
                            lot.red3 = Convert.ToInt32(HandOutTD(str1));
                            str      = str.Replace(str1, "");
                            str1     = HandTD(str);
                            lot.red4 = Convert.ToInt32(HandOutTD(str1));
                            str      = str.Replace(str1, "");
                            str1     = HandTD(str);
                            lot.red5 = Convert.ToInt32(HandOutTD(str1));
                            str      = str.Replace(str1, "");
                            str1     = HandTD(str);
                            lot.red6 = Convert.ToInt32(HandOutTD(str1));
                            str      = str.Replace(str1, "");
                            str1     = HandTD(str);
                            lot.blue = Convert.ToInt32(HandOutTD(str1));
                            //取时间
                            if (str.Length > 200)
                            {
                                str = str.Substring(0, str.IndexOf("</TBODY"));
                            }
                            str      = str.Substring(str.LastIndexOf("<TD"));
                            lot.date = Convert.ToDateTime(HandOutTD(str, false));


                            lotterys.Add(lot);
                            isget = true;
                        }
                        catch (Exception e) { }
                    }
                }
                catch (Exception e) { }
                #region 双色球
                dgv_lottery.DataSource             = lotterys;
                dgv_lottery.Columns[0].HeaderText  = "期数";
                dgv_lottery.Columns[1].HeaderText  = "开奖日期";
                dgv_lottery.Columns[2].HeaderText  = "红1";
                dgv_lottery.Columns[3].HeaderText  = "红2";
                dgv_lottery.Columns[4].HeaderText  = "红3";
                dgv_lottery.Columns[5].HeaderText  = "红4";
                dgv_lottery.Columns[6].HeaderText  = "红5";
                dgv_lottery.Columns[7].HeaderText  = "红6";
                dgv_lottery.Columns[8].HeaderText  = "蓝球";
                dgv_lottery.Columns[9].HeaderText  = "红色遗漏";
                dgv_lottery.Columns[10].HeaderText = "蓝色遗漏";
                dgv_lottery.Columns[0].Width       = 80;
                dgv_lottery.Columns[1].Width       = 80;
                dgv_lottery.Columns[2].Width       = 50;
                dgv_lottery.Columns[3].Width       = 50;
                dgv_lottery.Columns[4].Width       = 50;
                dgv_lottery.Columns[5].Width       = 50;
                dgv_lottery.Columns[6].Width       = 50;
                dgv_lottery.Columns[7].Width       = 50;
                dgv_lottery.Columns[8].Width       = 80;
                dgv_lottery.Columns[9].Width       = 80;
                dgv_lottery.Columns[10].Width      = 80;
                #endregion
                break;

            case 2:
                foreach (string sourcestr in all)
                {
                    try
                    {
                        Lottery3D l3d = new Lottery3D();
                        str         = sourcestr;
                        str1        = HandTD(str);
                        l3d.unit    = Convert.ToInt32(HandOutTD(str1, false));
                        str         = str.Replace(str1, "");
                        str1        = HandTD(str);
                        l3d.number  = HandOutTD(str1);
                        str         = str.Replace(str1, "");
                        str1        = HandTD(str);
                        l3d.addtion = Convert.ToInt32(HandOutTD(str1));
                        str1        = str.Substring(str.LastIndexOf("<TD"));
                        l3d.date    = Convert.ToDateTime(HandOutTD(str1, false));
                        string[] numbers = l3d.number.Split(' ');
                        l3d.number1 = Convert.ToInt32(numbers[0]);
                        l3d.number2 = Convert.ToInt32(numbers[1]);
                        l3d.number3 = Convert.ToInt32(numbers[2]);
                        l3ds.Add(l3d);
                    }
                    catch (Exception ex)
                    {
                        string mesg = "'" + sourcestr + "'";
                        continue;
                    }
                }
                dgv_lottery.DataSource            = l3ds;
                dgv_lottery.Columns[0].HeaderText = "期数";
                dgv_lottery.Columns[1].HeaderText = "开奖号";
                dgv_lottery.Columns[2].HeaderText = "和值";
                dgv_lottery.Columns[3].HeaderText = "时间";
                dgv_lottery.Columns[4].HeaderText = "球1";
                dgv_lottery.Columns[5].HeaderText = "球2";
                dgv_lottery.Columns[6].HeaderText = "球3";
                dgv_lottery.Columns[0].Width      = 80;
                dgv_lottery.Columns[1].Width      = 80;
                dgv_lottery.Columns[2].Width      = 80;
                dgv_lottery.Columns[3].Width      = 80;
                dgv_lottery.Columns[4].Width      = 50;
                dgv_lottery.Columns[5].Width      = 50;
                dgv_lottery.Columns[6].Width      = 50;
                break;
            }
        }