protected void Page_Load(object sender, EventArgs e) { AppKey = Globals.Settings.AppServiceSecureKey; var controlTicketID = String.Empty; var idListString = Request.QueryString["id"]; if (!String.IsNullOrEmpty(idListString)) { var deliveryCost = 0.00; List <string> idList = idListString.Split('-').ToList(); var sqlString = String.Empty; foreach (var id in idList) { sqlString = sqlString + "T.ID = " + id + " OR "; controlTicketID = id; double cost; if (double.TryParse(MoneyMethods.AgreedAssessedDeliveryCosts(id.ToString()), out cost)) { deliveryCost += cost; } } var fullSqlString = "SELECT * FROM `tickets` as T JOIN `city` as C on T.CityID = C.ID WHERE " + sqlString.Remove(sqlString.Length - 3) + "ORDER BY C.Name ASC"; var dm = new DataManager(); var dataset = dm.QueryWithReturnDataSet(fullSqlString); lblGruzobozCost.Text = MoneyMethods.MoneySeparator( dm.QueryWithReturnDataSet("SELECT SUM(T.`GruzobozCost`) FROM `tickets` as T JOIN `city` as C on T.CityID = C.ID WHERE " + sqlString.Remove(sqlString.Length - 3)).Tables[0].Rows[0][0].ToString()); lblDeliveryCost.Text = MoneyMethods.MoneySeparator(deliveryCost); var i = 1; dataset.Tables[0].Columns.Add("PNumber", typeof(String)); foreach (DataRow row in dataset.Tables[0].Rows) { row["PNumber"] = i++; } lvAllPrint.DataSource = dataset; lvAllPrint.DataBind(); var ticket = new Tickets { ID = Convert.ToInt32(controlTicketID) }; ticket.GetById(); DriverName = lblDriver.Text = DriversHelper.DriverIDToFioToPrint(ticket.DriverID.ToString()); lblDriverPhone.Text = DriversHelper.DriverIDToPhone(ticket.DriverID.ToString()); lblTrack.Text = lblTrack2.Text = CityHelper.CityToTrack(Convert.ToInt32(ticket.CityID), ticket.ID.ToString()); lblOperatorName.Text = CityHelper.CityToTrackOperatorName(Convert.ToInt32(ticket.CityID)); lblOperatorPhone.Text = CityHelper.CityToTrackOperatorPhone(Convert.ToInt32(ticket.CityID)); } lblDate.Text = DateTime.Now.AddDays(1).ToString("dd.MM.yyyy"); if (String.IsNullOrEmpty(idListString) || lvAllPrint.Items.Count == 0) { Page.Visible = false; Response.Write(Resources.PrintResources.PrintMapEmptyText); } }
public static void CreateXlsFile(HttpResponse responce, DataSet ds, String fileName, string exportType) { //создаем динамический гридвью, который можно как угодно вертеть var gridView = new GridView { AllowPaging = false, DataSource = ds.Tables[0] }; gridView.DataBind(); var sGenName = fileName + ".xls"; responce.Clear(); responce.Buffer = true; responce.AddHeader("content-disposition", "attachment;filename=" + sGenName); responce.Charset = ""; responce.ContentType = "application/vnd.ms-excel"; var sw = new StringWriter(); var hw = new HtmlTextWriter(sw); for (var i = 0; i < gridView.Rows.Count; i++) { //добавляем стиль к строкам gridView.Rows[i].Attributes.Add("class", "textmode"); //var index = gridView.Rows.IndexOf(currentRow); if (exportType == "users") { try { gridView.Rows[i].Cells[6].Text = UsersHelper.UserStatusToText(Convert.ToInt32(gridView.Rows[i].Cells[6].Text)); gridView.Rows[i].Cells[9].Text = OtherMethods.CheckboxView(Convert.ToInt32(gridView.Rows[i].Cells[9].Text)); gridView.Rows[i].Cells[10].Text = OtherMethods.CheckboxView(Convert.ToInt32(gridView.Rows[i].Cells[10].Text)); } catch (Exception) { } } if (exportType == "profiles") { try { gridView.Rows[i].Cells[8].Text = UsersProfilesHelper.UserProfileTypeToText(Convert.ToInt32(gridView.Rows[i].Cells[8].Text)); gridView.Rows[i].Cells[9].Text = UsersProfilesHelper.UserProfileStatusToText(Convert.ToInt32(gridView.Rows[i].Cells[9].Text)); gridView.Rows[i].Cells[24].Text = OtherMethods.CheckboxView(Convert.ToInt32(gridView.Rows[i].Cells[24].Text)); } catch (Exception) { } } if (exportType == "clients") { try { gridView.Rows[i].Cells[7].Text = UsersHelper.UserStatusStadyToText(Convert.ToInt32(gridView.Rows[i].Cells[7].Text)); } catch (Exception) { } } if (exportType == "calculation") { try { gridView.Rows[i].Cells[0].Text = OtherMethods.DateConvert(gridView.Rows[i].Cells[0].Text); gridView.Rows[i].Cells[1].Text = UsersProfilesHelper.UserProfileIDToFullFamilyOrCompanyname(gridView.Rows[i].Cells[1].Text); gridView.Rows[i].Cells[3].Text = OtherMethods.TicketStatusToTextWithoutColor(gridView.Rows[i].Cells[3].Text); gridView.Rows[i].Cells[4].Text = MoneyMethods.AgreedAssessedDeliveryCosts(gridView.Rows[i].Cells[4].Text); gridView.Rows[i].Cells[6].Text = (Convert.ToDecimal(MoneyMethods.AgreedAssessedDeliveryCosts(gridView.Rows[i].Cells[6].Text)) - Convert.ToDecimal(gridView.Rows[i].Cells[5].Text)).ToString(); gridView.Rows[i].Cells[8].Text = WebUtility.HtmlDecode(gridView.Rows[i].Cells[8].Text) .Replace("comment-history-body", "") .Replace("comment-history-name", "") .Replace("comment-history-date", "") .Replace("div", "") .Replace("span", "") .Replace("class", "") .Replace(" =", ""); gridView.Rows[i].Cells[9].Text = DriversHelper.DriverIdToName(gridView.Rows[i].Cells[9].Text); } catch (Exception) { } } } gridView.RenderControl(hw); //стиль приведение чисел к строкам const string style = @"<style> .textmode { mso-number-format:\@; } </style>"; responce.Write(style); responce.Output.Write(sw.ToString()); responce.Flush(); responce.End(); }
public static void GenerateXmlFile(string idListString, string data) { List <string> idList = idListString.Split('-').ToList(); var output = "<?xml version=\"1.0\"?> \r\n" + "\t<SmartRoutes.Data SchemaVersion=\"3\"> \r\n" + "\t\t<Variants> \r\n" + "\t\t\t<Variant> \r\n" + "\t\t\t\t<OrderCategoryExchangeCode>1891378909</OrderCategoryExchangeCode> \r\n" + "\t\t\t\t<Date>" + Convert.ToDateTime(data).ToString("yyyy-MM-dd") + "T00:00:00+03:00</Date> \r\n" + "\t\t\t\t<N>1</N> \r\n" + "\t\t\t\t<DataReading>Historical</DataReading> \r\n" + "\t\t\t\t<Characteristics> \r\n" + "\t\t\t\t\t<Characteristic> \r\n" + "\t\t\t\t\t\t<ExchangeCode>12345678</ExchangeCode> \r\n" + "\t\t\t\t\t\t<Title>Оцен./Согл. + за доставку</Title> \r\n" + "\t\t\t\t\t\t<Type>Number</Type> \r\n" + "\t\t\t\t\t\t<Notes>стоимость груза + за доставку</Notes> \r\n" + "\t\t\t\t\t</Characteristic> \r\n" + "\t\t\t\t</Characteristics> \r\n" + "\t\t\t\t<Orders> \r\n"; if (!String.IsNullOrEmpty(idListString)) { foreach (var id in idList) { var ticket = new Tickets { ID = Convert.ToInt32(id) }; ticket.GetById(); var address = String.Empty; if (!String.IsNullOrEmpty(ticket.RecipientKorpus)) { address = String.Format("Беларусь, {0} область, {2}, {3} {4}, {5}/{6}", CityHelper.CityIDToRegionName(ticket.CityID.ToString()), CityHelper.CityIDToDistrictName(ticket.CityID.ToString()), CityHelper.CityNameFilter(CityHelper.CityIDToCityNameWithotCustom(ticket.CityID.ToString())), ticket.RecipientStreetPrefix, ticket.RecipientStreet, ticket.RecipientStreetNumber, ticket.RecipientKorpus); } else { address = String.Format("Беларусь, {0} область, {2}, {3} {4}, {5}", CityHelper.CityIDToRegionName(ticket.CityID.ToString()), CityHelper.CityIDToDistrictName(ticket.CityID.ToString()), CityHelper.CityNameFilter(CityHelper.CityIDToCityNameWithotCustom(ticket.CityID.ToString())), ticket.RecipientStreetPrefix, ticket.RecipientStreet, ticket.RecipientStreetNumber); } var goodsObj = new Goods { TicketFullSecureID = ticket.FullSecureID }; var goodsDataSet = goodsObj.GetAllItems("ID", "ASC", "TicketFullSecureID"); var goodsString = goodsDataSet.Tables[0].Rows.Cast <DataRow>() .Aggregate(String.Empty, (current, goods) => current + String.Format("{0} {1}; ", goods[2], goods[3])) .Replace("&", ""); output += "\t\t\t\t\t<Order> \r\n" + "\t\t\t\t\t\t<ExchangeCode>" + ticket.SecureID + "</ExchangeCode> \r\n" + "\t\t\t\t\t\t<Title>" + goodsString + "</Title> \r\n" + "\t\t\t\t\t\t<Phone>" + ticket.RecipientPhone + "</Phone> \r\n" + "\t\t\t\t\t\t<Code>" + ticket.SecureID + "</Code> \r\n" + "\t\t\t\t\t\t<LoadingAddress> \r\n" + "\t\t\t\t\t\t\t<Location>Беларусь, Минск, Кальварийская улица, 4</Location> \r\n" + "\t\t\t\t\t\t\t<Latitude>0.9408116799</Latitude> \r\n" + "\t\t\t\t\t\t\t<Longitude>0.4806493073</Longitude> \r\n" + "\t\t\t\t\t\t</LoadingAddress> \r\n" + "\t\t\t\t\t\t<UnloadingAddress> \r\n" + "\t\t\t\t\t\t\t<Location>" + address + "</Location> \r\n" + "\t\t\t\t\t\t</UnloadingAddress> \r\n" + //время у клиента в xml-формате "PT30M" означает "30 минут" "\t\t\t\t\t\t<UnloadingDuration>" + "PT10M" + "</UnloadingDuration>" + "\t\t\t\t\t\t<CargoProperties>\r\n" + "\t\t\t\t\t\t\t<Property>\r\n" + "\t\t\t\t\t\t\t\t<CharacteristicExchangeCode>12345678</CharacteristicExchangeCode>\r\n" + "\t\t\t\t\t\t\t\t<Value>" + MoneyMethods.MoneySeparator(MoneyMethods.AgreedAssessedDeliveryCosts(ticket.ID.ToString())) + "</Value>\r\n" + "\t\t\t\t\t\t\t</Property>\r\n" + "\t\t\t\t\t\t</CargoProperties>\r\n" + "\t\t\t\t\t</Order> \r\n"; } output += " \t\t\t\t</Orders> \r\n" + "\t\t\t</Variant> \r\n" + "\t\t</Variants> \r\n" + "\t</SmartRoutes.Data>"; File.WriteAllText(HttpContext.Current.Server.MapPath("~/SendData.xml"), output); } }