private void FillDG(string sqlStr) { //string sqlStr; DataSet ds; int i; // sqlStr = "SELECT [MaHD], [MaKH], [NgayHD], [Tongtien], [Real], [Hoanthanh], [NoQH], [Laisuat] FROM [HOPDONG]"; ds = ContractDB.genDataset(sqlStr); if (ds != null) { dtGridContracts.DataSource = ds.Tables[0]; } else { return; } for (i = 0; i < dtGridContracts.Columns.Count; i++) { dtGridContracts.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; } for (i = 0; i < dtGridContracts.Rows.Count; i++) { if (rowColor) { dtGridContracts.Rows[i].DefaultCellStyle.BackColor = activeC; } else { dtGridContracts.Rows[i].DefaultCellStyle.BackColor = NegativeC; } rowColor = !rowColor; } }
private void FillDG(string sqlStr, DataGridView dtGridView) { DataSet ds; int i; ds = CashDB.genDataset(sqlStr); dtGridView.DataSource = ds.Tables[0]; for (i = 0; i < dtGridView.Columns.Count; i++) { dtGridView.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; } for (i = 0; i < dtGridView.Rows.Count; i++) { if (rowColor == true) { dtGridView.Rows[i].DefaultCellStyle.BackColor = activeC; rowColor = !rowColor; } else { dtGridView.Rows[i].DefaultCellStyle.BackColor = NegativeC; rowColor = !rowColor; } } rowColor = true; }
public void init(string database, string username) { DataSet ds; DataGridViewButtonColumn dtGridBt = new DataGridViewButtonColumn(); datafile = database; dtGridUser.AllowUserToAddRows = true; int i, cullCount; string sqlString = "SELECT [Username] AS [Ten nguoi dung], [Locked] AS [Khoa] FROM [QUANLYUSER]"; dbUser = new db(database); ds = dbUser.genDataset(sqlString); dtGridUser.DataSource = ds.Tables[0]; dtGridBt.Width = 60; dtGridBt.Text = "Cap nhat"; dtGridBt.Name = "capnhat"; dtGridBt.UseColumnTextForButtonValue = true; for (i = 0; i < dtGridUser.Columns.Count; i++) { dtGridUser.Columns[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; dtGridUser.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; } dtGridUser.Columns.Add(dtGridBt); cullCount = dtGridUser.Columns.Count; for (i = 0; i < dtGridUser.Rows.Count; i++) { dtGridUser.Rows[i].Cells[cullCount - 1].Value = "Cap nhat"; } dtGridUser.AllowUserToAddRows = false; if (username != "admin") { cmdDelete.Enabled = false; } }
public void init(string database, string username) { DataSet ds; DataGridViewButtonColumn dtGridBt = new DataGridViewButtonColumn(); datafile = database; dtGridUser.AllowUserToAddRows = true; int i, cullCount; string sqlString = "SELECT [Username] AS [Ten nguoi dung], [Locked] AS [Khoa] FROM [QUANLYUSER]"; dbUser = new db(database); ds = dbUser.genDataset(sqlString); dtGridUser.DataSource = ds.Tables[0]; dtGridBt.Width = 60; dtGridBt.Text = "Cap nhat"; dtGridBt.Name = "capnhat"; dtGridBt.UseColumnTextForButtonValue = true; for (i = 0; i < dtGridUser.Columns.Count; i++) { dtGridUser.Columns[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; dtGridUser.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; } dtGridUser.Columns.Add(dtGridBt); cullCount = dtGridUser.Columns.Count; for (i = 0; i < dtGridUser.Rows.Count; i++) { dtGridUser.Rows[i].Cells[cullCount - 1].Value = "Cap nhat"; } dtGridUser.AllowUserToAddRows = false; if (username != "admin") cmdDelete.Enabled = false; }
private void refreshdata() { string sqlString; DataSet ds; DataGridViewButtonColumn dtGridBt = new DataGridViewButtonColumn(); int i, cullCount; // dtGridUser.AllowUserToAddRows = true; while (dtGridUser.Rows.Count > 0) { dtGridUser.Rows.RemoveAt(dtGridUser.Rows.Count - 1); } while (dtGridUser.Columns.Count > 0) { dtGridUser.Columns.RemoveAt(dtGridUser.Columns.Count - 1); } dtGridUser.AllowUserToAddRows = true; sqlString = "SELECT [Username] AS [Ten nguoi dung], [Locked] AS [Khoa] FROM [QUANLYUSER]"; ds = dbUser.genDataset(sqlString); dtGridUser.DataSource = ds.Tables[0]; for (i = 0; i < dtGridUser.Columns.Count; i++) { dtGridUser.Columns[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; dtGridUser.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; dtGridUser.Columns[i].Tag = i; } dtGridBt.Width = 60; dtGridBt.Text = "Cap nhat"; dtGridBt.Name = "capnhat"; dtGridBt.UseColumnTextForButtonValue = true; dtGridUser.Columns.Add(dtGridBt); cullCount = dtGridUser.Columns.Count; for (i = 0; i < dtGridUser.Rows.Count; i++) { dtGridUser.Rows[i].Cells["capnhat"].Value = "Cap nhat"; } dtGridUser.AllowUserToAddRows = false; }