/// <summary> /// 读取id对应的附件列表 /// </summary> /// <param name="id"></param> /// <param name="conn"></param> /// <returns></returns> private static ProductAttachmentList ReadProductAttachmentList(int id, SQLiteConnection conn) { ProductAttachmentList attList = new ProductAttachmentList(); using (SQLiteCommand cmd = new SQLiteCommand(conn)) { cmd.CommandText = "select * from ProductAttachment where ProductID=@ProductID;"; cmd.Parameters.Add(new SQLiteParameter("@ProductID", id)); using (SQLiteDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { // 获取产品基本信息 int productID = int.Parse(dr["ProductID"].ToString()); AttachmentType type = (AttachmentType)Enum.Parse(typeof(AttachmentType), dr["AttachmentType"].ToString()); string path = dr["AttachmentPath"].ToString(); int? ftpID = null; if (Convert.IsDBNull(dr["FtpID"])) { ftpID = null; } else { ftpID = int.Parse(dr["FtpID"].ToString()); } ProductAttachment att = new ProductAttachment(productID, type, path, ftpID); attList.Add(att); } //eof while } //eof dr } //eof cmd return(attList); }
public ProductAttachmentEditDialog(ProductAttachmentList attList, ProductAttachment att) { InitializeComponent(); _attList = attList; _att = att; // 加载ftp列表 _ftpList = MailFtpStorage.ReadMailFtpList(); cbFtp.Items.Clear(); foreach (MailFtp ftp in _ftpList) { cbFtp.Items.Add(new ComboBoxFtpItem(ftp.FtpDesc, ftp.Id)); } ResetDialog(); }
//构造函数 public Product(int id, string productName, string mailTitle, string mailContent, bool disable, ProductAttachmentList attachmentList, ProductReceiverList receiverList, bool isCredit, bool isDelay, int?delaySeconds) { _id = id; _productName = productName; _mailTitle = mailTitle; _mailContent = mailContent; _disable = disable; _attachmentList = attachmentList; _receiverList = receiverList; _isCredit = isCredit; _isDelay = isDelay; _delaySeconds = delaySeconds; }
/// <summary> /// 读取一个产品 /// </summary> /// <param name="id"></param> /// <returns></returns> public static Product ReadProduct(int id) { Product product = null; try { using (SQLiteConnection cn = new SQLiteConnection(ConfigurationManager.AppSettings["conn"])) { cn.Open(); using (SQLiteCommand cmd = new SQLiteCommand(cn)) { cmd.CommandText = "select * from Product where ID=@ID"; cmd.Parameters.Add(new SQLiteParameter("@ID", id)); using (SQLiteDataReader dr = cmd.ExecuteReader()) { if (dr.HasRows) { dr.Read(); string productName = dr["ProductName"].ToString(); string mailTitle = dr["MailTitle"].ToString(); string mailContent = dr["MailContent"].ToString(); bool disable = bool.Parse(dr["Disable"].ToString()); bool isCredit = bool.Parse(dr["IsCredit"].ToString()); bool isDelay = bool.Parse(dr["IsDelay"].ToString()); // 2019-03-20发送前延迟是否单独设置 int? delaySeconds = null; // 2019-03-20发送前延迟秒数 if (Convert.IsDBNull(dr["DelaySeconds"])) { delaySeconds = null; } else { delaySeconds = int.Parse(dr["DelaySeconds"].ToString()); } // 获取附件列表 ProductAttachmentList attList = ReadProductAttachmentList(id, cn); // 获取收件人列表 ProductReceiverList receiverList = ReadProductReceiver(id, cn); product = new Product( id: id, productName: productName, mailTitle: mailTitle, mailContent: mailContent, disable: disable, attachmentList: attList, receiverList: receiverList, isCredit: isCredit, isDelay: isDelay, delaySeconds: delaySeconds); } else { throw new Exception(string.Format(@"记录ID[{0}]不存在!", id)); } } //eof dr } //eof cmd } //eof conn } catch (Exception ex) { throw new Exception(ex.Message); } return(product); }
/// <summary> /// 读取产品列表 /// </summary> /// <returns></returns> public static ProductList ReadProductlist() { ProductList productList = new ProductList(); try { using (SQLiteConnection cn = new SQLiteConnection(ConfigurationManager.AppSettings["conn"])) { cn.Open(); string query = "select * from Product"; using (SQLiteCommand cmd = new SQLiteCommand(query, cn)) { using (SQLiteDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { // 获取产品基本信息 int id = int.Parse(dr["ID"].ToString()); string productName = dr["ProductName"].ToString(); string mailTitle = dr["MailTitle"].ToString(); string mailContent = dr["MailContent"].ToString(); bool disable = bool.Parse(dr["Disable"].ToString()); bool isCredit = bool.Parse(dr["IsCredit"].ToString()); // 2018-12-20是否信用 bool isDelay = bool.Parse(dr["IsDelay"].ToString()); // 2019-03-20发送前延迟是否单独设置 int? delaySeconds = null; // 2019-03-20发送前延迟秒数 if (Convert.IsDBNull(dr["DelaySeconds"])) { delaySeconds = null; } else { delaySeconds = int.Parse(dr["DelaySeconds"].ToString()); } // 获取附件列表 ProductAttachmentList attList = ReadProductAttachmentList(id, cn); // 获取收件人列表 ProductReceiverList receiverList = ReadProductReceiver(id, cn); Product product = new Product( id: id, productName: productName, mailTitle: mailTitle, mailContent: mailContent, disable: disable, attachmentList: attList, receiverList: receiverList, isCredit: isCredit, isDelay: isDelay, delaySeconds: delaySeconds); productList.Add(product); } //eof while } //eof dr } //eof cmd } //eof conn } catch (Exception ex) { throw new Exception(ex.Message); } return(productList); }