예제 #1
0
 public ActionResult CounterView()
 {
     ViewBag.redirect_id = Request.Params["redirect_id"];
     ViewBag.group_id = Request.Params["group_id"];
     int group_id = 0;
     if (!string.IsNullOrEmpty(Request.Params["group_id"]))
     {
         group_id = int.Parse(Request.Params["group_id"]);
     }
     _rdGroupMgr = new RedirectGroupMgr(mySqlConnectionString);
     //獲得群組名稱
     ViewBag.group_name= _rdGroupMgr.GetGroupName(group_id);
     return View();
 }
예제 #2
0
 public ActionResult RedirectList()
 {
     ViewBag.group_id = Request.Params["group_id"];
     int group_id = 0;
     if (!string.IsNullOrEmpty(Request.Params["group_id"]))
     {
         group_id = int.Parse(Request.Params["group_id"]);
     }
     _rdGroupMgr = new RedirectGroupMgr(mySqlConnectionString);
     //獲得群組名稱
     ViewBag.group_name = _rdGroupMgr.GetGroupName(group_id);
     ViewBag.LinkAdress = LinkPath;
     ViewBag.BaseAddress = ConfigurationManager.AppSettings["webDavBaseAddress"];
     ViewBag.path = ConfigurationManager.AppSettings["webDavImage"];
     return View();
 }
예제 #3
0
        public HttpResponseBase RedirectGroupList()
        {
            List<RedirectGroupQuery> rgli = new List<RedirectGroupQuery>();
            string json = string.Empty;
            try
            {
                RedirectGroup RGModel = new RedirectGroup();
                RGModel.Start = Convert.ToInt32(Request.Params["start"] ?? "0");//用於分頁的變量
                RGModel.Limit = Convert.ToInt32(Request.Params["limit"] ?? "20");//用於分頁的變量
                _rdGroupMgr = new RedirectGroupMgr(mySqlConnectionString);
                RGModel.group_name = Request.Params["search_content"];
                int totalCount = 0;
                IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
                //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式     
                timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                rgli = _rdGroupMgr.QueryAll(RGModel, out totalCount);
                json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(rgli, 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:true,totalCount:0,data:[]}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
예제 #4
0
 public HttpResponseBase GetGroupName()
 {
     string json = string.Empty;
     int group_id = 0;
     string group_name = string.Empty;
     try
     {
         _rdGroupMgr = new RedirectGroupMgr(mySqlConnectionString);
         if (!string.IsNullOrEmpty(Request.Params["group_id"]))
         {
             group_id = Convert.ToInt32(Request.Params["group_id"]);
         }
         group_name = _rdGroupMgr.GetGroupName(group_id);
         json = "{success:true,data:'" + group_name + "'}";
     }
     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:true,totalCount:0,data:[]}";
     }
     this.Response.Clear();
     this.Response.Write(json);
     this.Response.End();
     return this.Response;
 }
