예제 #1
0
 private void simpleButton1_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Duyệt phiếu nhập này?", "Duyệt", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
     {
         try
         {
             var dbEntry = db.PHIEUNHAPs.SingleOrDefault(x => x.MAPHIEUNHAP == txtMaPhieuNhap.Text);
             dbEntry.STATUS = 1;
             var Chitiet = db.CHITIETNHAPs.Where(x => x.PHIEUNHAPID == dbEntry.ID).ToList();
             foreach (var item in Chitiet)
             {
                 MATHANG mh = db.MATHANGs.Where(p => p.ID == item.MATHANGID).FirstOrDefault();
                 mh.SOLUONG += item.SOLUONG;
             }
             db.SaveChanges();
             MessageBox.Show("Duyệt thành công !", "Duyệt", MessageBoxButtons.OK, MessageBoxIcon.Information);
             LoadDgvDanhSachHoaDon();
             btn_Xoa.Enabled   = false;
             btn_Duyet.Enabled = false;
         }
         catch
         {
             MessageBox.Show("Có lỗi xảy ra ! Vui lòng thử lại", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
 }
예제 #2
0
        private void btnTra_Click(object sender, EventArgs e)
        {
            CHITIETNHAP a = getChiTietNhapByForm();

            if (a.ID == 0)
            {
                MessageBox.Show("Chưa có chi tiết nhập nào được chọn",
                                "Thông báo",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            DialogResult rs = MessageBox.Show("Bạn có chắc chắn xóa chi tiết nhập này?",
                                              "Thông báo",
                                              MessageBoxButtons.OK,
                                              MessageBoxIcon.Warning);

            if (rs == DialogResult.Cancel)
            {
                return;
            }

            MATHANG mh = db.MATHANGs.Where(p => a.MATHANGID == p.ID).FirstOrDefault();

            mh.SOLUONG -= a.SOLUONG;
            if (mh.SOLUONG < 0)
            {
                mh.SOLUONG = 0;
            }

            pn.TONGTIEN -= a.SOLUONG * a.DONGIA;
            db.CHITIETNHAPs.Remove(a);

            try
            {
                db.SaveChanges();
                MessageBox.Show("Xóa chi tiết nhập thành công",
                                "Thông báo",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Xóa chi tiết nhập thất bại\n" + ex.Message,
                                "Thông báo",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            finally
            {
                LoadDgvChiTietNhap();
            }
        }
예제 #3
0
        private void btnHoanThanh_Click(object sender, EventArgs e)
        {
            if (Check())
            {
                CHITIETHOADON z = new CHITIETHOADON();
                z.MATHANGID = Helper.IDSanPham;
                z.SOLUONG   = (int)txtSoLuong.Value;

                MATHANG mhz = Helper.db.MATHANGs.Where(p => p.ID == Helper.IDSanPham).First();
                z.DONGIA    = Helper.GiaSanPham(mhz);
                z.THANHTIEN = z.SOLUONG * z.DONGIA;
                z.HOADONID  = pn.ID;

                CHITIETHOADON cthd = db.CHITIETHOADONs.Where(p => p.MATHANGID == z.MATHANGID && p.HOADONID == pn.ID).FirstOrDefault();

                if (cthd == null)
                {
                    db.CHITIETHOADONs.Add(z);
                }
                else
                {
                    cthd.SOLUONG   += z.SOLUONG;
                    cthd.THANHTIEN += z.THANHTIEN;
                }

                try
                {
                    db.SaveChanges();
                    MATHANG mh = db.MATHANGs.Where(p => p.ID == z.MATHANGID).FirstOrDefault();
                    mh.SOLUONG  -= z.SOLUONG;
                    pn.TONGTIEN += z.THANHTIEN;
                    db.SaveChanges();

                    MessageBox.Show("Thêm chi tiết hóa đơn thành công",
                                    "Thông báo",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);



                    this.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Thêm chi tiết hóa đơn thất bại\n" + ex.Message,
                                    "Thông báo",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    this.Close();
                }
            }
        }
예제 #4
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            if (btnThem.Text == "Thêm")
            {
                btnSua.Enabled = false;
                btnThem.Text   = "Lưu";
                btnXoa.Text    = "Hủy";

                ClearControl();
                UnlockControl();

                lblTaiKhoan.Visible = true;
                txtTaiKhoan.Visible = true;

                return;
            }

            if (btnThem.Text == "Lưu")
            {
                if (Check())
                {
                    btnThem.Text = "Thêm";
                    btnXoa.Text  = "Xóa";
                    LockControl();

                    lblTaiKhoan.Visible = false;
                    txtTaiKhoan.Visible = false;

                    NHANVIEN moi = getNhanVienByForm();
                    db.NHANVIENs.Add(moi);

                    try
                    {
                        db.SaveChanges();
                        MessageBox.Show("Thêm thông tin nhân viên thành công",
                                        "Thông báo",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Thêm thông tin nhân viên thất bại\n" + ex.Message,
                                        "Thông báo",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                    LoadDgvNhanVien();
                }
                return;
            }
        }
예제 #5
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            if (btnThem.Text == "Thêm")
            {
                btnSua.Enabled = false;
                btnThem.Text   = "Lưu";
                btnXoa.Text    = "Hủy";

                ClearControl();
                UnlockControl();

                return;
            }

            if (btnThem.Text == "Lưu")
            {
                if (Check())
                {
                    btnThem.Text = "Thêm";
                    btnXoa.Text  = "Xóa";
                    LockControl();

                    MATHANG moi = getMATHANGByForm();
                    moi.SOLUONG = 0;
                    db.MATHANGs.Add(moi);


                    try
                    {
                        db.SaveChanges();

                        MessageBox.Show("Thêm thông tin mặt hàng thành công",
                                        "Thông báo",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Thêm thông tin mặt hàng thất bại\n" + ex.Message,
                                        "Thông báo",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                    LoadDgvMATHANG();
                }
                return;
            }
        }
예제 #6
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            if (btnThem.Text == "Thêm")
            {
                btnSua.Enabled       = false;
                btnThem.Text         = "Lưu";
                btnXoa.Text          = "Hủy";
                gridControl1.Enabled = false;

                ClearControl();
                UnlockControl();


                return;
            }

            if (btnThem.Text == "Lưu")
            {
                if (Check())
                {
                    btnThem.Text = "Thêm";
                    btnXoa.Text  = "Xóa";
                    LockControl();

                    NHASANXUAT moi = getNHAXUATBANByForm();
                    db.NHASANXUATs.Add(moi);

                    try
                    {
                        db.SaveChanges();
                        MessageBox.Show("Thêm thông tin nhà sản xuất thành công",
                                        "Thông báo",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Thêm thông tin nhà sản xuất thất bại\n" + ex.Message,
                                        "Thông báo",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                    LoadDgvNHASANXUAT();
                    gridControl1.Enabled = true;
                }
                return;
            }
        }
예제 #7
0
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            THUE_MATHANG item = new THUE_MATHANG();

            item.ID_THUE    = Convert.ToInt16(comboBox1.SelectedValue.ToString());
            item.ID_MATHANG = idmh;
            var dbEntry = db.THUE_MATHANG.SingleOrDefault(x => x.ID_MATHANG == item.ID_MATHANG && x.ID_THUE == item.ID_THUE);

            if (dbEntry != null)
            {
                MessageBox.Show("Mặt hàng này đã áp dụng loại thuế này", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            try
            {
                db.THUE_MATHANG.Add(item);
                db.SaveChanges();
                MessageBox.Show("Áp dụng thuế thành công", "Thành công", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            catch
            {
                MessageBox.Show("Có lỗi xảy ra", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
예제 #8
0
        private void btnHoanThanh_Click(object sender, EventArgs e)
        {
            if (Check())
            {
                CHITIETNHAP z = new CHITIETNHAP();
                z.MATHANGID   = Helper.IDSanPham;
                z.SOLUONG     = (int)txtSoLuong.Value;
                z.DONGIA      = (int)txtDonGia.Value;
                z.THANHTIEN   = z.SOLUONG * z.DONGIA;
                z.PHIEUNHAPID = pn.ID;
                db.CHITIETNHAPs.Add(z);

                try
                {
                    db.SaveChanges();
                    MATHANG mh = db.MATHANGs.Where(p => p.ID == z.MATHANGID).FirstOrDefault();
                    mh.SOLUONG  += z.SOLUONG;
                    pn.TONGTIEN += z.THANHTIEN;
                    db.SaveChanges();

                    MessageBox.Show("Thêm chi tiết nhập thành công",
                                    "Thông báo",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);



                    this.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Thêm chi tiết nhập thất bại\n" + ex.Message,
                                    "Thông báo",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    this.Close();
                }
            }
        }
예제 #9
0
 private void btnThem_Click(object sender, EventArgs e)
 {
     if (btnThem.Text == "Thêm")
     {
         btnThem.Text     = "Lưu";
         btnSua.Enabled   = false;
         btnXoa.Text      = "Hủy";
         dgcThue.Enabled  = false;
         txtTen.ReadOnly  = false;
         txtThue.ReadOnly = false;
         txtTen.Text      = "";
         txtThue.Text     = "";
         return;
     }
     if (btnThem.Text == "Lưu")
     {
         THUE item = new THUE();
         try
         {
             item.Ten      = txtTen.Text;
             item.ThueXuat = Convert.ToInt16(txtThue.Text);
             db.THUEs.Add(item);
             db.SaveChanges();
             MessageBox.Show("Thêm thành công", "Thành công", MessageBoxButtons.OK, MessageBoxIcon.Information);
             btnThem.Text    = "Thêm";
             btnSua.Enabled  = true;
             btnXoa.Text     = "Xóa";
             dgcThue.Enabled = true;
             txtTen.Enabled  = true;
             txtThue.Enabled = true;
             LoadData();
         }
         catch
         {
             MessageBox.Show("Có lỗi xảy ra ! Xem lại các giá trị", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
예제 #10
0
        private void btnDoiMatKhau_Click(object sender, EventArgs e)
        {
            if (txtMatKhauCu.Text != nv.MATKHAU)
            {
                MessageBox.Show("Mật khẩu cũ không chính xác",
                                "Thông báo",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            if (txtMatKhauMoi.Text == "")
            {
                MessageBox.Show("Mật khẩu mới không được để trống",
                                "Thông báo",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            if (txtXacNhan.Text != txtMatKhauMoi.Text)
            {
                MessageBox.Show("Xác nhận mật khẩu không chính xác",
                                "Thông báo",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            nv.MATKHAU = txtMatKhauMoi.Text;

            try
            {
                db.SaveChanges();
                MessageBox.Show("Thay đổi mật khẩu thành công",
                                "Thông báo",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Thay đổi mật khẩu thất bại\n" + ex.Message,
                                "Thông báo",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                this.Close();
            }
        }
예제 #11
0
        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            if (!Check())
            {
                return;
            }

            try
            {
                nhanvien.TEN      = txtHoTen.Text;
                nhanvien.CHUCVU   = cbxChucVu.SelectedIndex;
                nhanvien.GIOITINH = cbxGioiTinh.SelectedIndex;
                nhanvien.NGAYSINH = dateNgaySinh.DateTime;
                nhanvien.SDT      = txtSDT.Text;
                nhanvien.QUEQUAN  = txtQueQuan.Text;
                nhanvien.EMAIL    = txtEmail.Text;

                nhanvien.ANH = Helper.imageToByteArray(imgAnh.Image);

                db.SaveChanges();
                MessageBox.Show("Thay đổi thông tin cá nhân thành công",
                                "Thông báo",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Thay đổi thông tin cá nhân không thành công\n" + ex.Message,
                                "Thông báo",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            finally
            {
                this.Close();
            }
        }