public List<Model.PromotionsBonusSerial> QueryById(PromotionsBonusSerial query, out int TotalCount) { try { return _bonusDao.QueryById(query, out TotalCount); } catch (Exception ex) { throw new Exception("PromotionsBonusMgr-->UpdateActive-->" + ex.Message, ex); } }
public HttpResponseBase PromotionsBonusSerialListsExport() { List<PromotionsBonusSerial> stores = new List<PromotionsBonusSerial>(); List<PromotionsBonusSerial> mystores = new List<PromotionsBonusSerial>(); string json = "false"; _promBnusSeral = new PromotionsBonusSerialMgr(mySqlConnectionString); int id = 0; if (!string.IsNullOrEmpty(Request.Params["ids"])) { id = Convert.ToInt32(Request.Params["ids"]); } stores = _promBnusSeral.QueryById(id); int j = 1; for (int i = 0; i < stores.Count; i++) { PromotionsBonusSerial query = new PromotionsBonusSerial(); query.id = stores[i].id; query.active = stores[i].active; query.promotion_id = stores[i].promotion_id; query.serial = stores[i].serial; query.myid = j++; mystores.Add(query); } DataTable dtHZ = new DataTable(); string newExcelName = string.Empty; dtHZ.Columns.Add("編號", typeof(string)); dtHZ.Columns.Add("序號", typeof(string)); dtHZ.Columns.Add("ACTIVE", typeof(string)); try { foreach (PromotionsBonusSerial dr_v in mystores) { DataRow dr = dtHZ.NewRow(); dr[0] = dr_v.myid.ToString(); dr[1] = dr_v.serial.ToString(); dr[2] = dr_v.active.ToString(); dtHZ.Rows.Add(dr); } string[] colname = new string[dtHZ.Columns.Count]; string filename = "promotions_bonus_serial.csv"; newExcelName = Server.MapPath(excelPath) + filename; for (int i = 0; i < dtHZ.Columns.Count; i++) { colname[i] = dtHZ.Columns[i].ColumnName; } if (System.IO.File.Exists(newExcelName)) { System.IO.File.Delete(newExcelName); } CsvHelper.ExportDataTableToCsv(dtHZ, newExcelName, colname, true); json = "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); } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
//public HttpResponseBase PromotionsBonusSerialLists() //{ // List<PromotionsBonusSerial> stores = new List<PromotionsBonusSerial>(); // List<PromotionsBonusSerial> mystores = new List<PromotionsBonusSerial>(); // _promBnusSeral = new PromotionsBonusSerialMgr(mySqlConnectionString); // string json = string.Empty; // try // { // int id = Convert.ToInt32(Request.Params["ids"]); // stores = _promBnusSeral.QueryById(id); // int i; // int j = 1; // for (i = 0; i < stores.Count; i++) // { // PromotionsBonusSerial query = new PromotionsBonusSerial(); // query.id = stores[i].id; // query.active = stores[i].active; // query.promotion_id = stores[i].promotion_id; // query.serial = stores[i].serial; // query.myid = j++; // mystores.Add(query); // } // json = "{success:true,data:" + JsonConvert.SerializeObject(mystores) + "}";//返回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:true,data:[]}"; // } // this.Response.Clear(); // this.Response.Write(json); // this.Response.End(); // return this.Response; //} #endregion public HttpResponseBase PromotionsBonusSerialLists2() { string json = string.Empty; int totalcount = 0; PromotionsBonusSerial query = new PromotionsBonusSerial(); query.Start = Convert.ToInt32(Request.Params["start"] ?? "0"); query.Limit = Convert.ToInt32(Request.Params["limit"] ?? "25"); List<PromotionsBonusSerial> stores = new List<PromotionsBonusSerial>(); _promBnusSeral = new PromotionsBonusSerialMgr(mySqlConnectionString); query.promotion_id = Convert.ToInt32(Request.Params["ids"]); try { // int id = Convert.ToInt32(Request.Params["ids"]); stores = _promBnusSeral.QueryById(query, out totalcount); int j = 1; for (int i = 0; i < stores.Count; i++) { stores[i].myid = j++; } // json = "{success:true,data:" + JsonConvert.SerializeObject(stores) + "}";//返回json數據 IsoDateTimeConverter timeConverter = new IsoDateTimeConverter(); timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; json = "{success:true,totalCount:" + totalcount + ",data:" + JsonConvert.SerializeObject(stores, 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,data:[]}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
//public HttpResponseBase PromotionsBonusSerialHistoryLists() //{ // List<PromotionsBonusSerialHistoryQuery> stores = new List<PromotionsBonusSerialHistoryQuery>(); // _promBnusSeralHitory = new PromotionsBonusSerialHistoryMgr(mySqlConnectionString); // PromotionsBonusSerialHistoryQuery query = new PromotionsBonusSerialHistoryQuery(); // string json = string.Empty; // try // { // int id = Convert.ToInt32(Request.Params["ids"]); // stores = _promBnusSeralHitory.QueryById(id); // foreach (var item in stores) // { // item.user_email = item.user_email.Split('@')[0] + "@***"; // } // IsoDateTimeConverter timeConverter = new IsoDateTimeConverter(); // //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式 // timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; // json = "{success:true,items:" + JsonConvert.SerializeObject(stores, 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:true,data:[]}"; // } // this.Response.Clear(); // this.Response.Write(json); // this.Response.End(); // return this.Response; //} #endregion #endregion #region 序號兌換-檢視序號-插入數據+HttpResponseBase InsertPromotionsBonusSerial() #region //public HttpResponseBase InsertPromotionsBonusSerial() //{ // string json = string.Empty; // try // { // _pbsd = new PromotionsBonusSerialDao(mySqlConnectionString); // _promBnusSeral = new PromotionsBonusSerialMgr(mySqlConnectionString); // PromotionsBonusSerial pbs = new PromotionsBonusSerial(); // int couts = Convert.ToInt32(Request.Params["xhsl"]); // int lenghts = Convert.ToInt32(Request.Params["xhcd"]); // int id = Convert.ToInt32(Request.Params["ids"]); // Random rd = new Random(); // for (int i = 0; i < couts; i++) // { // string serials = CommonFunction.Getserials(lenghts, rd); // List<PromotionsBonusSerial> ls = new List<PromotionsBonusSerial>(); // ls = _pbsd.YesOrNoExist(serials); // if (ls.Single().serial == serials) // { // continue; // } // else // { // int count = _promBnusSeral.Save(serials, id); // if (count > 0) // { // continue; // } // } // } // json = "{success:true}";//返回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; //} #endregion public HttpResponseBase InsertPromotionsBonusSerial2() { string json = string.Empty; try { //SuccessNum = 0; _pbsd = new PromotionsBonusSerialDao(mySqlConnectionString); _promBnusSeral = new PromotionsBonusSerialMgr(mySqlConnectionString); PromotionsBonusSerial pbs = new PromotionsBonusSerial(); int couts = Convert.ToInt32(Request.Params["xhsl"]); int lenghts = Convert.ToInt32(Request.Params["xhcd"]); int id = Convert.ToInt32(Request.Params["ids"]); Random rd = new Random(); StringBuilder sb = new StringBuilder(); _promBnusSeral = new PromotionsBonusSerialMgr(mySqlConnectionString); //FileStream fs = new FileStream("D:\\2.txt", FileMode.OpenOrCreate); //StreamWriter sw = new StreamWriter(fs); for (int i = 0; i < couts; i++) { string serials = CommonFunction.Getserials(lenghts, rd); List<PromotionsBonusSerial> ls = new List<PromotionsBonusSerial>(); ls = _pbsd.YesOrNoExist(serials); if (ls.Single().serial == serials) { continue; } else { // SuccessNum=i+1; ////// //开始写入 // sw.Write(SuccessNum+","); //清空缓冲区 sb.AppendFormat(" insert into promotions_bonus_serial(serial,active,promotion_id)values('{0}','{1}','{2}');", serials, 1, id); if (sb.ToString().Length > 1000) { _promBnusSeral.AddPromoBonusSerial(sb); sb.Clear(); } } } if (sb.ToString().Length > 0) { _promBnusSeral.AddPromoBonusSerial(sb); //執行事務 } //sw.Flush(); // //关闭流 //sw.Close(); //fs.Close(); json = "{success:true}";//返回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; }
public List<Model.PromotionsBonusSerial> QueryById(PromotionsBonusSerial query,out int TotalCount) { StringBuilder sb = new StringBuilder(); StringBuilder sbStr = new StringBuilder(); try { sb.AppendFormat("SELECT `PromotionBonusSerial`.`id`, `PromotionBonusSerial`.`promotion_id`, `PromotionBonusSerial`.`serial`, `PromotionBonusSerial`.`active` "); sbStr.AppendFormat(" FROM `promotions_bonus_serial` AS `PromotionBonusSerial` WHERE `PromotionBonusSerial`.`promotion_id`='{0}'", query.promotion_id); TotalCount = 0; if (query.IsPage) { DataTable _dt = _access.getDataTable(" select count(id) as ToTalCount " + sbStr.ToString()); if (_dt != null && _dt.Rows.Count > 0) { TotalCount = Convert.ToInt32(_dt.Rows[0]["ToTalCount"]); } sbStr.AppendFormat(" limit {0},{1}", query.Start, query.Limit); } return _access.getDataTableForObj<PromotionsBonusSerial>(sb.ToString() + sbStr.ToString()); } catch (Exception ex) { throw new Exception("PromotionsBonusSerialDao-->QueryById-->" + ex.Message + sb.ToString(), ex); } }