Beispiel #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                HoTro ht = new HoTro();
                string command = "select ProductId, MfgDate, ExpDate, ProdName, PurchasePrice, SalePrice,DisCount, BillSale.CreateDate"
                                    + " from product join ProductName"
                                    + " on Product.productNameid =  ProductName.productNameid"
                                    + " join BillSale"
                                    + " on Product.BillSaleId =  BillSale.BillSaleId";

                SqlDataAdapter adapter = new SqlDataAdapter(command, ht.KetNoi());
                BaoCao.DataSet2 dataset = new SSMP.BaoCao.DataSet2();
                adapter.Fill(dataset, "DataTable1");

                BaoCao.TestXuatCrystalReport report = new SSMP.BaoCao.TestXuatCrystalReport();
                report.SetDataSource(dataset);
                crystalReportViewer1.ReportSource = report;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.StackTrace);
            }
        }
Beispiel #2
0
        public void fillData(DataGridViewRow row)
        {
            try
            {
                textBoxMaPhieu.Text = row.Cells[0].Value.ToString();
                textBoxNgayTao.Text = row.Cells[1].Value.ToString();
                textBoxNguoiLapPhieu.Text = row.Cells[3].Value.ToString();

                HoTro ht = new HoTro();
                ht.TaiDuLieu(comboBoxKh, "Customer", "CustomerId", "CustomerName");
                string CusName = row.Cells[2].Value.ToString();
                CustomerManager pl = new CustomerManager();
                foreach (Customer p in pl.GetAll())
                {
                    if (p.CustomerName.Equals(CusName))
                    {
                        comboBoxKh.SelectedValue = p.ID;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #3
0
        private void btnDoiMatKhau_Click(object sender, EventArgs e)
        {
            //kiem tra mat khau cu khac rong
            if (txtMatKhauCu.Text.Length == 0)
            {
                MessageBox.Show(this, "Mật khẩu cũ không được trống", "Thông báo", MessageBoxButtons.OK);
                txtMatKhauCu.Focus();
                txtMatKhauCu.SelectAll();
                return;
            }

            //kiem tra mat khau moi khac rong
            else if (txtMatKhauMoi.Text.Length == 0)
            {
                MessageBox.Show(this, "Mật khẩu mới không được trống", "Thông báo", MessageBoxButtons.OK);
                txtMatKhauMoi.Focus();
                txtMatKhauMoi.SelectAll();
                return;
            }

            //kiem tra go lai mat khau giong mat khau
            else if (!txtMatKhauMoi.Text.Equals(txtXacNhanLaiMatKhau.Text))
            {
                MessageBox.Show(this, "Mật khẩu mới không trùng nhau", "Thông báo", MessageBoxButtons.OK);
                txtXacNhanLaiMatKhau.Focus();
                txtXacNhanLaiMatKhau.SelectAll();
                return;
            }
            else
            {
                try
                {
                    int userId = DangNhap.idNguoiDung;
                    HoTro ht = new HoTro();
                    SqlConnection conn = ht.KetNoi() ;
                    conn.Open();
                    SqlCommand comm = new SqlCommand("select password from Users where UserId=" + userId, conn);
                    string oldPass = comm.ExecuteScalar().ToString();
                    if (!oldPass.Equals(txtMatKhauCu.Text))
                    {
                        MessageBox.Show(this, "Mật khẩu cũ không đúng !", "Lỗi nhập mật khẩu cũ", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        txtMatKhauCu.Focus();
                        txtMatKhauCu.SelectAll();
                        return;
                    }
                    else {
                        comm = new SqlCommand("update Users set Password='******' where userId = " + userId, conn);
                        comm.ExecuteNonQuery();
                        MessageBox.Show(this, "Bạn đã thay đổi mật khẩu thành công!", "Thông báo thay đổi mật khẩu thành công");
                        this.Dispose();
                    }
                    conn.Close();
                }
                catch (Exception ex) {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Beispiel #4
0
        private void btnCapNhat_Click_1(object sender, EventArgs e)
        {
            try
            {
                ht = new HoTro();
                SqlCommand command = new SqlCommand();
                int maNguoiDung = DangNhap.idNguoiDung;

                for (int i = 0; i < dataGridViewDanhSach.Rows.Count; i++)
                {
                    DataGridViewRow row = dataGridViewDanhSach.Rows[i];
                    // insert PhieuNhapKho
                    int maNhaCungCap = ht.LayVeKhoa("Provider", "ProviderId", "ProviderName", row.Cells[8].Value.ToString());
                    command = new SqlCommand("insert into BillPurchase values(@ngaythang, @giaohang, @maNhacungcap, @manguoiDung)");
                    command.Parameters.Add("@ngaythang", ht.toSQLDateTime(txtNgayThang.Text));
                    command.Parameters.Add("@giaohang", row.Cells[9].Value.ToString());
                    command.Parameters.Add("@maNhacungcap", maNhaCungCap);
                    command.Parameters.Add("@manguoiDung", maNguoiDung);
                    ht.CapNhatDuLieu(command);

                    int soLuong = Int32.Parse(row.Cells[1].Value.ToString());
                    int donvi = ht.LayVeKhoa("Units", "UnitId", "UnitName", row.Cells[4].Value.ToString());
                    Int64 billPurchaseId = ht.LayGiaTriTruongKhoaVuaChen2("BillPurchase", "BillPurchaseId");
                    for (int j = 0; j < soLuong; j++)
                    {
                        // insert SanPham
                        int IdtenSp = ht.LayVeKhoa("ProductName", "ProductNameId", "ProdName", row.Cells[0].Value.ToString());
                        command = new SqlCommand("insert into Product values(" +
                            "@ngaysx, @ngayHetHan, @IdtenSP, @PurchasePrice, null," +
                            "null, @statusId, @billPurchaseId, null, @UnitId, @mota)");
                        command.Parameters.Add("@ngaysx", row.Cells[2].Value.ToString());
                        command.Parameters.Add("@ngayHetHan", row.Cells[3].Value.ToString());
                        command.Parameters.Add("@IdtenSP", IdtenSp);
                        command.Parameters.Add("@PurchasePrice", Int32.Parse(row.Cells[7].Value.ToString())); //VietLH change string to int on 9 Dec 2009
                        command.Parameters.Add("@statusId", 1);
                        command.Parameters.Add("@billPurchaseId", billPurchaseId);
                        command.Parameters.Add("@UnitId", donvi);
                        command.Parameters.Add("@mota", richTextBoxMota.Text);
                        ht.CapNhatDuLieu(command);
                    }
                }
                HoTro.thongBao("Nhập hàng thành công !");
                dataGridViewDanhSach.Rows.Clear();
            }
            catch (Exception ex)
            {
                HoTro.baoLoi(ex.Message);
            }
        }
Beispiel #5
0
        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            try
            {
                if (dataGridViewDS.Rows.Count < 1) {
                    HoTro.baoLoi("Nhập dữ liệu để cập nhật");
                    return;
                }

                HoTro ht = new HoTro() ;
                SqlConnection conn = ht.KetNoi();
                conn.Open();
                SqlCommand command = new SqlCommand();

                int maNguoiDung = DangNhap.idNguoiDung;
                for (int i = 0; i < dataGridViewDS.Rows.Count; i++)
                {
                    DataGridViewRow row = dataGridViewDS.Rows[i];
                    // insert PhieuXuatKho
                    command = new SqlCommand("select CustomerId from Customer where CusTomerName=@Cusname", conn);
                    command.Parameters.Add("@CusNAme", row.Cells[1].Value.ToString());
                    int cusId = Int32.Parse(command.ExecuteScalar().ToString()) ;

                    command = new SqlCommand("insert into BillSale values(@ngaythang, @nguoiMua, @manguoiDung)");
                    command.Parameters.Add("@ngaythang", ht.toSQLDateTime(txtNgayThang.Text));
                    command.Parameters.Add("@nguoiMua", cusId);
                    command.Parameters.Add("@manguoiDung", maNguoiDung);
                    ht.CapNhatDuLieu(command);

                    // update Product
                    Int64 billSaleId = ht.LayGiaTriTruongKhoaVuaChen2("BillSale", "BillSaleId");

                    command = new SqlCommand("update Product set StatusId = 2, billSaleId=@billSaleId where ProductId = @id");
                    command.Parameters.Add("@id", Int64.Parse(row.Cells[0].Value.ToString()));
                    command.Parameters.Add("@billSaleId", billSaleId);
                    ht.CapNhatDuLieu(command);
                }
                HoTro.thongBao("Đã cập nhật !");
                conn.Close();
                dataGridViewDS.Rows.Clear();
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.StackTrace);
                HoTro.baoLoi(ex.Message);
            }
        }
Beispiel #6
0
 public void taiDuLieu()
 {
     HoTro ht = new HoTro();
     if (tabControl1.SelectedIndex == 0)
     {
         ht.TaiDuLieu(comboBoxId, "Product", "ProductId", "ProductId");
         ht.TaiDuLieu(comboBoxIdKh, "Customer", "CustomerId", "CustomerId");
     }
     else if (tabControl1.SelectedIndex == 1)
     {
         string caulenh = "select BillSaleId as 'Mã phiếu', convert(varchar,createDate,103)  as 'Ngày tạo',Customername as 'Tên khách hàng', FullName as 'Người lập phiếu' " +
                      "from BillSale join Customer" +
                      " on BillSale.CustomerId = Customer.CustomerId" +
                      " inner join Users " +
                      "on BillSale.UserId = Users.UserId";
         ht.HienThiVaoDataGridView(dataGridViewDSPhieuBan, caulenh);
     }
 }
Beispiel #7
0
 private void buttonLuu_Click(object sender, EventArgs e)
 {
     try
     {
         HoTro ht = new HoTro();
         SqlCommand command = new SqlCommand("update BillSale set CustomerId=@maNguoiDung where BillSaleId=@ma");
         command.Parameters.Add("@maNguoiDung", Int32.Parse(comboBoxKh.SelectedValue.ToString()));
         command.Parameters.Add("@ma", Int64.Parse(textBoxMaPhieu.Text));
         ht.CapNhatDuLieu(command);
         HoTro.thongBao("Cập nhật thành công !");
         parent.taiDuLieu();
         this.Dispose();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Beispiel #8
0
 private void buttonLuu_Click(object sender, EventArgs e)
 {
     try
     {
         HoTro ht = new HoTro();
         SqlCommand command = new SqlCommand("update BillPurchase set DeliveryStaff=@giaohang, ProviderId=@maNhacungcap where BillPurchaseId=@ma");
         command.Parameters.Add("@giaohang", textBoxNhanVienGH.Text);
         command.Parameters.Add("@maNhacungcap", Int32.Parse(comboBoxNhaCungCap.SelectedValue.ToString()));
         command.Parameters.Add("@ma", Int64.Parse(textBoxMaPhieu.Text ));
         ht.CapNhatDuLieu(command);
         HoTro.thongBao("Cập nhật thành công !");
         parent.taiDuLieu();
         this.Dispose();
     }
     catch (Exception ex) {
         MessageBox.Show(ex.Message);
     }
 }
Beispiel #9
0
 public void taiDuLieu()
 {
     HoTro ht = new HoTro();
     if (tabQuanLyPhieuNhap.SelectedIndex == 0) {
         txtNgayThang.Text = DateTime.Now.ToString("dd/MM/yyyy");
         ht.TaiDuLieu(cboNhaCungCap, "Provider", "ProviderId", "ProviderName");
         ht.TaiDuLieu(cboLoaiSanPham, "Category", "CategoryId", "CategoryName");
         ht.TaiDuLieu(cboDonViTinh, "Units", "UnitId", "UnitName");
         ht.TaiDuLieu(cboTenSanPham, "ProductName", "ProductNameId", "ProdName");
         ht.TaiDuLieu(cboNguonGoc, "Country", "CountryId", "CountryName");
         ht.TaiDuLieu(cboNhaSanXuat, "Manufacturer", "ManId", "ManName");
     }
     else if (tabQuanLyPhieuNhap.SelectedIndex == 1) {
         string caulenh = "select BillPurchaseId as 'Mã phiếu', convert(varchar,createDate,103) as 'Ngày tạo', DeliveryStaff as 'Nhân viên giao hàng', ProviderName as 'Nhà cung cấp', FullName as 'Người lập phiếu' " +
                      "from BillPurchase join Provider" +
                      " on BillPurchase.ProviderId = Provider.ProviderId" +
                      " inner join Users " +
                      "on BillPurchase.UserId = Users.UserId";
         ht.HienThiVaoDataGridView(dataGridViewPhieuNhapHAng, caulenh);
     }
 }
Beispiel #10
0
        private void taiCrystalReport()
        {
            try
            {
                string tuNgay, denNgay;
                if (checkBoxNgay.Checked)
                {
                    tuNgay = dateTimePicker1.Value.ToShortDateString();
                    denNgay = dateTimePicker2.Value.ToShortDateString();
                }
                else
                {
                    tuNgay = "1/1/2009";
                    denNgay = DateTime.Now.ToShortDateString();
                }
                HoTro ht = new HoTro();
                SqlConnection conn = ht.KetNoi();
                string command = "select ProductId,convert(varchar,MfgDate,103) as 'MfgDate',convert(varchar,ExpDate,103) as 'ExpDate' , ProdName, PurchasePrice, SalePrice,DisCount,convert(varchar,BillSale.CreateDate,103) as 'CreateDate' "
                                    + " from product join ProductName"
                                    + " on Product.productNameid =  ProductName.productNameid"
                                    + " join BillSale"
                                    + " on Product.BillSaleId =  BillSale.BillSaleId"
                + " where BillSale.CreateDate >= '" + tuNgay + "' and BillSale.CreateDate <= '" + denNgay + "'";
                SqlDataAdapter adapter = new SqlDataAdapter(command, conn);
                BaoCao.DataSet2 dataset = new SSMP.BaoCao.DataSet2();
                adapter.Fill(dataset, "DataTable1");

                BaoCao.TestXuatCrystalReport report = new SSMP.BaoCao.TestXuatCrystalReport();
                report.SetDataSource(dataset);
                crystalReportViewer1.ReportSource = report;
                conn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #11
0
 private void cellClick(Int64 maPhieu)
 {
     HoTro ht = new HoTro();
     string caulenh = "select ProductId 'Mã sản phẩm', ProdName 'Tên sản phẩm', convert(varchar,mfgDate,103) 'Ngày sản xuất', convert(varchar,ExpDate,103) 'Ngày hết hạn', UnitName 'Đơn vị', PurchasePrice 'Giá bán', SalePrice 'Giá mua', discount 'Giảm giá', StatusName 'Trạng thái' " +
                      " from Product join ProductName" +
                      " on Product.ProductNameId = ProductName.ProductNameId" +
                      " join Units" +
                      " on Product.UnitId = Units.UnitId" +
                      " join ProductStatus" +
                      " on Product.StatusId = ProductStatus.StatusId" +
                      " where BillSaleId = " + maPhieu;
     ht.HienThiVaoDataGridView(dataGridViewHangHoa, caulenh);
 }
Beispiel #12
0
        private void buttonDelete_Click(object sender, EventArgs e)
        {
            try
            {
                // kiem tra xem co xoa dc ko
                if (HoTro.confirm("Bạn có chắc muốn xóa hóa đơn này ?", "Xác nhận").Equals("No")) return;

                Int64 maPhieu = Int64.Parse(dataGridViewDSPhieuBan.SelectedRows[0].Cells[0].Value.ToString());
                HoTro ht = new HoTro();
                SqlCommand com = new SqlCommand("update Product set BillSaleId=NULL, StatusId=1 where BillSaleId=" + maPhieu, ht.KetNoi());
                ht.CapNhatDuLieu(com);
                com = new SqlCommand("delete BillSale where BillSaleId=" + maPhieu, ht.KetNoi());
                ht.CapNhatDuLieu(com);

                taiDuLieu();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #13
0
        private void btnTimKiemQuanLy_Click(object sender, EventArgs e)
        {
            try {
                dataGridViewHangHoa.DataSource = null;
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
            if (txtTimKiemQuanLy.Text.Length == 0) {
                HoTro.baoLoi("Nhập thông tin để tìm kiếm") ;
                return ;
            }
            if (!checkBoxMaPhieu.Checked && !chkNhanviengh.Checked && !cbngaytao.Checked && !chkNguoiLapPhieu.Checked) {
                HoTro.baoLoi("Chọn trường để tìm kiếm");
                return;
            }

            HoTro ht = new HoTro();
            string caulenh = "select BillSaleId as 'Mã phiếu', createDate as 'Ngày tạo',Customername as 'Tên khách hàng', FullName as 'Người lập phiếu' " +
                         "from BillSale join Customer" +
                         " on BillSale.CustomerId = Customer.CustomerId" +
                         " inner join Users " +
                         "on BillSale.UserId = Users.UserId";
            StringBuilder builder = new StringBuilder();
            if (checkBoxMaPhieu.Checked) {
                try {
                    builder.Append("BillSale.BillSaleId = " + Int64.Parse(txtTimKiemQuanLy.Text));
                } catch (Exception ex) { }
            }
            if (chkNhanviengh.Checked) {
                if (builder.Length > 0) builder.Append(" or ") ;
                builder.Append("Customer.Customername like '%" + txtTimKiemQuanLy.Text + "%' " );
            }
            if (cbngaytao.Checked && ht.toSQLDateTime(txtTimKiemQuanLy.Text) != null)
            {
                if (builder.Length > 0) builder.Append(" or ");
                builder.Append("BillSale.createDate ='" + ht.toSQLDateTime(txtTimKiemQuanLy.Text).ToShortDateString() + "' " );
            }
            if (chkNguoiLapPhieu.Checked)
            {
                if (builder.Length > 0) builder.Append(" or ");
                builder.Append("Users.FullName like '%" + txtTimKiemQuanLy.Text + "%' ");
            }
            if (builder.Length > 0) {
                builder.Insert(0, " where ");
            }
            caulenh += builder.ToString();
            ht.HienThiVaoDataGridView(dataGridViewDSPhieuBan, caulenh);
        }
Beispiel #14
0
        private void btnDuaVaoPhieuXuat_Click(object sender, EventArgs e)
        {
            try
            {

                Int64.Parse(comboBoxId.Text);
                Int32.Parse(comboBoxIdKh.Text);
                HoTro ht = new HoTro();
                SqlConnection conn = ht.KetNoi() ;
                conn.Open() ;
                SqlCommand command = new SqlCommand("select CustomerName from Customer where CustomerId = @khachhang", conn);
                command.Parameters.Add("@khachhang", comboBoxIdKh.Text);
                String khachHang = command.ExecuteScalar().ToString();

                command = new SqlCommand("select StatusId from Product where ProductId = @id", conn);
                command.Parameters.Add("@id", Int64.Parse(comboBoxId.Text));
                int statusId = Int32.Parse(command.ExecuteScalar().ToString());
                if (statusId != 1) {
                    HoTro.baoLoi("Sản phẩm này đã được bán");
                    conn.Close();
                    return;
                }

                foreach (DataGridViewRow row in dataGridViewDS.Rows) {
                    if (row.Cells[0].Value.ToString().Contains(comboBoxId.Text)) {
                        HoTro.baoLoi("Sản phẩm này đã có trong phiếu");
                        conn.Close();
                        return;
                    }
                }

                command = new SqlCommand("select ProdName from ProductName where ProductNameId = (select max(ProductNameId) " +
                    " from  Product where ProductId = @id)", conn);
                command.Parameters.Add("@id", Int64.Parse(comboBoxId.Text));
                String tenSp = command.ExecuteScalar().ToString();

                command = new SqlCommand("select UnitName from Units where UnitId = (select max (UnitId) from Product " +
                    "where ProductId = @id)", conn);
                command.Parameters.Add("@id", comboBoxId.Text);
                String donvi = command.ExecuteScalar().ToString();

                command = new SqlCommand("select SalePrice from Product where ProductId = @id", conn);
                command.Parameters.Add("@id", Int64.Parse(comboBoxId.Text));
                String giaBan = command.ExecuteScalar().ToString();
                if (giaBan.Length == 0)
                {
                    HoTro.baoLoi("Sản phẩm này chưa được định giá bán.");
                    conn.Close();
                    return;
                }

                command = new SqlCommand("select Discount from Product where ProductId = @id", conn);
                command.Parameters.Add("@id", Int64.Parse(comboBoxId.Text));
                String giamGia = command.ExecuteScalar().ToString();

                conn.Close();
                String[] data = new String[] { comboBoxId.Text, khachHang, tenSp, donvi, giaBan, giamGia };
                dataGridViewDS.Rows.Add(data);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                HoTro.baoLoi("Dữ liệu nhập sai !");
            }
        }
Beispiel #15
0
        private void btnThemQuanLySanPham_Click(object sender, EventArgs e)
        {
            // validate
            if (txtTenSp.Text.Length == 0) {
                HoTro.baoLoi("Nhập tên sản phẩm");
                return;
            }

            if (!HoTro.IsWholeNumber(txtGiaban.Text)) {
                HoTro.baoLoi("Giá bán nhập không đúng");
                return;
            }

            try
            {
                if (txtGiamGia.Text.Length != 0)
                    Int32.Parse(txtGiamGia.Text);
            }
            catch (Exception ex)
            {
                HoTro.baoLoi("Giảm giá nhập không đúng");
                return;
            }

            try
            {
                ProductName productNameEntity;

                if (MODE == Constants.MODE.ADD)
                {
                    productNameEntity = new ProductName();
                }
                else if (MODE == Constants.MODE.UPDATE)
                {
                    int idxInList = -1;

                    foreach (ProductName objProductName in currentListProductName)
                    {
                        if (objProductName.ID == updateProductNameId)
                        {
                            idxInList = currentListProductName.IndexOf(objProductName);
                        }
                    }
                    productNameEntity = currentListProductName[idxInList];
                }
                else
                {
                    productNameEntity = new ProductName();
                }

                string tenSp = txtTenSp.Text;
                int loaiSp = (int)comboBoxLoaiSanPham.SelectedValue;
                int nhasx = (int)comboBoxNhasx.SelectedValue;
                string giaban = txtGiaban.Text;

                //if (strPassword != strPasswordConfirm)
                //{
                //    MessageBox.Show("Mật khẩu không trùng nhau. Vui lòng nhập lại", Constants.INFO, MessageBoxButtons.OK, MessageBoxIcon.Information);
                //}

                productNameEntity.ProdName = tenSp;
                productNameEntity.CategoryId = loaiSp;
                productNameEntity.ManId = nhasx;

                //Do save new entity
                productNameManager.SaveOrUpdate(productNameEntity);

                //Show message success
                if (MODE == Constants.MODE.ADD)
                {
                    MessageBox.Show("Tạo mới tên sản phẩm [" + productNameEntity.ID + " ] thành công", Constants.INFO, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (MODE == Constants.MODE.UPDATE)
                {
                    ht = new HoTro();
                    int maTenSP = productNameEntity.ID;
                    if (txtGiaban.Text.Length != 0) {
                        SqlCommand command = new SqlCommand("update Product set salePrice= @Giaban where ProductNameId=@ProductNameId");
                        command.Parameters.Add("@ProductNameId", maTenSP);
                        command.Parameters.Add("@Giaban", giaban);
                        ht.CapNhatDuLieu(command);
                    }
                    if (txtGiamGia.Text.Length != 0)
                    {
                        SqlCommand command = new SqlCommand("update Product set discount= @GiamGia where ProductNameId=@ProductNameId");
                        command.Parameters.Add("@ProductNameId", maTenSP);
                        command.Parameters.Add("@GiamGia", Int32.Parse(txtGiamGia.Text));
                        ht.CapNhatDuLieu(command);
                    }
                    MessageBox.Show("Cập nhật tên sản phẩm [" + productNameEntity.ID + " ] thành công", Constants.INFO, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    MODE = Constants.MODE.ADD;
                    btnProductNameSave.Text = "&Thêm mới";
                    this.ResetForm();
                }

                //Refresh grid view after insert successfully
                this.RefreshGridViewProductNames();

            }
            catch (Exception ex)
            {
                logger.Debug(ex.Message);
                logger.Debug(ex.StackTrace);
                MessageBox.Show(ex.StackTrace);
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #16
0
        private void btnTimKiemQuanLy_Click(object sender, EventArgs e)
        {
            if (txtTimKiemQuanLy.Text.Length == 0)
            {
                HoTro.baoLoi("Nhập thông tin để tìm kiếm");
                return;
            }
            if (!checkBoxMaPhieu.Checked && !chkNhanviengh.Checked && !cbngaytao.Checked && !chkNguoiLapPhieu.Checked && !chkNhacungcap.Checked)
            {
                HoTro.baoLoi("Chọn trường để tìm kiếm");
                return;
            }

            HoTro ht = new HoTro();
            string caulenh = "select BillPurchaseId as 'Mã phiếu', createDate as 'Ngày tạo', DeliveryStaff as 'Nhân viên giao hàng', ProviderName as 'Nhà cung cấp', FullName as 'Người lập phiếu' " +
                             "from BillPurchase join Provider" +
                             " on BillPurchase.ProviderId = Provider.ProviderId" +
                             " inner join Users " +
                             "on BillPurchase.UserId = Users.UserId";

            StringBuilder builder = new StringBuilder();
            if (checkBoxMaPhieu.Checked)
            {
                try
                {
                    builder.Append("BillPurchase.BillPurchaseId = " + Int64.Parse(txtTimKiemQuanLy.Text));
                }
                catch (Exception ex) { }
            }
            if (chkNhanviengh.Checked)
            {
                if (builder.Length > 0) builder.Append(" or ");
                builder.Append("BillPurchase.DeliveryStaff like '%" + txtTimKiemQuanLy.Text + "%' ");
            }
            if (cbngaytao.Checked && ht.toSQLDateTime(txtTimKiemQuanLy.Text) != null)
            {
                if (builder.Length > 0) builder.Append(" or ");
                builder.Append("BillPurchase.createDate ='" + ht.toSQLDateTime(txtTimKiemQuanLy.Text).ToShortDateString() + "' ");
            }
            if (chkNhacungcap.Checked)
            {
                if (builder.Length > 0) builder.Append(" or ");
                builder.Append("Provider.ProviderName like '%" + txtTimKiemQuanLy.Text + "%' ");
            }
            if (chkNguoiLapPhieu.Checked)
            {
                if (builder.Length > 0) builder.Append(" or ");
                builder.Append("Users.FullName like '%" + txtTimKiemQuanLy.Text + "%' ");
            }
            if (builder.Length > 0)
            {
                builder.Insert(0, " where ");
            }
            caulenh += builder.ToString();
            ht.HienThiVaoDataGridView(dataGridViewPhieuNhapHAng, caulenh);
        }
Beispiel #17
0
        private void cboNhaSanXuat_SelectedIndexChanged(object sender, EventArgs e)
        {
            ht = new HoTro() ;
            int manId = ht.LayVeKhoa("Manufacturer", "ManId", "ManName", cboNhaSanXuat.Text) ;
            SqlConnection conn = ht.KetNoi();
            try {
                int countryId = 0;
                string CauLenh = "select  countryId from Manufacturer where manId= " + manId;
                SqlCommand cmd = new SqlCommand(CauLenh, conn);
                cmd.Connection.Open();
                dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    cboNguonGoc.SelectedValue = (Object)dr.GetInt32(0);
                }

            } catch(Exception ex) {
                MessageBox.Show(ex.Message) ;
                conn.Close() ;
            }
        }
Beispiel #18
0
        private void buttonDelete_Click(object sender, EventArgs e)
        {
            try
            {
                // kiem tra xem co xoa dc ko
                if (HoTro.confirm("Bạn có chắc muốn xóa hóa đơn này ?", "Xác nhận").Equals("No")) return;

                Int64 maPhieu = Int64.Parse(dataGridViewPhieuNhapHAng.SelectedRows[0].Cells[0].Value.ToString());
                ht = new HoTro();
                SqlCommand com = new SqlCommand("select * from Product where BillPurchaseId=" + maPhieu + " and BillSaleId is not NULL", ht.KetNoi());
                com.Connection.Open();
                if (com.ExecuteScalar() != null)
                {
                    HoTro.baoLoi("Không xóa được hóa đơn mua này, có sản phẩm đã được bán");
                    return;
                }
                com.Connection.Close();
                com = new SqlCommand("delete Product where BillPurchaseId=" + maPhieu, ht.KetNoi());
                ht.CapNhatDuLieu(com);
                com = new SqlCommand("delete BillPurchase where BillPurchaseId=" + maPhieu, ht.KetNoi());
                ht.CapNhatDuLieu(com);

                taiDuLieu();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }