using System; using CoreSavingLibrary; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using DataLibrary; using System.Data; using System.Globalization; using System.Text; using System.IO; namespace Saving.SlipApp { public partial class xml_printing_master : System.Web.UI.Page { protected String xmlResult = ""; protected void Page_Load(object sender, EventArgs e) { String printingName = Request["printing_name"]; String printingTable = Request["printing_table"]; //////////////////////////////////////////////////////////////////////////// if (string.IsNullOrEmpty(printingName) || string.IsNullOrEmpty(printingTable)) { return; } //////////////////////////////////////////////////////////////////////////// String mode = "test"; try { mode = Request["mode"].Trim(); if (mode == "") { throw new Exception(); } } catch { mode = "test"; } String sql = ""; if (printingTable == "master") { sql = "select a.*, b.width as paper_width, b.height as paper_height from paprintingmaster a left join paucfpapersize b on a.paper_size = b.paper_size where a.printing_name = '" + printingName + "'"; } else { sql = "select * from paprintingdetail where printing_name = '" + printingName + "' order by PRINTING_NAME, POSITION, COLUMN_ORDER"; } if (true) { int conIndex = 0; try { conIndex = int.Parse(Request["con_index"]); } catch { } string gcoopPath = "C:\\GCOOP_ALL\\" + Request["vdir"] + "\\GCOOP\\"; Sta ta = new Sta(conIndex, gcoopPath); //WebUtil.PhysicalPath); try { Sdt dt = ta.Query(sql); if (dt.Next()) { this.xmlResult = CnvXmlStringFormat(dt); } } catch { } ta.Close(); } } private String CnvXmlStringFormat(DataTable dt) { try { if (dt.Rows.Count <= 0) throw new Exception("ไม่พบข้อมูล (row <= 0)"); CultureInfo en = new CultureInfo("en-US"); StringBuilder sss = new StringBuilder(); sss.Append("\n"); sss.Append("\n"); for (int i = 0; i < dt.Rows.Count; i++) { sss.Append("\t\n"); for (int j = 0; j < dt.Columns.Count; j++) { sss.Append("\t\t"); try { String value = dt.Columns[j].DataType.ToString() == "System.DateTime" ? Convert.ToDateTime(dt.Rows[i][j]).ToString("yyyy-MM-dd HH:mm:ss", en) : dt.Rows[i][j].ToString(); sss.Append("<" + dt.Columns[j].ColumnName.ToLower() + ">" + value + "\n"); } catch { sss.Append("<" + dt.Columns[j].ColumnName.ToLower() + "/>\n"); } } sss.Append("\t\n"); } sss.Append(""); StringReader strre = new StringReader(sss.ToString()); String xml = sss.ToString(); return xml; } catch (Exception ex) { throw ex; } } } }