/// <summary> /// 得到一个对象实体 主表 /// </summary> public SCZM.Model.System.sys_Mail_Send GetModelMain(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select ID,MailName,ReceivePerId,ReceivePerName,MailContent,Attachment,BillState,FlagDel,OperaId,OperaName,OperaTime from sys_Mail_Send "); strSql.Append(" where FlagDel=0 and ID=@ID "); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; SCZM.Model.System.sys_Mail_Send model = new SCZM.Model.System.sys_Mail_Send(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { #region 父表信息 model = DataRowToModel(ds.Tables[0].Rows[0]); #endregion 父表信息end return(model); } else { return(null); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(SCZM.Model.System.sys_Mail_Send model, string fileId, out string message) { message = "保存成功!"; int rowId = dal.Add(model); if (rowId < 1) { message = "保存失败!"; } else { if (fileId != "") { new DAL.System.sys_Attachment().UpdateUseList(fileId, "邮件", rowId); } if (model.Attachment != "") { new DAL.System.sys_Attachment().UpdateUseList(fileId, "邮件", rowId); } if (model.BillState == 1) { int result = dal.Send(rowId); if (result > 0) { message = "发送成功!"; } else { message = "发送失败!"; } } } return(rowId); }
/// <summary> /// 得到一个对象实体 子方法 从DataRow中 /// </summary> public SCZM.Model.System.sys_Mail_Send DataRowToModel(DataRow row) { SCZM.Model.System.sys_Mail_Send model = new SCZM.Model.System.sys_Mail_Send(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = int.Parse(row["ID"].ToString()); } if (row["MailName"] != null) { model.MailName = row["MailName"].ToString(); } if (row["ReceivePerId"] != null) { model.ReceivePerId = row["ReceivePerId"].ToString(); } if (row["ReceivePerName"] != null) { model.ReceivePerName = row["ReceivePerName"].ToString(); } if (row["MailContent"] != null) { model.MailContent = row["MailContent"].ToString(); } if (row["Attachment"] != null) { model.Attachment = row["Attachment"].ToString(); } if (row["BillState"] != null && row["BillState"].ToString() != "") { model.BillState = int.Parse(row["BillState"].ToString()); } if (row["FlagDel"] != null && row["FlagDel"].ToString() != "") { if ((row["FlagDel"].ToString() == "1") || (row["FlagDel"].ToString().ToLower() == "true")) { model.FlagDel = true; } else { model.FlagDel = false; } } if (row["OperaId"] != null && row["OperaId"].ToString() != "") { model.OperaId = int.Parse(row["OperaId"].ToString()); } if (row["OperaName"] != null) { model.OperaName = row["OperaName"].ToString(); } if (row["OperaTime"] != null && row["OperaTime"].ToString() != "") { model.OperaTime = DateTime.Parse(row["OperaTime"].ToString()); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(SCZM.Model.System.sys_Mail_Send model, string fileId, out string message) { message = "保存成功!"; int rows = dal.Update(model); if (rows == 0) { message = "对不起,该条数据已被其他人删除!"; return(false); } else { DAL.System.sys_Attachment attachDal = new DAL.System.sys_Attachment(); attachDal.DelUseList("邮件", model.ID); if (fileId != "") { attachDal.UpdateUseList(fileId, "邮件", model.ID); } if (model.Attachment != "") { attachDal.UpdateUseList(fileId, "邮件", model.ID); } if (model.BillState == 1) { int result = dal.Send(model.ID); if (result > 0) { message = "发送成功!"; } else { message = "发送失败!"; } } return(true); } }
/// <summary> /// 增加一条数据,及其子表数据 /// </summary> public int Add(SCZM.Model.System.sys_Mail_Send model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into sys_Mail_Send("); strSql.Append("MailName,ReceivePerId,ReceivePerName,MailContent,Attachment,BillState,FlagDel,OperaId,OperaName,OperaTime)"); strSql.Append(" values ("); strSql.Append("@MailName,@ReceivePerId,@ReceivePerName,@MailContent,@Attachment,@BillState,@FlagDel,@OperaId,@OperaName,@OperaTime)"); strSql.Append(";set @ReturnValue= @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@MailName", SqlDbType.NVarChar, 50), new SqlParameter("@ReceivePerId", SqlDbType.VarChar, 1000), new SqlParameter("@ReceivePerName", SqlDbType.NVarChar, 2000), new SqlParameter("@MailContent", SqlDbType.NText), new SqlParameter("@Attachment", SqlDbType.VarChar, 100), new SqlParameter("@BillState", SqlDbType.Int, 4), new SqlParameter("@FlagDel", SqlDbType.Bit, 1), new SqlParameter("@OperaId", SqlDbType.Int, 4), new SqlParameter("@OperaName", SqlDbType.NVarChar, 20), new SqlParameter("@OperaTime", SqlDbType.DateTime), new SqlParameter("@ReturnValue", SqlDbType.Int) }; parameters[0].Value = model.MailName; parameters[1].Value = model.ReceivePerId; parameters[2].Value = model.ReceivePerName; parameters[3].Value = model.MailContent; parameters[4].Value = model.Attachment; parameters[5].Value = model.BillState; parameters[6].Value = model.FlagDel; parameters[7].Value = model.OperaId; parameters[8].Value = model.OperaName; parameters[9].Value = model.OperaTime; parameters[10].Direction = ParameterDirection.Output; List <CommandInfo> sqllist = new List <CommandInfo>(); CommandInfo cmd = new CommandInfo(strSql.ToString(), parameters); sqllist.Add(cmd); StringBuilder strSql2; if (model.sys_Mail_Send_ReceivePersons != null) { foreach (SCZM.Model.System.sys_Mail_Send_ReceivePerson models in model.sys_Mail_Send_ReceivePersons) { strSql2 = new StringBuilder(); strSql2.Append("insert into sys_Mail_Send_ReceivePerson("); strSql2.Append("MailId,ReceivePerId,FlagDel)"); strSql2.Append(" values ("); strSql2.Append("@MailId,@ReceivePerId,@FlagDel)"); SqlParameter[] parameters2 = { new SqlParameter("@MailId", SqlDbType.Int, 4), new SqlParameter("@ReceivePerId", SqlDbType.Int, 4), new SqlParameter("@FlagDel", SqlDbType.Bit, 1) }; parameters2[0].Direction = ParameterDirection.InputOutput; parameters2[1].Value = models.ReceivePerId; parameters2[2].Value = models.FlagDel; cmd = new CommandInfo(strSql2.ToString(), parameters2); sqllist.Add(cmd); } } DbHelperSQL.ExecuteSqlTranWithIndentity(sqllist); return((int)parameters[10].Value); }
/// <summary> /// 得到一个对象实体 /// </summary> public SCZM.Model.System.sys_Mail_Send GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select ID,MailName,ReceivePerId,ReceivePerName,MailContent,Attachment,BillState,FlagDel,OperaId,OperaName,OperaTime from sys_Mail_Send "); strSql.Append(" where FlagDel=0 and ID=@ID "); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; SCZM.Model.System.sys_Mail_Send model = new SCZM.Model.System.sys_Mail_Send(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { #region 父表信息 model = DataRowToModel(ds.Tables[0].Rows[0]); #endregion 父表信息end #region 子表信息 StringBuilder strSql2 = new StringBuilder(); strSql2.Append("select ID,MailId,ReceivePerId,FlagDel from sys_Mail_Send_ReceivePerson "); strSql2.Append(" where FlagDel=0 and MailId=@MailId "); SqlParameter[] parameters2 = { new SqlParameter("@MailId", SqlDbType.Int, 4) }; parameters2[0].Value = ID; DataSet ds2 = DbHelperSQL.Query(strSql2.ToString(), parameters2); if (ds2.Tables[0].Rows.Count > 0) { #region 子表字段信息 int i = ds2.Tables[0].Rows.Count; List <SCZM.Model.System.sys_Mail_Send_ReceivePerson> models = new List <SCZM.Model.System.sys_Mail_Send_ReceivePerson>(); SCZM.Model.System.sys_Mail_Send_ReceivePerson modelt; for (int n = 0; n < i; n++) { modelt = new SCZM.Model.System.sys_Mail_Send_ReceivePerson(); if (ds2.Tables[0].Rows[n]["ID"].ToString() != null && ds2.Tables[0].Rows[n]["ID"].ToString() != "") { modelt.ID = int.Parse(ds2.Tables[0].Rows[n]["ID"].ToString()); } if (ds2.Tables[0].Rows[n]["MailId"].ToString() != null && ds2.Tables[0].Rows[n]["MailId"].ToString() != "") { modelt.MailId = int.Parse(ds2.Tables[0].Rows[n]["MailId"].ToString()); } if (ds2.Tables[0].Rows[n]["ReceivePerId"].ToString() != null && ds2.Tables[0].Rows[n]["ReceivePerId"].ToString() != "") { modelt.ReceivePerId = int.Parse(ds2.Tables[0].Rows[n]["ReceivePerId"].ToString()); } if (ds2.Tables[0].Rows[n]["FlagDel"].ToString() != null && ds2.Tables[0].Rows[n]["FlagDel"].ToString() != "") { if ((ds2.Tables[0].Rows[n]["FlagDel"].ToString() == "1") || (ds2.Tables[0].Rows[n]["FlagDel"].ToString().ToLower() == "true")) { modelt.FlagDel = true; } else { modelt.FlagDel = false; } } models.Add(modelt); } model.sys_Mail_Send_ReceivePersons = models; #endregion 子表字段信息end } #endregion 子表信息end return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public int Update(SCZM.Model.System.sys_Mail_Send model) { List <CommandInfo> sqllist = new List <CommandInfo>(); CommandInfo cmd = null; StringBuilder strSql = new StringBuilder(); strSql.Append("update sys_Mail_Send set "); strSql.Append("MailName=@MailName,"); strSql.Append("ReceivePerId=@ReceivePerId,"); strSql.Append("ReceivePerName=@ReceivePerName,"); strSql.Append("MailContent=@MailContent,"); strSql.Append("Attachment=@Attachment,"); strSql.Append("BillState=@BillState,"); strSql.Append("FlagDel=@FlagDel,"); strSql.Append("OperaId=@OperaId,"); strSql.Append("OperaName=@OperaName,"); strSql.Append("OperaTime=@OperaTime"); strSql.Append(" where FlagDel=0 and ID=@ID "); SqlParameter[] parameters = { new SqlParameter("@MailName", SqlDbType.NVarChar, 50), new SqlParameter("@ReceivePerId", SqlDbType.VarChar, 1000), new SqlParameter("@ReceivePerName", SqlDbType.NVarChar, 2000), new SqlParameter("@MailContent", SqlDbType.NText), new SqlParameter("@Attachment", SqlDbType.VarChar, 100), new SqlParameter("@BillState", SqlDbType.Int, 4), new SqlParameter("@FlagDel", SqlDbType.Bit, 1), new SqlParameter("@OperaId", SqlDbType.Int, 4), new SqlParameter("@OperaName", SqlDbType.NVarChar, 20), new SqlParameter("@OperaTime", SqlDbType.DateTime), new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = model.MailName; parameters[1].Value = model.ReceivePerId; parameters[2].Value = model.ReceivePerName; parameters[3].Value = model.MailContent; parameters[4].Value = model.Attachment; parameters[5].Value = model.BillState; parameters[6].Value = model.FlagDel; parameters[7].Value = model.OperaId; parameters[8].Value = model.OperaName; parameters[9].Value = model.OperaTime; parameters[10].Value = model.ID; cmd = new CommandInfo(strSql.ToString(), parameters); sqllist.Add(cmd); StringBuilder strSql2 = new StringBuilder(); strSql2.Append("delete from sys_Mail_Send_ReceivePerson where MailId=@MailId "); SqlParameter[] parameters2 = { new SqlParameter("@MailId", SqlDbType.Int, 4) }; parameters2[0].Value = model.ID; cmd = new CommandInfo(strSql2.ToString(), parameters2); sqllist.Add(cmd); StringBuilder strSql3; if (model.sys_Mail_Send_ReceivePersons != null) { foreach (SCZM.Model.System.sys_Mail_Send_ReceivePerson models in model.sys_Mail_Send_ReceivePersons) { strSql3 = new StringBuilder(); strSql3.Append("insert into sys_Mail_Send_ReceivePerson("); strSql3.Append("MailId,ReceivePerId,FlagDel)"); strSql3.Append(" values ("); strSql3.Append("@MailId,@ReceivePerId,@FlagDel)"); SqlParameter[] parameters3 = { new SqlParameter("@MailId", SqlDbType.Int, 4), new SqlParameter("@ReceivePerId", SqlDbType.Int, 4), new SqlParameter("@FlagDel", SqlDbType.Bit, 1) }; parameters3[0].Value = model.ID; parameters3[1].Value = models.ReceivePerId; parameters3[2].Value = models.FlagDel; cmd = new CommandInfo(strSql3.ToString(), parameters3); sqllist.Add(cmd); } } int rows = DbHelperSQL.ExecuteSqlTran(sqllist); return(rows); }