コード例 #1
0
ファイル: AddHangHoa.cs プロジェクト: longkoy3459/Barcocde
        private void CheckMaHangHoa()
        {
            try
            {
                // _id = Convert.ToInt64(gridView1.GetRowCellValue(0, colID));

                if (txtMa.Text == "")
                {
                    return;
                }
                else
                {
                    if (lkTenKhoHang.Text == "" || txtTenKhuVuc.Text == "")
                    {
                        MessageBox.Show("Chưa nhập tên khu vực và tên kho hàng");
                        txtMa.Text = "";
                        return;
                    }
                    else
                    {
                        string _productCode = txtMa.Text;
                        string IDStore      = (string)(lkTenKhoHang as LookUpEdit).EditValue; // ID Kho
                        string tenKV        = txtTenKhuVuc.Text;

                        var data = (from e in db.HangHoas
                                    where (e.MaHH == _productCode || e.MaGoiNho == _productCode)
                                    select new
                        {
                            IDHangHoa = e.HangHoaID,
                            MaHH = e.MaHH,
                            TenHH = e.TenHH,
                            MaGoiNho = e.MaGoiNho
                        }).ToList();

                        //sửa
                        //foreach(var c in data)
                        //{
                        //    var kiemke = new KiemKeHangHoa
                        //    {
                        //        STT = _SoTT,
                        //        ID_Users = ID_User,
                        //        ID_HangHoa = c.IDHangHoa,
                        //        ID_Kho = IDStore,

                        //        TenKeHang = tenKV,
                        //        SoLuong = 1,
                        //        NgayKiemKe = DateTime.Now,
                        //        updated_at = ThoiGian,
                        //        LoaiKiemKe = bLoaiKiemKe


                        //    };
                        //    db.KiemKeHangHoas.Add(kiemke);
                        //    db.SaveChanges();
                        //}

                        //string IDStore = (string)(lkTenKhoHang as LookUpEdit).EditValue;
                        if (data.Count != 0)
                        {
                            foreach (var c in data)
                            {
                                clsHangHoa entity = new clsHangHoa()
                                {
                                    // ID = _id+1 ,
                                    IDHangHoa   = c.IDHangHoa,
                                    SoTT        = _SoTT,
                                    ProductCode = c.MaHH,
                                    ProductName = c.TenHH,
                                    MaGoiNho    = c.MaGoiNho,
                                    //SoLuong = _SoLuong,
                                    ThoiGianQuet    = DateTime.Now,
                                    ThoiGianCapNhat = DateTime.Now,
                                    LoaiKiemKe      = bLoaiKiemKe
                                };

                                list.Add(entity);

                                bindingSource1.ResetBindings(true);
                                gcDSHangHoa.RefreshDataSource();
                                gcDSHangHoa.DataSource = list;
                                txtMessage.Text        = string.Format("Tìm thấy: {0}", txtMa.Text);
                                txtMessage.ForeColor   = Color.Green;

                                txtMa.Text  = "";
                                bLoaiKiemKe = 0;
                                // _id = _id + 1;
                                _SoTT = _SoTT + 1;
                            }
                        }
                        else if (data.Count == 0)
                        {
                            System.Media.SystemSounds.Beep.Play();
                            if (MessageBox.Show("Không tìm thấy mã trong kho ! \n Xem gợi ý hàng hóa ?", "Thông Báo ", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                            {
                                var frmSelect = new ListMaHH();
                                frmSelect._MaHHPartial = txtMa.Text;
                                frmSelect._MaGoiNho    = txtMa.Text;
                                if (frmSelect.GetListMa())
                                {
                                    if (frmSelect.ShowDialog() == DialogResult.OK)
                                    {
                                        _SoLuong = frmSelect._SoLuong;
                                        for (int i = 0; i < _SoLuong; i++)
                                        {
                                            txtMa.Text  = frmSelect.MaHHSelect;
                                            bLoaiKiemKe = 1;
                                            CheckMaHangHoa();
                                        }


                                        return;
                                    }
                                }

                                txtMessage.Text      = string.Format("{0}: {1}", txtMa.Text);
                                txtMessage.ForeColor = Color.Red;
                                txtMa.Text           = "";
                                bLoaiKiemKe          = 0;
                            }
                        }
                    }
                }
            }
            catch
            { }
        }
コード例 #2
0
        //check hàng
        private void CheckMaHangHoa()
        {
            try
            {
                if (txtMa.Text == "")
                {
                    return;
                }
                else
                {
                    if (lkTenKhoHang.Text == "" || txtTenKhuVuc.Text == "")
                    {
                        System.Media.SystemSounds.Beep.Play();
                        MessageBox.Show("Chưa nhập tên khu vực và tên kho hàng");
                        txtMa.Text = "";
                        return;
                    }
                    else
                    {
                        string _productCode = txtMa.Text;


                        var data = (from e in db.HangHoas
                                    where (e.MaHH == _productCode || e.MaGoiNho == _productCode)
                                    select new
                        {
                            IDHangHoa = e.HangHoaID,
                            MaHH = e.MaHH,
                            TenHH = e.TenHH,
                            MaGoiNho = e.MaGoiNho
                        }).ToList();


                        string IDStore = (string)(lkTenKhoHang as LookUpEdit).EditValue;
                        if (data.Count != 0)
                        {
                            foreach (var c in data)
                            {
                                clsHangHoa entity = new clsHangHoa()
                                {
                                    IDHangHoa   = c.IDHangHoa,
                                    SoTT        = _SoTT,
                                    ProductCode = c.MaHH,
                                    ProductName = c.TenHH,
                                    MaGoiNho    = c.MaGoiNho,
                                    //SoLuong = _SoLuong,
                                    ThoiGianQuet = DateTime.Now,
                                    LoaiKiemKe   = bLoaiKiemKe
                                };

                                list.Add(entity);

                                bindingSource1.ResetBindings(true);
                                gcDSHangHoa.RefreshDataSource();
                                txtMessage.Text      = string.Format("Tìm thấy: {0}", txtMa.Text);
                                txtMessage.ForeColor = Color.Green;

                                txtMa.Text  = "";
                                bLoaiKiemKe = 0;

                                _SoTT = _SoTT + 1;
                            }
                        }
                        else if (data.Count == 0)
                        {
                            System.Media.SystemSounds.Beep.Play();

                            // MessageBox.Show("Không tìm thấy mã trong kho ! \n Xem gợi ý hàng hóa ?", "Thông Báo ", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                            if (MessageBox.Show("Không tìm thấy mã trong kho ! \n Xem gợi ý hàng hóa ?", "Thông Báo ", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                            {
                                var frmSelect = new ListMaHH();
                                frmSelect._MaHHPartial = txtMa.Text;
                                frmSelect._MaGoiNho    = txtMa.Text;
                                if (frmSelect.GetListMa())
                                {
                                    if (frmSelect.ShowDialog() == DialogResult.OK)
                                    {
                                        _SoLuong = frmSelect._SoLuong;
                                        for (int i = 0; i < _SoLuong; i++)
                                        {
                                            txtMa.Text  = frmSelect.MaHHSelect;
                                            bLoaiKiemKe = 1;
                                            CheckMaHangHoa();
                                        }


                                        return;
                                    }
                                }

                                txtMessage.Text      = string.Format("{0}: {1}", txtMa.Text);
                                txtMessage.ForeColor = Color.Red;
                                txtMa.Text           = "";
                                bLoaiKiemKe          = 0;
                            }
                        }
                    }
                }
            }
            catch
            { }
        }