예제 #1
0
 public DataTable ReadFromExcels(string namefile)
 {
     try
     {
         QRcode    qrcode       = new QRcode();
         string    fileLocation = txtDuongDanFile.Text;
         string    name         = Path.GetFileName(txtDuongDanFile.Text);
         DataTable sheet        = new DataTable();
         OleDbConnectionStringBuilder csbuilder = new OleDbConnectionStringBuilder();
         csbuilder.Provider   = "Microsoft.ACE.OLEDB.12.0";
         csbuilder.DataSource = fileLocation.Substring(0, fileLocation.LastIndexOf('\\'));
         csbuilder.Add("Extended Properties", "Text;Excel 12.0;HDR=No;IMEX=1;FMT=Delimited");
         string selectSql = @"SELECT * FROM [" + name + "]";
         using (OleDbConnection connection = new OleDbConnection(csbuilder.ConnectionString))
             using (OleDbDataAdapter adapter = new OleDbDataAdapter(selectSql, connection))
             {
                 connection.Open();
                 adapter.Fill(sheet);
                 connection.Close();
             }
         DataSet ds = TableVeSo();
         Decimal No = 1;
         foreach (DataRow row in sheet.Rows)
         {
             LotteryPattern lotteryPattern = new LotteryPattern();
             lotteryPattern.NO = No.ToString();
             if (row[0] != null)
             {
                 lotteryPattern.LoaiVe = row[0].ToString();
             }
             if (row[1] != null)
             {
                 lotteryPattern.KyVe = row[1].ToString();
             }
             if (row[2] != null)
             {
                 lotteryPattern.NgaySo = Convert.ToDateTime(row[2].ToString());
             }
             if (row[3] != null)
             {
                 lotteryPattern.So = row[3].ToString();
             }
             if (row[4] != null)
             {
                 lotteryPattern.SoMaHoa = row[4].ToString();
             }
             byte[] qrcodebyte       = qrcode.ConertArrayByte(qrcode.GenerateQRCode(lotteryPattern.SoMaHoa, 70, 70));
             byte[] qrcodebytebottom = qrcode.ConertArrayByte(qrcode.GenerateQRCode(lotteryPattern.SoMaHoa, 40, 40));
             ds.Tables[0].Rows.Add(lotteryPattern.NO, lotteryPattern.NgaySo, lotteryPattern.So, lotteryPattern.SoMaHoa, lotteryPattern.KyVe, qrcodebyte, qrcodebytebottom, qrcodebyte, lotteryPattern.LoaiVe);
             No++;
         }
         return(ds.Tables[0]);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(null);
     }
 }
예제 #2
0
        public List <LotteryPattern> ReadFile(string csv)
        {
            var reader = new StreamReader(File.OpenRead("@" + csv));
            List <LotteryPattern> listA = new List <LotteryPattern>();

            while (!reader.EndOfStream)
            {
                var line   = reader.ReadLine();
                var values = line.Split(',');

                ////////Doc tung dong`////////////
                LotteryPattern obj = new LotteryPattern();
                if (values.Count() > 0)
                {
                    obj.KyTu   = values[0].ToString();
                    obj.NgayXo = Convert.ToDateTime(values[1].ToString());
                    obj.So     = Convert.ToInt16(values[2].ToString());
                }
                listA.Add(obj);
            }
            return(listA);
        }