private void btnAddChiTiet_Click(object sender, EventArgs e) { DialogResult dialogResult = MessageBox.Show("Are you want to create Invoice", "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.Yes) { string err = ""; // them hoa don hoaDon.NgayLap = DateTime.Now; hoaDon.MaNhanVien = 1; hoaDon.MaKhachHang = 1; bool result = invoiceBusiness.Add(hoaDon, ref err); if (result) { MessageBox.Show("Added successfully!", "Add a new invoice"); string mahoadon = invoiceBusiness.getLastId().Tables[0].Rows[0][0].ToString(); MessageBox.Show(mahoadon); for (int i = 0; i < dt.Rows.Count; i++) { // tim kiem san pham int proId = Int32.Parse(dt.Rows[i][0].ToString()); // tim kiem san pham DataTable dtpro = new DataTable(); dtpro.Clear(); dtpro = productBusiness.searchPro(proId); if (dtpro != null) { product.MaSanPham = Int32.Parse(dtpro.Rows[0][0].ToString()); product.GiaBan = Int32.Parse(dtpro.Rows[0][3].ToString()); int Amount = Int32.Parse(dt.Rows[i][2].ToString()); int Total = Amount * product.GiaBan; // tìm mã hóa đơn chiTietHoaDon.MaSanPham = product.MaSanPham; chiTietHoaDon.Soluong = Amount; chiTietHoaDon.tien = Total; chiTietHoaDon.MaHoaDon = Int32.Parse(mahoadon); bool result1 = listofProBusiness.Add(chiTietHoaDon, ref err); if (!result1) { MessageBox.Show("Failed to add a new product int invoice" + err); break; } } else { MessageBox.Show("Not Find!!!"); break; } } if (result) { MessageBox.Show("Add successfully"); this.Close(); } } else { MessageBox.Show("Failed to add a new invoice! Error" + err, "Add a new invoice"); } } }
private void btnLuu_Click(object sender, EventArgs e) { // tim san pham if (txtPro.Text.Trim() != null) { try { int proId = Int32.Parse(txtPro.Text.Trim()); // tim kiem san pham DataTable dtpro = new DataTable(); dtpro.Clear(); dtpro = productBusiness.searchPro(proId); if (dtpro != null) { product.MaSanPham = Int32.Parse(dtpro.Rows[0][0].ToString()); product.GiaBan = Int32.Parse(dtpro.Rows[0][3].ToString()); if (txtamount.Text.Trim() != null) { try { int Amout = Int32.Parse(txtamount.Text.Trim()); if (Amout >= 0) { int Tien = Amout * product.GiaBan; txtTien.Text = Tien.ToString(); chiTietHoaDon.MaHoaDon = Int32.Parse(txtInvoiceID.Text.Trim()); chiTietHoaDon.MaSanPham = product.MaSanPham; chiTietHoaDon.Soluong = Amout; chiTietHoaDon.tien = Tien; string err = ""; if (them == true) { bool result = listofProBusiness.Add(chiTietHoaDon, ref err); if (result) { MessageBox.Show("Added successfully!", "Add a new prodcut"); } else { MessageBox.Show("Failed to add a new category! Error" + err, "Add a new category"); } loadchitiet(); } else { bool result = listofProBusiness.Edit(chiTietHoaDon, ref err); if (result) { MessageBox.Show("Edited successfully!", "Edit a product"); } else { MessageBox.Show("Failed to edit a category!Error:" + err, "Edit a category"); } } loadchitiet(); } else { MessageBox.Show("Amount greater than 0!!!"); } } catch { MessageBox.Show("Text AMount is number!!!"); } } else { MessageBox.Show("Text Amount not null!!"); } } else { MessageBox.Show("Không tim thây mã!!!"); } } catch { MessageBox.Show("Text Product is number!!!"); } } }