public static void CreateWorkbookCsv(IReportBuilder iReportBuilder) { var path = Path.Combine(Entrence.CurrentFirmaPathReport, iReportBuilder.Filename + DateTime.Now.ToString("ddMMyyyy") + ".csv"); StringBuilder sb = new StringBuilder(); try { if (File.Exists(path)) { File.Delete(path); } var items = iReportBuilder.GetTXTAntetka(); if (items != null) { foreach (var item in items) { int i = 0; if (item != null) { foreach (var el in item) { if (iReportBuilder.ReportItems.ElementAt(i).IsShow) { sb.Append(el); sb.Append(";"); } i++; } } sb.AppendLine(); } Line(iReportBuilder, sb); } var titles = iReportBuilder.GetTitles(); if (titles != null && titles.Count > 0) { int i = 0; foreach (var footer in iReportBuilder.GetTitles()) { if (iReportBuilder.ReportItems.Count() > i && iReportBuilder.ReportItems.ElementAt(i).IsShow) { sb.Append(footer); sb.Append(";"); } i++; } sb.AppendLine(); } var sub = iReportBuilder.GetSubTitles(); if (sub != null && sub.Count > 0) { int i = 0; foreach (var footer in sub) { if (iReportBuilder.ReportItems.ElementAt(i).IsShow) { sb.Append(footer); sb.Append(";"); } i++; } sb.AppendLine(); } var it = iReportBuilder.GetItems(); if (it != null && it.Count > 0) { foreach (List <string> dList in it) { int i = 0; if (machfilters(dList, iReportBuilder)) { foreach (string s in dList) { if (iReportBuilder.ReportItems.Count() > i && iReportBuilder.ReportItems.ElementAt(i).IsShow) { if (s != null) { sb.Append(s.Replace("\n", " ")); } else { sb.Append(""); } sb.Append(";"); } i++; } sb.AppendLine(); } } } } catch (Exception err) { Logger.Instance().WriteLogError(err.Message, "public static void CreateWorkbookCsv(IReportBuilder iReportBuilder)"); } finally { Encoding srcEncodingFormat = Encoding.Unicode; Encoding dstEncodingFormat = Encoding.GetEncoding("windows-1251"); byte[] originalByteString = srcEncodingFormat.GetBytes(sb.ToString()); byte[] convertedByteString = Encoding.Convert(srcEncodingFormat, dstEncodingFormat, originalByteString); string finalString = dstEncodingFormat.GetString(convertedByteString); using (StreamWriter sw = new StreamWriter(path, false, dstEncodingFormat)) { sw.Write(finalString); } Process.Start(path); } }
public static void CreateWorkbookTxt(IReportBuilder iReportBuilder) { var path = AppDomain.CurrentDomain.BaseDirectory + iReportBuilder.Filename + ".txt"; StringBuilder sb = new StringBuilder(); try { if (File.Exists(path)) { File.Delete(path); } if (iReportBuilder.Title != null) { sb.AppendLine(iReportBuilder.Title); //sb.AppendFormat("{0:300}", "-"); Line(iReportBuilder, sb); } // Fill spreadsheet with sample data //int i = 0; bool showline = false; foreach (var footer in iReportBuilder.GetHeader()) { sb.AppendLine(footer); showline = true; } if (showline) { Line(iReportBuilder, sb); } // if (iReportBuilder.ReportItems.ElementAt(i).IsShow) // { // string ter = footer.Length > iReportBuilder.ReportItems.ElementAt(i).Width // ? footer.Substring(0, iReportBuilder.ReportItems.ElementAt(i).Width) // : footer; // sb.Append("|"); // sb.Append(ter.PadRight(iReportBuilder.ReportItems.ElementAt(i).Width)); // } // i++; //} //sb.Append("|"); int i = 0; foreach (var item in iReportBuilder.GetTXTAntetka()) { i = 0; foreach (var el in item) { if (iReportBuilder.ReportItems.ElementAt(i).IsShow) { string ter = el.Length > iReportBuilder.ReportItems.ElementAt(i).Width ? el.Substring(0, iReportBuilder.ReportItems.ElementAt(i).Width) : el; sb.Append("|"); sb.Append(ter.PadRight(iReportBuilder.ReportItems.ElementAt(i).Width)); } i++; } sb.Append("|"); sb.AppendLine(); } Line(iReportBuilder, sb); //foreach (var footer in iReportBuilder.GetTitles()) //{ // if (iReportBuilder.ReportItems.ElementAt(i).IsShow) // { // string ter = footer.Length > iReportBuilder.ReportItems.ElementAt(i).Width // ? footer.Substring(0, iReportBuilder.ReportItems.ElementAt(i).Width) // : footer; // sb.Append("|"); // sb.Append(ter.PadRight(iReportBuilder.ReportItems.ElementAt(i).Width)); // } // i++; //} //sb.Append("|"); //Line(iReportBuilder, sb); i = 0; foreach (var footer in iReportBuilder.GetSubTitles()) { if (iReportBuilder.ReportItems.ElementAt(i).IsShow) { string ter = footer.Length > iReportBuilder.ReportItems.ElementAt(i).Width ? footer.Substring(0, iReportBuilder.ReportItems.ElementAt(i).Width) : footer; sb.Append("|"); sb.Append(ter.PadRight(iReportBuilder.ReportItems.ElementAt(i).Width)); } i++; } sb.Append("|"); sb.AppendLine(); Line(iReportBuilder, sb); foreach (List <string> dList in iReportBuilder.GetItems()) { i = 0; foreach (string s in dList) { if (iReportBuilder.ReportItems.Count() > i && iReportBuilder.ReportItems.ElementAt(i).IsShow) { string ter = s.Length > iReportBuilder.ReportItems.ElementAt(i).Width ? s.Substring(0, iReportBuilder.ReportItems.ElementAt(i).Width) : s; sb.Append("|"); sb.Append(ter.PadRight(iReportBuilder.ReportItems.ElementAt(i).Width)); } i++; } sb.Append("|"); sb.AppendLine(); } Line(iReportBuilder, sb); //foreach (var footer in iReportBuilder.GetFuther()) //{ // sb.AppendFormat("{0,-30}", footer); //} sb.AppendLine(); } catch (Exception err) { Logger.Instance().WriteLogError(err.Message); } finally { using (StreamWriter sw = new StreamWriter(path)) { sw.Write(sb.ToString()); } Process.Start(path); } }
public static void CreateWorkbookTxt(IReportBuilder iReportBuilder) { var path = Path.Combine(Entrence.CurrentFirmaPathReport, iReportBuilder.Filename + DateTime.Now.ToString("ddMMyyyy") + ".txt"); StringBuilder sb = new StringBuilder(); try { if (File.Exists(path)) { File.Delete(path); } if (iReportBuilder.Title != null) { sb.AppendLine(iReportBuilder.Title); //sb.AppendFormat("{0:300}", "-"); //Line(iReportBuilder, sb); } if (iReportBuilder.SubTitle != null) { sb.AppendLine(iReportBuilder.SubTitle); //sb.AppendFormat("{0:300}", "-"); //Line(iReportBuilder, sb); } // Fill spreadsheet with sample data //int i = 0; bool showline = false; var hedar = iReportBuilder.GetHeader(); GenFilter(iReportBuilder, hedar); if (hedar != null) { foreach (var footer in hedar) { sb.AppendLine(footer); showline = true; } if (showline) { Line(iReportBuilder, sb); } } foreach (var item in iReportBuilder.ReportItems) { if (string.IsNullOrWhiteSpace(item.Filter)) { } } // if (iReportBuilder.ReportItems.ElementAt(i).IsShow) // { // string ter = footer.Length > iReportBuilder.ReportItems.ElementAt(i).Width // ? footer.Substring(0, iReportBuilder.ReportItems.ElementAt(i).Width) // : footer; // sb.Append("|"); // sb.Append(ter.PadRight(iReportBuilder.ReportItems.ElementAt(i).Width)); // } // i++; //} //sb.Append("|"); int i = 0; var items = iReportBuilder.GetTXTAntetka(); if (items != null) { foreach (var item in items) { i = 0; if (item != null) { foreach (var el in item) { if (iReportBuilder.ReportItems.ElementAt(i).IsShow) { string ter = el.Length > iReportBuilder.ReportItems.ElementAt(i).Width ? el.Substring(0, iReportBuilder.ReportItems.ElementAt(i).Width) : el; sb.Append("|"); sb.Append(ter.PadRight(iReportBuilder.ReportItems.ElementAt(i).Width)); } i++; } } sb.Append("|"); sb.AppendLine(); } Line(iReportBuilder, sb); } i = 0; var titles = iReportBuilder.GetTitles(); if (titles != null && titles.Count > 0) { foreach (var footer in iReportBuilder.GetTitles()) { if (iReportBuilder.ReportItems.ElementAt(i).IsShow) { string ter = footer.Length > iReportBuilder.ReportItems.ElementAt(i).Width ? footer.Substring(0, iReportBuilder.ReportItems.ElementAt(i).Width) : footer; sb.Append("|"); sb.Append(ter.PadRight(iReportBuilder.ReportItems.ElementAt(i).Width)); } i++; } sb.Append("|"); sb.AppendLine(); Line(iReportBuilder, sb); } i = 0; var sub = iReportBuilder.GetSubTitles(); if (sub != null && sub.Count > 0) { foreach (var footer in iReportBuilder.GetSubTitles()) { if (iReportBuilder.ReportItems.ElementAt(i).IsShow) { string ter = footer.Length > iReportBuilder.ReportItems.ElementAt(i).Width ? footer.Substring(0, iReportBuilder.ReportItems.ElementAt(i).Width) : footer; sb.Append("|"); sb.Append(ter.PadRight(iReportBuilder.ReportItems.ElementAt(i).Width)); } i++; } sb.Append("|"); sb.AppendLine(); Line(iReportBuilder, sb); } //sborno bool sborno = false; List <decimal> hs = new List <decimal> { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; var it = iReportBuilder.GetItems(); if (it != null && it.Count > 0) { var currentrow = 0; foreach (List <string> dList in it) { i = 0; if (machfilters(dList, iReportBuilder)) { foreach (string s in dList) { if (iReportBuilder.ReportItems.Count() > i && iReportBuilder.ReportItems.ElementAt(i).IsShow) { string ter = " "; if (s != null) { var s1 = s.Replace("\n", "|"); ter = s1.Length > iReportBuilder.ReportItems.ElementAt(i).Width ? s1.Substring(0, iReportBuilder.ReportItems.ElementAt(i).Width) : s1; } sb.Append("|"); //sb.Append(ter.PadRight(iReportBuilder.ReportItems.ElementAt(i).Width)); if (iReportBuilder.ReportItems.ElementAt(i).Sborno) { sb.Append(ter.PadLeft(iReportBuilder.ReportItems.ElementAt(i).Width)); hs[i] += decimal.Parse(s); sborno = true; } else { sb.Append(iReportBuilder.ReportItems.ElementAt(i).IsSuma ? ter.PadLeft(iReportBuilder.ReportItems.ElementAt(i).Width) : ter.PadRight(iReportBuilder.ReportItems.ElementAt(i).Width)); } } i++; } sb.Append("|"); sb.AppendLine(); if (iReportBuilder.Rowfoother != null && iReportBuilder.Rowfoother.ContainsKey(currentrow)) { //Line(iReportBuilder, sb); foreach (var foother in iReportBuilder.Rowfoother[currentrow]) { sb.Append(foother); sb.AppendLine(); } } } currentrow++; } if (iReportBuilder.Rowfoother == null) { Line(iReportBuilder, sb); } if (sborno) { i = 0; foreach (var rep in iReportBuilder.ReportItems) { if (rep.IsShow) { sb.Append("|"); if (rep.Sborno) { sb.Append(hs[i].ToString(Vf.LevFormatUI).PadLeft(rep.Width)); } else { sb.Append(" ".PadRight(rep.Width)); } } i++; } sb.Append("|"); sb.AppendLine(); Line(iReportBuilder, sb); } } var futher = iReportBuilder.GetFuther(); if (futher != null && futher.Count > 0) { foreach (var footer in iReportBuilder.GetFuther()) { sb.AppendLine(footer); } sb.AppendLine(); } } catch (Exception err) { Logger.Instance().WriteLogError(err.Message, "public static void CreateWorkbookTxt(IReportBuilder iReportBuilder)"); } finally { using (StreamWriter sw = new StreamWriter(path)) { sw.Write(sb.ToString()); } Process.Start(path); } }