コード例 #1
0
ファイル: EdmController.cs プロジェクト: lxh2014/gigade-net
 public HttpResponseBase Import()
 {
     string json = string.Empty;
     try
     {
         EdmGroupEmailQuery query = new EdmGroupEmailQuery();
         if (!string.IsNullOrEmpty(Request.Params["ImportCsv"]))
         {
             query.group_id = Convert.ToUInt32(Request.Params["group_id"]);
             HttpPostedFileBase file = Request.Files["ImportCsv"];
             FileManagement fileManagement = new FileManagement();
             string fileName = fileManagement.NewFileName(file.FileName);
             string newFileName = Server.MapPath(excelPath_export) + fileName;
             file.SaveAs(newFileName);
             DataTable _dt = CsvHelper.ReadCsvToDataTable_CN(newFileName, true);
             _edmGroup = new EdmGroupMgr(mySqlConnectionString);
             json = _edmGroup.Import(_dt, query);
         }
     }
     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;
 }
コード例 #2
0
ファイル: EdmController.cs プロジェクト: lxh2014/gigade-net
 public HttpResponseBase Export()
 {
     string json = string.Empty;
     try
     {
         EdmGroup query = new EdmGroup();
         if (!string.IsNullOrEmpty(Request.Params["group_id"]))
         {
             query.group_id = Convert.ToUInt32(Request.Params["group_id"]);
         }
         _edmGroup = new EdmGroupMgr(mySqlConnectionString);
         DataTable _dt = _edmGroup.Export(query);
         string fileName = DateTime.Now.ToString("yyyyMMdd_HHmmss") + "." + "csv";
         DataTable _newdt = new DataTable();
         DataRow dr;
         _newdt.Columns.Add("電子信箱", typeof(string));
         _newdt.Columns.Add("訂閱狀態", typeof(string));
         _newdt.Columns.Add("姓名", typeof(string));
         for (int i = 0; i < _dt.Rows.Count; i++)
         {
             dr = _newdt.NewRow();
             _newdt.Rows.Add(dr);
             _newdt.Rows[i]["電子信箱"] = _dt.Rows[i]["email_address"];
             _newdt.Rows[i]["姓名"] = _dt.Rows[i]["email_name"];
             uint email_status = Convert.ToUInt32(_dt.Rows[i]["email_status"].ToString());
             if (email_status == 1)
             {
                 _newdt.Rows[i]["訂閱狀態"] = "已訂閱";
             }
             else
             {
                 _newdt.Rows[i]["訂閱狀態"] = "未訂閱";
             }
         }
         StringWriter sw = ExcelHelperXhf.SetCsvFromData(_newdt, fileName);
         Response.Clear();
         Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
         Response.ContentType = "application/ms-excel";
         Response.ContentEncoding = Encoding.Default;
         Response.Write(sw);
         Response.End();
     }
     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;
 }
コード例 #3
0
ファイル: EdmController.cs プロジェクト: lxh2014/gigade-net
 public HttpResponseBase SaveEdmGroup()
 {
     EdmGroup query = new EdmGroup();
     string json = string.Empty;
     try
     {
         if (!string.IsNullOrEmpty(Request.Params["group_id"]))
         {
             query.group_id = Convert.ToUInt32(Request.Params["group_id"]);
         }
         if (!string.IsNullOrEmpty(Request.Params["group_name"]))
         {
             query.group_name = (Request.Params["group_name"]);
         }
         _edmGroup = new EdmGroupMgr(mySqlConnectionString);
         json = _edmGroup.SaveEdmGroup(query);
     }
     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;
 }
コード例 #4
0
ファイル: EdmController.cs プロジェクト: lxh2014/gigade-net
 public HttpResponseBase DeleteEdmGroup()
 {
     string json = string.Empty;
     EdmGroup query = null;
     _edmGroup = new EdmGroupMgr(mySqlConnectionString);
     List<EdmGroup> list = new List<EdmGroup>();
     try
     {
         if (!string.IsNullOrEmpty(Request.Form["rowID"]))
         {
             string rowIDs = Request.Form["rowID"];
             if (rowIDs.IndexOf("|") != -1)
             {
                 foreach (string id in rowIDs.Split('|'))
                 {
                     if (!string.IsNullOrEmpty(id))
                     {
                         query = new EdmGroup();
                         query.group_id = Convert.ToUInt32(id);
                         list.Add(query);
                     }
                 }
             }
             json = _edmGroup.DeleteEdmGroup(list);
         }
     }
     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;
 }
コード例 #5
0
ファイル: EdmController.cs プロジェクト: lxh2014/gigade-net
        public HttpResponseBase GetEdmGroupList()
        {
            List<EdmGroup> store = new List<EdmGroup>();
            EdmGroup query = new EdmGroup();
            int totalCount = 0;
            string json = string.Empty;

            query.Start = Convert.ToInt32(Request.Params["start"] ?? "0");
            query.Limit = Convert.ToInt32(Request.Params["limit"] ?? "25");
            if (!string.IsNullOrEmpty(Request.Params["selectType"]))
            {
                query.selectType = Request.Params["selectType"].ToString();
            }
            if (!string.IsNullOrEmpty(Request.Params["search_con"]))
            {
                query.search_con = Request.Params["search_con"].ToString();
            }
            if (!string.IsNullOrEmpty(Request.Params["dateType"]))
            {
                query.dateCondition = Convert.ToInt32(Request.Params["dateType"].ToString());
            }
            if (!string.IsNullOrEmpty(Request.Params["timestart"]))
            {
                query.start = (uint)CommonFunction.GetPHPTime(Request.Params["timestart"].ToString());
            }
            if (!string.IsNullOrEmpty(Request.Params["timeend"]))
            {
                query.end = (uint)CommonFunction.GetPHPTime(Request.Params["timeend"].ToString());
            }
            try
            {
                _edmGroup = new EdmGroupMgr(mySqlConnectionString);
                store = _edmGroup.GetEdmGroupList(query, out totalCount);
                IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
                timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(store, Formatting.Indented, timeConverter) + "}";
            }
            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,totalCount:0,data:[]}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }