public bool xoa(TiepNhanDTO tn)
        {
            string query = string.Empty;

            query += "DELETE FROM PhieuTiepNhan WHERE [matiepnhan] = @matiepnhan";
            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("@matiepnhan", tn.MaTiepNhan);
                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                        con.Dispose();
                    }
                    catch (Exception ex)
                    {
                        con.Close();
                        Console.WriteLine(ex);
                        throw;
                    }
                }
            }
            return(true);
        }
Esempio n. 2
0
 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)
     {
         TiepNhanDTO tn = new TiepNhanDTO();
         tn.MaTiepNhan = int.Parse(txtMaPTN.Text);
         bool kq2 = tnBus.xoa(tn);
         if (kq2 == 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();
         txtBienso.Text   = "";
         txtDiaChi.Text   = "";
         txtHT.Text       = "";
         txtSdt.Text      = "";
         cbTenHieuXe.Text = "";
         txtMaPTN.Text    = "";
     }
 }
Esempio n. 3
0
 private void btSua_Click(object sender, EventArgs e)
 {
     errorProvider1.Clear();
     errorProvider2.Clear();
     errorProvider4.Clear();
     errorProvider5.Clear();
     errorProvider6.Clear();
     if (txtHT.Text == "")
     {
         errorProvider1.SetError(txtHT, "Tên khách hàng không được để trống!");
     }
     else if (txtBienso.Text == "")
     {
         errorProvider2.SetError(txtBienso, "Biển số xe không được để trống!");
     }
     else if (txtDiaChi.Text == "")
     {
         errorProvider3.SetError(txtDiaChi, "Địa chỉ không được để trống!");
     }
     else if (txtSdt.Text == "")
     {
         errorProvider4.SetError(txtSdt, "Số điện thoại không được để trống!");
     }
     else if (txtSdt.Text.Length > 11 || txtSdt.Text.Length < 9)
     {
         errorProvider5.SetError(txtSdt, "Số điện thoại không hợp lệ!");
     }
     else if (cbTenHieuXe.Text == "")
     {
         errorProvider6.SetError(cbTenHieuXe, "Tên hiệu xe không được để trống!");
     }
     else
     {
         TiepNhanDTO tn = new TiepNhanDTO();
         tn.MaTiepNhan   = int.Parse(txtMaPTN.Text);
         tn.HT           = txtHT.Text;
         tn.Ngaytiepnhan = dtNgaytiepnhan.Text;
         tn.DiaChi       = txtDiaChi.Text;
         tn.HieuXe       = cbTenHieuXe.Text;
         tn.Sdt          = txtSdt.Text;
         tn.Bienso       = txtBienso.Text;
         bool kq1 = tnBus.sua(tn);
         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();
         txtBienso.Text   = "";
         txtDiaChi.Text   = "";
         txtHT.Text       = "";
         txtSdt.Text      = "";
         cbTenHieuXe.Text = "";
         txtMaPTN.Text    = "";
     }
 }
        public List <TiepNhanDTO> select()
        {
            string query = string.Empty;

            query += "SELECT [ht], [bienso], [sdt], [ngaytiepnhan], [diachi], [hieuxe], [matiepnhan]";
            query += "FROM [PhieuTiepNhan]";

            List <TiepNhanDTO> lsTiepNhan = new List <TiepNhanDTO>();

            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())
                            {
                                TiepNhanDTO tn = new TiepNhanDTO();
                                tn.HT           = reader["ht"].ToString();
                                tn.Bienso       = reader["bienso"].ToString();
                                tn.Sdt          = reader["sdt"].ToString();
                                tn.Ngaytiepnhan = reader["ngaytiepnhan"].ToString();
                                tn.DiaChi       = reader["diachi"].ToString();
                                tn.HieuXe       = reader["hieuxe"].ToString();
                                tn.MaTiepNhan   = int.Parse(reader["matiepnhan"].ToString());
                                lsTiepNhan.Add(tn);
                            }
                        }

                        con.Close();
                        con.Dispose();
                    }
                    catch (Exception ex)
                    {
                        con.Close();
                        Console.WriteLine(ex);
                        throw;
                    }
                }
            }
            return(lsTiepNhan);
        }
        public List <TiepNhanDTO> selectBS()
        {
            string query = string.Empty;

            query += "SELECT [bienso]";
            query += "FROM [PhieuTiepNhan]";

            List <TiepNhanDTO> IsBienSo = new List <TiepNhanDTO>();

            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())
                            {
                                TiepNhanDTO tn = new TiepNhanDTO();
                                tn.Bienso = reader["bienso"].ToString();
                                IsBienSo.Add(tn);
                            }
                        }

                        con.Close();
                        con.Dispose();
                    }
                    catch (Exception ex)
                    {
                        con.Close();
                        Console.WriteLine(ex);
                        throw;
                    }
                }
            }
            return(IsBienSo);
        }
        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 them(TiepNhanDTO tn)
        {
            string query = string.Empty;

            query += "INSERT INTO [PhieuTiepNhan] (ht, bienso, sdt, ngaytiepnhan, diachi, hieuxe, matiepnhan)";
            query += "VALUES (@ht,@bienso,@sdt,@ngaytiepnhan,@diachi,@hieuxe,@matiepnhan)";
            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("@ht", tn.HT);
                    cmd.Parameters.AddWithValue("@bienso", tn.Bienso);
                    cmd.Parameters.AddWithValue("@sdt", tn.Sdt);
                    cmd.Parameters.AddWithValue("@ngaytiepnhan", tn.Ngaytiepnhan);
                    cmd.Parameters.AddWithValue("@diachi", tn.DiaChi);
                    cmd.Parameters.AddWithValue("@hieuxe", tn.HieuXe);
                    cmd.Parameters.AddWithValue("@matiepnhan", tn.MaTiepNhan);
                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                        con.Dispose();
                    }
                    catch (Exception ex)
                    {
                        con.Close();
                        Console.WriteLine(ex);
                        throw;
                    }
                }
            }
            return(true);
        }
        public bool sua(TiepNhanDTO tn)
        {
            string query = string.Empty;

            query += "UPDATE PhieuTiepNhan SET [ht] = @ht, [bienso] = @bienso, [sdt] = @sdt, [ngaytiepnhan] = @ngaytiepnhan, [diachi] = @diachi, [hieuxe] = @hieuxe WHERE [matiepnhan] = @matiepnhan";
            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("@ht", tn.HT);
                    cmd.Parameters.AddWithValue("@bienso", tn.Bienso);
                    cmd.Parameters.AddWithValue("@sdt", tn.Sdt);
                    cmd.Parameters.AddWithValue("@ngaytiepnhan", tn.Ngaytiepnhan);
                    cmd.Parameters.AddWithValue("@diachi", tn.DiaChi);
                    cmd.Parameters.AddWithValue("@hieuxe", tn.HieuXe);
                    cmd.Parameters.AddWithValue("@matiepnhan", tn.MaTiepNhan);
                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                        con.Dispose();
                    }
                    catch (Exception ex)
                    {
                        con.Close();
                        Console.WriteLine(ex);
                        throw;
                    }
                }
            }
            return(true);
        }
        public bool sua(TiepNhanDTO tn)
        {
            bool re = tnDAO.sua(tn);

            return(re);
        }
Esempio n. 10
0
        public bool them(TiepNhanDTO tn)
        {
            bool re = tnDAO.them(tn);

            return(re);
        }