示例#1
0
        private void buttonFlow_Click(object sender, EventArgs e)
        {
            try
            {
                labelInfo.Text = "";
                TimeSpan  ts        = new TimeSpan();
                string    dbType    = comboBoxDbType.Text;
                string    sql       = textBoxSql.Text;
                int       pageSize  = (int)numericUpDownPageSize.Value;
                int       pageIndex = (int)numericUpDownPageIndex.Value;
                int       start     = (pageIndex - 1) * pageSize + 1;
                int       rowsCount = 0;
                DataTable dt        = new DataTable();
                using (BDBHelper dbHelper = new BDBHelper(dbType, textBoxConn.Text))
                {
                    DateTime begin = DateTime.Now;
                    using (IDataReader reader = dbHelper.ExecuteReader(sql))
                    {
                        for (int c = 0; c < reader.FieldCount; c++)
                        {
                            dt.Columns.Add(reader.GetName(c), reader.GetFieldType(c));
                        }

                        int i = 0;
                        while (reader.Read())
                        {
                            i++;
                            if (i < start)
                            {
                                continue;
                            }

                            DataRow dr = dt.NewRow();
                            for (int c = 0; c < reader.FieldCount; c++)
                            {
                                dr[c] = reader.GetValue(c);
                            }

                            dt.Rows.Add(dr);

                            rowsCount++;

                            if (rowsCount >= pageSize)
                            {
                                break;
                            }
                        }
                        ts = DateTime.Now - begin;
                    }
                }

                dataGridView1.DataSource = dt;
                labelTime.Text           = ts.TotalMilliseconds + "毫秒";
                labelInfo.Text           = "返回时间:" + DateTime.Now.ToString();
            }
            catch (Exception ex)
            {
                labelInfo.Text = ex.Message;
            }
        }
示例#2
0
        private void button13_Click(object sender, EventArgs e)
        {
            int    rowsCount   = 0;
            int    pageSize    = 50;
            int    pageIndex   = 0;
            string sql         = "select * from EM_MODULE_EVENT";
            string dbType      = "oracle";
            string ip          = "139.196.212.68";
            int    port        = 1521;
            string user        = "******";
            string password    = "******";
            string serviceName = "ORCL";

            using (BDBHelper dbHelper = new BDBHelper(dbType, ip, port, user, password, serviceName, serviceName))
            {
                using (IDataReader reader = dbHelper.ExecuteReader(sql))
                {
                    int i = 0;

                    DataTable dt = new DataTable();
                    for (int c = 0; c < reader.FieldCount; c++)
                    {
                        dt.Columns.Add(reader.GetName(c), reader.GetFieldType(c));
                    }

                    bool isCanRead = reader.Read();

                    while (true && isCanRead)
                    {
                        DataRow dr = dt.NewRow();
                        for (int c = 0; c < reader.FieldCount; c++)
                        {
                            dr[c] = reader.GetValue(c);
                        }

                        dt.Rows.Add(dr);
                        i++;
                        rowsCount++;

                        isCanRead = reader.Read();
                        if (i >= pageSize || isCanRead == false)
                        {
                            pageIndex++;
                            string fileName = "G:/dt_" + pageIndex + ".txt";
                            WriteDataTableIntoFile(dt, fileName);
                            dt.Rows.Clear();
                            i = 0;
                        }

                        if (isCanRead == false)
                        {
                            break;
                        }
                    }
                }
            }

            MessageBox.Show(string.Format("共有{0}页,{1}条记录,已经写入文件。", pageIndex, rowsCount));
        }
示例#3
0
        public string GetUserRole(int userId)
        {
            string strResult = "";

            if (userId <= 0)
            {
                return(strResult);
            }

            using (BDBHelper dbHelper = new BDBHelper())
            {
                string strSql    = "select menu_ids from bf_user us left join BF_ROLE role on US.ROLE_IDS=ROLE.ID where us.id=" + userId;
                object objResult = dbHelper.ExecuteReader(strSql);
                if (objResult != null)
                {
                    return(objResult.ToString());
                }
            }
            return(strResult);
        }