| | |
| | | using System;
|
| | | using System.Data;
|
| | | using System.Configuration;
|
| | | using System.Web;
|
| | | using System.Web.Security;
|
| | | using System.Web.UI;
|
| | | using System.Web.UI.HtmlControls;
|
| | | using System.Web.UI.WebControls;
|
| | | using System.Web.UI.WebControls.WebParts;
|
| | | using System.Runtime.CompilerServices;
|
| | | using System.Data.OracleClient;
|
| | | |
| | | using System.Runtime.CompilerServices;
|
| | |
|
| | | namespace CCSTrace.CCS.Function
|
| | | {
|
| | | public class InitialEventData
|
| | | {
|
| | | private String m_AcceptNum = "";
|
| | | private int m_CaseID = 0;
|
| | | private int m_Year = 0;
|
| | | private bool m_ChangeYear = false;
|
| | | private string m_NowYear = string.Empty;
|
| | | private String m_AcceptTime = "";
|
| | | private RecordLog _PLog;
|
| | | private OracleConnection _ConnectionTPC;
|
| | | private string _mAcceptNum = "";
|
| | | private int _mCaseId = 0;
|
| | | private int _mYear = 0;
|
| | | private bool _mChangeYear = false;
|
| | | private string _mNowYear = string.Empty;
|
| | | private readonly string _mAcceptTime = "";
|
| | | private readonly RecordLog _pLog;
|
| | | private readonly OracleConnection _connectionTpc;
|
| | |
|
| | | //New CaseID and New AcceptNum must be seen by others,so it need not controled by transaction
|
| | | [MethodImpl(MethodImplOptions.Synchronized)]
|
| | | public InitialEventData(OracleConnection _Conn, RecordLog _Log) |
| | | public InitialEventData(OracleConnection conn, RecordLog log)
|
| | | {
|
| | | _ConnectionTPC = _Conn;
|
| | | _PLog = _Log;
|
| | | _connectionTpc = conn;
|
| | | _pLog = log;
|
| | |
|
| | | String SqlStmt = "SELECT ACCEPTNUM,CASEID,YEAR,TO_CHAR(SYSDATE,'YYYY/MM/DD') as ACCEPTTIME FROM EOS.EVENTNUM";
|
| | | string sqlStmt = "SELECT ACCEPTNUM,CASEID,YEAR,TO_CHAR(SYSDATE,'YYYY/MM/DD') as ACCEPTTIME FROM EOS.EVENTNUM";
|
| | |
|
| | | OracleCommand Command = new OracleCommand(SqlStmt, _ConnectionTPC);
|
| | | OracleDataReader reader = Command.ExecuteReader();
|
| | | OracleCommand command = new OracleCommand(sqlStmt, _connectionTpc);
|
| | | OracleDataReader reader = command.ExecuteReader();
|
| | |
|
| | | try
|
| | | {
|
| | | if (reader.Read())
|
| | | {
|
| | | m_AcceptNum = reader["ACCEPTNUM"].ToString();
|
| | | m_CaseID = Convert.ToInt32(reader["CASEID"].ToString());
|
| | | m_Year = Convert.ToInt32(reader["YEAR"].ToString());
|
| | | m_AcceptTime = reader["ACCEPTTIME"].ToString();
|
| | | _mAcceptNum = reader["ACCEPTNUM"].ToString();
|
| | | _mCaseId = Convert.ToInt32(reader["CASEID"].ToString());
|
| | | _mYear = Convert.ToInt32(reader["YEAR"].ToString());
|
| | | _mAcceptTime = reader["ACCEPTTIME"].ToString();
|
| | | }
|
| | | else
|
| | | {
|
| | | _PLog.Error("起始號碼資料遺失!");
|
| | | _pLog.Error("起始號碼資料遺失!");
|
| | | return;
|
| | | }
|
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | _PLog.Error("Problems occur when Initializing EventData: " + e.Message);
|
| | | _pLog.Error("Problems occur when Initializing EventData: " + e.Message);
|
| | | Console.WriteLine(e.StackTrace);
|
| | | return;
|
| | | }
|
| | | finally
|
| | | {
|
| | | reader.Close();
|
| | | Command.Dispose();
|
| | | command.Dispose();
|
| | | }
|
| | |
|
| | | CheckAcceptNum();
|
| | |
|
| | | while (!UpdateDataBase(m_ChangeYear)) {
|
| | | this.RegetNumber();
|
| | | while (!UpdateDataBase(_mChangeYear))
|
| | | {
|
| | | RegetNumber();
|
| | | CheckAcceptNum();
|
| | | }
|
| | | }
|
| | |
|
| | | public int getNewCaseID() {
|
| | | return this.m_CaseID;
|
| | | public int GetNewCaseId()
|
| | | {
|
| | | return _mCaseId;
|
| | | }
|
| | |
|
| | | public String getNewAcceptNum() {
|
| | | return this.m_AcceptNum;
|
| | | public string GetNewAcceptNum()
|
| | | {
|
| | | return _mAcceptNum;
|
| | | }
|
| | |
|
| | | private bool UpdateDataBase(bool m_ChangeYear) {
|
| | | String SqlStmt;
|
| | | bool m_Result = false;
|
| | | private bool UpdateDataBase(bool mChangeYear)
|
| | | {
|
| | | string sqlStmt;
|
| | | bool mResult = false;
|
| | |
|
| | | if (m_ChangeYear)
|
| | | SqlStmt = "UPDATE EOS.EVENTNUM SET ACCEPTNUM = '" + (Convert.ToInt32(m_AcceptNum) + 1).ToString() + "',CASEID = "
|
| | | + (m_CaseID + 1) + ",YEAR = " + m_NowYear + " WHERE CASEID = " + this.m_CaseID;
|
| | | if (mChangeYear)
|
| | | sqlStmt = "UPDATE EOS.EVENTNUM SET ACCEPTNUM = '" + (Convert.ToInt32(_mAcceptNum) + 1).ToString() + "',CASEID = "
|
| | | + (_mCaseId + 1) + ",YEAR = " + _mNowYear + " WHERE CASEID = " + _mCaseId;
|
| | | else
|
| | | SqlStmt = "UPDATE EOS.EVENTNUM SET ACCEPTNUM = '" + (Convert.ToInt32(m_AcceptNum) + 1).ToString() + "',CASEID = "
|
| | | + (m_CaseID + 1) + " WHERE CASEID = " + this.m_CaseID + " AND ACCEPTNUM = '" + m_AcceptNum + "'";
|
| | | sqlStmt = "UPDATE EOS.EVENTNUM SET ACCEPTNUM = '" + (Convert.ToInt32(_mAcceptNum) + 1).ToString() + "',CASEID = "
|
| | | + (_mCaseId + 1) + " WHERE CASEID = " + _mCaseId + " AND ACCEPTNUM = '" + _mAcceptNum + "'";
|
| | |
|
| | | OracleCommand Command = new OracleCommand(SqlStmt, _ConnectionTPC);
|
| | | |
| | | OracleCommand command = new OracleCommand(sqlStmt, _connectionTpc);
|
| | |
|
| | | try
|
| | | {
|
| | | if (Command.ExecuteNonQuery() > 0)
|
| | | m_Result = true;
|
| | | if (command.ExecuteNonQuery() > 0)
|
| | | mResult = true;
|
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | _PLog.Error("Problems occur during EventNumCreating: " + e.Message);
|
| | | _pLog.Error("Problems occur during EventNumCreating: " + e.Message);
|
| | | Console.WriteLine(e.StackTrace);
|
| | | throw e;
|
| | | }
|
| | | finally
|
| | | { |
| | | Command.Dispose();
|
| | | {
|
| | | command.Dispose();
|
| | | }
|
| | |
|
| | | return m_Result;
|
| | | return mResult;
|
| | | }
|
| | |
|
| | | private void CheckAcceptNum() {
|
| | | int NowYear = Convert.ToInt32(m_AcceptTime.Substring(0, 4)) - 1911;
|
| | | int NowMonth = Convert.ToInt32(m_AcceptTime.Substring(5, 2));
|
| | | String Tmp = this.m_AcceptNum;
|
| | | private void CheckAcceptNum()
|
| | | {
|
| | | int nowYear = Convert.ToInt32(_mAcceptTime.Substring(0, 4)) - 1911;
|
| | | int nowMonth = Convert.ToInt32(_mAcceptTime.Substring(5, 2));
|
| | | string tmp = _mAcceptNum;
|
| | |
|
| | | if (Convert.ToInt32(Tmp.Substring(0, 3)) == NowYear)
|
| | | if (Convert.ToInt32(tmp.Substring(0, 3)) == nowYear)
|
| | | {
|
| | | if (Convert.ToInt32(Tmp.Substring(3, 2)) != NowMonth)
|
| | | if (Convert.ToInt32(tmp.Substring(3, 2)) != nowMonth)
|
| | | {
|
| | | // 新月份
|
| | | if (NowMonth < 10)
|
| | | m_AcceptNum = NowYear.ToString() + "0" + NowMonth.ToString() + "0001";
|
| | | if (nowMonth < 10)
|
| | | _mAcceptNum = nowYear.ToString() + "0" + nowMonth.ToString() + "0001";
|
| | | else
|
| | | m_AcceptNum = NowYear.ToString() + NowMonth.ToString() + "0001";
|
| | | _mAcceptNum = nowYear.ToString() + nowMonth.ToString() + "0001";
|
| | | }
|
| | | } else {
|
| | | m_AcceptNum = NowYear.ToString() + "010001"; // 新年度
|
| | | m_NowYear = NowYear.ToString();
|
| | | this.m_ChangeYear = true;
|
| | | }
|
| | | else
|
| | | {
|
| | | _mAcceptNum = nowYear.ToString() + "010001"; // 新年度
|
| | | _mNowYear = nowYear.ToString();
|
| | | _mChangeYear = true;
|
| | | }
|
| | |
|
| | | if ( !m_ChangeYear)
|
| | | { |
| | | if (!_mChangeYear)
|
| | | {
|
| | | }
|
| | | }
|
| | |
|
| | | private void RegetNumber() |
| | | private void RegetNumber()
|
| | | {
|
| | | String SqlStmt = "SELECT ACCEPTNUM,CASEID,YEAR FROM EOS.EVENTNUM";
|
| | | OracleCommand Command = new OracleCommand(SqlStmt, _ConnectionTPC);
|
| | | OracleDataReader reader = Command.ExecuteReader();
|
| | | string sqlStmt = "SELECT ACCEPTNUM,CASEID,YEAR FROM EOS.EVENTNUM";
|
| | | OracleCommand command = new OracleCommand(sqlStmt, _connectionTpc);
|
| | | OracleDataReader reader = command.ExecuteReader();
|
| | |
|
| | | try
|
| | | {
|
| | | if (reader.Read())
|
| | | {
|
| | | m_AcceptNum = reader["ACCEPTNUM"].ToString();
|
| | | m_CaseID = Convert.ToInt32(reader["CASEID"].ToString());
|
| | | m_Year = Convert.ToInt32(reader["YEAR"].ToString());
|
| | | _mAcceptNum = reader["ACCEPTNUM"].ToString();
|
| | | _mCaseId = Convert.ToInt32(reader["CASEID"].ToString());
|
| | | _mYear = Convert.ToInt32(reader["YEAR"].ToString());
|
| | | }
|
| | | }
|
| | | catch (Exception e)
|
| | |
| | | Console.WriteLine(e.StackTrace);
|
| | | }
|
| | | finally
|
| | | { |
| | | {
|
| | | reader.Close();
|
| | | Command.Dispose();
|
| | | command.Dispose();
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | } |