public bool sua(PhuTungDTO pt) { string query = string.Empty; query += "UPDATE PhuTung SET [tenphutung] = @tenphutung, [dongia] = @dongia, [tondau] = @tondau, [toncuoi] = @toncuoi WHERE [maphutung] = @maphutung"; using (SqlConnection con = new SqlConnection(ConnectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = con; cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = query; cmd.Parameters.AddWithValue("@tenphutung", pt.Tenphutung); cmd.Parameters.AddWithValue("@maphutung", pt.Maphutung); cmd.Parameters.AddWithValue("@dongia", pt.Dongia); cmd.Parameters.AddWithValue("@tondau", pt.Tondau); cmd.Parameters.AddWithValue("@toncuoi", pt.Toncuoi); try { con.Open(); cmd.ExecuteNonQuery(); con.Close(); con.Dispose(); } catch (Exception ex) { con.Close(); Console.WriteLine(ex); throw; } } } return(true); }
private void btXoa_Click(object sender, EventArgs e) { DialogResult = MessageBox.Show("Bạn có chắc chắn muốn xóa ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (DialogResult == DialogResult.Yes) { PhuTungDTO pt = new PhuTungDTO(); pt.Maphutung = int.Parse(txtmaphutung.Text); pt.Tenphutung = txttenphutung.Text; pt.Tondau = int.Parse(txttđ.Text); pt.Toncuoi = int.Parse(txttc.Text); pt.Dongia = Decimal.Parse(txtdongia.Text); bool kq1 = ptBus.xoa(pt); if (kq1 == false) { MessageBox.Show("Xóa thông tin thất bại. Vui lòng kiểm tra lại dữ liệu"); } else { MessageBox.Show("Xóa thông tin thành công"); } this.loadData_Vao_GridView(); txttenphutung.Text = ""; txtmaphutung.Text = ""; txttc.Text = ""; txttđ.Text = ""; txtdongia.Text = ""; } }
public static PhuTungDTO SelectPhuTungById(String phutungID) { PhuTungDTO phutung = new PhuTungDTO(); try { // Create List Sql Parameter List <MySqlParameter> parameters = new List <MySqlParameter>(); parameters.Add(new MySqlParameter("@MaPT", phutungID)); DataTable dt = MySqlDataAccessHelper.ExecuteQuery("SELECT * FROM phutung WHERE MaPT = @MaPT", parameters); DataRow dr = dt.Rows[0]; phutung.MaPT = dr["MaPT"].ToString(); phutung.TenPT = dr["TenPT"].ToString(); phutung.MoTa = dr["MoTa"].ToString(); phutung.ThoiHanBH = int.Parse(dr["ThoiHanBH"].ToString()); phutung.GiaPT = int.Parse(dr["GiaPT"].ToString()); phutung.DonViTinh = dr["DVT"].ToString(); } catch (Exception ex) { throw ex; } return(phutung); }
public bool xoa(PhuTungDTO pt) { string query = string.Empty; query += "DELETE FROM PhuTung WHERE [maphutung] = @maphutung";; using (SqlConnection con = new SqlConnection(ConnectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = con; cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = query; cmd.Parameters.AddWithValue("@maphutung", pt.Maphutung); try { con.Open(); cmd.ExecuteNonQuery(); con.Close(); con.Dispose(); } catch (Exception ex) { con.Close(); Console.WriteLine(ex); throw; } } } return(true); }
public bool them(PhuTungDTO pt) { string query = string.Empty; query += "INSERT INTO [PhuTung] (tenphutung,maphutung,dongia,tondau,toncuoi) "; query += "VALUES (@tenphutung,@maphutung,@dongia,@tondau,@toncuoi)"; using (SqlConnection con = new SqlConnection(ConnectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = con; cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = query; cmd.Parameters.AddWithValue("@tenphutung", pt.Tenphutung); cmd.Parameters.AddWithValue("@maphutung", pt.Maphutung); cmd.Parameters.AddWithValue("@dongia", pt.Dongia); cmd.Parameters.AddWithValue("@tondau", pt.Tondau); cmd.Parameters.AddWithValue("@toncuoi", pt.Toncuoi); try { con.Open(); cmd.ExecuteNonQuery(); con.Close(); con.Dispose(); } catch (Exception ex) { con.Close(); Console.WriteLine(ex); throw; } } } return(true); }
public List <PhuTungDTO> TimKiem(string Keyword) { string query = string.Empty; query += "SELECT [tenphutung], [dongia], [tondau], [toncuoi], [maphutung]"; query += "FROM [PhuTung]"; query += " WHERE ([tenphutung] LIKE CONCAT('%',@Keyword,'%'))"; query += " OR ([maphutung] LIKE CONCAT('%',@Keyword,'%'))"; query += " OR ([dongia] LIKE CONCAT('%',@Keyword,'%'))"; query += " OR ([tondau] LIKE CONCAT('%',@Keyword,'%'))"; query += " OR ([toncuoi] LIKE CONCAT('%',@Keyword,'%'))"; List <PhuTungDTO> lsTimKiem = new List <PhuTungDTO>(); using (SqlConnection con = new SqlConnection(ConnectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = con; cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = query; cmd.Parameters.AddWithValue("@Keyword", Keyword); try { con.Open(); SqlDataReader reader = null; reader = cmd.ExecuteReader(); if (reader.HasRows == true) { while (reader.Read()) { PhuTungDTO pt = new PhuTungDTO(); pt.Tenphutung = reader["tenphutung"].ToString(); pt.Maphutung = int.Parse(reader["maphutung"].ToString()); pt.Toncuoi = int.Parse(reader["toncuoi"].ToString()); pt.Tondau = int.Parse(reader["tondau"].ToString()); pt.Dongia = Decimal.Parse(reader["dongia"].ToString()); lsTimKiem.Add(pt); } } con.Close(); con.Dispose(); } catch (Exception ex) { con.Close(); Console.WriteLine(ex); throw; } } } return(lsTimKiem); }
private void btSua_Click(object sender, EventArgs e) { errorProvider1.Clear(); errorProvider2.Clear(); errorProvider3.Clear(); errorProvider4.Clear(); errorProvider5.Clear(); if (txttenphutung.Text == "") { errorProvider1.SetError(txttenphutung, "Tên phụ tùng không được để trống!"); } else if (txtmaphutung.Text == "") { errorProvider2.SetError(txtmaphutung, "Mã phụ tùng không được để trống!"); } if (txtdongia.Text == "") { errorProvider3.SetError(txtdongia, "Đơn giá không được để trống!"); } else if (txttc.Text == "") { errorProvider5.SetError(txttc, "Số lượng tồn kho không được để trống!"); } if (txttđ.Text == "") { errorProvider4.SetError(txttđ, "Số lượng nhập về không được để trống!"); } else { PhuTungDTO pt = new PhuTungDTO(); pt.Maphutung = int.Parse(txtmaphutung.Text); pt.Tenphutung = txttenphutung.Text; pt.Tondau = int.Parse(txttđ.Text); pt.Toncuoi = int.Parse(txttc.Text); pt.Dongia = Decimal.Parse(txtdongia.Text); bool kq1 = ptBus.sua(pt); if (kq1 == false) { MessageBox.Show("Sửa thông tin thất bại. Vui lòng kiểm tra lại dữ liệu"); } else { MessageBox.Show("Sửa thông tin thành công"); } this.loadData_Vao_GridView(); txttenphutung.Text = ""; txtmaphutung.Text = ""; txttc.Text = ""; txttđ.Text = ""; txtdongia.Text = ""; } }
public List <PhuTungDTO> select() { string query = string.Empty; query += "SELECT [tenphutung], [dongia], [tondau], [toncuoi], [maphutung]"; query += "FROM [PhuTung]"; List <PhuTungDTO> lsTenPhuTung = new List <PhuTungDTO>(); using (SqlConnection con = new SqlConnection(ConnectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = con; cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = query; try { con.Open(); SqlDataReader reader = null; reader = cmd.ExecuteReader(); if (reader.HasRows == true) { while (reader.Read()) { PhuTungDTO pt = new PhuTungDTO(); pt.Tenphutung = reader["tenphutung"].ToString(); pt.Maphutung = int.Parse(reader["maphutung"].ToString()); pt.Toncuoi = int.Parse(reader["toncuoi"].ToString()); pt.Tondau = int.Parse(reader["tondau"].ToString()); pt.Dongia = Decimal.Parse(reader["dongia"].ToString()); lsTenPhuTung.Add(pt); } } con.Close(); con.Dispose(); } catch (Exception ex) { con.Close(); Console.WriteLine(ex); throw; } } } return(lsTenPhuTung); }
public List <PhuTungDTO> selectgia(string sKeyword) { string query = string.Empty; query += "SELECT [dongia]"; query += "FROM [PhuTung]"; query += " WHERE ([tenphutung] LIKE CONCAT('%',@sKeyword,'%'))"; List <PhuTungDTO> lsDonGia = new List <PhuTungDTO>(); using (SqlConnection con = new SqlConnection(ConnectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = con; cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = query; cmd.Parameters.AddWithValue("@sKeyword", sKeyword); try { con.Open(); SqlDataReader reader = null; reader = cmd.ExecuteReader(); if (reader.HasRows == true) { while (reader.Read()) { PhuTungDTO pt = new PhuTungDTO(); pt.Dongia = Decimal.Parse(reader["dongia"].ToString()); lsDonGia.Add(pt); } } con.Close(); con.Dispose(); } catch (Exception ex) { con.Close(); Console.WriteLine(ex); throw; } } } return(lsDonGia); }
private void LapPhieuSuaChua_Load(object sender, EventArgs e) { PhuTungDTO pt = new PhuTungDTO(); ptBus = new PhuTungBUS(); List <PhuTungDTO> ListTenPhuTung = ptBus.selectTenPhuTung(); if (ListTenPhuTung == null) { MessageBox.Show("Có lỗi khi lấy thông tin từ table PhuTung"); return; } cbPhuTung.DataSource = ListTenPhuTung; TienCongDTO tc = new TienCongDTO(); tcBus = new TienCongBUS(); List <TienCongDTO> Listtendichvu = tcBus.selecttendichvu(); if (Listtendichvu == null) { MessageBox.Show("Có lỗi khi lấy thông tin từ table TienCong"); return; } cbDV.DataSource = Listtendichvu; TiepNhanDTO tn = new TiepNhanDTO(); tnBus = new TiepNhanBUS(); List <TiepNhanDTO> ListBienSo = tnBus.selectBS(); if (ListBienSo == null) { MessageBox.Show("Có lỗi khi lấy thông tin từ table PhieuSuaChua"); return; } cbBS.DataSource = ListBienSo; ngaysuachua.Format = DateTimePickerFormat.Custom; ngaysuachua.CustomFormat = "yyyy/MM/dd"; txtThanhtien.Enabled = false; //txtsoluong.Text = "1"; //thtien = Decimal.Parse(cbGTC.Text) + Decimal.Parse(lbPhuTung.Text) * int.Parse(txtsoluong.Text); //txtThanhtien.Text = thtien.ToString(); }
public bool sua(PhuTungDTO pt) { bool re = ptDao.sua(pt); return(re); }
public bool them(PhuTungDTO pt) { bool re = ptDao.them(pt); return(re); }