Ejemplo n.º 1
0
 private void SaveMatHang()
 {
     if (Check())
     {
         try
         {
             ConnectionUtil.Instance.BeginTransaction();
             if (frmMH.isAdd)
             {
                 DmSanPhamProvider.Insert(SetMatHang());
                 ConnectionUtil.Instance.CommitTransaction();
             }
             else
             {
                 dm.IdSanPham = frmMH.Oid;
                 DmSanPhamProvider.Update(SetMatHang());
                 ConnectionUtil.Instance.CommitTransaction();
             }
         }
         catch (Exception)
         {
             ConnectionUtil.Instance.RollbackTransaction();
             throw;
         }
     }
 }
Ejemplo n.º 2
0
 private void LoadData()
 {
     dgvDanhSachMatHang.AutoGenerateColumns = false;
     liSanPham = DmSanPhamProvider.GetListDmSanPhamInfo();
     //dgvDanhSachMatHang.DataSource = null;
     dgvDanhSachMatHang.DataSource = liSanPham;
 }
Ejemplo n.º 3
0
        private void btnFilter_Click(object sender, EventArgs e)
        {
            #region old
            //string dk = "1=1";
            //if (!String.IsNullOrEmpty(txtFilterMa.Text)) {
            //    dk += String.Format(" and MaSanPham like '{0}'", txtFilterMa.Text);
            //}
            //if (!String.IsNullOrEmpty(txtFilterTen.Text)) {
            //    dk += String.Format(" and TenSanPham like N'{0}'", txtFilterTen.Text);
            //}

            //string sql = "Select * from tbl_SanPham where " + dk;
            //this.dtHangHoa = DBTools.getData("tbl_SanPham", sql).Tables["tbl_SanPham"];
            //this.ThemTruongSoTT();

            //this.dv = this.dtHangHoa.DefaultView;
            //this.CapNhatDuLieuCotSoTT(0);
            //this.dgvDanhSachMatHang.DataSource = dv;

            //this.LuoiHienThi_CotAn();

            //cm = (CurrencyManager)this.BindingContext[this.dv];
            //cm.PositionChanged += new EventHandler(this.Position_Changed);
            //this.HienThiThongTin(this.cm.Position);
            #endregion

            dgvDanhSachMatHang.DataSource = null;
            dgvDanhSachMatHang.DataSource = DmSanPhamProvider.Search(new DMSanPhamInfo {
                TenSanPham = txtFilterTen.Text.Trim(), MaSanPham = txtFilterMa.Text.Trim()
            });
        }
Ejemplo n.º 4
0
 private void btnFilter_Click(object sender, EventArgs e)
 {
     liSanPham.Clear();
     liSanPham = DmSanPhamProvider.Search(new DMSanPhamInfo {
         MaSanPham = txtFilterMa.Text.Trim(), TenSanPham = txtFilterTen.Text.Trim().ToUpper()
     });
     grcBase.DataSource = liSanPham;
 }
Ejemplo n.º 5
0
 private void Delete()
 {
     DmSanPhamProvider.Delete(new DMSanPhamInfo {
         IdSanPham = Oid
     });
     MessageBox.Show("Xóa thành công bản ghi");
     LoadData();
     SetControl(false);
 }
        private void frm_ChiTiet_CauHinhSanPham_Load(object sender, EventArgs e)
        {
            //if (frmCauHinh.isAdd)
            //{
            //    bteSanPham.Enabled = true;
            //    txtNhaCC.Text = "";
            //    txtLogo.Text = "";
            //    //pteLogo.
            //    //grcChiTietCauHinh.DataSource = lst;
            //    grcChiTietCauHinh.DataSource = new BindingList<DMCauHinhSanPhamInfo>(lst)
            //                                       {
            //                                           AllowEdit = true,
            //                                           AllowNew = true,
            //                                           AllowRemove = true,
            //                                       };
            //}
            //else
            //{
            txtLogo.Enabled  = false;
            txtNhaCC.Enabled = false;
            bteSanPham.Tag   = DmSanPhamProvider.GetSanPhamById(IdSanPham);
            bteSanPham.Text  = TenSanPham;
            //txtLogo.Text = Logo;
            DMCauHinhSanPhamInfo nhaCC = DMCauHinhSanPhamDataProvider.Instance.GetNhaCCByIdSanPham(IdSanPham);

            txtNhaCC.Text = nhaCC.Hang;
            try
            {
                string path = String.Format("http://logo.trananh.com.vn/{0}.jpg", txtNhaCC.Text);
                System.Net.WebRequest  req      = System.Net.WebRequest.Create(path);
                System.Net.WebResponse response = req.GetResponse();
                System.IO.Stream       stream   = response.GetResponseStream();
                if (path != null)
                {
                    //Image im = new Bitmap(path, true);
                    Image im = Image.FromStream(stream);
                    pteLogo.Image = im;
                    //Crop(im, 192, 83, AnchorPosition.Center);
                }
            }
            catch (Exception)
            {
                clsUtils.MsgCanhBao("Sản phẩm chưa có Logo!");
            }

            lst = DMCauHinhSanPhamDataProvider.Instance.GetCauHinhByIdSanPham(IdSanPham);
            grcChiTietCauHinh.DataSource = new BindingList <DMCauHinhSanPhamInfo>(lst)
            {
                AllowEdit   = true,
                AllowNew    = true,
                AllowRemove = true,
            };
            //grcChiTietCauHinh.DataSource = null;
            //grcChiTietCauHinh.DataSource = lst;
            //}
        }
