예제 #1
0
파일: BanHang.cs 프로젝트: hamalawy/ssmp
        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);
            }
        }
예제 #2
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);
     }
 }
예제 #3
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);
     }
 }
예제 #4
0
파일: BanHang.cs 프로젝트: hamalawy/ssmp
        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);
            }
        }
예제 #5
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);
            }
        }
예제 #6
0
파일: NhapHang.cs 프로젝트: hamalawy/ssmp
        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);
            }
        }
예제 #7
0
파일: NhapHang.cs 프로젝트: hamalawy/ssmp
        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);
            }
        }