public void Truy_xuat_Bang_ma_lenh() { //string connection_SQL = "server=(local);database=3_ngay44;user=sa;password=psbinh"; SqlConnection conn = new SqlConnection(connection_SQL); SqlCommand comm; SqlDataAdapter adapter; DataSet ds = new DataSet(); if (conn.State != ConnectionState.Open) { try { conn.Open(); if (conn.State == ConnectionState.Open) { txtSQL_Status.Text = "KẾT NỐI SQL: TỐT"; txtSQL_Status.BackColor = Color.LightGreen; } //MessageBox.Show("Kết nối DataBase SQL thành công"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); txtSQL_Status.Text = "KẾT NỐI SQL: LỖI"; } } comm = new SqlCommand("SELECT Time_tao_lenh AS 'T.Gian TẠO LỆNH', Ma_lenh AS 'MÃ LỆNH', Ma_hang AS 'MÃ HÀNG', Ma_hong AS 'MÃ HỌNG', so_ptien AS 'SỐ XE', ma_ngan AS 'MÃ NGĂN', Nhiet_do AS 'NHIỆT ĐỘ', Luong_dat AS 'LƯỢNG ĐẶT', Luong_thuc_te AS 'LƯỢNG THỰC XUẤT' FROM BX_BangMaLenh ORDER BY Time_tao_lenh", conn); adapter = new SqlDataAdapter(comm); adapter.Fill(ds); var GiaTriLay = from GiaTri in ds.Tables[0].AsEnumerable() where (GiaTri.Field <DateTime>("T.Gian TẠO LỆNH") >= DateTime.Today) select GiaTri; dataGridView1.DataSource = null; dataGridView1.DataSource = GiaTriLay.AsDataView(); foreach (DataGridViewRow row in dataGridView1.Rows) { row.HeaderCell.Value = String.Format("{000}", row.Index + 1); } conn.Dispose(); adapter.Dispose(); comm.Dispose(); malenhxuattoday = dataGridView1.RowCount; tinh_tong_luong_thuc_xuat(); }
private void btnViewBX_alrm_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(connection_SQL); SqlCommand comm; SqlDataAdapter adapter; DataSet ds = new DataSet(); if (conn.State != ConnectionState.Open) { try { conn.Open(); if (conn.State == ConnectionState.Open) { txtSQL_Status.Text = "KẾT NỐI SQL: TỐT"; txtSQL_Status.BackColor = Color.LightGreen; } //MessageBox.Show("Kết nối DataBase SQL thành công"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); txtSQL_Status.Text = "KẾT NỐI SQL: LỖI"; } } comm = new SqlCommand("SELECT Time AS 'THỜI GIAN', Ma_hong AS 'MÃ HỌNG', Ma_lenh AS 'MÃ LỆNH', Luong_dat AS 'LƯỢNG ĐẶT', Luong_tt AS 'LƯỢNG THỰC', ToC AS 'NHIỆT ĐỘ', ToC_tb AS 'NHIỆT ĐỘ TB', Luu_toc AS 'LƯU TỐC', BOM AS 'BƠM', Van1 AS 'VAN NO', Van2 AS 'VAN NC', Auto_man AS 'AUTO/MAN', Dung_su_co AS 'DỪNG SỰ CỐ' FROM BX_Historys ORDER BY Time", conn); adapter = new SqlDataAdapter(comm); adapter.Fill(ds); var GiaTriLay = from GiaTri in ds.Tables[0].AsEnumerable() where GiaTri.Field <int?>("MÃ HỌNG") == (cbbMaH.SelectedIndex + 1) where (GiaTri.Field <DateTime>("THỜI GIAN") >= dateTimePicker5.Value) && (GiaTri.Field <DateTime>("THỜI GIAN") < dateTimePicker6.Value) select GiaTri; dataGridView1.DataSource = null; dataGridView1.DataSource = GiaTriLay.AsDataView(); conn.Dispose(); adapter.Dispose(); comm.Dispose(); }
public void Show_BN_BangMaLenh() { SqlConnection conn = new SqlConnection(connection_SQL); SqlCommand comm; SqlDataAdapter adapter; DataSet ds = new DataSet(); if (conn.State != ConnectionState.Open) { try { conn.Open(); if (conn.State == ConnectionState.Open) { txtSQL_Status.Text = "KẾT NỐI SQL: TỐT"; txtSQL_Status.BackColor = Color.LightGreen; } //MessageBox.Show("Kết nối DataBase SQL thành công"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); txtSQL_Status.Text = "KẾT NỐI SQL: LỖI"; } } comm = new SqlCommand("SELECT * FROM BN_BangMaLenh", conn); adapter = new SqlDataAdapter(comm); adapter.Fill(ds); var GiaTriLay = from GiaTri in ds.Tables[0].AsEnumerable() where (GiaTri.Field <DateTime>("Time_tao") >= DateTime.Today) select GiaTri; dataGridView1.DataSource = null; dataGridView1.DataSource = GiaTriLay.AsDataView(); conn.Dispose(); adapter.Dispose(); comm.Dispose(); }
private void button1_Click_1(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(connection_SQL); SqlCommand comm; SqlDataAdapter adapter; DataSet ds = new DataSet(); if (conn.State != ConnectionState.Open) { try { conn.Open(); if (conn.State == ConnectionState.Open) { txtSQL_Status.Text = "KẾT NỐI SQL: TỐT"; txtSQL_Status.BackColor = Color.LightGreen; } //MessageBox.Show("Kết nối DataBase SQL thành công"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); txtSQL_Status.Text = "KẾT NỐI SQL: LỖI"; } } comm = new SqlCommand("SELECT Time AS 'THỜI GIAN', Ma_hong AS 'MÃ HỌNG', Canh_bao AS 'CẢNH BÁO' FROM BX_Canhbao ORDER BY Time", conn); adapter = new SqlDataAdapter(comm); adapter.Fill(ds); if (comboBox1.SelectedIndex == 0) { var GiaTriLay = from GiaTri in ds.Tables[0].AsEnumerable() //where GiaTri.Field<int?>("MÃ HỌNG") == (comboBox1.SelectedIndex + 1) where (GiaTri.Field <DateTime>("THỜI GIAN") >= dateTimePicker1.Value) && (GiaTri.Field <DateTime>("THỜI GIAN") < dateTimePicker2.Value) select GiaTri; dataGridView1.DataSource = null; dataGridView1.DataSource = GiaTriLay.AsDataView(); } else if (comboBox1.SelectedIndex > 0) { var GiaTriLay = from GiaTri in ds.Tables[0].AsEnumerable() where GiaTri.Field <int?>("MÃ HỌNG") == (comboBox1.SelectedIndex - 1) where (GiaTri.Field <DateTime>("THỜI GIAN") >= dateTimePicker1.Value) && (GiaTri.Field <DateTime>("THỜI GIAN") < dateTimePicker2.Value) select GiaTri; dataGridView1.DataSource = null; dataGridView1.DataSource = GiaTriLay.AsDataView(); } else { var GiaTriLay = from GiaTri in ds.Tables[0].AsEnumerable() //where GiaTri.Field<int?>("MÃ HỌNG") == (comboBox1.SelectedIndex) where (GiaTri.Field <DateTime>("THỜI GIAN") >= dateTimePicker1.Value) && (GiaTri.Field <DateTime>("THỜI GIAN") < dateTimePicker2.Value) select GiaTri; dataGridView1.DataSource = null; dataGridView1.DataSource = GiaTriLay.AsDataView(); } conn.Dispose(); adapter.Dispose(); comm.Dispose(); }
private void btn_Xem_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(connection_SQL); SqlCommand comm; SqlDataAdapter adapter; DataSet ds = new DataSet(); if (conn.State != ConnectionState.Open) { try { conn.Open(); if (conn.State == ConnectionState.Open) { txtSQL_Status.Text = "KẾT NỐI SQL: TỐT"; txtSQL_Status.BackColor = Color.LightGreen; } //MessageBox.Show("Kết nối DataBase SQL thành công"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); txtSQL_Status.Text = "KẾT NỐI SQL: LỖI"; } } comm = new SqlCommand("SELECT Time_tao_lenh AS 'T.Gian TẠO LỆNH', Ma_lenh AS 'MÃ LỆNH', Ma_hang AS 'MÃ HÀNG', Ma_hong AS 'MÃ HỌNG', so_ptien AS 'SỐ XE', ma_ngan AS 'MÃ NGĂN', Nhiet_do AS 'NHIỆT ĐỘ', Luong_dat AS 'LƯỢNG ĐẶT', Luong_thuc_te AS 'LƯỢNG THỰC XUẤT' FROM BX_BangMaLenh ORDER BY Time_tao_lenh", conn); adapter = new SqlDataAdapter(comm); adapter.Fill(ds); //1000 THEO NGAY if ((checkBox_THEONGAY.Checked) && (!checkBox_THEOHONG.Checked) && (!checkBox_THEOMAHANG.Checked) && (!checkBox_THEOMALENH.Checked)) { var GiaTriLay = from GiaTri in ds.Tables[0].AsEnumerable() where (GiaTri.Field <DateTime>("T.Gian TẠO LỆNH") >= dateTimePicker3.Value.Date) && (GiaTri.Field <DateTime>("T.Gian TẠO LỆNH") < dateTimePicker4.Value.Date) select GiaTri; dataGridView1.DataSource = null; dataGridView1.DataSource = GiaTriLay.AsDataView(); tinh_tong_luong_thuc_xuat(); } //0100 THEO HONG else if ((!checkBox_THEONGAY.Checked) && (checkBox_THEOHONG.Checked) && (!checkBox_THEOMAHANG.Checked) && (!checkBox_THEOMALENH.Checked)) { var GiaTriLay = from GiaTri in ds.Tables[0].AsEnumerable() where GiaTri.Field <int?>("MÃ HỌNG") == (comboBox2.SelectedIndex + 1) select GiaTri; dataGridView1.DataSource = null; dataGridView1.DataSource = GiaTriLay.AsDataView(); tinh_tong_luong_thuc_xuat(); } //1100 THEO NGAY & THEO HONG else if ((checkBox_THEONGAY.Checked) & (checkBox_THEOHONG.Checked) & (!checkBox_THEOMAHANG.Checked) & (!checkBox_THEOMALENH.Checked)) { var GiaTriLay = from GiaTri in ds.Tables[0].AsEnumerable() where (GiaTri.Field <DateTime>("T.Gian TẠO LỆNH") >= dateTimePicker3.Value.Date) && (GiaTri.Field <DateTime>("T.Gian TẠO LỆNH") < dateTimePicker4.Value.Date) where GiaTri.Field <int?>("MÃ HỌNG") == (comboBox2.SelectedIndex + 1) select GiaTri; dataGridView1.DataSource = null; dataGridView1.DataSource = GiaTriLay.AsDataView(); tinh_tong_luong_thuc_xuat(); } //0010 THEO MA HANG else if ((!checkBox_THEONGAY.Checked) & (!checkBox_THEOHONG.Checked) & (checkBox_THEOMAHANG.Checked) & (!checkBox_THEOMALENH.Checked)) { var GiaTriLay = from GiaTri in ds.Tables[0].AsEnumerable() where GiaTri.Field <string>("MÃ HÀNG") == textBox3.Text select GiaTri; dataGridView1.DataSource = null; dataGridView1.DataSource = GiaTriLay.AsDataView(); tinh_tong_luong_thuc_xuat(); } //1010 THEO NGAY & THEO MA HANG else if ((checkBox_THEONGAY.Checked) & (!checkBox_THEOHONG.Checked) & (checkBox_THEOMAHANG.Checked) & (!checkBox_THEOMALENH.Checked)) { var GiaTriLay = from GiaTri in ds.Tables[0].AsEnumerable() where (GiaTri.Field <DateTime>("T.Gian TẠO LỆNH") >= dateTimePicker3.Value.Date) && (GiaTri.Field <DateTime>("T.Gian TẠO LỆNH") < dateTimePicker4.Value.Date) where GiaTri.Field <string>("MÃ HÀNG") == textBox3.Text select GiaTri; dataGridView1.DataSource = null; dataGridView1.DataSource = GiaTriLay.AsDataView(); tinh_tong_luong_thuc_xuat(); } //0110 THEO HONG & THEO MA HANG else if ((!checkBox_THEONGAY.Checked) & (checkBox_THEOHONG.Checked) & (checkBox_THEOMAHANG.Checked) & (!checkBox_THEOMALENH.Checked)) { var GiaTriLay = from GiaTri in ds.Tables[0].AsEnumerable() where GiaTri.Field <int?>("MÃ HỌNG") == (comboBox2.SelectedIndex + 1) where GiaTri.Field <string>("MÃ HÀNG") == textBox3.Text select GiaTri; dataGridView1.DataSource = null; dataGridView1.DataSource = GiaTriLay.AsDataView(); tinh_tong_luong_thuc_xuat(); } //1110 THEO NGAY & THEO HONG & THEO MA HANG else if ((checkBox_THEONGAY.Checked) & (checkBox_THEOHONG.Checked) & (checkBox_THEOMAHANG.Checked) & (!checkBox_THEOMALENH.Checked)) { var GiaTriLay = from GiaTri in ds.Tables[0].AsEnumerable() where (GiaTri.Field <DateTime>("T.Gian TẠO LỆNH") >= dateTimePicker3.Value.Date) && (GiaTri.Field <DateTime>("T.Gian TẠO LỆNH") < dateTimePicker4.Value.Date) where GiaTri.Field <int?>("MÃ HỌNG") == (comboBox2.SelectedIndex + 1) where GiaTri.Field <string>("MÃ HÀNG") == textBox3.Text select GiaTri; dataGridView1.DataSource = null; dataGridView1.DataSource = GiaTriLay.AsDataView(); tinh_tong_luong_thuc_xuat(); } //0001 THEO MA LENH else if ((!checkBox_THEONGAY.Checked) & (!checkBox_THEOHONG.Checked) & (!checkBox_THEOMAHANG.Checked) & (checkBox_THEOMALENH.Checked)) { var GiaTriLay = from GiaTri in ds.Tables[0].AsEnumerable() where GiaTri.Field <int?>("MÃ LỆNH") == int.Parse(textBox2.Text) select GiaTri; dataGridView1.DataSource = null; dataGridView1.DataSource = GiaTriLay.AsDataView(); tinh_tong_luong_thuc_xuat(); } //1001 THEO NGAY & THEO MA LENH else if ((checkBox_THEONGAY.Checked) & (!checkBox_THEOHONG.Checked) & (!checkBox_THEOMAHANG.Checked) & (checkBox_THEOMALENH.Checked)) { var GiaTriLay = from GiaTri in ds.Tables[0].AsEnumerable() where (GiaTri.Field <DateTime>("T.Gian TẠO LỆNH") >= dateTimePicker3.Value.Date) && (GiaTri.Field <DateTime>("T.Gian TẠO LỆNH") < dateTimePicker4.Value.Date) //where GiaTri.Field<int?>("MÃ HỌNG") == (comboBox2.SelectedIndex + 1) //where GiaTri.Field<string>("MÃ HÀNG") == textBox3.Text where GiaTri.Field <int?>("MÃ LỆNH") == int.Parse(textBox2.Text) select GiaTri; dataGridView1.DataSource = null; dataGridView1.DataSource = GiaTriLay.AsDataView(); tinh_tong_luong_thuc_xuat(); } //0101 THEO HONG & THEO MA LENH else if ((!checkBox_THEONGAY.Checked) & (checkBox_THEOHONG.Checked) & (!checkBox_THEOMAHANG.Checked) & (checkBox_THEOMALENH.Checked)) { var GiaTriLay = from GiaTri in ds.Tables[0].AsEnumerable() //where (GiaTri.Field<DateTime>("T.Gian TẠO LỆNH") >= dateTimePicker3.Value.Date) && (GiaTri.Field<DateTime>("T.Gian TẠO LỆNH") < dateTimePicker4.Value.Date) where GiaTri.Field <int?>("MÃ HỌNG") == (comboBox2.SelectedIndex + 1) //where GiaTri.Field<string>("MÃ HÀNG") == textBox3.Text where GiaTri.Field <int?>("MÃ LỆNH") == int.Parse(textBox2.Text) select GiaTri; dataGridView1.DataSource = null; dataGridView1.DataSource = GiaTriLay.AsDataView(); tinh_tong_luong_thuc_xuat(); } //1101 THEO NGAY & THEO HONG & THEO MA LENH else if ((checkBox_THEONGAY.Checked) & (checkBox_THEOHONG.Checked) & (!checkBox_THEOMAHANG.Checked) & (checkBox_THEOMALENH.Checked)) { var GiaTriLay = from GiaTri in ds.Tables[0].AsEnumerable() where (GiaTri.Field <DateTime>("T.Gian TẠO LỆNH") >= dateTimePicker3.Value.Date) && (GiaTri.Field <DateTime>("T.Gian TẠO LỆNH") < dateTimePicker4.Value.Date) where GiaTri.Field <int?>("MÃ HỌNG") == (comboBox2.SelectedIndex + 1) //where GiaTri.Field<string>("MÃ HÀNG") == textBox3.Text where GiaTri.Field <int?>("MÃ LỆNH") == int.Parse(textBox2.Text) select GiaTri; dataGridView1.DataSource = null; dataGridView1.DataSource = GiaTriLay.AsDataView(); tinh_tong_luong_thuc_xuat(); } //0011 THEO MA HANG & THEO MA LENH else if ((!checkBox_THEONGAY.Checked) & (!checkBox_THEOHONG.Checked) & (checkBox_THEOMAHANG.Checked) & (checkBox_THEOMALENH.Checked)) { var GiaTriLay = from GiaTri in ds.Tables[0].AsEnumerable() //where (GiaTri.Field<DateTime>("T.Gian TẠO LỆNH") >= dateTimePicker3.Value.Date) && (GiaTri.Field<DateTime>("T.Gian TẠO LỆNH") < dateTimePicker4.Value.Date) //where GiaTri.Field<int?>("MÃ HỌNG") == (comboBox2.SelectedIndex + 1) where GiaTri.Field <string>("MÃ HÀNG") == textBox3.Text where GiaTri.Field <int?>("MÃ LỆNH") == int.Parse(textBox2.Text) select GiaTri; dataGridView1.DataSource = null; dataGridView1.DataSource = GiaTriLay.AsDataView(); tinh_tong_luong_thuc_xuat(); } //1011 THEO NGAY & THEO MA HANG & THEO MA LENH else if ((checkBox_THEONGAY.Checked) & (!checkBox_THEOHONG.Checked) & (checkBox_THEOMAHANG.Checked) & (checkBox_THEOMALENH.Checked)) { var GiaTriLay = from GiaTri in ds.Tables[0].AsEnumerable() where (GiaTri.Field <DateTime>("T.Gian TẠO LỆNH") >= dateTimePicker3.Value.Date) && (GiaTri.Field <DateTime>("T.Gian TẠO LỆNH") < dateTimePicker4.Value.Date) //where GiaTri.Field<int?>("MÃ HỌNG") == (comboBox2.SelectedIndex + 1) where GiaTri.Field <string>("MÃ HÀNG") == textBox3.Text where GiaTri.Field <int?>("MÃ LỆNH") == int.Parse(textBox2.Text) select GiaTri; dataGridView1.DataSource = null; dataGridView1.DataSource = GiaTriLay.AsDataView(); tinh_tong_luong_thuc_xuat(); } //0111 THEO HONG & THEO MA HANG & THEO MA LENH else if ((!checkBox_THEONGAY.Checked) & (checkBox_THEOHONG.Checked) & (checkBox_THEOMAHANG.Checked) & (checkBox_THEOMALENH.Checked)) { var GiaTriLay = from GiaTri in ds.Tables[0].AsEnumerable() //where (GiaTri.Field<DateTime>("T.Gian TẠO LỆNH") >= dateTimePicker3.Value.Date) && (GiaTri.Field<DateTime>("T.Gian TẠO LỆNH") < dateTimePicker4.Value.Date) where GiaTri.Field <int?>("MÃ HỌNG") == (comboBox2.SelectedIndex + 1) where GiaTri.Field <string>("MÃ HÀNG") == textBox3.Text where GiaTri.Field <int?>("MÃ LỆNH") == int.Parse(textBox2.Text) select GiaTri; dataGridView1.DataSource = null; dataGridView1.DataSource = GiaTriLay.AsDataView(); tinh_tong_luong_thuc_xuat(); } //1111 THEO NGAY & THEO HONG & THEO MA HANG & THEO MA LENH else if ((checkBox_THEONGAY.Checked) & (checkBox_THEOHONG.Checked) & (checkBox_THEOMAHANG.Checked) & (checkBox_THEOMALENH.Checked)) { var GiaTriLay = from GiaTri in ds.Tables[0].AsEnumerable() where (GiaTri.Field <DateTime>("T.Gian TẠO LỆNH") >= dateTimePicker3.Value.Date) && (GiaTri.Field <DateTime>("T.Gian TẠO LỆNH") < dateTimePicker4.Value.Date) where GiaTri.Field <int?>("MÃ HỌNG") == (comboBox2.SelectedIndex + 1) where GiaTri.Field <string>("MÃ HÀNG") == textBox3.Text where GiaTri.Field <int?>("MÃ LỆNH") == int.Parse(textBox2.Text) select GiaTri; dataGridView1.DataSource = null; dataGridView1.DataSource = GiaTriLay.AsDataView(); tinh_tong_luong_thuc_xuat(); } // Xem tat ca bang ma lenh else { var GiaTriLay = from GiaTri in ds.Tables[0].AsEnumerable() select GiaTri; dataGridView1.DataSource = null; dataGridView1.DataSource = GiaTriLay.AsDataView(); tinh_tong_luong_thuc_xuat(); } foreach (DataGridViewRow row in dataGridView1.Rows) { row.HeaderCell.Value = String.Format("{000}", row.Index + 1); } conn.Dispose(); adapter.Dispose(); comm.Dispose(); malenhxuattoday = dataGridView1.RowCount; }