ngày 31-03-2016
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace TestWebService
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
bool isFinish = false;
com.somee.testdrthanh.mywebservice test = new com.somee.testdrthanh.mywebservice();
//Nút hiển thị danh sách Catalog
private void button1_Click(object sender, EventArgs e)
{
isFinish = false;
List<com.somee.testdrthanh.Catalog> listCate = test.getListCatalog().ToList();
listbox_cate.DataSource = listCate;
listbox_cate.DisplayMember="CateName";
listbox_cate.ValueMember="CateId";
isFinish = true;
}
//xử lý hiển thị danh sách sản phẩm theo danh mục
private void listbox_cate_SelectedIndexChanged(object sender, EventArgs e)
{
if (!isFinish) return;
if (listbox_cate.SelectedItem != null)
{
com.somee.testdrthanh.Catalog cate = listbox_cate.SelectedItem as com.somee.testdrthanh.Catalog;
List<com.somee.testdrthanh.Product> listProduct = test.getListProductByCatalogId(cate.CateId).ToList();
listbox_product.DataSource = listProduct;
listbox_product.DisplayMember = "ProductName";
listbox_product.ValueMember = "ProductId";
}
}
//xử lý nút xóa Product
private void button2_Click(object sender, EventArgs e)
{
if (listbox_product.SelectedItem == null)
return;
DialogResult ret = MessageBox.Show("Muốn xóa Product này hả?", "Xác nhận xóa", MessageBoxButtons.YesNo);
if (ret == DialogResult.Yes)
{
com.somee.testdrthanh.Product p = listbox_product.SelectedItem as com.somee.testdrthanh.Product;
bool isDelete= test.deleteProduct(p.ProductId);
if (isDelete)
{
com.somee.testdrthanh.Catalog cate = listbox_cate.SelectedItem as com.somee.testdrthanh.Catalog;
List<com.somee.testdrthanh.Product> listProduct = test.getListProductByCatalogId(cate.CateId).ToList();
listbox_product.DataSource = listProduct;
listbox_product.DisplayMember = "ProductName";
listbox_product.ValueMember = "ProductId";
}
else
{
MessageBox.Show("Không xóa được");
}
}
}
}
}
|