using System; using System.Collections.Generic; using System.Linq; using System.Text; using DataLibrary; using System.Collections; using System.IO; namespace CoreSavingLibrary { public class PageWebSheet : PageWeb { private bool isConfirmOnNew = false; public bool IsConfirmOnNew { get { return isConfirmOnNew; } set { isConfirmOnNew = value; } } private bool ignoreReadable = false; public bool IgnoreReadable { get { return ignoreReadable; } set { ignoreReadable = value; } } private bool fullScreen = false; public bool FullScreen { get { return fullScreen; } set { fullScreen = value; } } public String WebSheetType { get { return "Saving.PageWebSheet"; } } public int ScrollTop { get; set; } protected void Page_Load(object sender, EventArgs e) { ScrollTop = -1; isConfirmOnNew = false; tDwDates = new List(); String SaveWebSheet = WebUtil.JsPostBack(this, "SaveWebSheet"); String saveJavaScript = SaveWebSheet + @" "; initJavaScript = ""; Type t = this.GetType(); String lastFocus = ""; try { lastFocus = Request["tempLastFocus"]; } catch { } String dsTempElementEnter = "\n\n"; dsTempElementEnter += saveJavaScript; dsTempElementEnter += "\n"; dsTempElementEnter += "\n\n"; ClientScript.RegisterClientScriptBlock(t, "DsTempElementEnter", dsTempElementEnter); } protected void Page_LoadComplete(object sender, EventArgs e) { String s = sender.ToString(); } protected void SetJsOpenIFrame(int width, int height, string w_sheet_name, string queryString) { String script = "Gcoop.OpenIFrame(" + width + ", " + height + ", \"" + w_sheet_name + "\", \"" + queryString + "\");"; SetOnLoadedScript(script); } protected void SetJsOpenIFrameExtend(int width, int height, string w_sheet_name, string queryString) { String script = "Gcoop.OpenIFrameExtend(" + width + ", " + height + ", \"" + w_sheet_name + "\", \"" + queryString + "\");"; SetOnLoadedScript(script); } protected void SetJsOpenDialog(int width, int height, string w_sheet_name, string queryString) { String script = "Gcoop.OpenDlg(" + width + ", " + height + ", \"" + w_sheet_name + "\", \"" + queryString + "\");"; SetOnLoadedScript(script); } public string getXMLStringValue(String xml, String name) { string value = ""; name = "<" + name + ">"; int pos = xml.IndexOf(name); if (pos > 0) { string tmp = xml.Substring(pos + name.Length); pos = tmp.IndexOf("= 0; string column_value = sdtX.GetString(column_name); string sql_set = column_name + "="; for (int x = 0; x < col_pk_nm.Length; x++) { if (column_name.ToLower() == col_pk_nm[x]) { column_value = column_value.Replace(col_pk_src[x], col_pk_rp[x]); } } //sql_1 += column_name; //sql_2 += "'" + date_type+":" + column_value + "'"; if (date_type == "datetime") { if (Sta.IS_MYSQL_MODE) column_value = "str_to_date('" + sdtX.GetDate(column_name).ToString("dd/MM/yyyy HH:mm:ss") + "','%d/%m/%Y %T')"; else column_value = "to_date('" + sdtX.GetDate(column_name).ToString("dd/MM/yyyy HH:mm:ss") + "','dd/mm/yyyy hh24:mi:ss')"; if (column_value.IndexOf("1370") > 0) sql_set += "null"; else sql_set += column_value; } else if (date_type == "date") { if (Sta.IS_MYSQL_MODE) column_value = "str_to_date('" + sdtX.GetDate(column_name).ToString("dd/MM/yyyy") + "','%d/%m/%Y')"; else column_value = "to_date('" + sdtX.GetDate(column_name).ToString("dd/MM/yyyy") + "','dd/mm/yyyy')"; if (column_value.IndexOf("1370") > 0) sql_set += "null"; else sql_set += column_value; } else if (date_type.IndexOf("char") >= 0) { if (column_value.Length <= 0) sql_set += "null"; else sql_set += "'" + column_value + "'"; } else if (date_type.IndexOf("decimal") >= 0) { if (column_value.Length <= 0) sql_set += "null"; else sql_set += "'" + column_value + "'"; } else { sql_set += "'" + column_value + "'"; } i++; found = i < columnList.Count; if (column_key) { sql_2 += sql_set; if (column_key) sql_2 += " and "; } else { } } sql_2 += "}"; sql_2 = sql_2.Replace("and }", ""); sql = sql_1 + sql_2; sql = sql.Replace("} where", " where"); if (logssql_flag) results += "\r\n SQL=" + sql + " \r\n \r\n"; results_sql += sql + ";\n"; } //INSERT SQL if (insert_flag) { String sql_1 = "insert into " + table_name + " ("; String sql_2 = ")values("; bool found = true; int i = 0; while (found) { String[] cols = new String[2]; cols = (String[])columnList[i]; string column_name = cols[0]; string date_type = cols[1]; bool column_key = pk_columns.IndexOf(column_name) >= 0; string column_value = sdtX.GetString(column_name); for (int x = 0; x < col_pk_nm.Length;x++ ) { if (column_name.ToLower() == col_pk_nm[x]) { column_value = column_value.Replace(col_pk_src[x], col_pk_rp[x]); } } sql_1 += column_name; //sql_2 += "'" + date_type+":" + column_value + "'"; if (date_type == "datetime") { if(Sta.IS_MYSQL_MODE) column_value = "str_to_date('" + sdtX.GetDate(column_name).ToString("dd/MM/yyyy HH:mm:ss") + "','%d/%m/%Y %T')"; else column_value = "to_date('" + sdtX.GetDate(column_name).ToString("dd/MM/yyyy HH:mm:ss") + "','dd/mm/yyyy hh24:mi:ss')"; if (column_value.IndexOf("1370") > 0) sql_2 += "null"; else sql_2 += column_value; } else if (date_type == "date") { if (Sta.IS_MYSQL_MODE) column_value = "str_to_date('" + sdtX.GetDate(column_name).ToString("dd/MM/yyyy") + "','%d/%m/%Y')"; if (column_value.IndexOf("1370") > 0) sql_2 += "null"; else sql_2 += column_value; } else if (date_type.IndexOf("char") >= 0) { if (column_value.Length <= 0) sql_2 += "null"; else sql_2 += "'" + column_value + "'"; } else if (date_type.IndexOf("decimal") >= 0) { if (column_value.Length <= 0) sql_2 += "null"; else sql_2 += "'" + column_value + "'"; } else { sql_2 += "'" + column_value + "'"; } i++; found = i < columnList.Count; if (found) { sql_1 += ","; sql_2 += ","; } } sql_2 += ")"; sql = sql_1 + sql_2; } else { String sql_1 = "update " + table_name + " set "; String sql_2 = " where "; bool found = true; int i = 0; while (found) { String[] cols = new String[2]; cols = (String[])columnList[i]; string column_name = cols[0]; string date_type = cols[1]; bool column_key = pk_columns.IndexOf(column_name) >= 0; string column_value = sdtX.GetString(column_name); string sql_set = column_name + "="; for (int x = 0; x < col_pk_nm.Length; x++) { if (column_name.ToLower() == col_pk_nm[x]) { column_value = column_value.Replace(col_pk_src[x], col_pk_rp[x]); } } //sql_1 += column_name; //sql_2 += "'" + date_type+":" + column_value + "'"; if (date_type == "datetime") { if (Sta.IS_MYSQL_MODE) column_value = "str_to_date('" + sdtX.GetDate(column_name).ToString("dd/MM/yyyy HH:mm:ss") + "','%d/%m/%Y %T')"; else column_value = "to_date('" + sdtX.GetDate(column_name).ToString("dd/MM/yyyy HH:mm:ss") + "','dd/mm/yyyy hh24:mi:ss')"; if (column_value.IndexOf("1370") > 0) sql_set += "null"; else sql_set += column_value; } else if (date_type == "date") { if (Sta.IS_MYSQL_MODE) column_value = "str_to_date('" + sdtX.GetDate(column_name).ToString("dd/MM/yyyy") + "','%d/%m/%Y')"; else column_value = "to_date('" + sdtX.GetDate(column_name).ToString("dd/MM/yyyy") + "','dd/mm/yyyy')"; if (column_value.IndexOf("1370") > 0) sql_set += "null"; else sql_set += column_value; } else if (date_type.IndexOf("char") >= 0) { if (column_value.Length <= 0) sql_set += "null"; else sql_set += "'" + column_value + "'"; } else if (date_type.IndexOf("decimal") >= 0) { if (column_value.Length <= 0) sql_set += "null"; else sql_set += "'" + column_value + "'"; } else { sql_set += "'" + column_value + "'"; } i++; found = i < columnList.Count; if (column_key) { sql_2 += sql_set; if (column_key) sql_2 += " and "; } else { sql_1 += sql_set; if (column_key == false) sql_1 += " , "; } } sql_1 += "}"; sql_1 = sql_1.Replace(", }", ""); sql_2 += "}"; sql_2 = sql_2.Replace("and }", ""); sql = sql_1 + sql_2; sql = sql.Replace("} where", " where"); } if (logssql_flag) results += "\r\n SQL=" + sql + " \r\n \r\n"; results_sql += sql + ";\n"; } } } public void logResultTextFile(String logsFilePath, ref String results, ref String results_sql, bool clear_flag, bool post_flag, bool create_flag) { if (create_flag) { CreateTextFile(logsFilePath, ref results, true); if (post_flag) CreateTextFile(logsFilePath + ".sql", ref results_sql, true); } else { AppendTextFile(logsFilePath, ref results, true); if (post_flag) AppendTextFile(logsFilePath + ".sql", ref results_sql, true); } } public void CreateTextFile(String logsFilePath,ref String results,bool clear_flag) { File.WriteAllText(logsFilePath, results); if (clear_flag) results = ""; } public void AppendTextFile(String logsFilePath, ref String results, bool clear_flag) { File.AppendAllText(logsFilePath, results); if (clear_flag) results = ""; } public void initProcessing(String outputProcess, String object_name, String criteria_xml, String criteria_xml_1, String criteria_xml_2) { this.criteria_xml = criteria_xml; this.criteria_xml_1 = criteria_xml_1; this.criteria_xml_2 = criteria_xml_2; this.object_name = object_name; this.process_id = outputProcess.Substring(outputProcess.IndexOf("?p=") + 3, outputProcess.IndexOf("&d=") - outputProcess.IndexOf("?p=") - 3); this.initProcessing(); } public void initProcessing() { WriteLine(process_id + " " + connectionString); taMain = new Sta(connectionString); taQuery = new Sta(connectionString); try { taMain.Transection(); } catch (Exception e) { e.ToString(); WriteLine(e.ToString()); } finally { } } } }