Example #1
0
        //wpf loaded
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            DateTime _toDay = DateTime.Today;

            dateTuNgay.SelectedDate  = new DateTime(_toDay.Year, _toDay.Month, 1, 0, 0, 0);
            dateDenNgay.SelectedDate = _toDay;

            //Hiển thị cbo
            List <NhomSanPhamPublic> _lstNhomSP = KiemKeBusiness.LayNSP();

            cboNhomSanPham.ItemsSource   = _lstNhomSP;
            cboNhomSanPham.SelectedIndex = 0;
            HienThi(cboNhomSanPham.SelectedValue.ToString(), dateTuNgay.SelectedDate.Value, dateDenNgay.SelectedDate.Value);
            string _str;

            if (cboNhomSanPham.SelectedValue.ToString() != "")
            {
                _str = "Doanh thu theo sản phẩm từ " + dateTuNgay.SelectedDate.Value.ToString("dd-MM-yy") + " đến " + dateDenNgay.SelectedDate.Value.ToString("dd-MM-yy") + "( Nhóm sản phẩm: " + (cboNhomSanPham.SelectedItem as NhomSanPhamPublic).TenNSP_NSP + " )";
            }
            else
            {
                _str = "Doanh thu theo sản phẩm từ " + dateTuNgay.SelectedDate.Value.ToString("dd-MM-yy") + " đến " + dateDenNgay.SelectedDate.Value.ToString("dd-MM-yy") + "( Tất cả sản phẩm )";
            }
            lbStatus.Content = _str;
        }
        //Phương thức sửa số lượng
        private void SuaSoLuong(object sender, EventArgs e)
        {
            //Lấy thông tin
            KiemKeSuaPresentation wpf = (KiemKeSuaPresentation)sender;
            SanPhamPublic         _sp = wpf._sp;

            //Cập nhật số lượng
            if (KiemKeBusiness.CapNhatSoLuong(_sp.MaSP_SP, _sp.SoLuong_SP))
            {
                lbWarning.Visibility = System.Windows.Visibility.Visible;
                lbWarning.Content    = "Cập nhật thành công sản phẩm: " + _sp.TenSP_SP + " số lượng: " + _sp.SoLuong_SP;

                //Cập nhật dữ liệu trên listSP
                _listSP.Where(item => item.MaSP_SP == _sp.MaSP_SP).First().SoLuong_SP = _sp.SoLuong_SP;
                dgDsSanPham.ItemsSource = _listSP;
                dgDsSanPham.Items.Refresh();

                int _index = _listSP.FindIndex(item => item.MaSP_SP == _sp.MaSP_SP);
                dgDsSanPham.SelectedIndex = _index;
                dgDsSanPham.ScrollIntoView(dgDsSanPham.SelectedItem);
                HienThiTongSP();
            }

            else
            {
                lbWarning.Visibility = System.Windows.Visibility.Visible;
                lbWarning.Content    = "Thao tác cập nhật thất bại";
            }
        }
        //Kiểm tra mã sp
        private bool KiemTraMaSP()
        {
            string _strTim = txtMaTenSP.Text;

            if (_strTim.StartsWith(">"))
            {
                string _StrNumber  = "^([0-9]*)$";
                string _strSoLuong = _strTim.Substring(1);
                if (System.Text.RegularExpressions.Regex.IsMatch(_strSoLuong, _StrNumber))
                {
                    int _sl = Convert.ToInt32(_strSoLuong);
                    _listSP = KiemKeBusiness.LaySPTheoNhom(cboNhomSP.SelectedValue.ToString());
                    _listSP.RemoveAll(item => item.SoLuong_SP < _sl);
                    dgDsSanPham.ItemsSource = _listSP;
                    dgDsSanPham.Items.Refresh();
                    return(false);
                }
            }

            if (_strTim.StartsWith("<"))
            {
                string _StrNumber  = "^([0-9]*)$";
                string _strSoLuong = _strTim.Substring(1);
                if (System.Text.RegularExpressions.Regex.IsMatch(_strSoLuong, _StrNumber))
                {
                    int _sl = Convert.ToInt32(_strSoLuong);
                    _listSP = KiemKeBusiness.LaySPTheoNhom(cboNhomSP.SelectedValue.ToString());
                    _listSP.RemoveAll(item => item.SoLuong_SP > _sl);
                    dgDsSanPham.ItemsSource = _listSP;
                    dgDsSanPham.Items.Refresh();
                    return(false);
                }
            }

            string _maSP = txtMaTenSP.Text.Trim();

            if (String.IsNullOrEmpty(_maSP))
            {
                lbWarning.Visibility = System.Windows.Visibility.Visible;
                lbWarning.Content    = "Nhập mã sản phẩm!";
                txtMaTenSP.Focus();
                txtMaTenSP.SelectAll();
                return(false);
            }

            string _strKiemTraMaSP = @"^([a-zA-Z0-9.?-]*)$";

            if (!System.Text.RegularExpressions.Regex.IsMatch(_maSP, _strKiemTraMaSP))
            {
                lbWarning.Visibility = System.Windows.Visibility.Visible;
                lbWarning.Content    = "Nhập sai định dạng.";
                txtMaTenSP.Focus();
                txtMaTenSP.SelectAll();
                return(false);
            }

            lbWarning.Visibility = System.Windows.Visibility.Hidden;
            return(true);
        }
 //Nút reset
 private void btnReset_Click(object sender, RoutedEventArgs e)
 {
     _listSP.Clear();
     _listSP = KiemKeBusiness.LaySPTheoNhom(cboNhomSP.SelectedValue.ToString());
     dgDsSanPham.ItemsSource = _listSP;
     dgDsSanPham.Items.Refresh();
     txtMaTenSP.Clear();
 }
 //CBO worker dowork
 private void CboSelectionChange_dowork(string _maNSP)
 {
     //Lấy danh sách sản phẩm theo nhóm
     _listSP.Clear();
     _listSP = KiemKeBusiness.LaySPTheoNhom(_maNSP);
 }
 //Loaded worker dowork
 private void Loaded_dowork()
 {
     //Load dữ liệu cho combobox
     _ListNhomSP = KiemKeBusiness.LayNSP();
     _listSP     = KiemKeBusiness.LaySPTheoNhom(_ListNhomSP[0].MaNSP_NSP);
 }