Esempio n. 1
0
 public FormBanHangThem(bool isThem, string title, string maHDBH, ChiTietHDBH obj)
 {
     InitializeComponent();
     this.isThem = isThem;
     this.Text   = title;
     this.maHDBH = maHDBH;
     this.obj    = obj;
 }
Esempio n. 2
0
 private void btnBH_Sua_Click(object sender, EventArgs e)
 {
     if (dgvBH.CurrentRow.Index < 0)
     {
         return;
     }
     //  try
     {
         ChiTietHDBH obj = new ChiTietHDBH();
         //  MessageBox.Show("mahdbh-mahh:" + txtBH_MaHD.Text + " " + dgvBH.CurrentRow.Cells["MaHH"].Value.ToString());
         obj = banHangBUS.HoaDonBanHang_Query(txtBH_MaHD.Text)[dgvBH.CurrentRow.Index];// cthdbh.ChiTietHDBH_GetByTop("", "MaHDBH = '"++"' and MaHH ='" + dgvBH.CurrentRow.Cells["MaHH"].Value.ToString() + "'", "")[0];
         new FormBanHangThem(false, "Sửa", txtBH_MaHD.Text, obj).ShowDialog();
     }
     // catch
     {
         //MessageBox.Show("Chọn 1 sản phẩm muốn sửa!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Esempio n. 3
0
 public bool ChiTietHDBH_Update(ChiTietHDBH data)
 {
     return(obj.ChiTietHDBH_Update(data));
 }
Esempio n. 4
0
 public bool ChiTietHDBH_Insert(ChiTietHDBH data)
 {
     return(obj.ChiTietHDBH_Insert(data));
 }
Esempio n. 5
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (checkValid())
            {
                //them vao ct hoa don
                ChiTietHDBH hh = new ChiTietHDBH();
                hh.MaHDBH = maHDBH;
                if (String.IsNullOrEmpty(cmbThemHH.SelectedValue.ToString()))
                {
                    MessageBox.Show("Nhập đầy đủ thông tin", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                else
                {
                    hh.MaHH = cmbThemHH.SelectedValue.ToString();
                }

                HangHoaObj o1 = hhBUS.HangHoa_GetByTop("", "MaHH='" + hh.MaHH + "'", "")[0];
                hh.MaLoai     = o1.MaLoai;
                hh.TenLoai    = loaiHangBUS.LoaiHang_GetByTop("", "MaLoai='" + hh.MaLoai + "'", "")[0].TenLoai;
                hh.SoLuongMua = txtSoLuong.Text;
                hh.GiaBan     = txtGia.Text;

                bool isExisted = false;
                var  lst       = new HoaDonBanHangBUS().HoaDonBanHang_Query("", " and tb_HDBanHang.MaHDBH='" + hh.MaHDBH + "' and tb_HangHoa.MaHH='" + hh.MaHH + "'", "");

                if (lst.Count == 1)
                {
                    isExisted = true;
                }
                else
                {
                    isExisted = false;
                }

                if (isThem)
                {
                    if (!isExisted)
                    {
                        if (cthdbhBUS.ChiTietHDBH_Insert(hh))
                        {
                            MessageBox.Show("Ok Add 1 item");
                        }
                        else
                        {
                            MessageBox.Show("Fail Add 1 item");
                        }
                    }
                    else
                    {
                        int sl = int.Parse(lst[0].SoLuongMua);
                        hh.SoLuongMua = (sl + int.Parse(txtSoLuong.Text)).ToString();

                        if (cthdbhBUS.ChiTietHDBH_Update(hh))
                        {
                            MessageBox.Show("Ok Add 1 item!");
                        }
                        else
                        {
                            MessageBox.Show(" Fail Add 1 item!");
                        }
                    }
                }
                else
                {
                    if (cthdbhBUS.ChiTietHDBH_Update(hh))
                    {
                        MessageBox.Show("Ok Update 1 item");
                    }
                    else
                    {
                        MessageBox.Show("Fail Update 1 item");
                    }
                }
                // ucBH.bindDataGridView();
            }
            else
            {
                txtSoLuong.Focus();
            }
        }