/// <summary> /// contestId must be set in the url /// </summary> /// <returns></returns> string GetContestEnties() { if (HttpContext.Current.Request["contestid"] == null) { return(""); } AWAPI_BusinessLibrary.library.ContestLibrary lib = new AWAPI_BusinessLibrary.library.ContestLibrary(); long contestId = Convert.ToInt64(HttpContext.Current.Request["contestid"]); System.Text.StringBuilder sb = new System.Text.StringBuilder(); //GET CONTEST IFNO AWAPI_Data.CustomEntities.ContestExtended contest = lib.GetContest(contestId, false); if (contest == null) { return(""); } sb.Append("Contest entries report\n"); sb.AppendFormat("Report date:,{0}\n\n", DateTime.Now); sb.AppendFormat("ContestId:,{0}\n", contest.contestId.ToString()); sb.AppendFormat("Name:,{0}\n", contest.title); sb.AppendFormat("Description:,{0}\n", contest.description.Replace(",", " ").Replace("\n", " ")).Replace("\"", " ");; sb.AppendFormat("StartDate:,{0}\n", contest.pubDate); sb.AppendFormat("EndDate:,{0}\n", contest.pubEndDate); sb.Append("\n"); IList <AWAPI_Data.CustomEntities.ContestEntryExtended> list = lib.GetContestEntryList(contestId); if (list == null || list.Count == 0) { return(""); } sb.Append("entryId,isEnabled,cultureCode,email,firstName,lastName,title, " + "fileUrl,phone,phoneType,address,city,province," + "postalCode,country,createDate,description\n"); foreach (AWAPI_Data.CustomEntities.ContestEntryExtended c in list) { c.email = c.email == null ? "" : c.email.Replace(",", " ").Replace("\"", " "); c.firstName = c.firstName == null ? "" : c.firstName.Replace(",", " ").Replace("\"", " ");; c.lastName = c.lastName == null ? "" : c.lastName.Replace(",", " ").Replace("\"", " ");; c.title = c.title == null ? "" : c.title.Replace(",", " ").Replace("\"", " ");; c.fileUrl = c.fileUrl == null ? "" : c.fileUrl.Replace(",", " ").Replace("\"", " ");; c.tel = c.tel == null ? "" : c.tel.Replace(",", " ").Replace("\"", " ");; c.telType = c.telType == null ? "" : c.telType.Replace(",", " ").Replace("\"", " ");; c.address = c.address == null ? "" : c.address.Replace(",", " ").Replace("\"", " ");; c.city = c.city == null ? "" : c.city.Replace(",", " ").Replace("\"", " ");; c.province = c.province == null ? "" : c.province.Replace(",", " ").Replace("\"", " ");; c.postalCode = c.postalCode == null ? "" : c.postalCode.Replace(",", " ").Replace("\"", " ");; c.country = c.country == null ? "" : c.country.Replace(",", " ").Replace("\"", " ");; c.description = c.description == null ? "" : c.description.Replace(",", " ").Replace("\n", " ").Replace("\r", "").Replace("\"", " ");; sb.AppendFormat("{0},{1},{2},{3},{4},{5}," + "{6},{7},{8},{9},{10},{11},{12}," + "{13},{14},{15},{16}", c.contestEntryId, c.isEnabled, c.cultureCode, c.email.Replace(",", " "), c.firstName.Replace(",", " "), c.lastName.Replace(",", " "), c.title.Replace(",", " "), c.fileUrl.Replace(",", " "), c.tel.Replace(",", " "), c.telType.Replace(",", " "), c.address.Replace(",", " "), c.city.Replace(",", " "), c.province.Replace(",", " "), c.postalCode.Replace(",", " "), c.country.Replace(",", " "), c.createDate, c.description.Replace(",", " ").Replace("\n", " ").Replace("\r", "") + "\n"); } return(sb.ToString()); }
/// <summary> /// Prepare an xml file and insert the records... /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void _btnPrepareData_Click(object sender, EventArgs e) { AWAPI_BusinessLibrary.library.ContestLibrary lib = new AWAPI_BusinessLibrary.library.ContestLibrary(); IList <AWAPI_Data.CustomEntities.ContestEntryExtended> list = lib.GetContestEntryListByGroupId(Convert.ToInt64(_groupId.Text), "", null); if (list == null || list.Count == 0) { Response.Write("<font color='#ff0000'>No entries has been found</font><br/>"); return; } //filter based on start and end dates DateTime?dtStart = AWAPI_Common.library.MiscLibrary.ConvertStringToDate(_startDate.Text); DateTime?dtEnd = AWAPI_Common.library.MiscLibrary.ConvertStringToDate(_endDate.Text); if (dtStart == null || dtEnd == null) { Response.Write("<font color='#ff0000'>Start and End dates are required</font><br/>"); return; } var tmpList = from l in list where l.createDate >= dtStart.Value && l.createDate <= dtEnd.Value orderby l.email select l; if (tmpList == null || tmpList.Count() == 0) { Response.Write("<font color='#ff0000'>No entries has been found in the date range</font><br/>"); return; } list = tmpList.ToList(); //Write the results to the xml System.Data.DataTable dt = new System.Data.DataTable("contestentries"); dt.Columns.Add("email"); dt.Columns.Add("firstname"); dt.Columns.Add("lastname"); dt.Columns.Add("createdate"); dt.Columns.Add("sent"); System.IO.TextWriter tw = new System.IO.StreamWriter("c:\\emaillist.txt"); System.Collections.ArrayList emails = new System.Collections.ArrayList(); foreach (AWAPI_Data.CustomEntities.ContestEntryExtended ent in list) { string email = ent.email.ToLower().Trim(); if (isEmail(email)) { if (emails.BinarySearch(email) >= 0) { continue; } System.Data.DataRow dr = dt.NewRow(); dr["email"] = email; dr["firstname"] = ent.firstName; dr["lastname"] = ent.lastName; dr["sent"] = "0"; dt.Rows.Add(dr); emails.Add(email); tw.Write(email + ","); } } dt.WriteXml(XML_Path); tw.Close(); _prepareDataResult.Text = "Number of records : " + dt.Rows.Count.ToString() + "<br/>" + "Files location: " + XML_Path; _resultList.DataSource = dt; _resultList.DataBind(); }