/// <summary> /// /// </summary> /// <param name="CODE"></param> /// <param name="SYSAP"></param> /// <param name="SESSION_KEY"></param> /// <param name="USERIP"></param> /// <param name="USERID"></param> /// <param name="COMMENTS"></param> /// <param name="Parameters"></param> /// <returns></returns> public string SYSLOG(SysCode CODE, string SYSAP, string SESSION_KEY, string USERIP, string USERID, string COMMENTS, ref List <IDataParameter> Parameters) { #region SQL Command string strSql = "Insert Into SYSLOG (\n" + " CODE\n" + " ,SESSION_KEY\n" + " ,DATETIME\n" + " ,SYSAP\n" + " ,USERIP\n" + " ,USERID\n" + " ,COMMENTS\n" + ")\n" + "Values (\n" + " @CODE\n" + " ,@SESSION_KEY\n" + " ,GetDate()\n" + " ,@SYSAP\n" + " ,@USERIP\n" + " ,@USERID\n" + " ,@COMMENTS\n" + ")\n"; #endregion Parameters = new List <IDataParameter>(); Parameters.Add(new SqlParameter(string.Format("@{0}", "CODE"), CODE.ToString().ToUpper())); Parameters.Add(new SqlParameter(string.Format("@{0}", "SYSAP"), SYSAP)); Parameters.Add(new SqlParameter(string.Format("@{0}", "SESSION_KEY"), SESSION_KEY)); Parameters.Add(new SqlParameter(string.Format("@{0}", "USERIP"), USERIP)); Parameters.Add(new SqlParameter(string.Format("@{0}", "USERID"), USERID)); Parameters.ParametersAdd("COMMENTS", COMMENTS); return(strSql); }
public void ProcessRequest(HttpContext context) { this.MyUtility.InitLog("DeleteIMG"); context.Response.Clear(); context.Response.ContentType = "application/json"; string json = string.Empty, data = string.Empty, message = string.Empty; SysCode code = SysCode.A000; XmlDocument xmlDoc = null; string xPath = string.Empty, strSql = string.Empty; List <IDataParameter> para = null; DataTable dt = null; string session_key = string.Empty, year_and_month = string.Empty, file_seq = string.Empty; try { #region 取得參數 data = context.GetRequest("data"); if (String.IsNullOrEmpty(data)) { throw new Utility.ProcessException(string.Format("參數為空值"), ref code, SysCode.E004); } this.MyUtility.WriteLog(Mode.LogMode.DEBUG, context, string.Format("DATA.JSON:{0}", data)); #endregion xmlDoc = JsonConvert.DeserializeXmlNode(data); XmlNode xmlNodeProcessInfo = xmlDoc.SelectSingleNode(xPath = string.Format("./CHANGINGTEC/PROCESS_INFO")); if (xmlNodeProcessInfo == null) { throw new Utility.ProcessException(xPath, ref code, SysCode.E003); } session_key = xmlNodeProcessInfo.SelectSingleNode(string.Format("SESSION_KEY"), ref code); year_and_month = xmlNodeProcessInfo.SelectSingleNode(string.Format("FILE_SEQ"), ref code); file_seq = xmlNodeProcessInfo.SelectSingleNode(string.Format("YM"), ref code, false); this.MyUtility.CheckAndCreateTable(context, year_and_month, ref code); strSql = this.MyUtility.Select.CASE_TABLE(year_and_month, session_key, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion dt = this.MyUtility.DBConn.GeneralSqlCmd.ExecuteToDataTable(strSql, para); if (dt.Rows.Count.Equals(0)) { throw new Utility.ProcessException(string.Format("查詢資料不存在"), ref code, SysCode.E007); } string case_state = dt.Rows[0]["CASE_STATE"].ToString(); strSql = this.MyUtility.Select.FILE_TABLE(year_and_month, session_key, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion dt = this.MyUtility.DBConn.GeneralSqlCmd.ExecuteToDataTable(strSql, para); if (dt.Rows.Count.Equals(0)) { throw new Utility.ProcessException(string.Format("沒有任何檔案"), ref code, SysCode.E007); } if (!String.IsNullOrEmpty(file_seq)) { DataRow[] dr = dt.Select(string.Format("FILE_SEQ='{0}'", file_seq)); if (dr.Length.Equals(0)) { throw new Utility.ProcessException(string.Format("檔案不存在"), ref code, SysCode.E007); } strSql = this.MyUtility.Update.FILE_TABLE_STOP(year_and_month, session_key, file_seq, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion } else { strSql = this.MyUtility.Update.FILE_TABLE_STOP(year_and_month, session_key, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion } int result = this.MyUtility.DBConn.GeneralSqlCmd.ExecuteNonQuery(strSql, para); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("Result:{0}", result)); if (result.Equals(0)) { throw new Utility.ProcessException(string.Format("檔案刪除失敗"), ref code, SysCode.E002); } this.MyUtility.DBLog(context, code, "DeleteIMG", session_key, string.Empty, string.Empty); } catch (System.Exception ex) { message = ex.Message; this.MyUtility.WriteLog(Mode.LogMode.ERROR, context, ex.ToString()); code = !code.Equals(SysCode.A000) ? code : SysCode.E999; this.MyUtility.DBLog(context, code, "DeleteIMG", session_key, string.Empty, ex.Message); this.MyUtility.SendEMail(context, "DeleteIMG", session_key, code); } finally { json = JsonConvert.SerializeObject(new PARSE_CASE_RESPOSE() { CHANGINGTEC = new PARSE_CASE_SYSTEM_CLASS() { SYSTEM = new SYSTEM_INFO_CLASS() { CODE = code.ToString(), MESSAGE = message.EncryptBase64() } } }); dt = null; xmlDoc = null; para = null; this.MyUtility.CloseConn(); xmlDoc = null; GC.Collect(); GC.WaitForPendingFinalizers(); context.Response.Write(json); context.Response.End(); } }
public void ProcessRequest(HttpContext context) { this.MyUtility.InitLog("ParseCase"); context.Response.Clear(); context.Response.ContentType = "application/json"; string json = string.Empty, data = string.Empty, message = string.Empty; SysCode code = SysCode.A000; XmlDocument xmlDoc = null; string xPath = string.Empty, strSql = string.Empty; List <IDataParameter> para = null; DataTable dt = null; string session_key = string.Empty; string year_and_month = DateTime.Now.ToString("yyyyMM"); try { #region 取得參數 data = context.GetRequest("data"); if (String.IsNullOrEmpty(data)) { throw new Utility.ProcessException(string.Format("參數為空值"), ref code, SysCode.E004); } this.MyUtility.WriteLog(Mode.LogMode.DEBUG, context, string.Format("DATA.JSON:{0}", data)); #endregion xmlDoc = JsonConvert.DeserializeXmlNode(data); XmlNode xmlNodeProcessInfo = xmlDoc.SelectSingleNode(xPath = string.Format("./CHANGINGTEC/PROCESS_INFO")); if (xmlNodeProcessInfo == null) { throw new Utility.ProcessException(xPath, ref code, SysCode.E003); } session_key = xmlNodeProcessInfo.SelectSingleNode(string.Format("SESSION_KEY"), ref code, false); year_and_month = xmlNodeProcessInfo.SelectSingleNode(string.Format("YM"), ref code); this.MyUtility.CheckAndCreateTable(context, year_and_month, ref code); strSql = this.MyUtility.Select.CASE_TABLE(year_and_month, session_key, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion dt = this.MyUtility.DBConn.GeneralSqlCmd.ExecuteToDataTable(strSql, para); if (dt.Rows.Count.Equals(0)) { throw new Utility.ProcessException(string.Format("查詢資料不存在"), ref code, SysCode.E007); } string case_state = dt.Rows[0]["CASE_STATE"].ToString(); switch (case_state) { case "0": code = SysCode.A000; message = string.Empty; break; case "1": code = SysCode.A003; message = "拆檔中"; break; case "9": code = SysCode.E005; message = "拆檔發生錯誤"; break; case "99": code = SysCode.E010; message = "案件已刪除"; break; } this.MyUtility.DBLog(context, code, "ParseCase", session_key, string.Empty, string.Empty); } catch (System.Exception ex) { message = ex.Message; this.MyUtility.WriteLog(Mode.LogMode.ERROR, context, ex.ToString()); code = !code.Equals(SysCode.A000) ? code : SysCode.E999; this.MyUtility.DBLog(context, code, "ParseCase", session_key, string.Empty, ex.Message); this.MyUtility.SendEMail(context, "ParseCase", session_key, code); } finally { json = JsonConvert.SerializeObject(new PARSE_CASE_RESPOSE() { CHANGINGTEC = new PARSE_CASE_SYSTEM_CLASS() { SYSTEM = new SYSTEM_INFO_CLASS() { CODE = code.ToString(), MESSAGE = message.EncryptBase64() } } }); dt = null; xmlDoc = null; para = null; this.MyUtility.CloseConn(); xmlDoc = null; GC.Collect(); GC.WaitForPendingFinalizers(); context.Response.Write(json); context.Response.End(); } }
public void ProcessRequest(HttpContext context) { this.MyUtility.InitLog("SendFile"); context.Response.Clear(); context.Response.ContentType = "application/json"; string json = string.Empty, data = string.Empty, message = string.Empty; SysCode code = SysCode.A000; XmlDocument xmlDoc = null; string xPath = string.Empty, strSql = string.Empty; List <IDataParameter> para = null; string USERID = string.Empty; string session_key = string.Empty, session_temp_dir_path = string.Empty; bool exists = false; try { #region 取得參數 data = context.GetRequest("data"); if (String.IsNullOrEmpty(data)) { throw new Utility.ProcessException(string.Format("參數為空值"), ref code, SysCode.E004); } this.MyUtility.WriteLog(Mode.LogMode.DEBUG, context, string.Format("DATA.JSON:{0}", data)); #endregion xmlDoc = JsonConvert.DeserializeXmlNode(data); XmlNode xmlNodeProcessInfo = xmlDoc.SelectSingleNode(xPath = string.Format("./CHANGINGTEC/PROCESS_INFO")); if (xmlNodeProcessInfo == null) { throw new Utility.ProcessException(xPath, ref code, SysCode.E003); } USERID = xmlNodeProcessInfo.SelectSingleNode(string.Format("SESSION_KEY"), ref code); session_key = xmlNodeProcessInfo.SelectSingleNode(string.Format("SESSION_KEY"), ref code); #region SESSION_TEMP_PATH strSql = this.MyUtility.Select.SETTING("SESSION_TEMP_PATH", ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion string session_temp_root_path = this.MyUtility.DBConn.GeneralSqlCmd.ExecuteByColumnName(strSql, para, "PARAMETER"); exists = Directory.Exists(session_temp_root_path); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("SESSION_TEMP_PATH (ROOT):{0},{1}", session_temp_root_path, exists)); if (!exists) { throw new Utility.ProcessException(string.Format("目錄不存在:{0}", session_temp_root_path), ref code, SysCode.E001); } #endregion #region SESSION_TEMP_PATH session_temp_dir_path = Path.Combine(session_temp_root_path, session_key); exists = Directory.Exists(session_temp_dir_path); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("SESSION_TEMP_PATH:{0},{1}", session_temp_dir_path, exists)); if (!exists) { throw new Utility.ProcessException(string.Format("目錄不存在:{0}", session_temp_dir_path), ref code, SysCode.E001); } #endregion string FILE_BODY = xmlNodeProcessInfo.SelectSingleNode(string.Format("FILE_BODY"), ref code); int FILE_SEQ = Convert.ToInt32(xmlNodeProcessInfo.SelectSingleNode(string.Format("FILE_SEQ"), ref code)); string FILE_NAME = xmlNodeProcessInfo.SelectSingleNode(string.Format("FILE_NAME"), ref code, true); string FILE_EXTENSION = xmlNodeProcessInfo.SelectSingleNode(string.Format("FILE_EXTENSION"), ref code); int FILE_TYPE = Convert.ToInt32(xmlNodeProcessInfo.SelectSingleNode(string.Format("FILE_TYPE"), ref code)); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, message = string.Format("FILE_SEQ={0},FILE_NAME={1},FILE_EXTENSION={2},FILE_TYPE={3},FILE_BODY={4}", FILE_SEQ, FILE_NAME, FILE_EXTENSION, FILE_TYPE, FILE_BODY.Length)); string file_path = Path.Combine(session_temp_dir_path, string.Format("[FILE]_{0}_{1}_{2}_{3}.{4}", FILE_TYPE, FILE_SEQ.ToString(), !String.IsNullOrEmpty(FILE_NAME) ? FILE_NAME : FILE_SEQ.ToString().PadLeft(3, '0'), USERID, FILE_EXTENSION)); file_path.DeleteSigleFile(); this.MyUtility.CreateFile(file_path, FILE_BODY, ref code); this.MyUtility.DBLog(context, code, "SendFile", session_key, USERID, message); } catch (System.Exception ex) { session_key = string.Empty; message = ex.Message; this.MyUtility.WriteLog(Mode.LogMode.ERROR, context, ex.ToString()); code = !code.Equals(SysCode.A000) ? code : SysCode.E999; this.MyUtility.DBLog(context, code, "SendFile", session_key, USERID, ex.Message); this.MyUtility.SendEMail(context, "SendFile", session_key, code); } finally { json = JsonConvert.SerializeObject(new SEND_FILE_RESPOSE() { CHANGINGTEC = new SEND_FILE_SYSTEM_CLASS() { SYSTEM = new SYSTEM_INFO_CLASS() { CODE = code.ToString(), MESSAGE = message.EncryptBase64() } } }); xmlDoc = null; para = null; this.MyUtility.CloseConn(); xmlDoc = null; GC.Collect(); GC.WaitForPendingFinalizers(); context.Response.Write(json); context.Response.End(); } }
public void ProcessRequest(HttpContext context) { this.MyUtility.InitLog("GetSessionID"); context.Response.Clear(); context.Response.ContentType = "application/json"; string json = string.Empty, data = string.Empty, message = string.Empty; SysCode code = SysCode.A000; XmlDocument xmlDoc = null; string xPath = string.Empty, strSql = string.Empty; List <IDataParameter> para = null; string USERID = string.Empty; string session_key = string.Empty, session_temp_dir_path = string.Empty; string year_and_month = DateTime.Now.ToString("yyyyMM"); DataTable dt = null; bool exists = false; try { #region 取得參數 data = context.GetRequest("data"); if (String.IsNullOrEmpty(data)) { throw new Utility.ProcessException(string.Format("參數為空值"), ref code, SysCode.E004); } this.MyUtility.WriteLog(Mode.LogMode.DEBUG, context, string.Format("DATA.JSON:{0}", data)); #endregion xmlDoc = JsonConvert.DeserializeXmlNode(data); XmlNode xmlNodeProcessInfo = xmlDoc.SelectSingleNode(xPath = string.Format("./CHANGINGTEC/PROCESS_INFO")); if (xmlNodeProcessInfo == null) { throw new Utility.ProcessException(xPath, ref code, SysCode.E003); } USERID = xmlNodeProcessInfo.SelectSingleNode(string.Format("USERID"), ref code, false); string CHANNEL_CODE = xmlNodeProcessInfo.SelectSingleNode(string.Format("CHANNEL_CODE"), ref code); string TXN_TYPE = xmlNodeProcessInfo.SelectSingleNode(string.Format("TXN_TYPE"), ref code); string TXN_ID = xmlNodeProcessInfo.SelectSingleNode(string.Format("TXN_ID"), ref code); string REPORT_TYPE = xmlNodeProcessInfo.SelectSingleNode(string.Format("REPORT_TYPE"), ref code); string GUID = xmlNodeProcessInfo.SelectSingleNode(string.Format("GUID"), ref code); strSql = this.MyUtility.Select.CASE_TABLE(year_and_month, CHANNEL_CODE, TXN_TYPE, TXN_ID, REPORT_TYPE, GUID, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion dt = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteToDataTable(strSql, para); if (dt != null && dt.Rows.Count > 0 && dt.Rows[0]["CASE_STATE"].ToString().Trim().Equals("1")) { throw new Utility.ProcessException(string.Format("重覆上傳"), ref code, SysCode.E008); } #region SESSION_TEMP_PATH strSql = this.MyUtility.Select.SETTING("SESSION_TEMP_PATH", ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion string session_temp_root_path = this.MyUtility.DBConn.GeneralSqlCmd.ExecuteByColumnName(strSql, para, "PARAMETER"); exists = Directory.Exists(session_temp_root_path); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("SESSION_TEMP_PATH (ROOT):{0},{1}", session_temp_root_path, exists)); if (!exists) { throw new Utility.ProcessException(string.Format("目錄不存在:{0}", session_temp_root_path), ref code, SysCode.E001); } #endregion session_key = Guid.NewGuid().GenerateSessionKey(year_and_month); session_temp_dir_path = Path.Combine(session_temp_root_path, session_key); if (!Directory.Exists(session_temp_dir_path)) { Directory.CreateDirectory(session_temp_dir_path); } string ini_file_path = Path.Combine(session_temp_dir_path, string.Format("{0}.ini", session_key)); ini_file_path.DeleteSigleFile(); string INI_BASE64 = xmlNodeProcessInfo.SelectSingleNode(string.Format("INI_BASE64"), ref code, false); if (!String.IsNullOrEmpty(INI_BASE64)) { this.MyUtility.CreateFile(ini_file_path, INI_BASE64, ref code); } string xml_path = Path.Combine(session_temp_dir_path, string.Format("{0}_{1}.xml", session_key, year_and_month)); xmlDoc = new XmlDocument(); xmlDoc.LoadXml(string.Format("<?xml version=\"1.0\" encoding=\"utf-8\"?>{0}", xmlNodeProcessInfo.OuterXml)); xmlDoc.Save(xml_path); this.MyUtility.DBLog(context, code, "GetSessionID", session_key, USERID, string.Empty); } catch (System.Exception ex) { session_key = string.Empty; message = ex.Message; this.MyUtility.WriteLog(Mode.LogMode.ERROR, context, ex.ToString()); code = !code.Equals(SysCode.A000) ? code : SysCode.E999; this.MyUtility.DBLog(context, code, "GetSessionID", session_key, USERID, ex.Message); session_temp_dir_path.DeleteDirectory(); this.MyUtility.SendEMail(context, "GetSessionID", session_key, code); } finally { json = JsonConvert.SerializeObject(new GET_SESSION_ID_RESPOSE() { CHANGINGTEC = new GET_SESSION_ID_SYSTEM_CLASS() { SYSTEM = new GET_SESSION_ID_SYSTEM_INFO_CLASS() { CODE = code.ToString(), MESSAGE = message.EncryptBase64(), SESSION_KEY = session_key } } }); dt = null; xmlDoc = null; para = null; this.MyUtility.CloseConn(); xmlDoc = null; GC.Collect(); GC.WaitForPendingFinalizers(); context.Response.Write(json); context.Response.End(); } }
public void ProcessRequest(HttpContext context) { this.MyUtility.InitLog("T24UpdateState"); context.Response.Clear(); context.Response.ContentType = "application/json"; string json = string.Empty, data = string.Empty, message = string.Empty; SysCode code = SysCode.A000; XmlDocument xmlDoc = null; string xPath = string.Empty, strSql = string.Empty; List <IDataParameter> para = null; string USERID = string.Empty, TRANSACTION_ID = string.Empty, TRANS_STATE = string.Empty, CHARGE = string.Empty, SUPERVISOR = string.Empty; string AUTHORIZE_ID = string.Empty, CONFIRM_ID = string.Empty, TXN_MEMO = string.Empty; string year_and_month = DateTime.Now.ToString("yyyyMM"); DataTable dt = null; int result = -1; List <string> delete_list = new List <string>(); try { #region 取得參數 data = context.GetRequest("data"); if (String.IsNullOrEmpty(data)) { throw new Utility.ProcessException(string.Format("參數為空值"), ref code, SysCode.E004); } this.MyUtility.WriteLog(Mode.LogMode.DEBUG, context, string.Format("DATA.JSON:{0}", data)); #endregion xmlDoc = JsonConvert.DeserializeXmlNode(data); XmlNode xmlNodeProcessInfo = xmlDoc.SelectSingleNode(xPath = string.Format("./CHANGINGTEC/PROCESS_INFO")); if (xmlNodeProcessInfo == null) { throw new Utility.ProcessException(xPath, ref code, SysCode.E003); } TRANSACTION_ID = xmlNodeProcessInfo.SelectSingleNode("TRANSACTION_ID", ref code); TRANS_STATE = xmlNodeProcessInfo.SelectSingleNode("TRANS_STATE", ref code); CHARGE = xmlNodeProcessInfo.SelectSingleNode("CHARGE", ref code, false); SUPERVISOR = xmlNodeProcessInfo.SelectSingleNode("SUPERVISOR", ref code, false); AUTHORIZE_ID = xmlNodeProcessInfo.SelectSingleNode("AUTHORIZE_ID", ref code, false); CONFIRM_ID = xmlNodeProcessInfo.SelectSingleNode("CONFIRM_ID", ref code, false); TXN_MEMO = xmlNodeProcessInfo.SelectSingleNode("TXN_MEMO", ref code, false); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("TRANS_STATE:{0}", TRANS_STATE)); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("AUTHORIZE_ID:{0}", AUTHORIZE_ID)); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("CONFIRM_ID:{0}", CONFIRM_ID)); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("TXN_MEMO:{0}", TXN_MEMO)); this.MyUtility.DBLog(context, SysCode.A001, "T24UpdateState", TRANSACTION_ID, USERID, string.Empty); bool is_delete = TRANS_STATE.Trim().ToUpper().Equals("DELE"); bool is_reve = TRANS_STATE.Trim().ToUpper().Equals("REVE"); bool is_inau = TRANS_STATE.Trim().ToUpper().Equals("INAU"); bool is_live = TRANS_STATE.Trim().ToUpper().Equals("LIVE"); this.MyUtility.CheckAndCreateTable(context, year_and_month, ref code); //移除CASE_STATE='0' strSql = this.MyUtility.Select.CASE_TABLE_T24(year_and_month, TRANSACTION_ID, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion dt = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteToDataTable(strSql, para); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("dt.Rows.Count:{0}", dt.Rows.Count.ToString())); bool case_data_check = dt != null && dt.Rows.Count > 0; if (!case_data_check) { year_and_month = year_and_month.GetPreviousYM(); strSql = this.MyUtility.Select.CASE_TABLE_T24(year_and_month, TRANSACTION_ID, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion dt = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteToDataTable(strSql, para); case_data_check = dt != null && dt.Rows.Count > 0; } if (!case_data_check) { strSql = this.MyUtility.Select.CASE_TABLE_T24_EXISTS(year_and_month, TRANSACTION_ID, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion DataTable dtCheck = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteToDataTable(strSql, para); case_data_check = dtCheck != null && dtCheck.Rows.Count > 0; this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("dtCheck.Rows.Count:{0}", dtCheck.Rows.Count.ToString())); //如果查無資料則跳出 if (!case_data_check) { throw new Utility.ProcessException(string.Format("查詢資料不存在"), ref code, SysCode.E007); } //if (!case_data_check) //{ // strSql = this.MyUtility.Select.T24_UPDATE_STATE(TRANSACTION_ID, ref para); // #region SQL Debug // this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); // this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); // #endregion // dtCheck = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteToDataTable(strSql, para); // case_data_check = dtCheck != null && dtCheck.Rows.Count > 0; // if (case_data_check) // { // strSql = this.MyUtility.Update.T24_UPDATE_STATE(TRANSACTION_ID, TRANS_STATE.Trim().ToUpper(), ref para); // } // else // { // strSql = this.MyUtility.Insert.T24_UPDATE_STATE(year_and_month, TRANSACTION_ID, TRANS_STATE.Trim().ToUpper(), ref para); // } // #region SQL Debug // this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); // this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); // #endregion // result = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para); // this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("Result:{0}", result)); // if (!result.Equals(1)) throw new Utility.ProcessException(string.Format("T24_UPDATE_STATE資料新增失敗"), ref code, SysCode.E002); // this.MyUtility.DBConnTransac.GeneralSqlCmd.Transaction.Commit(); // return; //} //else //{ // throw new Utility.ProcessException(string.Format("查詢資料不存在"), ref code, SysCode.E007); //} } bool is_dril = is_delete || is_reve || is_inau || is_live; if (is_dril) { for (int i = 0; i < dt.Rows.Count; i++) { string trans_state = dt.Rows[i]["TRANS_STATE"] != DBNull.Value ? dt.Rows[i]["TRANS_STATE"].ToString().Trim().ToUpper() : string.Empty; this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("is_reve:{0}", is_reve)); bool check = false; if (is_delete) { check = String.IsNullOrEmpty(trans_state) || trans_state.Equals("INAU") || trans_state.Equals("LIVE") || trans_state.Equals("INCF"); } else if (is_reve) { check = String.IsNullOrEmpty(trans_state) || trans_state.Equals("LIVE") || trans_state.Equals("INAU"); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("check:{0},state:{1}", check, trans_state)); } else if (is_inau) { string confirm_id = dt.Rows[i]["CONFIRM_ID"] != DBNull.Value ? dt.Rows[i]["CONFIRM_ID"].ToString().Trim() : string.Empty; this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("CONFIRM_ID:{0},TRANS_STATE:{1}", confirm_id, trans_state)); check = (String.IsNullOrEmpty(confirm_id) && trans_state.Equals("INCF")) || trans_state.Equals("INAU"); } else if (is_live) { string authorize_id = dt.Rows[i]["AUTHORIZE_ID"] != DBNull.Value ? dt.Rows[i]["AUTHORIZE_ID"].ToString().Trim() : string.Empty; this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("AUTHORIZE_ID:{0},TRANS_STATE:{1}", authorize_id, trans_state)); check = String.IsNullOrEmpty(authorize_id) && trans_state.Equals("INAU"); } this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("Check:{0}", check)); if (!check) { throw new Utility.ProcessException(string.Format("TRANS_STATE 不符合規範"), ref code, SysCode.E012); } } } this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("Data.Count:{0}", dt.Rows.Count)); //增加if else條件式,如果CASE_STATE = '1',狀態為DELE時不更新FILE_TABLE中的狀態 if (is_delete) { strSql = this.MyUtility.Select.CASE_TABLE_T24_STATE(year_and_month, TRANSACTION_ID, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion dt = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteToDataTable(strSql, para); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("dt.Rows.Count:{0}", dt.Rows.Count.ToString())); bool case_data_state_check = dt != null && dt.Rows.Count > 0; if (case_data_state_check) { //CASE_STATE='0' for (int i = 0; i < dt.Rows.Count; i++) { strSql = this.MyUtility.Update.FILE_TABLE_STOP(year_and_month, dt.Rows[i]["SESSION_KEY"].ToString(), ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion result = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("Result:{0}", result)); } } } this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("TRANS_STATE:{0}", TRANS_STATE)); if (!String.IsNullOrEmpty(TRANS_STATE)) { if (is_live) { strSql = this.MyUtility.Update.CASE_TABLE_T24_TRANS_STATE_BY_LIVE(year_and_month, TRANSACTION_ID, TRANS_STATE.ToUpper(), USERID, AUTHORIZE_ID, CONFIRM_ID, TXN_MEMO, ref para); } else if (is_inau) { strSql = this.MyUtility.Update.CASE_TABLE_T24_TRANS_STATE_BY_INAU(year_and_month, TRANSACTION_ID, TRANS_STATE.ToUpper(), USERID, AUTHORIZE_ID, CONFIRM_ID, TXN_MEMO, ref para); } else if (is_reve) { strSql = this.MyUtility.Update.CASE_TABLE_T24_TRANS_STATE_BY_REVE(year_and_month, TRANSACTION_ID, TRANS_STATE.ToUpper(), USERID, AUTHORIZE_ID, CONFIRM_ID, TXN_MEMO, ref para); } else if (is_delete) { strSql = this.MyUtility.Update.CASE_TABLE_T24_TRANS_STATE_BY_DELE(year_and_month, TRANSACTION_ID, TRANS_STATE.ToUpper(), USERID, AUTHORIZE_ID, CONFIRM_ID, TXN_MEMO, ref para); } else { strSql = this.MyUtility.Update.CASE_TABLE_T24_TRANS_STATE(year_and_month, TRANSACTION_ID, TRANS_STATE.ToUpper(), USERID, AUTHORIZE_ID, CONFIRM_ID, TXN_MEMO, ref para); } #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion result = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("Result:{0}", result)); } if (!String.IsNullOrEmpty(CHARGE) || !String.IsNullOrEmpty(SUPERVISOR)) { strSql = this.MyUtility.Update.CASE_TABLE_T24(year_and_month, TRANSACTION_ID, CHARGE, SUPERVISOR, USERID, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion result = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("Result:{0}", result)); } this.MyUtility.DBConnTransac.GeneralSqlCmd.Transaction.Commit(); this.MyUtility.DBLog(context, SysCode.A002, "T24UpdateState", TRANSACTION_ID, USERID, string.Empty); } catch (System.Exception ex) { this.MyUtility.Rollback(); message = ex.Message; this.MyUtility.WriteLog(Mode.LogMode.ERROR, context, ex.ToString()); code = !code.Equals(SysCode.A000) ? code : SysCode.E999; this.MyUtility.DBLog(context, code, "T24UpdateState", TRANSACTION_ID, USERID, ex.Message); this.MyUtility.SendEMail(context, "T24UpdateState", TRANSACTION_ID, code); } finally { json = JsonConvert.SerializeObject(new T24UPDATE_STATE_RESPOSE_RESPOSE() { CHANGINGTEC = new T24UPDATE_STATE_RESPOSE_SYSTEM_CLASS() { SYSTEM = new SYSTEM_INFO_CLASS() { CODE = code.ToString(), MESSAGE = message.EncryptBase64() } } }); dt = null; xmlDoc = null; para = null; this.MyUtility.CloseConnTransac(); xmlDoc = null; GC.Collect(); GC.WaitForPendingFinalizers(); context.Response.Write(json); context.Response.End(); } }
public void ProcessRequest(HttpContext context) { this.MyUtility.InitLog("GetPDFBase64"); context.Response.Clear(); context.Response.ContentType = "application/json"; string json = string.Empty, data = string.Empty, message = string.Empty; SysCode code = SysCode.B000; XmlDocument xmlDoc = null; string xPath = string.Empty, strSql = string.Empty; List <IDataParameter> para = null; DataTable dt = null; string USERID = string.Empty; string year_and_month = string.Empty; string session_key = string.Empty, session_info = string.Empty; PDF_BASE64_CLASS.PDF_BASE64_ITEM pdf_info_item = new PDF_BASE64_CLASS.PDF_BASE64_ITEM(); try { #region 取得參數 data = context.GetRequest("data"); if (String.IsNullOrEmpty(data)) { throw new Utility.ProcessException(string.Format("參數為空值"), ref code, SysCode.E004); } this.MyUtility.WriteLog(Mode.LogMode.DEBUG, context, string.Format("DATA.JSON:{0}", data)); #endregion xmlDoc = JsonConvert.DeserializeXmlNode(data); XmlNode xmlNodeProcessInfo = xmlDoc.SelectSingleNode(xPath = string.Format("./CHANGINGTEC/PROCESS_INFO")); if (xmlNodeProcessInfo == null) { throw new Utility.ProcessException(xPath, ref code, SysCode.E003); } USERID = xmlNodeProcessInfo.SelectSingleNode(string.Format("USERID"), ref code, false); session_key = xmlNodeProcessInfo.SelectSingleNode(string.Format("SESSION_KEY"), ref code, false); this.MyUtility.WriteLog(context, string.Format("SESSION_KEY:{0}", session_key)); if (String.IsNullOrEmpty(session_key)) { year_and_month = xmlNodeProcessInfo.SelectSingleNode(string.Format("YM"), ref code); this.MyUtility.CheckAndCreateTable(context, year_and_month, ref code); string CHANNEL_CODE = xmlNodeProcessInfo.SelectSingleNode(string.Format("CHANNEL_CODE"), ref code); string TXN_TYPE = xmlNodeProcessInfo.SelectSingleNode(string.Format("TXN_TYPE"), ref code); string TXN_ID = xmlNodeProcessInfo.SelectSingleNode(string.Format("TXN_ID"), ref code); string REPORT_SERIAL_NO = xmlNodeProcessInfo.SelectSingleNode(string.Format("REPORT_SERIAL_NO"), ref code); string GUID = xmlNodeProcessInfo.SelectSingleNode(string.Format("GUID"), ref code); this.MyUtility.DBLog(context, SysCode.B001, "GetPDFBase64", string.Empty, USERID, session_info = string.Format("{0}_{1}_{2}_{3}_{4}_{5}", year_and_month, CHANNEL_CODE, TXN_TYPE, TXN_ID, REPORT_SERIAL_NO, GUID)); strSql = this.MyUtility.Select.FILE_TABLE(year_and_month, CHANNEL_CODE, TXN_TYPE, TXN_ID, REPORT_SERIAL_NO, GUID, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion dt = this.MyUtility.DBConn.GeneralSqlCmd.ExecuteToDataTable(strSql, para); if (dt.Rows.Count.Equals(0)) { year_and_month = year_and_month.GetPreviousYM(); this.MyUtility.CheckAndCreateTable(context, year_and_month, ref code); strSql = this.MyUtility.Select.FILE_TABLE(year_and_month, CHANNEL_CODE, TXN_TYPE, TXN_ID, REPORT_SERIAL_NO, GUID, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion dt = this.MyUtility.DBConn.GeneralSqlCmd.ExecuteToDataTable(strSql, para); } } else { year_and_month = session_key.Split('-')[0]; this.MyUtility.CheckAndCreateTable(context, year_and_month, ref code); this.MyUtility.DBLog(context, SysCode.B001, "GetPDFBase64", string.Empty, USERID, session_info = string.Format("{0}_{1}", year_and_month, session_key)); strSql = this.MyUtility.Select.FILE_TABLE(year_and_month, session_key, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion dt = this.MyUtility.DBConn.GeneralSqlCmd.ExecuteToDataTable(strSql, para); } if (dt.Rows.Count.Equals(0)) { throw new Utility.ProcessException(string.Format("查無資料"), ref code, SysCode.E007); } this.MyUtility.DBLog(context, SysCode.A001, "GetPDFBase64", session_key = dt.Rows[0]["SESSION_KEY"].ToString(), USERID, string.Empty); this.MyUtility.WriteLog(context, string.Format("SESSION_KEY:{0}", session_key)); DataRow[] dr_pdf = dt.Select(string.Format("FILE_TYPE=1")); string file_id = string.Empty, file_full_path = string.Empty, file_root = string.Empty, file_path = string.Empty; bool exists = false; this.MyUtility.WriteLog(context, string.Format("PDF.Count:{0}", dr_pdf.Length)); if (dr_pdf.Length > 0) { file_root = dr_pdf[0]["FILE_ROOT"].ToString(); file_path = dr_pdf[0]["FILE_PATH"].ToString(); file_id = dr_pdf[0]["FILE_ID"].ToString(); file_full_path = file_root.FilePathCombine(file_path); exists = File.Exists(file_full_path); this.MyUtility.WriteLog(context, string.Format("{0},{1},{2}", file_id, file_full_path, exists)); } if (!exists) { DataRow[] dr_file = dt.Select(string.Format("FILE_TYPE=3")); this.MyUtility.WriteLog(context, string.Format("File.Count:{0}", dr_file.Length)); if (dr_file.Length.Equals(0)) { file_root = dr_file[0]["FILE_ROOT"].ToString(); file_path = dr_file[0]["FILE_PATH"].ToString(); file_id = dr_file[0]["FILE_ID"].ToString(); file_full_path = file_root.FilePathCombine(file_path); exists = File.Exists(file_full_path); this.MyUtility.WriteLog(context, string.Format("{0},{1},{2}", file_id, file_full_path, exists)); } } if (!File.Exists(file_full_path)) { throw new Utility.ProcessException(string.Format("檔案不存在"), ref code, SysCode.E006); } pdf_info_item.FILE_ID = file_id; pdf_info_item.BODY = file_full_path.FileSerialize(); this.MyUtility.DBLog(context, SysCode.B000, "GetPDFBase64", session_key, USERID, session_info); } catch (System.Exception ex) { message = ex.Message; this.MyUtility.WriteLog(Mode.LogMode.ERROR, context, ex.ToString()); code = !code.Equals(SysCode.B000) ? code : SysCode.E999; this.MyUtility.DBLog(context, code, "GetPDFBase64", session_key, USERID, ex.Message); this.MyUtility.SendEMail(context, "GetPDFBase64", session_key, code); } finally { json = JsonConvert.SerializeObject(new PDF_BASE64_RESPOSE() { CHANGINGTEC = new PDF_BASE64_SYSTEM_CLASS() { SYSTEM = new PDF_BASE64_SYSTEM_INFO_CLASS() { //CODE = code.Equals(SysCode.B000) ? SysCode.A000.ToString() : code.Equals(SysCode.E007) ? SysCode.A003.ToString() : code.ToString(), CODE = code.Equals(SysCode.B000) ? SysCode.A000.ToString() : code.ToString(), MESSAGE = message.EncryptBase64(), CASE_INFO = new PDF_BASE64_CLASS() { PDF_ITEM = pdf_info_item } } } }); dt = null; xmlDoc = null; para = null; this.MyUtility.CloseConn(); xmlDoc = null; GC.Collect(); GC.WaitForPendingFinalizers(); context.Response.Write(json); context.Response.End(); } }
/// <summary> /// /// </summary> /// <param name="Context"></param> /// <param name="APIName"></param> /// <param name="SessionKey"></param> /// <param name="Code"></param> public void SendEMail(HttpContext Context, string APIName, string SessionKey, SysCode Code) { this.InitMailLog("SendEMail"); this.WriteMailLog(Mode.LogMode.INFO, Context, string.Format("Code::{0}", Code)); if (Code != SysCode.E002 && Code != SysCode.E003 && Code != SysCode.E005 && Code != SysCode.E999) { return; } MailInfo info = new MailInfo(); DBLib.DBConn dbConn = null; DataTable dt = null; string strSql = string.Empty; try { dbConn = new DBLib.DBConn(new DBLibUtility.Mode.FreeMode() { APMode = DBLibUtility.Mode.APMode.Web, DBMode = DBLibUtility.Mode.DBMode.MSSQL, ConnectionString = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString.ToString().DecryptDES() }); strSql = this.Select.SMTP(); #region SQL Debug this.WriteMailLog(Context, strSql); #endregion dt = dbConn.GeneralSqlCmd.ExecuteToDataTable(strSql); this.WriteMailLog(Mode.LogMode.INFO, Context, string.Format("SMTP::{0}", dt.Rows.Count)); if (dt.Rows.Count.Equals(0)) { return; } info = new MailInfo() { SMTPServer = dt.Select(string.Format("FUNCTION_CODE='{0}'", "SMTP_IP"))[0]["PARAMETER"].ToString(), Port = Convert.ToInt32(dt.Select(string.Format("FUNCTION_CODE='{0}'", "SMTP_POST"))[0]["PARAMETER"].ToString()), Account = dt.Select(string.Format("FUNCTION_CODE='{0}'", "SMTP_USER"))[0]["PARAMETER"].ToString(), Password = dt.Select(string.Format("FUNCTION_CODE='{0}'", "SMTP_PWD"))[0]["PARAMETER"].ToString(), From = dt.Select(string.Format("FUNCTION_CODE='{0}'", "SMTP_FROM"))[0]["PARAMETER"].ToString(), Address = dt.Select(string.Format("FUNCTION_CODE='{0}'", "SMTP_ERROR_TO_ADDRESS"))[0]["PARAMETER"].ToString(), Subject = "eFiling 系統發生錯誤" }; string message = string.Format("案件代碼:{0}<br/>API名稱:{1}<br/>IP:{2}<br/>錯誤代碼:{3}<br/>", SessionKey, APIName, this.GetClientIPv4(), Code.ToString()); this.SendEMail(Context, info, message, dt.Select(string.Format("FUNCTION_CODE='{0}'", "SMTP_SSL"))[0]["PARAMETER"].ToString().Trim().ToLower().Equals("true")); } catch (System.Exception ex) { this.WriteMailLog(Mode.LogMode.ERROR, Context, string.Format("SendEMail.Exception::{0}", ex.Message)); throw ex; } finally { dt = null; if (dbConn != null) { dbConn.Dispose(); } dbConn = null; } }
public void ProcessRequest(HttpContext context) { this.MyUtility.InitLog("GetImageBase64"); context.Response.Clear(); context.Response.ContentType = "application/json"; string json = string.Empty, data = string.Empty, message = string.Empty; SysCode code = SysCode.B000; XmlDocument xmlDoc = null; string xPath = string.Empty, strSql = string.Empty; List <IDataParameter> para = null; DataTable dt = null; string USERID = string.Empty; string year_and_month = string.Empty; string session_key = string.Empty, session_info = string.Empty; Aspose.Pdf.License license = new Aspose.Pdf.License(); license.SetLicense("Aspose.Pdf.lic"); IMAGE_BASE64_CLASS.IMAGE_BASE64_ITEM[] image_item_list = null; try { #region 取得參數 data = context.GetRequest("data"); if (String.IsNullOrEmpty(data)) { throw new Utility.ProcessException(string.Format("參數為空值"), ref code, SysCode.E004); } this.MyUtility.WriteLog(Mode.LogMode.DEBUG, context, string.Format("DATA.JSON:{0}", data)); #endregion xmlDoc = JsonConvert.DeserializeXmlNode(data); XmlNode xmlNodeProcessInfo = xmlDoc.SelectSingleNode(xPath = string.Format("./CHANGINGTEC/PROCESS_INFO")); if (xmlNodeProcessInfo == null) { throw new Utility.ProcessException(xPath, ref code, SysCode.E003); } USERID = xmlNodeProcessInfo.SelectSingleNode(string.Format("USERID"), ref code, false); session_key = xmlNodeProcessInfo.SelectSingleNode(string.Format("SESSION_KEY"), ref code, false); this.MyUtility.WriteLog(context, string.Format("SESSION_KEY:{0}", session_key)); if (String.IsNullOrEmpty(session_key)) { year_and_month = xmlNodeProcessInfo.SelectSingleNode(string.Format("YM"), ref code); this.MyUtility.CheckAndCreateTable(context, year_and_month, ref code); string CHANNEL_CODE = xmlNodeProcessInfo.SelectSingleNode(string.Format("CHANNEL_CODE"), ref code); string TXN_TYPE = xmlNodeProcessInfo.SelectSingleNode(string.Format("TXN_TYPE"), ref code); string TXN_ID = xmlNodeProcessInfo.SelectSingleNode(string.Format("TXN_ID"), ref code); string REPORT_SERIAL_NO = xmlNodeProcessInfo.SelectSingleNode(string.Format("REPORT_SERIAL_NO"), ref code); string GUID = xmlNodeProcessInfo.SelectSingleNode(string.Format("GUID"), ref code); this.MyUtility.DBLog(context, SysCode.B001, "GetImageBase64", string.Empty, USERID, session_info = string.Format("{0}_{1}_{2}_{3}_{4}_{5}", year_and_month, CHANNEL_CODE, TXN_TYPE, TXN_ID, REPORT_SERIAL_NO, GUID)); strSql = this.MyUtility.Select.FILE_TABLE(year_and_month, CHANNEL_CODE, TXN_TYPE, TXN_ID, REPORT_SERIAL_NO, GUID, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion dt = this.MyUtility.DBConn.GeneralSqlCmd.ExecuteToDataTable(strSql, para); if (dt.Rows.Count.Equals(0)) { year_and_month = year_and_month.GetPreviousYM(); this.MyUtility.CheckAndCreateTable(context, year_and_month, ref code); strSql = this.MyUtility.Select.FILE_TABLE(year_and_month, CHANNEL_CODE, TXN_TYPE, TXN_ID, REPORT_SERIAL_NO, GUID, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion dt = this.MyUtility.DBConn.GeneralSqlCmd.ExecuteToDataTable(strSql, para); } } else { year_and_month = session_key.Split('-')[0]; this.MyUtility.CheckAndCreateTable(context, year_and_month, ref code); this.MyUtility.DBLog(context, SysCode.B001, "GetImageBase64", string.Empty, USERID, session_info = string.Format("{0}_{1}", year_and_month, session_key)); strSql = this.MyUtility.Select.FILE_TABLE(year_and_month, session_key, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion dt = this.MyUtility.DBConn.GeneralSqlCmd.ExecuteToDataTable(strSql, para); } if (dt.Rows.Count.Equals(0)) { throw new Utility.ProcessException(string.Format("查無資料"), ref code, SysCode.E007); } this.MyUtility.DBLog(context, SysCode.A001, "GetImageBase64", session_key = dt.Rows[0]["SESSION_KEY"].ToString(), USERID, string.Empty); this.MyUtility.WriteLog(context, string.Format("SESSION_KEY:{0}", session_key)); DataRow[] dr_pdf = dt.Select(string.Format("FILE_TYPE=1")); string pdf_file_full_path = string.Empty; bool pdf_exists = false; if (dr_pdf.Length > 0) { string pdf_file_root = dr_pdf[0]["FILE_ROOT"].ToString(); string pdf_file_path = dr_pdf[0]["FILE_PATH"].ToString(); pdf_file_full_path = pdf_file_root.FilePathCombine(pdf_file_path); pdf_exists = File.Exists(pdf_file_full_path); this.MyUtility.WriteLog(context, string.Format("{0},{1}", pdf_file_full_path, pdf_exists)); } DataRow[] dr_image = dt.Select(string.Format("FILE_TYPE=11")); this.MyUtility.WriteLog(context, string.Format("Image.Count:{0}", dr_image.Length)); if (dr_image.Length.Equals(0)) { throw new Utility.ProcessException(string.Format("查無資料"), ref code, SysCode.E007); } image_item_list = new IMAGE_BASE64_CLASS.IMAGE_BASE64_ITEM[dr_image.Length]; for (int i = 0; i < dr_image.Length; i++) { session_key = dr_image[i]["SESSION_KEY"].ToString(); string file_id = dr_image[i]["FILE_ID"].ToString(); int file_seq = Convert.ToInt16(dr_image[i]["FILE_SEQ"].ToString()); string file_root = dr_image[i]["FILE_ROOT"].ToString(); string file_path = dr_image[i]["FILE_PATH"].ToString(); string file_full_path = file_root.FilePathCombine(file_path); bool exists = File.Exists(file_full_path); this.MyUtility.WriteLog(context, string.Format("{0},{1},{2}", file_seq, file_full_path, exists)); if (!exists && pdf_exists) { #region PDF 切割 try { using (Document pdfDocument = new Document(pdf_file_full_path)) { Aspose.Pdf.Devices.Resolution resolution = new Aspose.Pdf.Devices.Resolution(150); Aspose.Pdf.Devices.JpegDevice jpegDeviceLarge = new Aspose.Pdf.Devices.JpegDevice(resolution); if (file_seq <= 0 || file_seq > pdfDocument.Pages.Count) { this.MyUtility.WriteLog(Mode.LogMode.ERROR, context, string.Format("PDF.Pages.Count:{0},FILE_SEQ:{1}", pdfDocument.Pages.Count, file_seq)); throw new Utility.ProcessException(string.Format("查無影像檔及無法從PDF內拆檔"), ref code, SysCode.E005); } jpegDeviceLarge.Process(pdfDocument.Pages[file_seq], file_full_path); if (!File.Exists(file_full_path)) { throw new Utility.ProcessException(string.Format("頁次{0}拆檔失敗", file_seq), ref code, SysCode.E005); } } } catch (System.Exception ex) { this.MyUtility.WriteLog(Mode.LogMode.ERROR, context, ex.ToString()); throw new Utility.ProcessException(ex.Message, ref code, SysCode.E005); } #endregion } if (!File.Exists(file_full_path)) { throw new Utility.ProcessException(string.Format("頁次{0}圖檔不存在", file_seq), ref code, SysCode.E001); } image_item_list[i] = new IMAGE_BASE64_CLASS.IMAGE_BASE64_ITEM() { FILE_ID = file_id, BODY = file_full_path.FileSerialize() }; } this.MyUtility.DBLog(context, SysCode.B000, "GetImageBase64", session_key, USERID, session_info); } catch (System.Exception ex) { message = ex.Message; this.MyUtility.WriteLog(Mode.LogMode.ERROR, context, ex.ToString()); code = !code.Equals(SysCode.B000) ? code : SysCode.E999; this.MyUtility.DBLog(context, code, "GetImageBase64", session_key, USERID, ex.Message); this.MyUtility.SendEMail(context, "GetImageBase64", session_key, code); } finally { json = JsonConvert.SerializeObject(new IMAGE_BASE64_RESPOSE() { CHANGINGTEC = new IMAGE_BASE64_SYSTEM_CLASS() { SYSTEM = new IMAGE_BASE64_SYSTEM_INFO_CLASS() { //CODE = code.Equals(SysCode.B000) ? SysCode.A000.ToString() : code.Equals(SysCode.E007) ? SysCode.A003.ToString() : code.ToString(), CODE = code.Equals(SysCode.B000) ? SysCode.A000.ToString() : code.ToString(), MESSAGE = message.EncryptBase64(), CASE_INFO = new IMAGE_BASE64_CLASS() { JPG_ITEM = image_item_list } } } }); dt = null; license = null; xmlDoc = null; para = null; this.MyUtility.CloseConn(); xmlDoc = null; GC.Collect(); GC.WaitForPendingFinalizers(); context.Response.Write(json); context.Response.End(); } }
public void ProcessRequest(HttpContext context) { this.MyUtility.InitLog("T24UpdateTransState"); context.Response.Clear(); context.Response.ContentType = "application/json"; string json = string.Empty, data = string.Empty, message = string.Empty; SysCode code = SysCode.A000; XmlDocument xmlDoc = null; string xPath = string.Empty, strSql = string.Empty; List <IDataParameter> para = null; string USERID = string.Empty, SESSION_KEY = string.Empty, TRANS_STATE = string.Empty; string year_and_month = DateTime.Now.ToString("yyyyMM"); DataTable dt = null; int result = -1; List <string> delete_list = new List <string>(); try { #region 取得參數 data = context.GetRequest("data"); if (String.IsNullOrEmpty(data)) { throw new Utility.ProcessException(string.Format("參數為空值"), ref code, SysCode.E004); } this.MyUtility.WriteLog(Mode.LogMode.DEBUG, context, string.Format("DATA.JSON:{0}", data)); #endregion xmlDoc = JsonConvert.DeserializeXmlNode(data); XmlNode xmlNodeProcessInfo = xmlDoc.SelectSingleNode(xPath = string.Format("./CHANGINGTEC/PROCESS_INFO")); if (xmlNodeProcessInfo == null) { throw new Utility.ProcessException(xPath, ref code, SysCode.E003); } SESSION_KEY = xmlNodeProcessInfo.SelectSingleNode("SESSION_KEY", ref code); TRANS_STATE = xmlNodeProcessInfo.SelectSingleNode("TRANS_STATE", ref code); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("SESSION_KEY:{0}", SESSION_KEY)); this.MyUtility.DBLog(context, SysCode.A001, "T24UpdateTransState", SESSION_KEY, USERID, string.Empty); bool is_delete = TRANS_STATE.Trim().ToUpper().Equals("DELE"); this.MyUtility.CheckAndCreateTable(context, year_and_month, ref code); strSql = this.MyUtility.Select.CASE_TABLE_T24_Trans(year_and_month, SESSION_KEY, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion dt = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteToDataTable(strSql, para); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("dt.Rows.Count:{0}", dt.Rows.Count.ToString())); bool case_data_check = dt != null && dt.Rows.Count > 0; if (!case_data_check) { year_and_month = year_and_month.GetPreviousYM(); strSql = this.MyUtility.Select.CASE_TABLE_T24_Trans(year_and_month, SESSION_KEY, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion dt = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteToDataTable(strSql, para); case_data_check = dt != null && dt.Rows.Count > 0; } if (!case_data_check) { throw new Utility.ProcessException(string.Format("查詢資料不存在"), ref code, SysCode.E007); } if (is_delete) { for (int i = 0; i < dt.Rows.Count; i++) { if (dt.Rows[i]["CASE_STATE"].ToString() == "0") { strSql = this.MyUtility.Update.FILE_TABLE_STOP(year_and_month, dt.Rows[i]["SESSION_KEY"].ToString(), ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion result = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("Result:{0}", result)); } } } this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("TRANS_STATE:{0}", TRANS_STATE)); strSql = this.MyUtility.Update.CASE_TABLE_T24_TRANS_STATE_Trans(year_and_month, SESSION_KEY, TRANS_STATE.ToUpper(), USERID, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion result = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("Result:{0}", result)); this.MyUtility.DBConnTransac.GeneralSqlCmd.Transaction.Commit(); this.MyUtility.DBLog(context, SysCode.A002, "T24UpdateTransState", SESSION_KEY, USERID, string.Empty); } catch (System.Exception ex) { this.MyUtility.Rollback(); message = ex.Message; this.MyUtility.WriteLog(Mode.LogMode.ERROR, context, ex.ToString()); code = !code.Equals(SysCode.A000) ? code : SysCode.E999; this.MyUtility.DBLog(context, code, "T24UpdateTransState", SESSION_KEY, USERID, ex.Message); this.MyUtility.SendEMail(context, "T24UpdateTransState", SESSION_KEY, code); } finally { json = JsonConvert.SerializeObject(new T24UPDATE_STATE_RESPOSE_RESPOSE() { CHANGINGTEC = new T24UPDATE_STATE_RESPOSE_SYSTEM_CLASS() { SYSTEM = new SYSTEM_INFO_CLASS() { CODE = code.ToString(), MESSAGE = message.EncryptBase64() } } }); dt = null; xmlDoc = null; para = null; this.MyUtility.CloseConnTransac(); xmlDoc = null; GC.Collect(); GC.WaitForPendingFinalizers(); context.Response.Write(json); context.Response.End(); } }
public void ProcessRequest(HttpContext context) { this.MyUtility.InitLog("CloseSession"); context.Response.Clear(); context.Response.ContentType = "application/json"; string json = string.Empty, data = string.Empty, message = string.Empty; SysCode code = SysCode.A000; XmlDocument xmlDoc = null; string xPath = string.Empty, strSql = string.Empty; List <IDataParameter> para = null; string session_key = string.Empty, session_temp_dir_path = string.Empty; string year_and_month = string.Empty; DirectoryInfo dirInfo = null; DataTable dt = null; Hashtable para_data = null; string USERID = string.Empty; int result = -1; List <string> delete_image_list = new List <string>(); bool exists = false; try { #region 取得參數 data = context.GetRequest("data"); if (String.IsNullOrEmpty(data)) { throw new Utility.ProcessException(string.Format("參數為空值"), ref code, SysCode.E004); } this.MyUtility.WriteLog(Mode.LogMode.DEBUG, context, string.Format("DATA.JSON:{0}", data)); #endregion xmlDoc = JsonConvert.DeserializeXmlNode(data); XmlNode xmlNodeProcessInfo = xmlDoc.SelectSingleNode(xPath = string.Format("./CHANGINGTEC/PROCESS_INFO")); if (xmlNodeProcessInfo == null) { throw new Utility.ProcessException(xPath, ref code, SysCode.E003); } USERID = xmlNodeProcessInfo.SelectSingleNode(string.Format("SESSION_KEY"), ref code); session_key = xmlNodeProcessInfo.SelectSingleNode(string.Format("SESSION_KEY"), ref code); this.MyUtility.CheckAndCreateTable(context, year_and_month, ref code); #region SESSION_TEMP_PATH strSql = this.MyUtility.Select.SETTING("SESSION_TEMP_PATH", ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion string session_temp_root_path = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteByColumnName(strSql, para, "PARAMETER"); exists = Directory.Exists(session_temp_root_path); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("SESSION_TEMP_PATH (ROOT):{0},{1}", session_temp_root_path, exists)); if (!exists) { throw new Utility.ProcessException(string.Format("目錄不存在:{0}", session_temp_root_path), ref code, SysCode.E001); } #endregion #region SESSION_TEMP_PATH session_temp_dir_path = Path.Combine(session_temp_root_path, session_key); exists = Directory.Exists(session_temp_dir_path); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("SESSION_TEMP_PATH:{0},{1}", session_temp_dir_path, exists)); if (!exists) { throw new Utility.ProcessException(string.Format("目錄不存在:{0}", session_temp_dir_path), ref code, SysCode.E001); } #endregion #region FILE_ROOT strSql = this.MyUtility.Select.SETTING("FILE_ROOT", ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion string file_root = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteByColumnName(strSql, para, "PARAMETER"); exists = Directory.Exists(file_root); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("FILE_ROOT:{0},{1}", file_root, exists)); if (!exists) { throw new Utility.ProcessException(string.Format("目錄不存在:{0}", file_root), ref code, SysCode.E001); } #endregion dirInfo = new DirectoryInfo(session_temp_dir_path); FileInfo xml_file = dirInfo.GetFiles("*.xml")[0]; year_and_month = xml_file.Name.Replace(xml_file.Extension, "").Split('_')[1]; this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("YM:{0}", year_and_month)); xmlDoc = new XmlDocument(); xmlDoc.Load(xml_file.FullName); xml_file = null; xmlNodeProcessInfo = xmlDoc.SelectSingleNode(xPath = string.Format("./PROCESS_INFO")); string CHANNEL_CODE = xmlNodeProcessInfo.SelectSingleNode(string.Format("CHANNEL_CODE"), ref code); string TXN_TYPE = xmlNodeProcessInfo.SelectSingleNode(string.Format("TXN_TYPE"), ref code); string TXN_ID = xmlNodeProcessInfo.SelectSingleNode(string.Format("TXN_ID"), ref code); string REPORT_TYPE = xmlNodeProcessInfo.SelectSingleNode(string.Format("REPORT_TYPE"), ref code); string GUID = xmlNodeProcessInfo.SelectSingleNode(string.Format("GUID"), ref code); strSql = this.MyUtility.Select.CASE_TABLE(year_and_month, CHANNEL_CODE, TXN_TYPE, TXN_ID, REPORT_TYPE, GUID, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion dt = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteToDataTable(strSql, para); bool case_data_check = dt != null && dt.Rows.Count > 0; string case_state = string.Empty, file_path = string.Empty; int case_version = 1; if (case_data_check) { #region 重覆件處理 (FILE_TABLE) case_version = Convert.ToInt32(dt.Rows[0]["VERSION"].ToString().Trim()); case_state = dt.Rows[0]["CASE_STATE"].ToString().Trim(); session_key = dt.Rows[0]["SESSION_KEY"].ToString().Trim(); if (case_state.Equals("1")) { throw new Utility.ProcessException(string.Format("重覆上傳"), ref code, SysCode.E008); } strSql = this.MyUtility.Select.FILE_TABLE(year_and_month, CHANNEL_CODE, TXN_TYPE, TXN_ID, REPORT_TYPE, GUID, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion dt = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteToDataTable(strSql, para); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("File.Total:{0}", dt.Rows.Count)); for (int i = 0; i < dt.Rows.Count; i++) { delete_image_list.Add(dt.Rows[i]["FILE_ROOT"].ToString().FilePathCombine(dt.Rows[i]["FILE_PATH"].ToString())); } strSql = this.MyUtility.Delete.FILE_TABLE(year_and_month, session_key, case_version.ToString(), ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion result = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("Result:{0}", result)); #endregion } #region INSERT.CASE_TABLE para_data = new Hashtable(); para_data.Add("SESSION_KEY", session_key); para_data.Add("CHANNEL_CODE", CHANNEL_CODE); para_data.Add("TXN_TYPE", TXN_TYPE); para_data.Add("TXN_ID", TXN_ID); para_data.Add("REPORT_TYPE", REPORT_TYPE); para_data.Add("GUID", GUID); para_data.Add("VERSION", case_version.ToString()); para_data.Add("CREATE_USERID", USERID); para_data.Add("MODIFY_USERID", USERID); string ini_file_path = Path.Combine(session_temp_dir_path, string.Format("{0}.ini", session_key)); if (File.Exists(ini_file_path)) { #region ReadINI this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("ReadINI.Start")); string line = string.Empty; using (StreamReader file = new StreamReader(ini_file_path, Encoding.UTF8)) { while ((line = file.ReadLine()) != null) { if (line.IndexOf('=') == -1) { continue; } string[] line_temp = line.Trim().Split('='); this.MyUtility.WriteLog(Mode.LogMode.DEBUG, context, line); if (!para_data.ContainsKey(line_temp[0].Trim().ToUpper())) { para_data.Add(line_temp[0].Trim().ToUpper(), line_temp[1].Trim()); } } file.Close(); } this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("ReadINI.End")); #endregion } strSql = this.MyUtility.Insert.CASE_TABLE(para_data, year_and_month, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion result = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("Result:{0}", result)); if (!result.Equals(1)) { throw new Utility.ProcessException(string.Format("案件資料新增失敗"), ref code, SysCode.E002); } #endregion FileInfo[] files = dirInfo.GetFiles(); string file_dir_path = file_root.CreateSubDirectory(); for (int i = 0; i < files.Length; i++) { FileInfo fi = files[i]; if (fi.Extension.ToLower().EndsWith(".xml")) { continue; } bool is_image_file = fi.Name.ToUpper().StartsWith("[FILE]"); bool is_ini_file = fi.Extension.ToLower().EndsWith(".ini"); string[] file_infos = fi.Name.Replace(fi.Extension, "").Replace("[FILE]_", "").Split('_'); #region IMAGE string file_id = Guid.NewGuid().ToString(); string image_full_path = Path.Combine(file_dir_path, string.Format("{0}{1}", file_id, fi.Extension)); file_path = image_full_path.Replace(file_root, ""); if (file_path.StartsWith(@"\") || file_path.StartsWith("/")) { file_path = file_path.Remove(0, 1); } Hashtable ht = new Hashtable(); ht.Add("FILE_ID", file_id); ht.Add("SESSION_KEY", session_key); ht.Add("VERSION", case_version); ht.Add("FILE_ROOT", file_root); ht.Add("FILE_PATH", file_path); ht.Add("FILE_SIZE", fi.Length); if (is_image_file) { ht.Add("FILE_TYPE", Convert.ToInt16(file_infos[0])); ht.Add("FILE_SEQ", Convert.ToInt16(file_infos[1])); ht.Add("FILE_NAME", file_infos[2]); } else { ht.Add("FILE_TYPE", is_ini_file ? 2 : 3); ht.Add("FILE_SEQ", 1); ht.Add("FILE_NAME", "001"); } strSql = this.MyUtility.Insert.FILE_TABLE(ht, year_and_month, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion result = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para); if (!result.Equals(1)) { throw new Exception(string.Format("資料新增失敗::{0}", fi.Name)); } fi.CopyTo(image_full_path); fi = null; if (!File.Exists(image_full_path)) { throw new Exception(string.Format("檔案搬移失敗::{0}", fi.Name)); } delete_image_list.Add(image_full_path); #endregion } files = null; this.MyUtility.DBConnTransac.GeneralSqlCmd.Transaction.Commit(); this.MyUtility.DBLog(context, code, "CloseSession", session_key, USERID, message); try { session_temp_dir_path.DeleteDirectory(); } catch (System.Exception ex) { this.MyUtility.WriteLog(Mode.LogMode.ERROR, context, ex.ToString()); } } catch (System.Exception ex) { this.MyUtility.Rollback(); message = ex.Message; this.MyUtility.WriteLog(Mode.LogMode.ERROR, context, ex.ToString()); code = !code.Equals(SysCode.A000) ? code : SysCode.E999; this.MyUtility.DBLog(context, code, "CloseSession", session_key, USERID, ex.Message); if (delete_image_list != null) { foreach (string e in delete_image_list) { e.DeleteSigleFile(); } } this.MyUtility.SendEMail(context, "CloseSession", session_key, code); } finally { json = JsonConvert.SerializeObject(new CLOSE_SESSION_RESPOSE() { CHANGINGTEC = new CLOSE_SESSION_SYSTEM_CLASS() { SYSTEM = new CLOSE_SESSION_SYSTEM_INFO_CLASS() { CODE = code.ToString(), MESSAGE = message.EncryptBase64(), SESSION_KEY = session_key, YM = year_and_month } } }); dt = null; dirInfo = null; xmlDoc = null; para = null; this.MyUtility.CloseConnTransac(); xmlDoc = null; GC.Collect(); GC.WaitForPendingFinalizers(); context.Response.Write(json); context.Response.End(); } }
public void ProcessRequest(HttpContext context) { context.Response.Clear(); context.Response.ContentType = "application/json"; string json = string.Empty, data = string.Empty, message = string.Empty; SysCode code = SysCode.A000; XmlDocument xmlDoc = null; string xPath = string.Empty, strSql = string.Empty; List <IDataParameter> para = null; string USERID = string.Empty; string year_and_month = DateTime.Now.ToString("yyyyMM"); string session_key = string.Empty; bool exists = false; DataTable dt = null; Hashtable para_data = null; int result = -1; List <string> delete_list = new List <string>(); try { #region 取得參數 data = context.GetRequest("data"); if (String.IsNullOrEmpty(data)) { throw new Utility.ProcessException(string.Format("參數為空值"), ref code, SysCode.E004); } #endregion xmlDoc = JsonConvert.DeserializeXmlNode(data); XmlNode xmlNodeProcessInfo = xmlDoc.SelectSingleNode(xPath = string.Format("./CHANGINGTEC/PROCESS_INFO")); if (xmlNodeProcessInfo == null) { throw new Utility.ProcessException(xPath, ref code, SysCode.E003); } USERID = xmlNodeProcessInfo.SelectSingleNode(string.Format("USERID"), ref code, false); string TRANSACTION_ID = xmlNodeProcessInfo.SelectSingleNode(string.Format("TRANSACTION_ID"), ref code, false); this.MyUtility.InitPDFUploadLog(string.Format("PDFUploadFile_{0}", DateTime.Now.Hour.ToString())); this.MyUtility.WritePDFUploadLog(Mode.LogMode.DEBUG, context, string.Format("DATA.JSON:{0}", data)); this.MyUtility.DBLog(context, SysCode.A001, "PDFUploadFile", session_key, USERID, string.Empty); string PDF_BASE64 = xmlNodeProcessInfo.SelectSingleNode(string.Format("PDF_BASE64"), ref code); string INI_BASE64 = xmlNodeProcessInfo.SelectSingleNode(string.Format("INI_BASE64"), ref code); string MODE = xmlNodeProcessInfo.SelectSingleNode(string.Format("MODE"), ref code).ToUpper(); if (!String.IsNullOrEmpty(MODE)) { year_and_month = xmlNodeProcessInfo.SelectSingleNode(string.Format("YM"), ref code); } #region WACH_PATH strSql = this.MyUtility.Select.SETTING("WACH_PATH", ref para); #region SQL Debug this.MyUtility.WritePDFUploadLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WritePDFUploadLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion string wach_dir_path = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteByColumnName(strSql, para, "PARAMETER"); exists = Directory.Exists(wach_dir_path); this.MyUtility.WritePDFUploadLog(Mode.LogMode.INFO, context, string.Format("WACH_PATH:{0},{1}", wach_dir_path, exists)); if (!exists) { throw new Utility.ProcessException(string.Format("目錄不存在:{0}", wach_dir_path), ref code, SysCode.E001); } #endregion if (String.IsNullOrEmpty(PDF_BASE64) || String.IsNullOrEmpty(INI_BASE64)) { throw new Utility.ProcessException(string.Format("缺少檔案內容"), ref code, SysCode.E006); } int case_version = 1; para_data = new Hashtable(); para_data.Add("VERSION", case_version.ToString()); para_data.Add("CREATE_USERID", USERID); para_data.Add("MODIFY_USERID", USERID); #region ReadINI this.MyUtility.WritePDFUploadLog(Mode.LogMode.INFO, context, string.Format("ReadINI.Start")); string line = string.Empty; //using (MemoryStream memStream = new MemoryStream(Convert.FromBase64String(INI_BASE64.Replace(" ", "+")))) //{ // using (StreamReader file = new StreamReader(memStream, Encoding.UTF8)) // { // string[] lines = file.ReadToEnd().Split(new char[] { '\n' }); // Parallel.ForEach(lines, (currentLines) => // { // if (currentLines.IndexOf('=') == -1) return; // string[] line_temp = currentLines.Trim().Split('='); // this.MyUtility.WritePDFUploadLog(Mode.LogMode.DEBUG, context, line); // if (!para_data.ContainsKey(line_temp[0].Trim().ToUpper())) // { // this.MyUtility.WritePDFUploadLog(Log.Mode.LogMode.INFO, context, string.Format("INI:{0}", line)); // para_data.Add(line_temp[0].Trim().ToUpper(), line_temp[1].Trim()); // } // }); // } //} using (StreamReader file = new StreamReader(new MemoryStream(Convert.FromBase64String(INI_BASE64.Replace(" ", "+"))), Encoding.UTF8)) { while ((line = file.ReadLine()) != null) { if (line.IndexOf('=') == -1) { continue; } string[] line_temp = line.Trim().Split('='); this.MyUtility.WritePDFUploadLog(Mode.LogMode.DEBUG, context, line); if (!para_data.ContainsKey(line_temp[0].Trim().ToUpper())) { this.MyUtility.WritePDFUploadLog(Log.Mode.LogMode.INFO, context, string.Format("INI:{0}", line)); para_data.Add(line_temp[0].Trim().ToUpper(), line_temp[1].Trim()); } } file.Close(); } this.MyUtility.WritePDFUploadLog(Mode.LogMode.INFO, context, string.Format("ReadINI.End")); #endregion if (!para_data.ContainsKey("TXN_DATE")) { throw new Utility.ProcessException(string.Format("TXN_DATE is Null"), ref code, SysCode.E004); } this.MyUtility.WritePDFUploadLog(Log.Mode.LogMode.INFO, context, string.Format("TXN_DATE:{0}", para_data.ContainsKey("TXN_DATE"))); if (para_data.ContainsKey("TXN_DATE")) { year_and_month = DateTime.Parse(para_data["TXN_DATE"].ToString().ToDate()).ToString("yyyyMM"); } this.MyUtility.CheckAndCreateTable(context, year_and_month, ref code); session_key = Guid.NewGuid().GenerateSessionKey(year_and_month); para_data.Add("SESSION_KEY", session_key); this.MyUtility.WritePDFUploadLog(Mode.LogMode.INFO, context, string.Format("SESSION_KEY:{0}", session_key)); string case_state = string.Empty, file_path = string.Empty, ini_file_path = string.Empty; bool pdf_split = true; if (String.IsNullOrEmpty(MODE)) { #region Anew if (!para_data.ContainsKey("TXN_ID") || !para_data.ContainsKey("GUID") || !para_data.ContainsKey("CHANNEL_CODE") || !para_data.ContainsKey("TXN_TYPE") || !para_data.ContainsKey("REPORT_SERIAL_NO")) { throw new Utility.ProcessException(string.Format("INI內容必要資料不足"), ref code, SysCode.E004); } strSql = this.MyUtility.Select.CASE_TABLE(year_and_month, para_data["CHANNEL_CODE"].ToString(), para_data["TXN_TYPE"].ToString(), para_data["TXN_ID"].ToString(), para_data["REPORT_SERIAL_NO"].ToString(), para_data["GUID"].ToString(), ref para); #region SQL Debug this.MyUtility.WritePDFUploadLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WritePDFUploadLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion dt = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteToDataTable(strSql, para); bool case_data_check = dt != null && dt.Rows.Count > 0; this.MyUtility.WritePDFUploadLog(Log.Mode.LogMode.INFO, context, string.Format("CheckCase:{0}", case_data_check)); string case_session_key = session_key; if (case_data_check) { pdf_split = false; if (!para_data.ContainsKey("TRANS_STATE")) { para_data.Add("TRANS_STATE", "REPT"); } else { para_data["TRANS_STATE"] = "REPT"; } } bool check = para_data["TRANS_STATE"].ToString().Equals("LIVE") && para_data.ContainsKey("SUPERVISOR_ID") && !String.IsNullOrEmpty(para_data["SUPERVISOR_ID"].ToString()); this.MyUtility.WritePDFUploadLog(Mode.LogMode.INFO, context, string.Format("TRANS_STATE.LIVE:{0},{1}", para_data["TRANS_STATE"].ToString(), check)); //if (check) //{ // if (!para_data.ContainsKey("AUTHORIZE_ID")) para_data.Add("AUTHORIZE_ID", para_data["SUPERVISOR_ID"].ToString()); // else para_data["AUTHORIZE_ID"] = para_data["SUPERVISOR_ID"].ToString(); // if (!para_data.ContainsKey("AUTHORIZE_ID_DATE")) para_data.Add("AUTHORIZE_ID_DATE", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")); // else para_data["AUTHORIZE_ID_DATE"] = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); // this.MyUtility.WritePDFUploadLog(Mode.LogMode.INFO, context, string.Format("AUTHORIZE_ID:{0}", para_data["AUTHORIZE_ID"].ToString())); //} strSql = this.MyUtility.Insert.CASE_TABLE(para_data, year_and_month, ref para); #region SQL Debug this.MyUtility.WritePDFUploadLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WritePDFUploadLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion result = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para); this.MyUtility.WritePDFUploadLog(Mode.LogMode.INFO, context, string.Format("Result:{0}", result)); if (!result.Equals(1)) { throw new Utility.ProcessException(string.Format("案件資料新增失敗"), ref code, SysCode.E002); } file_path = Path.Combine(wach_dir_path, string.Format("[ANEW]_{0}_{1}_{2}_{3}.pdf", year_and_month, case_version.ToString(), case_session_key, USERID)); file_path.DeleteSigleFile(); ini_file_path = Path.Combine(wach_dir_path, string.Format("[ANEW]_{0}_{1}_{2}_{3}.ini", year_and_month, case_version.ToString(), case_session_key, USERID)); ini_file_path.DeleteSigleFile(); #endregion } else if (MODE.Equals("updateTxNo".ToUpper())) { #region updateTxNo if (!para_data.ContainsKey("CHANNEL_CODE") || !para_data.ContainsKey("TXN_TYPE") || !para_data.ContainsKey("TXN_ID") || !para_data.ContainsKey("REPORT_SERIAL_NO") || !para_data.ContainsKey("GUID")) { throw new Utility.ProcessException(string.Format("INI內容必要資料不足"), ref code, SysCode.E004); } strSql = this.MyUtility.Select.CASE_TABLE_UPDATE_TXNO(year_and_month, para_data["CHANNEL_CODE"].ToString(), para_data["TXN_TYPE"].ToString(), para_data["TXN_ID"].ToString(), para_data["REPORT_SERIAL_NO"].ToString(), ref para); #region SQL Debug this.MyUtility.WritePDFUploadLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WritePDFUploadLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion dt = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteToDataTable(strSql, para); bool case_data_check = dt != null && dt.Rows.Count > 0; if (!case_data_check) { year_and_month = year_and_month.GetPreviousYM(); strSql = this.MyUtility.Select.CASE_TABLE_UPDATE_TXNO(year_and_month, para_data["CHANNEL_CODE"].ToString(), para_data["TXN_TYPE"].ToString(), para_data["TXN_ID"].ToString(), para_data["REPORT_SERIAL_NO"].ToString(), ref para); #region SQL Debug this.MyUtility.WritePDFUploadLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WritePDFUploadLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion dt = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteToDataTable(strSql, para); case_data_check = dt != null && dt.Rows.Count > 0; } if (!case_data_check) { throw new Utility.ProcessException(string.Format("查詢資料不存在"), ref code, SysCode.E007); } this.MyUtility.WritePDFUploadLog(Log.Mode.LogMode.INFO, context, string.Format("Data.Count:{0}", dt.Rows.Count)); for (int i = 0; i < dt.Rows.Count; i++) { if (dt.Rows[i]["REPORT_SERIAL_NO"] != DBNull.Value && !String.IsNullOrEmpty(dt.Rows[i]["REPORT_SERIAL_NO"].ToString().Trim())) { continue; } strSql = this.MyUtility.Update.CASE_TABLE_REPORT_SERIAL_NO(year_and_month, dt.Rows[i]["SESSION_KEY"].ToString().Trim(), para_data["REPORT_SERIAL_NO"].ToString(), USERID, ref para); #region SQL Debug this.MyUtility.WritePDFUploadLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WritePDFUploadLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion result = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para); this.MyUtility.WritePDFUploadLog(Mode.LogMode.INFO, context, string.Format("Result:{0}", result)); if (!result.Equals(1)) { throw new Utility.ProcessException(string.Format("變更REPORT_SERIAL_NO失敗,SESSION_KEY={0}", dt.Rows[i]["SESSION_KEY"].ToString().Trim()), ref code, SysCode.E002); } } strSql = this.MyUtility.Insert.CASE_TABLE(para_data, year_and_month, ref para); #region SQL Debug this.MyUtility.WritePDFUploadLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WritePDFUploadLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion result = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para); this.MyUtility.WritePDFUploadLog(Mode.LogMode.INFO, context, string.Format("Result:{0}", result)); if (!result.Equals(1)) { throw new Utility.ProcessException(string.Format("案件資料新增失敗"), ref code, SysCode.E002); } file_path = Path.Combine(wach_dir_path, string.Format("[UPDATE_TXNO]_{0}_{1}_{2}_{3}.pdf", year_and_month, case_version.ToString(), session_key, USERID)); file_path.DeleteSigleFile(); ini_file_path = Path.Combine(wach_dir_path, string.Format("[UPDATE_TXNO]_{0}_{1}_{2}_{3}.ini", year_and_month, case_version.ToString(), session_key, USERID)); ini_file_path.DeleteSigleFile(); #endregion } else if (MODE.Equals("rewrite".ToUpper())) { #region rewrite if (!para_data.ContainsKey("CHANNEL_CODE") || !para_data.ContainsKey("TXN_TYPE") || !para_data.ContainsKey("TXN_ID") || !para_data.ContainsKey("REPORT_SERIAL_NO") || !para_data.ContainsKey("GUID")) { throw new Utility.ProcessException(string.Format("INI內容必要資料不足"), ref code, SysCode.E004); } strSql = this.MyUtility.Select.CASE_TABLE(year_and_month, para_data["CHANNEL_CODE"].ToString(), para_data["TXN_TYPE"].ToString(), para_data["TXN_ID"].ToString(), para_data["REPORT_SERIAL_NO"].ToString(), para_data["GUID"].ToString(), ref para); #region SQL Debug this.MyUtility.WritePDFUploadLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WritePDFUploadLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion dt = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteToDataTable(strSql, para); bool case_data_check = dt != null && dt.Rows.Count > 0; if (!case_data_check) { year_and_month = year_and_month.GetPreviousYM(); strSql = this.MyUtility.Select.CASE_TABLE(year_and_month, para_data["CHANNEL_CODE"].ToString(), para_data["TXN_TYPE"].ToString(), para_data["TXN_ID"].ToString(), para_data["REPORT_SERIAL_NO"].ToString(), para_data["GUID"].ToString(), ref para); #region SQL Debug this.MyUtility.WritePDFUploadLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WritePDFUploadLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion dt = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteToDataTable(strSql, para); case_data_check = dt != null && dt.Rows.Count > 0; } if (!case_data_check) { throw new Utility.ProcessException(string.Format("查詢資料不存在"), ref code, SysCode.E007); } this.MyUtility.WritePDFUploadLog(Log.Mode.LogMode.INFO, context, string.Format("Data.Count:{0}", dt.Rows.Count)); for (int i = 0; i < dt.Rows.Count; i++) { strSql = this.MyUtility.Update.CASE_TABLE_GUID(year_and_month, dt.Rows[i]["SESSION_KEY"].ToString().Trim(), para_data["GUID"].ToString(), para_data["TXN_TIME"].ToString(), para_data["TRANS_STATE"].ToString(), USERID, ref para); #region SQL Debug this.MyUtility.WritePDFUploadLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WritePDFUploadLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion result = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para); this.MyUtility.WritePDFUploadLog(Mode.LogMode.INFO, context, string.Format("Result:{0}", result)); if (!result.Equals(1)) { throw new Utility.ProcessException(string.Format("變更GUID失敗,SESSION_KEY={0}", dt.Rows[i]["SESSION_KEY"].ToString().Trim()), ref code, SysCode.E002); } } file_path = Path.Combine(wach_dir_path, string.Format("[REWRITE]_{0}_{1}_{2_{3}}.pdf", year_and_month, case_version.ToString(), session_key, USERID)); file_path.DeleteSigleFile(); ini_file_path = Path.Combine(wach_dir_path, string.Format("[REWRITE]_{0}_{1}_{2}_{3}.ini", year_and_month, case_version.ToString(), session_key, USERID)); ini_file_path.DeleteSigleFile(); #endregion } else { throw new Utility.ProcessException(string.Format("MODE參數錯誤"), ref code, SysCode.E004); } if (pdf_split) { this.MyUtility.CreateFile(ini_file_path, INI_BASE64, ref code); this.MyUtility.CreateFile(file_path, PDF_BASE64, ref code); } this.MyUtility.DBConnTransac.GeneralSqlCmd.Transaction.Commit(); this.MyUtility.DBLog(context, SysCode.A002, "PDFUploadFile", session_key, USERID, string.Empty); try { foreach (string path in delete_list) { path.DeleteSigleFile(); } } catch (System.Exception ex) { this.MyUtility.WritePDFUploadLog(Mode.LogMode.ERROR, context, string.Format("Delete.File.Exception::\r\n{0}", ex.ToString())); } } catch (System.Exception ex) { this.MyUtility.Rollback(); message = ex.Message; this.MyUtility.WritePDFUploadLog(Mode.LogMode.ERROR, context, ex.ToString()); code = !code.Equals(SysCode.A000) ? code : SysCode.E999; this.MyUtility.DBLog(context, code, "PDFUploadFile", session_key, USERID, ex.Message); this.MyUtility.SendEMail(context, "PDFUploadFile", session_key, code); } finally { json = JsonConvert.SerializeObject(new PDF_UPLOAD_FILE_RESPOSE() { CHANGINGTEC = new PDF_UPLOAD_FILE_SYSTEM_CLASS() { SYSTEM = new PDF_UPLOAD_FILE_SYSTEM_INFO_CLASS() { CODE = code.ToString(), MESSAGE = message.EncryptBase64(), PROCESS_INFO = new Dictionary <string, string>() { { "SESSION_KEY", session_key }, { "YM", year_and_month } } } } }); dt = null; xmlDoc = null; para = null; this.MyUtility.CloseConnTransac(); xmlDoc = null; GC.Collect(); GC.WaitForPendingFinalizers(); context.Response.Write(json); context.Response.End(); } }
public void ProcessRequest(HttpContext context) { this.MyUtility.InitLog("UpdateState"); context.Response.Clear(); context.Response.ContentType = "application/json"; string json = string.Empty, data = string.Empty, message = string.Empty; SysCode code = SysCode.A000; XmlDocument xmlDoc = null; string xPath = string.Empty, strSql = string.Empty; List <IDataParameter> para = null; DataTable dt = null; string USERID = string.Empty; string year_and_month = DateTime.Now.ToString("yyyyMM"); string session_key = string.Empty; int result = -1; try { #region 取得參數 data = context.GetRequest("data"); if (String.IsNullOrEmpty(data)) { throw new Utility.ProcessException(string.Format("參數為空值"), ref code, SysCode.E004); } this.MyUtility.WriteLog(Mode.LogMode.DEBUG, context, string.Format("DATA.JSON:{0}", data)); #endregion xmlDoc = JsonConvert.DeserializeXmlNode(data); XmlNode xmlNodeProcessInfo = xmlDoc.SelectSingleNode(xPath = string.Format("./CHANGINGTEC/PROCESS_INFO")); if (xmlNodeProcessInfo == null) { throw new Utility.ProcessException(xPath, ref code, SysCode.E003); } USERID = xmlNodeProcessInfo.SelectSingleNode(string.Format("USERID"), ref code, false); year_and_month = xmlNodeProcessInfo.SelectSingleNode(string.Format("YM"), ref code); string CHANNEL_CODE = xmlNodeProcessInfo.SelectSingleNode(string.Format("CHANNEL_CODE"), ref code); string TXN_TYPE = xmlNodeProcessInfo.SelectSingleNode(string.Format("TXN_TYPE"), ref code); string TXN_ID = xmlNodeProcessInfo.SelectSingleNode(string.Format("TXN_ID"), ref code); string REPORT_SERIAL_NO = xmlNodeProcessInfo.SelectSingleNode(string.Format("REPORT_SERIAL_NO"), ref code); string GUID = xmlNodeProcessInfo.SelectSingleNode(string.Format("GUID"), ref code); string TRANS_STATE = xmlNodeProcessInfo.SelectSingleNode(string.Format("TRANS_STATE"), ref code); string CHARGE = xmlNodeProcessInfo.SelectSingleNode(string.Format("CHARGE"), ref code); string CHARGE_DATE = DateTime.Parse(xmlNodeProcessInfo.SelectSingleNode(string.Format("CHARGE_DATE"), ref code)).ToString("yyyy/MM/dd HH:mm:ss"); string SUPERVISOR = xmlNodeProcessInfo.SelectSingleNode(string.Format("SUPERVISOR"), ref code); string SUPERVISOR_DATE = DateTime.Parse(xmlNodeProcessInfo.SelectSingleNode(string.Format("SUPERVISOR_DATE"), ref code)).ToString("yyyy/MM/dd HH:mm:ss"); this.MyUtility.CheckAndCreateTable(context, year_and_month, ref code); strSql = this.MyUtility.Select.CASE_TABLE(year_and_month, CHANNEL_CODE, TXN_TYPE, TXN_ID, REPORT_SERIAL_NO, GUID, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion dt = this.MyUtility.DBConn.GeneralSqlCmd.ExecuteToDataTable(strSql, para); if (dt.Rows.Count.Equals(0)) { throw new Utility.ProcessException(string.Format("查詢資料不存在"), ref code, SysCode.E007); } bool is_delete = TRANS_STATE.Trim().ToUpper().Equals("AF") || TRANS_STATE.Trim().ToUpper().Equals("AG"); session_key = dt.Rows[0]["SESSION_KEY"].ToString().Trim(); string case_state = dt.Rows[0]["CASE_STATE"].ToString().Trim(); string case_version = dt.Rows[0]["VERSION"].ToString().Trim(); strSql = this.MyUtility.Update.CASE_TABLE_TRANSSTATE(year_and_month , TRANS_STATE , CHARGE , CHARGE_DATE , SUPERVISOR , SUPERVISOR_DATE , is_delete ? "99" : case_state , USERID , CHANNEL_CODE , TXN_TYPE , TXN_ID , REPORT_SERIAL_NO , GUID , ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion result = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("Result:{0}", result)); if (!result.Equals(1)) { throw new Utility.ProcessException(string.Format("案件狀態變更失敗"), ref code, SysCode.E002); } if (is_delete) { strSql = this.MyUtility.Update.FILE_TABLE_STOP(year_and_month, session_key, case_version, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion result = this.MyUtility.DBConn.GeneralSqlCmd.ExecuteNonQuery(strSql, para); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("Result:{0}", result)); if (result.Equals(0)) { throw new Utility.ProcessException(string.Format("檔案刪除失敗"), ref code, SysCode.E002); } } this.MyUtility.DBLog(context, code, "UpdateState", session_key, USERID, string.Empty); } catch (System.Exception ex) { message = ex.Message; this.MyUtility.WriteLog(Mode.LogMode.ERROR, context, ex.ToString()); code = !code.Equals(SysCode.A000) ? code : SysCode.E999; this.MyUtility.DBLog(context, code, "UpdateState", session_key, string.Empty, ex.Message); this.MyUtility.SendEMail(context, "UpdateState", session_key, code); } finally { json = JsonConvert.SerializeObject(new UPLOAD_STATE_RESPOSE() { CHANGINGTEC = new UPLOAD_STATE_SYSTEM_CLASS() { SYSTEM = new SYSTEM_INFO_CLASS() { CODE = code.ToString(), MESSAGE = message.EncryptBase64() } } }); dt = null; xmlDoc = null; para = null; this.MyUtility.CloseConn(); xmlDoc = null; GC.Collect(); GC.WaitForPendingFinalizers(); context.Response.Write(json); context.Response.End(); } }
public void ProcessRequest(HttpContext context) { this.MyUtility.InitLog("GetImageURL"); context.Response.Clear(); context.Response.ContentType = "application/json"; string json = string.Empty, data = string.Empty, message = string.Empty; SysCode code = SysCode.B000; XmlDocument xmlDoc = null; string xPath = string.Empty, strSql = string.Empty; List <IDataParameter> para = null; DataTable dt = null; string USERID = string.Empty; string year_and_month = DateTime.Now.ToString("yyyyMM"); string session_key = string.Empty, session_info = string.Empty; IMAGE_URL_CLASS.IMAGE_URL_ITEM[] image_item_list = null; try { #region 取得參數 data = context.GetRequest("data"); if (String.IsNullOrEmpty(data)) { throw new Utility.ProcessException(string.Format("參數為空值"), ref code, SysCode.E004); } this.MyUtility.WriteLog(Mode.LogMode.DEBUG, context, string.Format("DATA.JSON:{0}", data)); #endregion xmlDoc = JsonConvert.DeserializeXmlNode(data); XmlNode xmlNodeProcessInfo = xmlDoc.SelectSingleNode(xPath = string.Format("./CHANGINGTEC/PROCESS_INFO")); if (xmlNodeProcessInfo == null) { throw new Utility.ProcessException(xPath, ref code, SysCode.E003); } USERID = xmlNodeProcessInfo.SelectSingleNode(string.Format("USERID"), ref code, false); session_key = xmlNodeProcessInfo.SelectSingleNode(string.Format("SESSION_KEY"), ref code, false); this.MyUtility.WriteLog(context, string.Format("SESSION_KEY:{0}", session_key)); if (String.IsNullOrEmpty(session_key)) { year_and_month = xmlNodeProcessInfo.SelectSingleNode(string.Format("YM"), ref code); this.MyUtility.CheckAndCreateTable(context, year_and_month, ref code); string CHANNEL_CODE = xmlNodeProcessInfo.SelectSingleNode(string.Format("CHANNEL_CODE"), ref code); string TXN_TYPE = xmlNodeProcessInfo.SelectSingleNode(string.Format("TXN_TYPE"), ref code); string TXN_ID = xmlNodeProcessInfo.SelectSingleNode(string.Format("TXN_ID"), ref code); string REPORT_SERIAL_NO = xmlNodeProcessInfo.SelectSingleNode(string.Format("REPORT_SERIAL_NO"), ref code); string GUID = xmlNodeProcessInfo.SelectSingleNode(string.Format("GUID"), ref code); this.WaitingCase(context, year_and_month, CHANNEL_CODE, TXN_TYPE, TXN_ID, REPORT_SERIAL_NO, GUID); this.MyUtility.DBLog(context, SysCode.B001, "GetImageURL", string.Empty, USERID, session_info = string.Format("{0}_{1}_{2}_{3}_{4}_{5}", year_and_month, CHANNEL_CODE, TXN_TYPE, TXN_ID, REPORT_SERIAL_NO, GUID)); strSql = this.MyUtility.Select.FILE_TABLE(year_and_month, CHANNEL_CODE, TXN_TYPE, TXN_ID, REPORT_SERIAL_NO, GUID, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion dt = this.MyUtility.DBConn.GeneralSqlCmd.ExecuteToDataTable(strSql, para); if (dt.Rows.Count.Equals(0)) { year_and_month = year_and_month.GetPreviousYM(); this.MyUtility.CheckAndCreateTable(context, year_and_month, ref code); strSql = this.MyUtility.Select.FILE_TABLE(year_and_month, CHANNEL_CODE, TXN_TYPE, TXN_ID, REPORT_SERIAL_NO, GUID, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion dt = this.MyUtility.DBConn.GeneralSqlCmd.ExecuteToDataTable(strSql, para); } } else { year_and_month = session_key.Split('-')[0]; this.MyUtility.CheckAndCreateTable(context, year_and_month, ref code); this.WaitingCase(context, year_and_month, session_key); this.MyUtility.DBLog(context, SysCode.B001, "GetImageURL", string.Empty, USERID, session_info = string.Format("{0}_{1}", year_and_month, session_key)); strSql = this.MyUtility.Select.FILE_TABLE(year_and_month, session_key, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion dt = this.MyUtility.DBConn.GeneralSqlCmd.ExecuteToDataTable(strSql, para); } if (dt.Rows.Count.Equals(0)) { throw new Utility.ProcessException(string.Format("查無資料"), ref code, SysCode.E007); } this.MyUtility.DBLog(context, SysCode.A001, "GetImageURL", session_key = dt.Rows[0]["SESSION_KEY"].ToString(), USERID, string.Empty); this.MyUtility.WriteLog(context, string.Format("SESSION_KEY:{0}", session_key)); DataRow[] dr_image = dt.Select(string.Format("FILE_TYPE=11")); this.MyUtility.WriteLog(context, string.Format("Image.Count:{0}", dr_image.Length)); if (dr_image.Length.Equals(0)) { throw new Utility.ProcessException(string.Format("查無資料"), ref code, SysCode.E007); } image_item_list = new IMAGE_URL_CLASS.IMAGE_URL_ITEM[dr_image.Length]; for (int i = 0; i < dr_image.Length; i++) { session_key = dr_image[i]["SESSION_KEY"].ToString(); string file_id = dr_image[i]["FILE_ID"].ToString(); int file_seq = Convert.ToInt16(dr_image[i]["FILE_SEQ"].ToString()); int file_type = Convert.ToInt16(dr_image[i]["FILE_TYPE"].ToString()); string file_root = dr_image[i]["FILE_ROOT"].ToString(); string file_path = dr_image[i]["FILE_PATH"].ToString(); string file_full_path = file_root.FilePathCombine(file_path); this.MyUtility.WriteLog(context, string.Format("AbsoluteUri:{0}", context.Request.Url.AbsoluteUri)); string image_url = context.Request.Url.AbsoluteUri.Replace("GetImageURL", ""); image_url = image_url.EndsWith("/") ? image_url.Remove(image_url.Length - 1, 1) : image_url; image_url = string.Format("{0}/{1}?data={2}", image_url, "Images", string.Format("{0}|{1}|{2}|{3}|{4}|{5}|{6}", file_id, file_type, year_and_month, session_key, file_full_path, file_seq.ToString(), USERID).EncryptDES()); this.MyUtility.WriteLog(context, string.Format("ImageUrl:{0}", image_url)); image_item_list[i] = new IMAGE_URL_CLASS.IMAGE_URL_ITEM() { FILE_ID = file_id, URL = image_url.EncryptBase64() }; } this.MyUtility.DBLog(context, SysCode.B000, "GetImageURL", session_key, USERID, session_info); } catch (System.Exception ex) { message = ex.Message; this.MyUtility.WriteLog(Mode.LogMode.ERROR, context, ex.ToString()); code = !code.Equals(SysCode.B000) ? code : SysCode.E999; this.MyUtility.DBLog(context, code, "GetImageURL", session_key, USERID, ex.Message); this.MyUtility.SendEMail(context, "GetImageURL", session_key, code); } finally { json = JsonConvert.SerializeObject(new IMAGE_URL_RESPOSE() { CHANGINGTEC = new IMAGE_URL_SYSTEM_CLASS() { SYSTEM = new IMAGE_URL_SYSTEM_INFO_CLASS() { //CODE = code.Equals(SysCode.B000) ? SysCode.A000.ToString() : code.Equals(SysCode.E007) ? SysCode.A003.ToString() : code.ToString(), CODE = code.Equals(SysCode.B000) ? SysCode.A000.ToString() : code.ToString(), MESSAGE = message.EncryptBase64(), CASE_INFO = new IMAGE_URL_CLASS() { JPG_ITEM = image_item_list } } } }); dt = null; xmlDoc = null; para = null; this.MyUtility.CloseConn(); xmlDoc = null; GC.Collect(); GC.WaitForPendingFinalizers(); context.Response.Write(json); context.Response.End(); } }
public void ProcessRequest(HttpContext context) { this.MyUtility.InitLog("UploadFile"); context.Response.Clear(); context.Response.ContentType = "application/json"; string year_and_month = DateTime.Now.ToString("yyyyMM"); string json = string.Empty, data = string.Empty, message = string.Empty; SysCode code = SysCode.A000; XmlDocument xmlDoc = null; string xPath = string.Empty, strSql = string.Empty; List <IDataParameter> para = null; DataTable dt = null; Dictionary <string, string> session_key = new Dictionary <string, string>(); session_key.Add("SESSION_KEY", Guid.NewGuid().GenerateSessionKey(year_and_month)); session_key.Add("YM", year_and_month); Hashtable para_data = null; string USERID = string.Empty; int result = -1; List <string> delete_list = new List <string>(); bool exists = false; try { #region 取得參數 data = context.GetRequest("data"); if (String.IsNullOrEmpty(data)) { throw new Utility.ProcessException(string.Format("參數為空值"), ref code, SysCode.E004); } this.MyUtility.WriteLog(Mode.LogMode.DEBUG, context, string.Format("DATA.JSON:{0}", data)); #endregion xmlDoc = JsonConvert.DeserializeXmlNode(data); XmlNode xmlNodeProcessInfo = xmlDoc.SelectSingleNode(xPath = string.Format("./CHANGINGTEC/PROCESS_INFO")); if (xmlNodeProcessInfo == null) { throw new Utility.ProcessException(xPath, ref code, SysCode.E003); } USERID = xmlNodeProcessInfo.SelectSingleNode(string.Format("USERID"), ref code, false); this.MyUtility.DBLog(context, SysCode.A001, "UploadFile", session_key["SESSION_KEY"], USERID, string.Empty); this.MyUtility.CheckAndCreateTable(context, year_and_month, ref code); #region WACH_PATH strSql = this.MyUtility.Select.SETTING("WACH_PATH", ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion string wach_dir_path = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteByColumnName(strSql, para, "PARAMETER"); exists = Directory.Exists(wach_dir_path); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("WACH_PATH:{0},{1}", wach_dir_path, exists)); if (!exists) { throw new Utility.ProcessException(string.Format("目錄不存在:{0}", wach_dir_path), ref code, SysCode.E001); } #endregion string FILE_EXTENSION = xmlNodeProcessInfo.SelectSingleNode(string.Format("FILE_EXTENSION"), ref code).ToLower(); string PDF_BASE64 = xmlNodeProcessInfo.SelectSingleNode(string.Format("PDF_BASE64"), ref code); string INI_BASE64 = xmlNodeProcessInfo.SelectSingleNode(string.Format("INI_BASE64"), ref code, false); string CHANNEL_CODE = xmlNodeProcessInfo.SelectSingleNode(string.Format("CHANNEL_CODE"), ref code); string TXN_TYPE = xmlNodeProcessInfo.SelectSingleNode(string.Format("TXN_TYPE"), ref code); string TXN_ID = xmlNodeProcessInfo.SelectSingleNode(string.Format("TXN_ID"), ref code); string REPORT_TYPE = xmlNodeProcessInfo.SelectSingleNode(string.Format("REPORT_TYPE"), ref code); string GUID = xmlNodeProcessInfo.SelectSingleNode(string.Format("GUID"), ref code); strSql = this.MyUtility.Select.CASE_TABLE(year_and_month, CHANNEL_CODE, TXN_TYPE, TXN_ID, REPORT_TYPE, GUID, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion dt = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteToDataTable(strSql, para); bool case_data_check = dt != null && dt.Rows.Count > 0; string case_state = string.Empty, file_path = string.Empty; int case_version = 1; if (case_data_check) { #region 重覆件處理 (FILE_TABLE) case_version = Convert.ToInt32(dt.Rows[0]["VERSION"].ToString().Trim()); case_state = dt.Rows[0]["CASE_STATE"].ToString().Trim(); if (case_state.Equals("1")) { throw new Utility.ProcessException(string.Format("重覆上傳"), ref code, SysCode.E008); } session_key["SESSION_KEY"] = dt.Rows[0]["SESSION_KEY"].ToString().Trim(); strSql = this.MyUtility.Select.FILE_TABLE(year_and_month, CHANNEL_CODE, TXN_TYPE, TXN_ID, REPORT_TYPE, GUID, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion dt = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteToDataTable(strSql, para); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("File.Total:{0}", dt.Rows.Count)); for (int i = 0; i < dt.Rows.Count; i++) { delete_list.Add(dt.Rows[i]["FILE_ROOT"].ToString().FilePathCombine(dt.Rows[i]["FILE_PATH"].ToString())); } strSql = this.MyUtility.Delete.FILE_TABLE(year_and_month, session_key["SESSION_KEY"].ToString(), case_version.ToString(), ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion result = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("Result:{0}", result)); #endregion } file_path = Path.Combine(wach_dir_path, string.Format("[ANEW]_{0}_{1}_{2}_{3}.{4}", year_and_month, case_version.ToString(), session_key["SESSION_KEY"].ToString(), USERID, FILE_EXTENSION)); file_path.DeleteSigleFile(); string ini_file_path = Path.Combine(wach_dir_path, string.Format("[ANEW]_{0}_{1}_{2}_{3}.ini", year_and_month, case_version.ToString(), session_key["SESSION_KEY"].ToString(), USERID)); ini_file_path.DeleteSigleFile(); if (!String.IsNullOrEmpty(INI_BASE64)) { this.MyUtility.CreateFile(ini_file_path, INI_BASE64, ref code); } para_data = new Hashtable(); para_data.Add("SESSION_KEY", session_key["SESSION_KEY"].ToString()); para_data.Add("CHANNEL_CODE", CHANNEL_CODE); para_data.Add("TXN_TYPE", TXN_TYPE); para_data.Add("TXN_ID", TXN_ID); para_data.Add("REPORT_TYPE", REPORT_TYPE); para_data.Add("GUID", GUID); para_data.Add("VERSION", case_version.ToString()); para_data.Add("CREATE_USERID", USERID); para_data.Add("MODIFY_USERID", USERID); if (File.Exists(ini_file_path)) { #region ReadINI this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("ReadINI.Start")); string line = string.Empty; using (StreamReader file = new StreamReader(ini_file_path, Encoding.UTF8)) { while ((line = file.ReadLine()) != null) { if (line.IndexOf('=') == -1) { continue; } string[] line_temp = line.Trim().Split('='); this.MyUtility.WriteLog(Mode.LogMode.DEBUG, context, line); if (!para_data.ContainsKey(line_temp[0].Trim().ToUpper())) { para_data.Add(line_temp[0].Trim().ToUpper(), line_temp[1].Trim()); } } file.Close(); } this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("ReadINI.End")); #endregion } if (case_data_check) { #region 重覆件處理 (CASE_TABLE) strSql = this.MyUtility.Delete.CASE_TABLE(year_and_month, session_key["SESSION_KEY"].ToString(), case_version.ToString(), ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion result = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("Result:{0}", result)); #endregion } strSql = this.MyUtility.Insert.CASE_TABLE(para_data, year_and_month, ref para); #region SQL Debug this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, strSql); this.MyUtility.WriteLog(Log.Mode.LogMode.DEBUG, context, para.ToLog()); #endregion result = this.MyUtility.DBConnTransac.GeneralSqlCmd.ExecuteNonQuery(strSql, para); this.MyUtility.WriteLog(Mode.LogMode.INFO, context, string.Format("Result:{0}", result)); if (!result.Equals(1)) { throw new Utility.ProcessException(string.Format("案件資料新增失敗"), ref code, SysCode.E002); } this.MyUtility.CreateFile(file_path, PDF_BASE64, ref code); this.MyUtility.DBConnTransac.GeneralSqlCmd.Transaction.Commit(); this.MyUtility.DBLog(context, SysCode.A002, "UploadFile", session_key["SESSION_KEY"], USERID, string.Empty); try { foreach (string path in delete_list) { path.DeleteSigleFile(); } } catch (System.Exception ex) { this.MyUtility.WriteLog(Mode.LogMode.ERROR, context, string.Format("Delete.File.Exception::\r\n{0}", ex.ToString())); } } catch (System.Exception ex) { this.MyUtility.Rollback(); message = ex.Message; this.MyUtility.WriteLog(Mode.LogMode.ERROR, context, ex.ToString()); code = !code.Equals(SysCode.A000) ? code : SysCode.E999; this.MyUtility.DBLog(context, code, "UploadFile", session_key["SESSION_KEY"], USERID, ex.Message); this.MyUtility.SendEMail(context, "UploadFile", session_key["SESSION_KEY"], code); } finally { json = JsonConvert.SerializeObject(new UPLOAD_FILE_RESPOSE() { CHANGINGTEC = new UPLOAD_FILE_SYSTEM_CLASS() { SYSTEM = new UPLOAD_FILE_SYSTEM_INFO_CLASS() { CODE = code.ToString(), MESSAGE = message.EncryptBase64(), PROCESS_INFO = session_key } } }); dt = null; xmlDoc = null; session_key = null; para = null; para_data = null; this.MyUtility.CloseConnTransac(); xmlDoc = null; GC.Collect(); GC.WaitForPendingFinalizers(); context.Response.Write(json); context.Response.End(); } }