/// <summary> /// 读取id对应的收件人列表 /// </summary> /// <param name="id"></param> /// <param name="conn"></param> /// <returns></returns> private static ProductReceiverList ReadProductReceiver(int id, SQLiteConnection conn) { ProductReceiverList receiverList = new ProductReceiverList(); string query = string.Format("select * from ProductReceiver where ProductID='{0}';", id); using (SQLiteCommand cmd = new SQLiteCommand(query, conn)) { using (SQLiteDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { // 获取产品基本信息 int productID = int.Parse(dr["ProductID"].ToString()); string emailAddress = dr["EmailAddress"].ToString(); ReceiverType receiverType = (ReceiverType)Enum.Parse(typeof(ReceiverType), dr["ReceiverType"].ToString()); ProductReceiver receiver = new ProductReceiver(productID, emailAddress, receiverType); receiverList.Add(receiver); } //eof while } //eof dr } //eof cmd return(receiverList); }
/// <summary> /// 收件人删除(内存) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void menuReceiverDel_Click(object sender, EventArgs e) { if (lvReceiver.SelectedItems.Count > 0) { ProductReceiver receiver = (ProductReceiver)lvReceiver.SelectedItems[0].Tag; Product.ProductReceiverList.Remove(receiver); // 删除对象 ResetReceiverList(); // 刷新界面 } }
public ProductReceiverEditDialog(ProductReceiverList receiverList, ProductReceiver receiver) { InitializeComponent(); _receiverList = receiverList; _receiver = receiver; ResetDialog(); }
/// <summary> /// 收件人修改(内存) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void menuReceiverEdit_Click(object sender, EventArgs e) { if (lvReceiver.SelectedItems.Count > 0) { ProductReceiver receiver = (ProductReceiver)lvReceiver.SelectedItems[0].Tag; using (ProductReceiverEditDialog dlg = new ProductReceiverEditDialog(Product.ProductReceiverList, receiver)) { if (dlg.ShowDialog() == DialogResult.OK) { // 刷新界面 ResetReceiverList(); } } } }
/// <summary> /// 收件人增加(内存) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void menuReceiverAdd_Click(object sender, EventArgs e) { ProductReceiver tmpReceiver = new ProductReceiver(Product.Id, string.Empty, ReceiverType.收件人); using (ProductReceiverEditDialog dlg = new ProductReceiverEditDialog(Product.ProductReceiverList, tmpReceiver)) { if (dlg.ShowDialog() == DialogResult.OK) { // 增加对象 Product.ProductReceiverList.Add(tmpReceiver); // 刷新界面 ResetReceiverList(); } } }