예제 #5
0
        public HttpResponseBase GetDailyGrid()
        {
            string json = string.Empty;
            try
            {
                //  string selectdate = Request.Params["selectDate"].ToString();
                string selectdate = "2015/2";
                DateTime getMonthDaily = Convert.ToDateTime(Convert.ToDateTime(selectdate).ToString("yyyy-MM-dd 23:59:59"));
                int year = getMonthDaily.Year;
                int month = getMonthDaily.Month;
                RedirectClickQuery RcQuery = new RedirectClickQuery();
                RcQuery.startdate = Convert.ToInt32(year.ToString("0000") + month.ToString("00") + getMonthDaily.Day.ToString("00") + "00");
                RcQuery.enddate = Convert.ToInt32(year.ToString("0000") + getMonthDaily.AddMonths(1).Month.ToString("00") + getMonthDaily.Day.ToString("00") + "00");
                int dayNum = (getMonthDaily.AddMonths(1) - getMonthDaily).Days;
                uint group_id = Convert.ToUInt32(Request.Params["group_id"].ToString());
                _rdGroupMgr = new RedirectGroupMgr(mySqlConnectionString);
                List<Redirect> rgli = _rdGroupMgr.QueryRedirectAll(group_id);
                if (rgli.Count != 0)
                {
                    foreach (var item in rgli)
                    {
                        if (string.IsNullOrEmpty(RcQuery.redirectstr))
                        {
                            RcQuery.redirectstr += item.redirect_id;
                        }
                        else
                        {
                            RcQuery.redirectstr += "," + item.redirect_id;
                        }
                    }
                }
                List<RedirectClick> reCli = _rdGroupMgr.QueryRedirectClictAll(RcQuery);
                uint[] redayArray = new uint[dayNum];
                uint[] reweekArray = new UInt32[7];
                uint[] rehourArray = new UInt32[24];
                StringBuilder dayJson = new StringBuilder();
                //dayJson.Append("{\"day\":[");
                StringBuilder weekJson = new StringBuilder();
                weekJson.Append("{\"week\":[");
                StringBuilder hourJson = new StringBuilder();
                hourJson.Append("{\"hour\":[");
                foreach (var item in reCli)
                {
                    redayArray[item.click_day - 1] += item.click_total;
                    reweekArray[item.click_week] += item.click_total;
                    rehourArray[item.click_hour] += item.click_total;
                }
                DateTime Wday = new DateTime();
                for (int i = 1; i < redayArray.Length; i++)
                {
                    int wd = 0;
                    Wday = Convert.ToDateTime(year.ToString("0000") + "/" + month.ToString("00") + "/" + i.ToString("00"));
                    if (Wday.DayOfWeek == DayOfWeek.Sunday || Wday.DayOfWeek == DayOfWeek.Saturday)
                    {
                        wd = 1;
                    }
                    dayJson.Append("{");
                    dayJson.Append(string.Format("\"datetime\":\"{0}\",\"click_total\":\"{1}\",\"holiday\":\"{2}\"", Wday.ToShortDateString(), redayArray[i - 1], wd));
                    dayJson.Append("}");
                }
                //dayJson.Append("]}");

                for (int i = 0; i < reweekArray.Length; i++)
                {
                    weekJson.Append("{");
                    weekJson.Append(string.Format("\"datetime\":\"{0}\",\"click_total\":\"{1}\"", i, reweekArray[i]));
                    weekJson.Append("}");
                }
                weekJson.Append("]}");
                //weekJson.ToString().Replace("}{", "},{"); 
                for (int i = 0; i < rehourArray.Length; i++)
                {
                    hourJson.Append("{");
                    hourJson.Append(string.Format("\"datetime\":\"{0}\",\"click_total\":\"{1}\"", i, rehourArray[i]));
                    hourJson.Append("}");
                }
                hourJson.Append("]}");
                //hourJson.ToString().Replace("}{", "},{");
                //json = "{success:true,data:[" + (dayJson.ToString() + weekJson.ToString() + hourJson.ToString()).Replace("}{", "},{") + "]}";
                json = "{success:true,data:[" + (dayJson.ToString()).Replace("}{", "},{") + "]}";
            }
            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:true,totalCount:0,data:[]}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