Ejemplo n.º 7
0
 private void LoadSanPhamAll()
 {
     liSP = DmSanPhamProvider.GetCboDmSanPhamInfo();
     chkLstSanPham.DataSource    = liSP;
     chkLstSanPham.DisplayMember = "TenSanPham";
     chkLstSanPham.ValueMember   = "IdSanPham";
     colSanPham.DataSource       = liSP;
     colSanPham.DisplayMember    = "TenSanPham";
     colSanPham.ValueMember      = "IdSanPham";
 }
 protected override void OnLoad()
 {
     if (idKho == -1)
     {
         ListInitInfo = DmSanPhamProvider.GetListSanPhamBrief(idNhomNguoiDung, suDung, chietKhau);
     }
     else
     {
         ListInitInfo = DmSanPhamProvider.GetListSanPhamTonBrief(idNhomNguoiDung, suDung, chietKhau, idKho, tonAll);
     }
 }
Ejemplo n.º 9
0
 protected override void OnLoad()
 {
     if (idKho == 0 && idTrungTam == 0 && !exists)
     {
         base.OnLoad();
     }
     else
     {
         ListInitInfo = DmSanPhamProvider.GetListDmSanPhamInfo(idKho, idTrungTam, exists, isTonAo);
     }
 }
Ejemplo n.º 10
0
 private void Delete()
 {
     if (MessageBox.Show("Bạn có chắc chắn muốn xóa bản ghi này ?", "Thông báo", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         //dm.IdSanPham = OidMatHang;
         DmSanPhamProvider.Delete(new DMSanPhamInfo {
             IdSanPham = OidMatHang
         });
         MessageBox.Show("Xóa thành công bản ghi");
     }
     LoadData();
     SetControl(false);
 }
Ejemplo n.º 11
0
        //private void LoadLoaiHang()
        //{
        //todo: @HanhBD (DONE) su dung loai san pham
        //cboLoaiMatHang.DataSource = DMLoaiSanPhamDataProvider.GetLoaiSPPairInfor();
        //cboLoaiMatHang.DisplayMember = "TenLoaiSP";
        //cboLoaiMatHang.ValueMember = "IdLoaiSP";
        //}
        #endregion

        #region Delete
        private void Delete()
        {
            if (frmMH.isAdd)
            {
                throw new InvalidOperationException("Bạn không thể xóa khi đang thêm mới !");
            }
            if (frmMH.IsSync)
            {
                throw new InvalidOperationException("Bạn không thể xóa dữ liệu được đồng bộ!");
            }
            DmSanPhamProvider.Delete(new DMSanPhamInfo {
                IdSanPham = frmMH.Oid
            });
        }
Ejemplo n.º 12
0
        private void LoadData()
        {
            if (frmMH.isAdd)
            {
                txtMaSanPham.Enabled = true;
                txtMaSanPham.Focus();
                txtTenTat.Text       = "";
                txtTenSanPham.Text   = "";
                txtMoTa.Text         = "";
                txtMaVach.Text       = "";
                txtMaSanPham.Text    = "";
                txtGiaNhap.Text      = "0";
                txtBaoHanhHang.Text  = "0";
                txtBaohanhKhach.Text = "0";
                txtMaSanPham.Focus();
                btnXoa.Enabled = false;
            }
            else
            {
                txtMaSanPham.Enabled = false;
                dm = DmSanPhamProvider.GetSanPhamById(frmMH.Oid);

                txtTenTat.Text             = dm.TenVietTat;
                txtTenSanPham.Text         = dm.TenSanPham;
                txtMoTa.Text               = dm.MoTa;
                txtMaVach.Text             = dm.MaVach;
                txtMaSanPham.Text          = dm.MaSanPham;
                txtGiaNhap.Text            = Convert.ToString(dm.GiaNhap);
                txtBaoHanhHang.Text        = Convert.ToString(dm.BaoHanhHang);
                txtBaohanhKhach.Text       = Convert.ToString(dm.BaoHanhKhach);
                cboDonViTinh.SelectedValue = dm.IdDonViTinh;
                cbTyLeVAT.SelectedValue    = dm.TyLeVAT;
                bteLoaiSanPham.Tag         = DMLoaiSanPhamDataProvider.Instance.GetFullInfoByKey(dm.IdCha);
                if (bteLoaiSanPham.Tag != null)
                {
                    bteLoaiSanPham.Text = ((DMLoaiSanPhamInfo)bteLoaiSanPham.Tag).TenLoaiSP;
                }
                chkSuDung.Checked      = dm.SuDung == 1;
                chkTrungMaVach.Checked = dm.TrungMaVach == 1;
                chkChietKhau.Checked   = dm.ChietKhau == 1;
            }
            if (frmMH.IsSync)
            {
                //không cho phép người dùng sửa, xóa các thông tin trên form.
                txtMaSanPham.Enabled = false;
                txtMaVach.Enabled    = false;
                btnXoa.Enabled       = false;
            }
        }
        public void TestMatHang05_InsertSuccess()
        {
            frmDM_HangHoa frm = new frmDM_HangHoa();

            frm.Oid   = 0;
            frm.isAdd = true;
            frmChiTiet_MatHang frmChiTietListDM = new frmChiTiet_MatHang(frm);

            frmChiTietListDM.SetInput("sản phẩm 1", "11111", "SP1", "123654", 120000, "UnitsTest sản phẩm", 1, 0, 0);
            frmChiTietListDM.TestSave();
            List <DMSanPhamInfo> list = DmSanPhamProvider.Search(new DMSanPhamInfo {
                MaSanPham = "11111"
            });

            Assert.AreEqual(1, list.Count);
        }
Ejemplo n.º 14
0
        private bool Check()
        {
            if (String.IsNullOrEmpty(txtMaSanPham.Text))
            {
                txtMaSanPham.Focus();
                throw new InvalidOperationException("Mã sản phẩm không được để trống !");
            }
            //if (String.IsNullOrEmpty(txtTenTat.Text))
            //{
            //    txtTenTat.Focus();
            //    throw new InvalidOperationException("Tên viết tắt không được để trống !");
            //}
            //if (String.IsNullOrEmpty(txtTenSanPham.Text))
            //{
            //    txtTenSanPham.Focus();
            //    throw new InvalidOperationException("Tên sản phẩm không được để trống !");
            //}
            //if (String.IsNullOrEmpty(txtGiaNhap.Text))
            //{
            //    txtGiaNhap.Focus();
            //    throw new InvalidOperationException("Giá nhập không được để trống !");
            //}
            if (frmMH.IsSync)
            {
                //if (txtMaVach.Text != dm.MaVach)
                //{
                //    throw new InvalidOperationException("Mã vạch đã bị thay đổi !");
                //}
                //if (txtMaSanPham.Text != dm.MaSanPham)
                //{
                //    throw new InvalidOperationException("Mã sản phẩm đã bị thay đổi !");
                //}
            }

            if (DmSanPhamProvider.KiemTra(new DMSanPhamInfo {
                IdSanPham = frmMH.Oid, MaSanPham = txtMaSanPham.Text.Trim()
            }))
            {
                throw new InvalidOperationException("Mã sản phẩm đã tồn tại trong hệ thống !");
            }
            return(true);
        }
        public frmDmMatHangTestUnits()
        {
            frmLogin frmLogin = new frmLogin();

            frmLogin.TestLogin("quantri", "quantri");

            //chuẩn bị dữ liệu để test
            List <DMSanPhamInfo> list = DmSanPhamProvider.GetListDmSanPhamInfo();

            if (list != null)
            {
                List <DMSanPhamInfo> listMatch = list.FindAll(delegate(DMSanPhamInfo match)
                {
                    return(match.MaSanPham == "11111");
                });
                foreach (var dmLoaiThuChiInfo in listMatch)
                {
                    DmSanPhamProvider.Delete(dmLoaiThuChiInfo);
                }
            }
        }
        public void TestMatHang03_MaMatHangHasExistedOnUpdate()
        {
            try
            {
                TestMatHang05_InsertSuccess();
                List <DMSanPhamInfo> list  = DmSanPhamProvider.GetListDmSanPhamInfo();
                DMSanPhamInfo        infor = list.Find(delegate(DMSanPhamInfo match)
                {
                    return(match.MaSanPham == "11111");
                });

                frmDM_HangHoa frm = new frmDM_HangHoa();
                frm.isAdd = false;
                frm.Oid   = Convert.ToInt32(infor.MaSanPham);
                frmChiTiet_MatHang frmChiTietListDM = new frmChiTiet_MatHang(frm);
                frmChiTietListDM.SetInput("sản phẩm 1", "1234", "SP1", "123654", 120000, "UnitsTest sản phẩm", 1, 0, 0);
                frmChiTietListDM.TestSave();
                list = DmSanPhamProvider.GetListDmSanPhamInfo();
                List <DMSanPhamInfo> listDuplicate = list.FindAll(delegate(DMSanPhamInfo match)
                {
                    return(match.MaSanPham == "1234");
                });
                frmChiTietListDM.TestDelete();
                Assert.AreEqual(1, listDuplicate.Count);
            }
            catch (Exception ex)
            {
                if (ex.GetType() != typeof(AssertFailedException))
                {
                    Assert.AreEqual(ex.Message, "Mã sản phẩm đã tồn tại trong hệ thống !");
                }
                else
                {
                    throw;
                }
            }
        }
        public void TestMatHang07_DeleteSuccess()
        {
            TestMatHang05_InsertSuccess();
            List <DMSanPhamInfo> list  = DmSanPhamProvider.GetListDmSanPhamInfo();
            DMSanPhamInfo        infor = list.Find(delegate(DMSanPhamInfo match)
            {
                return(match.MaSanPham == "11111");
            });

            frmDM_HangHoa frm = new frmDM_HangHoa();

            frm.isAdd = false;
            frm.Oid   = infor.IdSanPham;
            frmChiTiet_MatHang frmChiTietListDM = new frmChiTiet_MatHang(frm);

            frmChiTietListDM.TestDelete();
            list  = DmSanPhamProvider.GetListDmSanPhamInfo();
            infor = list.Find(delegate(DMSanPhamInfo match)
            {
                return(match.MaSanPham == "11111");
            });

            Assert.AreEqual(infor, null);
        }
Ejemplo n.º 18
0
        private void GenMaVachTuDong()
        {
            string    sql              = String.Empty;
            DataSet   dsKho            = null;
            DataSet   dsTonDauKy       = null;
            DataSet   dsHangHoaChiTiet = null;
            DMKhoInfo dmKho;

            try
            {
                ConnectionUtil.Instance.BeginTransaction();

                sql   = "Select distinct MaKho from tbl_tmp_mavach_chuan_t3 order by MaKho";
                dsKho = SqlHelper.ExecuteDataset(ConnectionUtil.Instance.GetConnection(), CommandType.Text, sql);


                sql        = "Select MaKho, MaSanPham, SUM(SoLuong) as SoLuong from tbl_tmp_mavach_chuan_t3 group by MaKho, MaSanPham order by MaKho";
                dsTonDauKy = SqlHelper.ExecuteDataset(ConnectionUtil.Instance.GetConnection(), CommandType.Text, sql);

                //frmProgress.Instance.Description = "Đang xóa dữ liệu kho...";
                //frmProgress.Instance.MaxValue = dsKho.Tables[0].Rows.Count;
                //frmProgress.Instance.Value = 0;
                //foreach (DataRow dataRow in dsKho.Tables[0].Rows)
                //{
                //    dmKho = DMKhoDataProvider.Instance.GetKhoInfoByCode(Convert.ToString(dataRow["MaKho"]), 0);
                //    frmProgress.Instance.Description =dmKho.MaKho+ ":Đang xóa dữ liệu kho...";
                //    frmProgress.Instance.Value += 1;
                //    if (dmKho != null)
                //    {
                //        sql = "select * from tbl_hanghoa_dudauky_t2 where idkho=" + dmKho.IdKho;
                //        object dado = SqlHelper.ExecuteScalar(ConnectionUtil.Instance.GetConnection(), CommandType.Text, sql);
                //        //if(dado != null) throw new Exception("Kho này đã đổ tồn.");
                //        //KhoThongKeHangTonDataProvider.Instance.DeleteData(dmKho.IdKho, 0);
                //    }

                //}

                frmProgress.Instance.MaxValue = dsTonDauKy.Tables[0].Rows.Count;
                frmProgress.Instance.Value    = 0;
                foreach (DataRow dataRow in dsTonDauKy.Tables[0].Rows)
                {
                    dmKho = DMKhoDataProvider.Instance.GetKhoInfoByCode(Convert.ToString(dataRow["MaKho"]), 0);
                    if (dmKho == null)
                    {
                        continue;
                    }
                    frmProgress.Instance.Description = dmKho.MaKho + ":Đang cập nhật tồn đầu kỳ ...";
                    //int soluong = (Convert.ToInt32(dataRow["SoLuong"]) < 100 ? 100 : Convert.ToInt32(dataRow["SoLuong"]));
                    int soluong   = Convert.ToInt32(dataRow["SoLuong"]);
                    int idKho     = dmKho.IdKho;
                    int idSanPham =
                        DmSanPhamProvider.GetSanPhamBriefByMa(Convert.ToString(dataRow["MaSanPham"])).IdSanPham;
                    frmProgress.Instance.Value += 1;

                    //sql = "delete tbl_hanghoa_dudauky_t2 where idkho=" +
                    //    idKho + " and idsanpham=" +
                    //    idSanPham;

                    //SqlHelper.ExecuteNonQuery(ConnectionUtil.Instance.GetConnection(), CommandType.Text, sql);

                    //sql = "insert into tbl_hanghoa_dudauky_t2 (idkho, idsanpham, soluong, thoigian) values(" +
                    //    idKho + "," +
                    //    idSanPham + "," +
                    //    soluong + ", "+
                    //    "to_date('28/02/2013','dd/mm/yyyy')"+
                    //")";

                    SqlHelper.ExecuteNonQuery(ConnectionUtil.Instance.GetConnection(), CommandType.Text, sql);

                    //sql = "delete tbl_hangtonkho_t2 where idkho=" +
                    //    idKho + " and idsanpham=" +
                    //    idSanPham;

                    //SqlHelper.ExecuteNonQuery(ConnectionUtil.Instance.GetConnection(), CommandType.Text, sql);

                    //sql = "insert into tbl_hangtonkho_t2 (idkho, idsanpham, soluong, tonao) values(" +
                    //      idKho + "," +
                    //      idSanPham + "," +
                    //      soluong + "," +
                    //      soluong +
                    //      ")";

                    SqlHelper.ExecuteNonQuery(ConnectionUtil.Instance.GetConnection(), CommandType.Text, sql);

                    sql = "select iddudauky from tbl_hanghoa_dudauky_t2 where idsanpham= " + idSanPham + "and idkho=" + idKho;

                    int idDuDauKy = Convert.ToInt32(SqlHelper.ExecuteScalar(ConnectionUtil.Instance.GetConnection(), CommandType.Text,
                                                                            sql));

                    //sql = "delete tbl_hanghoa_chitiet_t2 where idkho=" +
                    //      idKho + " and idsanpham=" +
                    //      idSanPham;

                    //SqlHelper.ExecuteNonQuery(ConnectionUtil.Instance.GetConnection(), CommandType.Text, sql);

                    sql =
                        String.Format(
                            "Select MaKho, MaSanPham, Serial, SoLuong from tbl_tmp_mavach_chuan_t2 where MaKho='{0}' and MaSanPham='{1}'",
                            dataRow["MaKho"], dataRow["MaSanPham"]);

                    dsHangHoaChiTiet = SqlHelper.ExecuteDataset(ConnectionUtil.Instance.GetConnection(), CommandType.Text, sql);
                    frmProgress.Instance.PushStatus();
                    frmProgress.Instance.MaxValue = dsHangHoaChiTiet.Tables[0].Rows.Count;
                    frmProgress.Instance.Value    = 0;

                    foreach (DataRow drHangHoaChiTiet in dsHangHoaChiTiet.Tables[0].Rows)
                    {
                        frmProgress.Instance.Description = dmKho.MaKho + ":Đang cập nhật tồn mã vạch ...";

                        sql = "select sp.trungmavach from tbl_sanpham sp where sp.idsanpham =" + idSanPham;
                        int trungMaVach =
                            Convert.ToInt32(SqlHelper.ExecuteScalar(ConnectionUtil.Instance.GetConnection(),
                                                                    CommandType.Text, sql));
                        if (trungMaVach == 0)
                        {
                            sql  = "select 1 from tbl_hanghoa_chitiet_t2 hhct ";
                            sql += "where hhct.mavach='" + drHangHoaChiTiet["Serial"] + "'";
                            object exists = SqlHelper.ExecuteScalar(ConnectionUtil.Instance.GetConnection(), CommandType.Text, sql);

                            if (exists != null)
                            {
                                throw new Exception("Trùng mã vạch");
                            }
                        }

                        sql = "insert into tbl_hanghoa_chitiet_t2 (iddudauky, idkho, idsanpham, mavach, soluong) values(" +
                              idDuDauKy + "," +
                              idKho + "," +
                              idSanPham + ",'" +
                              drHangHoaChiTiet["Serial"] + "'," +
                              //"to_date('" + BaoHanhHangTu.ToString("dd/MM/yyyy") + "','dd/mm/yyyy')," +
                              //"to_date('" + BaoHanhHangTu.AddMonths(ThoiHanBaoHanh).ToString("dd/MM/yyyy") + "','dd/mm/yyyy')," +
                              drHangHoaChiTiet["SoLuong"] +
                              ")";

                        SqlHelper.ExecuteNonQuery(ConnectionUtil.Instance.GetConnection(), CommandType.Text, sql);
                        frmProgress.Instance.Value += 1;
                    }
                    frmProgress.Instance.PopStatus();
                }
                ConnectionUtil.Instance.CommitTransaction();
                frmProgress.Instance.Description = "Đã hoàn thành";
                frmProgress.Instance.Value       = frmProgress.Instance.MaxValue;
                frmProgress.Instance.IsCompleted = true;
            }
            catch (Exception exception)
            {
                ConnectionUtil.Instance.RollbackTransaction();
                Debug.Print(exception.ToString());
                Debug.Print(sql);
                frmProgress.Instance.Description = "Không hoàn thành";
                frmProgress.Instance.Value       = frmProgress.Instance.MaxValue;
                frmProgress.Instance.IsCompleted = true;
#if DEBUG
                MessageBox.Show(exception.ToString());
#else
                MessageBox.Show(exception.Message);
#endif

                return;
            }
        }
Ejemplo n.º 19
0
        private void InputDataFromCode(string code)
        {
            try
            {
                DMSanPhamBriefInfo sp = DmSanPhamProvider.GetSanPhamBriefByNSDMa(code, nguoiDung.IdNhomNguoiDung);
                if (sp == null)
                {
                    frmLookUp_HangHoa frm = new frmLookUp_HangHoa(false,
                                                                  (Common.Int2Bool(nguoiDung.SupperUser)
                                                                       ? -1
                                                                       : nguoiDung.IdNhomNguoiDung), 1, -1);
                    if (frm.ShowDialog() == DialogResult.OK)
                    {
                        sp = frm.SelectedItem;
                    }
                }

                if (sp != null)
                {
                    BangGiaBanChiTietInfor spb;
                    spb = liBangGiaBan.Find(delegate(BangGiaBanChiTietInfor match)
                    {
                        return(match.MaSanPham.Equals(code));
                    });
                    if (spb == null)
                    {
                        spb = BangGiaDataProvider.Instance.GetGiaBan(IdTTamSelected, IdKhoSelected, sp.MaSanPham);
                    }

                    if (spb == null)
                    {
                        MessageBox.Show("Giá chưa thiết lập!");
                        return;
                    }
                    else if (!DatTruoc && spb.ChietKhau != 1 && GetTonConLai(spb) <= 0)
                    {
                        MessageBox.Show("Hàng đã hết tồn kho!");
                        return;
                    }

                    liBangGiaBan.Add(spb);
                    int    isHangKem  = (rdHangBanKem.Checked ? 1 : 0);
                    string tenHangKem = (rdHangBanKem.Checked ? strMuaKem : strKhuyenMai);
                    ChungTuBanHangChiTietInfor ctu = liSanPhamSelected.Find(delegate(ChungTuBanHangChiTietInfor match)
                    {
                        return(match.MaSanPham.Equals(spb.MaSanPham) && match.LoaiHangKem == isHangKem);
                    });
                    if (ctu != null)
                    {
                        ctu.SoLuong          += 1;
                        ctu.TienSauChietKhau += spb.DonGiaChuaVAT;
                        ctu.TienVAT          += spb.TienVAT;
                        ctu.ThanhTien        += spb.DonGiaCoVAT;
                        ctu.ThuongNong       += spb.ThuongNong;
                        ctu.NoKhuyenMai       = (spb.TonKho >= ctu.SoLuong || DatTruoc || rdHangBanKem.Checked) ? 0 : ctu.SoLuong - spb.TonKho;
                        ctu.GhiChu            = Common.Int2Bool(spb.ChietKhau) ? "CK" : (ctu.NoKhuyenMai > 0 ? "Nợ khuyến mại" : "");
                        ctu.SoLuongOld        = ctu.SoLuong;

                        ((BindingList <ChungTuBanHangChiTietInfor>)gSanPham.DataSource).ResetBindings();
                    }
                    else
                    {
                        //add san pham ban
                        ChungTuBanHangChiTietInfor ct = null;
                        if (rdHangBanKem.Checked)
                        {
                            ct = BanHangDataProvider.Instance.ConvertBG2SanPhamBan(spb);
                        }
                        else
                        {
                            ct         = BanHangDataProvider.Instance.ConvertBG2SanPhamKM(spb);
                            ct.TyleVAT = Common.Int2Bool(spb.ChietKhau) ? spb.TyLeVAT : 0;
                            //if (liSanPhamSelected.Exists(delegate (ChungTuBanHangChiTietInfor match)
                            //                                 {
                            //                                     return
                            //                                         match.MaSanPham.Equals(ct.MaSanPham) && match.LoaiHangKem == 0;
                            //                                 }))
                            //{
                            //    ct.TyleChietKhau = 0;
                            //}
                        }
                        ct.NoKhuyenMai    = (spb.TonKho >= ct.SoLuong || DatTruoc || rdHangBanKem.Checked) ? 0 : ct.SoLuong - spb.TonKho;
                        ct.LoaiHangKem    = isHangKem;
                        ct.TenLoaiHangKem = tenHangKem;
                        ct.IdSanPhamBan   = CTu.IdSanPham;
                        ct.TenSanPhamBan  = CTu.TenSanPham;
                        ct.GhiChu         = Common.Int2Bool(spb.ChietKhau) ? "CK" : (ct.NoKhuyenMai > 0 ? "Nợ khuyến mại" : "");
                        ct.SoLuongOld     = ct.SoLuong;
                        ((BindingList <ChungTuBanHangChiTietInfor>)gSanPham.DataSource).Add(ct);
                    }
                    //spb.TonKho = spb.TonKho - 1;
                }
            }
            catch (System.Exception ex)
            {
#if DEBUG
                //MessageBox.Show("Lỗi ngoại lệ: " + ex.ToString(), Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
#else
                //MessageBox.Show("Lỗi ngoại lệ: " + ex.Message, Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
#endif
            }
        }
Ejemplo n.º 20
0
 protected override void OnLoad()
 {
     ListInitInfo = DmSanPhamProvider.GetListDmSanPhamInfo();
 }
Ejemplo n.º 21
0
 protected override void LoadData()
 {
     grcBase.DataSource = DmSanPhamProvider.GetListDmSanPhamInfo();
     btnFilter.Text     = Resources.btnSearch;
 }