Exemple #1
0
  public List<MailSendQuery> GetData(MailSendQuery query, out int totalCount)
 {
     try
     {
         return dao.GetData(query, out totalCount);
     }
     catch (Exception ex)
     {
         throw new Exception("MailSendMgr->GetData:"+ex.Message);
     }
 }
Exemple #2
0
        /// <summary>
        /// 獲取數據
        /// </summary>
        /// <param name="sqltText">執行語句</param>
        /// <returns>返回數據表</returns>
        public List<MailSendQuery> GetData(MailSendQuery query, out int totalCount)
        {
            StringBuilder sql = new StringBuilder();
            StringBuilder sqlCondi = new StringBuilder();
            StringBuilder sqlCount = new StringBuilder();
            try
            {
                totalCount = 0;
                ///獲得數據sql 
                sql.AppendFormat("SELECT rowid, mailfrom, mailto, subject, mailbody,status,kuser, kdate, senddate,source,weight");
                ///查詢總數sql
                sqlCount.Append(" select count(rowid) as totalCount ");
                ///條件限制aql
                sqlCondi.Append(" from mail_send  where 1=1 ");
                if (!string.IsNullOrEmpty(query.startT)&&!string.IsNullOrEmpty(query.endT))
                {

                    sqlCondi.AppendFormat(" AND kdate BETWEEN '{0}' AND '{1}' ",Convert.ToDateTime(query.startT).ToString("yyyy-MM-dd HH:mm:ss"), Convert.ToDateTime(query.endT).ToString("yyyy-MM-dd HH:mm:ss"));
                }
                if (!string.IsNullOrEmpty(query.search))
                {
                    sqlCondi.AppendFormat(" AND ( mailto LIKE N'%{0}%' or subject LIKE N'%{1}%') ",query.search,query.search);
                }
                ///是否分頁
                if (query.IsPage)
                {
                    sqlCount.Append(sqlCondi.ToString());
                    DataTable _dt = _accessMySql.getDataTable(sqlCount.ToString());
                    if (_dt != null && _dt.Rows.Count > 0)
                    {
                        //得到滿足條件的總行數
                        totalCount = Convert.ToInt32(_dt.Rows[0]["totalCount"]);
                    }
                }
                ///得到應分頁的數據
                sqlCondi.AppendFormat(" ORDER BY rowid ASC LIMIT {0},{1} ;", query.Start, query.Limit);
                List<MailSendQuery> listStore = _accessMySql.getDataTableForObj<MailSendQuery>(sql.Append(sqlCondi).ToString());
               return listStore;
            }
            catch (Exception ex)
            {
                throw new Exception("MailSendDao.GetData-->" + ex.Message+sql.ToString());
            }
        }
 /// <summary>
 /// 獲取列表數據
 /// </summary>
 /// <returns></returns>
 public HttpResponseBase GetList()
 {
     List<MailSendQuery> stores = new List<MailSendQuery>();
     string json = string.Empty;
     try
     {
         MailSendQuery query = new MailSendQuery();
         query.Start = Convert.ToInt32(Request.Params["Start"] ?? "0");
         if (!string.IsNullOrEmpty(Request.Params["Limit"]))
         {
             query.Limit = Convert.ToInt32(Request.Params["Limit"]);
         }
         if (!string.IsNullOrEmpty(Request.Params["startT"]))
         {
             query.startT = Request.Params["startT"];
         }
         if (!string.IsNullOrEmpty(Request.Params["endT"]))
         {
             query.endT = Request.Params["endT"];
         }
         if (!string.IsNullOrEmpty(Request.Params["search"]))
         {
             query.search = Request.Params["search"];
         }
         stores = mailMgr.GetData(query, out totalCount);
         IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
         //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式     
        timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
        json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(stores, Formatting.Indented, timeConverter) + "}";//返回json數據
     }
     catch (Exception ex)
     {
         Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
         logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
         logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
         log.Error(logMessage);
         json = "{success:false}";
     }
     this.Response.Clear();
     this.Response.Write(json);
     this.Response.End();
     return this.Response;
 }