예제 #6
0
        public void GroupExportCSV()
        {
            string newCsvName = string.Empty;
            string json = string.Empty;
            _rdGroupMgr = new RedirectGroupMgr(mySqlConnectionString);
            DataTable dt = new DataTable();
            DataTable dtCsv = new DataTable();
            string newExcelName = string.Empty;
            try
            {
                _redirectMgr = new RedirectMgr(mySqlConnectionString);
                RedirectQuery query = new RedirectQuery();
                if (!string.IsNullOrEmpty(Request.Params["group_id"]))
                {
                    query.group_id = Convert.ToUInt32(Request.Params["group_id"].ToString());
                }
                #region 歷史
                //RedirectGroup rgModel = new RedirectGroup();
                //rgModel.group_id = Convert.ToUInt32(Request.Params["group_id"].ToString());
                //List<Redirect> rli = _rdGroupMgr.QueryRedirectAll(rgModel.group_id);
                //dt.Columns.Add("日期");
                //// Array rename = rli.GroupBy(m => m.redirect_name).Select(m => m.Key).ToArray();
                //// Array reID = rli.GroupBy(m => m.redirect_id).Select(m => m.Key).ToArray();
                //string[] reArray = null;
                //foreach (var li in rli)
                //{
                //    dt.Columns.Add(li.redirect_name);
                //    reArray[li.redirect_id] = li.redirect_name;
                //}
                //// 查詢點率次數
                //List<RedirectClick> reCli = _rdGroupMgr.QueryRedirectClictAll(null);
                //uint minClick = Convert.ToUInt32(reCli.Min(m => m.click_id).ToString());
                //if (minClick > 3000123123)
                //{
                //    minClick = 3000123123;
                //}
                //string[][] reclickArray = null;
                //foreach (var cli in reCli)
                //{
                //    //minClick = minClick > cli.click_id ? cli.click_id : minClick;
                //    int redid = (int)cli.redirect_id;
                //    string d = cli.click_year + "-" + cli.click_month.ToString().Substring(0, 2) + "-" + cli.click_day.ToString().Substring(0, 2);

                //    if (reclickArray['d'][redid] != null)
                //    {
                //        reclickArray['d'][redid] = reclickArray['a'][redid] + cli.click_total;
                //    }
                //    else
                //    {
                //        reclickArray['d'][redid] = cli.click_total.ToString();
                //    }
                //}
                //// int count = 0;
                #endregion
                int totalCount = 0;
                query.IsPage = false;
                dt = _redirectMgr.GetRedirectList(query, out totalCount);
                dtCsv = dt.DefaultView.ToTable(false, new string[] { "group_id", "group_name", "redirect_url", "redirect_total", "redirect_status" });
                for (int i = 0; i < dtCsv.Rows.Count; i++)
                {
                    switch (dtCsv.Rows[i]["redirect_status"].ToString())
                    {
                        case "1":
                            dtCsv.Rows[i]["invoice_status"] = "正常";
                            break;
                        case "2":
                            dtCsv.Rows[i]["invoice_status"] = "停用";
                            break;
                        default:
                            break;
                    }
                    }
                string[] colname = { "群組編號", "群組名稱", "目的連結", "點閱次數", "狀態" };
                string filename = "group_click_" + DateTime.Now.ToString("yyyyMMdd") + ".csv";
                newExcelName = Server.MapPath(excelPath) + filename;
                if (System.IO.File.Exists(newExcelName))
                    {
                    //設置文件的屬性,以防刪除文件的時候因為文件的屬性造成無法刪除
                    System.IO.File.SetAttributes(newExcelName, FileAttributes.Normal);
                    System.IO.File.Delete(newExcelName);
                }
                StringWriter sw = ExcelHelperXhf.SetCsvFromData(dt, filename);
                Response.Clear();
                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(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 = "false";
            }
        }
예제 #7
0
        public HttpResponseBase SaveGroup()
        {
            string json = string.Empty;
            try
            {
                RedirectGroup rgModel = new RedirectGroup();
                _rdGroupMgr = new RedirectGroupMgr(mySqlConnectionString);
                if (!string.IsNullOrEmpty(Request.Params["group_id"]))
                {
                    rgModel.group_id = Convert.ToUInt32(Request.Params["group_id"].ToString());
                    rgModel.group_name = Request.Params["group_name"].ToString();
                    rgModel.group_updatedate = Convert.ToUInt32(CommonFunction.GetPHPTime());
                    if (!string.IsNullOrEmpty(Request.Params["group_type"].ToString()))
                    {
                        rgModel.group_type = Request.Params["group_type"].ToString();
                    }
                    rgModel.group_ipfrom = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList.FirstOrDefault().ToString();
                    if (_rdGroupMgr.Update(rgModel) > 0)
                    {
                        json = "{success:true}";
                    }
                }
                else
                {
                    rgModel.group_name = Request.Params["group_name"].ToString();
                    if (!string.IsNullOrEmpty(Request.Params["group_type"].ToString()))
                    {
                        rgModel.group_type = Request.Params["group_type"].ToString();
                    }
                    rgModel.group_createdate = Convert.ToUInt32(CommonFunction.GetPHPTime());
                    rgModel.group_updatedate = rgModel.group_createdate;
                    rgModel.group_ipfrom = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList.FirstOrDefault().ToString();
                    if (_rdGroupMgr.Save(rgModel) > 0)
                    {
                        json = "{success:true}";
                    }
                }

            }
            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;
        }
예제 #8
0
 public void RedirectClickExport()
 {
     string newCsvName = string.Empty;
     string json = string.Empty;
     _rdGroupMgr = new RedirectGroupMgr(mySqlConnectionString);
     DataTable dt = new DataTable();
     DataTable dtCsv = new DataTable();
     string newExcelName = string.Empty;
     try
     {
         _redirectMgr = new RedirectMgr(mySqlConnectionString);
         RedirectQuery query = new RedirectQuery();
         if (!string.IsNullOrEmpty(Request.Params["group_id"]))
         {
             query.group_id = Convert.ToUInt32(Request.Params["group_id"].ToString());
         }
         int totalCount = 0;
         query.IsPage = false;
         dt = _redirectMgr.GetRedirectList(query, out totalCount);
         dtCsv = dt.DefaultView.ToTable(false, new string[] { "group_id", "group_name", "redirect_url", "redirect_total", "status" });
         string[] colname = { "群組編號", "群組名稱", "目的連結", "點閱次數", "狀態" };
         string filename = "group_click_" + DateTime.Now.ToString("yyyyMMdd") + ".csv";
         newExcelName = Server.MapPath(excelPath) + filename;
         if (System.IO.File.Exists(newExcelName))
         {
             System.IO.File.SetAttributes(newExcelName, FileAttributes.Normal);
             System.IO.File.Delete(newExcelName);
         }
         StringWriter sw = ExcelHelperXhf.SetCsvFromData(dt, filename);
         Response.Clear();
         Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(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 = "false";
     }
 }