private void btnAddProductAgency_Click(object sender, EventArgs e)
        {
            if (txtIDProductDL.Text == "" || txtNameProductDL.Text == "" || cmbIDAgency.Text == "" || txtUnitDL.Text == "" || txtPriceDL.Text == "" || txtAmountDL.Text == "")
            {
                MessageBox.Show("Bạn phải điền đầy đủ thông tin !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                ClearDisplay();
                return;
            }
            SanPhamDL_DTO sanpham = new SanPhamDL_DTO();

            sanpham.MaSPDL  = txtIDProductDL.Text;
            sanpham.TenSP   = txtNameProductDL.Text;
            sanpham.MaDL    = cmbIDAgency.SelectedValue.ToString();
            sanpham.DonVi   = txtUnitDL.Text;
            sanpham.Gia     = Double.Parse(txtPriceDL.Text.ToString());
            sanpham.SoLuong = Int32.Parse(txtAmountDL.Text.ToString());


            if (SanPhamDL_BUS.ThemSPDL(sanpham))
            {
                MessageBox.Show("Thêm Sản phẩm Đại Lí thành công !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                LoadSanPhamDL();
                ClearDisplay();

                return;
            }
            MessageBox.Show("Thêm Sản phẩm Đại Lí thất bại !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Example #2
0
        public static bool SuaSanPhamDL(SanPhamDL_DTO sanpham)
        {
            SqlConnection con = DataProvider.KetNoi();
            SqlCommand    cmd = new SqlCommand("SuaSPDL", con);

            try
            {
                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter p = new SqlParameter("@MaSPDL", sanpham.MaSPDL);
                cmd.Parameters.Add(p);
                p = new SqlParameter("@TenSP", sanpham.TenSP);
                cmd.Parameters.Add(p);
                p = new SqlParameter("@MaDL", sanpham.MaDL);
                cmd.Parameters.Add(p);
                p = new SqlParameter("@DonVi", sanpham.DonVi);
                cmd.Parameters.Add(p);
                p = new SqlParameter("@Gia", sanpham.Gia);
                cmd.Parameters.Add(p);
                p = new SqlParameter("@SoLuong", sanpham.SoLuong);
                cmd.Parameters.Add(p);

                cmd.ExecuteNonQuery();

                DataProvider.DongKetNoi(con);
                return(true);
            }
            catch
            {
                DataProvider.DongKetNoi(con);
                return(false);
            }
        }
        private void btnAddProductAgency_Click(object sender, EventArgs e)
        {
            if (txtIDProductDL.Text == "" || txtNameProductDL.Text == "" || cmbIDAgency.Text == "" || txtUnitDL.Text == "" || txtPriceDL.Text == "" || txtParameter.Text == "")
            {
                XtraMessageBox.Show("Bạn phải điền đầy đủ thông tin !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                ClearDisplay();
                return;
            }
            SanPhamDL_DTO sanpham = new SanPhamDL_DTO();

            sanpham.MaSPDL  = txtIDProductDL.Text;
            sanpham.TenSP   = txtNameProductDL.Text;
            sanpham.MaDL    = cmbIDAgency.SelectedValue.ToString();
            sanpham.DonVi   = txtUnitDL.Text;
            sanpham.Gia     = Double.Parse(txtPriceDL.Text.ToString());
            sanpham.ThongSo = txtParameter.Text.ToString();

            try
            {
                if (SanPhamDL_BUS.ThemSPDL(sanpham))
                {
                    XtraMessageBox.Show("Thêm Sản phẩm Đại Lí thành công !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    LoadSanPhamDL();
                    uctSanPhamCH.uctSPCH.LoadSanPhamCH1();
                    ClearDisplay();

                    return;
                }
            }catch (Exception ex)
            {
                XtraMessageBox.Show("Thêm Sản phẩm Đại Lí thất bại !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
        public void btnDeleteProductAgency_Click(object sender, EventArgs e)
        {
            try
            {
                SanPhamDL_DTO sanpham = new SanPhamDL_DTO();
                sanpham.MaSPDL = (string)dtgvProductListOfAgency.CurrentRow.Cells["MaSPDL"].Value;

                if (txtIDProductDL.Text == "" || txtNameProductDL.Text == "" || cmbIDAgency.Text == "" || txtUnitDL.Text == "" || txtPriceDL.Text == "")
                {
                    XtraMessageBox.Show("Bạn phải chọn Sản phẩm để xóa", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    ClearDisplay();
                    return;
                }

                if (SanPhamDL_BUS.XoaSPDL(sanpham))
                {
                    LoadSanPhamDL();
                    XtraMessageBox.Show("Xóa Sản phẩm Đại lí thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    ClearDisplay();
                    return;
                }
            }catch
            {
                XtraMessageBox.Show("Xóa Sản phẩm Đại lí thất bại !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
        public static bool SuaSanPhamDL(SanPhamDL_DTO sanpham)
        {
            SqlConnection con = DataProvider.KetNoi();
            SqlCommand    cmd = new SqlCommand("SuaSPDL", con);

            try
            {
                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter p = new SqlParameter("@MaSPDL", sanpham.MaSPDL);
                cmd.Parameters.Add(p);
                p = new SqlParameter("@TenSP", sanpham.TenSP);
                cmd.Parameters.Add(p);
                p = new SqlParameter("@MaDL", sanpham.MaDL);
                cmd.Parameters.Add(p);
                p = new SqlParameter("@DonVi", sanpham.DonVi);
                cmd.Parameters.Add(p);
                p = new SqlParameter("@Gia", sanpham.Gia);
                cmd.Parameters.Add(p);
                p = new SqlParameter("@ThongSo", sanpham.ThongSo);
                cmd.Parameters.Add(p);

                cmd.ExecuteNonQuery();

                DataProvider.DongKetNoi(con);
                return(true);
            }
            catch (Exception ex)
            {
                DataProvider.DongKetNoi(con);
                MessageBox.Show(ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }
Example #6
0
        public static List <SanPhamDL_DTO> LoadSanPhamDL()
        {
            // 1. Tạo chuối kết nối
            SqlConnection con = DataProvider.KetNoi();

            // 2. Tạo chuối truy vấn và thực thi truy vấn
            SqlCommand cmd = new SqlCommand("DSSanPhamDL", con);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.ExecuteNonQuery();
            SqlDataAdapter da = new SqlDataAdapter();

            da.SelectCommand = cmd;

            // 3. Đổ dữ liệu lên DataTable
            DataTable dt = new DataTable();

            da.Fill(dt);

            if (dt.Rows.Count == 0)
            {
                return(null);
            }
            // 4. Đỏ dữ liệu lên List
            List <SanPhamDL_DTO> listSP = new List <SanPhamDL_DTO>();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                SanPhamDL_DTO sanpham = new SanPhamDL_DTO();
                sanpham.MaSPDL  = dt.Rows[i]["MaSPDL"].ToString();
                sanpham.TenSP   = dt.Rows[i]["TenSP"].ToString();
                sanpham.MaDL    = dt.Rows[i]["MaDL"].ToString();
                sanpham.Gia     = Double.Parse(dt.Rows[i]["Gia"].ToString());
                sanpham.DonVi   = dt.Rows[i]["DonVi"].ToString();
                sanpham.SoLuong = Int32.Parse(dt.Rows[i]["SoLuong"].ToString());

                listSP.Add(sanpham);
            }

            DataProvider.DongKetNoi(con);
            return(listSP);
        }
Example #7
0
        public static bool XoaSPDL(SanPhamDL_DTO sanpham)
        {
            SqlConnection con = DataProvider.KetNoi();
            SqlCommand    cmd = new SqlCommand("XoaSPDL", con);

            try
            {
                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter p = new SqlParameter("@MaSPDL", sanpham.MaSPDL);
                cmd.Parameters.Add(p);

                cmd.ExecuteNonQuery();

                DataProvider.DongKetNoi(con);
                return(true);
            }
            catch
            {
                DataProvider.DongKetNoi(con);
                return(false);
            }
        }
 public static bool XoaSPDL(SanPhamDL_DTO sanpham)
 {
     return(SanPhamDL_DAL.XoaSPDL(sanpham));
 }
 public static bool ThemSPDL(SanPhamDL_DTO sanpham)
 {
     return(SanPhamDL_DAL.ThemSanPhamDL(sanpham));
 }