protected void Page_Load(object sender, EventArgs e) { try { #region 清空Message this.ErrorMsgLabel.Text = string.Empty; this.RightMsgLabel.Text = string.Empty; #endregion if (!IsPostBack) { #region Attributes this.but_Close.Attributes["onclick"] += "window.close();"; #endregion #region 取得異常資料 #region 傳入參數 ParameterList.Clear(); ParameterList.Add(Session["UID"].ToString()); #endregion #region 連結資料庫 BCO.ImportCOLLPO bco = new BCO.ImportCOLLPO(ConntionDB); DataTable dt_Return = bco.QUERYERRORBYFIND(ParameterList); #endregion #region 檢查回傳資料 if (dt_Return.Rows.Count == 0) { this.ErrorMsgLabel.Text = "查無資料"; return; } else { this.gv_Result.DataSource = dt_Return; this.gv_Result.DataBind(); } #endregion #endregion } } catch (Exception ex) { WaringLogProcess(ex.Message); this.ErrorMsgLabel.Text = ex.Message; } finally { } }
/// <summary> /// 檢查文字檔條件 /// </summary> /// <param name="s_FileLine"></param> /// <returns></returns> private ArrayList Check_Condition_FileLine(string s_FileLine, DataTable dt_Temp) { #region 規則 /* *格式代號 VARCHAR2(2) [INV_FORM] :1~2 *流水號 NUMBER(16) [SEQ_NO] :12~18 *年月 VARCHAR2(6) [INV_YM] :19~23 *客戶統編 VARCHAR2(10) [RFNO] :24~31 *銷項發票 VARCHAR2(10) [INV_NO] :40~49 *銷售額 NUMBER(12) [INV_UAMT] :50~61 *課稅別 NUMBER(1) [TAX_TYPE] :62 *稅額 NUMBER(12) [INV_TAX] :63~72 */ #endregion #region 宣告 BCO.CAACommon CAAComm = new BCO.CAACommon(); BCO.ImportCOLLPO bco = new BCO.ImportCOLLPO(ConntionDB); ArrayList arl_Return = new ArrayList(); arl_Return.Add(string.Empty);//該欄位放Focus欄位之ClientID arl_Return.Add(string.Empty);//該欄位放錯誤訊息 #endregion #region 檢查字串長度 //字串每一行都固定有81個字 if (s_FileLine.Length < 81) { arl_Return = CAAComm.ToMakeUp_Err_ArrayList(arl_Return, "字串長度不正確;", "1", string.Empty); } #endregion #region 如果檢查字串長度有誤,則Return if (arl_Return[1].ToString() != string.Empty) { return arl_Return; } #endregion #region 檢查數字格式 arl_Return = CAAComm.Check_Format_Int(s_FileLine.Substring(11, 7), "[流水號]數字格式有誤;", "32", "1", string.Empty, arl_Return);//流水號 arl_Return = CAAComm.Check_Format_Int(s_FileLine.Substring(49, 12), "[銷售額]數字格式有誤;", "64", "1", string.Empty, arl_Return);//銷售額 arl_Return = CAAComm.Check_Format_Int(s_FileLine.Substring(62, 10), "[稅額]數字格式有誤;", "64", "1", string.Empty, arl_Return);//稅額 #endregion #region 檢查必填欄位 arl_Return = CAAComm.Check_MustFillin_Column(s_FileLine.Substring(0, 2), "text", "[格式代號]為必填欄位;", "1", string.Empty, arl_Return); arl_Return = CAAComm.Check_MustFillin_Column(s_FileLine.Substring(11, 7), "text", "[流水號]為必填欄位;", "1", string.Empty, arl_Return); arl_Return = CAAComm.Check_MustFillin_Column(s_FileLine.Substring(18, 5), "text", "[年月]為必填欄位;", "1", string.Empty, arl_Return); arl_Return = CAAComm.Check_MustFillin_Column(s_FileLine.Substring(39, 10), "text", "[銷項發票]為必填欄位;", "1", string.Empty, arl_Return); arl_Return = CAAComm.Check_MustFillin_Column(s_FileLine.Substring(49, 12), "text", "[銷售額]為必填欄位;", "1", string.Empty, arl_Return); arl_Return = CAAComm.Check_MustFillin_Column(s_FileLine.Substring(61, 1), "text", "[課稅別]為必填欄位;", "1", string.Empty, arl_Return); arl_Return = CAAComm.Check_MustFillin_Column(s_FileLine.Substring(62, 10), "text", "[稅額]為必填欄位;", "1", string.Empty, arl_Return); #endregion #region 如果檢查數字格式,必填欄位有誤,則Return if (arl_Return[1].ToString() != string.Empty) { return arl_Return; } #endregion #region 檢查年月格式 try { string s_YearMonth = Convert.ToString(int.Parse(s_FileLine.Substring(18, 5)) + 191100); arl_Return = CAAComm.Check_Format_YearMonth(s_YearMonth, "[年月]年月格式有誤;", "1", string.Empty, arl_Return);//年月 } catch { arl_Return = CAAComm.ToMakeUp_Err_ArrayList(arl_Return, "[年月]年月格式有誤;", "1", string.Empty); } #endregion #region 檢查格式代號 if (s_FileLine.Substring(0, 2) != "31" && s_FileLine.Substring(0, 2) != "32" && s_FileLine.Substring(0, 2) != "33" && s_FileLine.Substring(0, 2) != "34") { arl_Return = CAAComm.ToMakeUp_Err_ArrayList(arl_Return, "[格式代號]只有31,32,33,34四種格式;", "1", string.Empty); } #endregion #region 檢查發票字軌 System.Text.RegularExpressions.Regex reg1 = new System.Text.RegularExpressions.Regex(@"^[A-Z]+$"); bool b_Inv_Track = reg1.IsMatch(s_FileLine.Substring(39, 2)); if (b_Inv_Track == false) { arl_Return = CAAComm.ToMakeUp_Err_ArrayList(arl_Return, "[發票字軌]格式有誤;", "1", string.Empty); } #endregion return arl_Return; }
/// <summary> /// 頁籤=資料轉入處理 BUTTON [確定匯入] /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void but_Import_Click(object sender, EventArgs e) { try { #region 檢查條件 ArrayList arl_Check_Condition = Check_Condition("BUTTON [確定匯入]"); #region 如果檢查有誤,則Return if (arl_Check_Condition[1].ToString() != string.Empty) { #region 錯誤訊息 this.ErrorMsgLabel.Text = arl_Check_Condition[1].ToString(); #endregion return; } #endregion #endregion #region 將TempTable的資料寫入正式Table #region 傳入參數 string s_SourcePath = Server.MapPath("..\\") + System.Configuration.ConfigurationManager.AppSettings["UploadPath"] + "CAA\\"; string s_DestinationPath = Server.MapPath("..\\") + System.Configuration.ConfigurationManager.AppSettings["BackPath"] + "CAA\\"; ParameterList.Clear(); ParameterList.Add(Session["UID"].ToString()); ParameterList.Add(DateTime.Now); ParameterList.Add(s_SourcePath);//來源資料路徑 ParameterList.Add(s_DestinationPath);//目的地資料路徑 #endregion #region 連結資料庫 BCO.ImportCOLLPO bco = new BCO.ImportCOLLPO(ConntionDB); DataTable dt_Return = bco.TmpToDB(null, ParameterList); #endregion #region 計算[總筆數][正常筆數][錯誤筆數] int i_Total_Count = 0;//總筆數 int i_Success_Count = 0;//正常筆數 int i_Failure_Count = 0;//錯誤筆數 string s_FilterExpression = string.Empty; s_FilterExpression = "STATUS ='1'";//1:正常資料; DataRow[] dr_Success = dt_Return.Select(s_FilterExpression); if (dr_Success.Length == 1) { i_Success_Count = int.Parse(dr_Success[0]["count"].ToString()); } s_FilterExpression = "STATUS ='2'";//2:錯誤資料; DataRow[] dr_Failure = dt_Return.Select(s_FilterExpression); if (dr_Failure.Length == 1) { i_Failure_Count = int.Parse(dr_Failure[0]["count"].ToString()); } i_Total_Count = i_Success_Count + i_Failure_Count; this.UploadStatusPanel1.ImportSum = i_Total_Count;//匯入結果總筆數 this.UploadStatusPanel1.ImportOK = i_Success_Count;//匯入結果正常筆數 this.UploadStatusPanel1.ImportNG = i_Failure_Count;//匯入結果錯誤筆數 #endregion #region 設定控制項 if ((i_Total_Count == i_Success_Count) && (i_Failure_Count == 0)) { this.but_Import.Enabled = false;//確定匯入 this.but_Error.Enabled = false;//檢視異常 } if (i_Failure_Count > 0) { this.but_Import.Enabled = false;//確定匯入 this.but_Error.Enabled = true;//檢視異常 } #endregion #endregion } catch (Exception ex) { WaringLogProcess(ex.Message); this.ErrorMsgLabel.Text = ex.Message; } }
/// <summary> /// 頁籤=資料轉入處理 BUTTON [載入檔案] /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void but_LoadFile_Click(object sender, EventArgs e) { try { #region 將Client端的檔案上傳至AP端 #region 宣告變數 string s_UploadPath = string.Empty; ArrayList arl_Return = new ArrayList(); #endregion #region 將Client端的檔案上傳至AP端 s_UploadPath = Server.MapPath("..\\") + System.Configuration.ConfigurationManager.AppSettings["UploadPath"] + "CAA\\"; BCO.ImportCOLLPO bco = new BCO.ImportCOLLPO(ConntionDB); arl_Return = bco.FileUpload(s_UploadPath, this.fileupload_Path, Session["UID"].ToString()); #endregion #region 檢查回傳結果 if (arl_Return[0].ToString() == "FALSE") { this.ErrorMsgLabel.Text = arl_Return[1].ToString(); return; } #endregion #endregion #region 依據AP端檔案資料匯入TmpTable #region 取得 TempTable VDS_CAA_COLL_TMP 的 SCHEMA BCO.CAACommon CAAComm = new BCO.CAACommon(); DataTable dt_Temp = new DataTable(); ParameterList.Clear(); ParameterList.Add(CAAComm.GetValueSetParameter(Session["UID"].ToString(), "string", false));//V_LOG_UPDATEUID dt_Temp = bco.GET_VDS_CAA_COLL_TMP_SCHEMA(ParameterList); #endregion #region 將資料寫入 TempTable DateTime d_Now = DateTime.Now; string s_FileLine = string.Empty; System.IO.StreamReader str = new System.IO.StreamReader(arl_Return[1].ToString()); DataTable dt_Month_Close = new DataTable(); #region 取得月結的資料 ParameterList.Clear(); ParameterList.Add(CAAComm.GetValueSetParameter(Session["UID"].ToString(), "string", false));//V_LOG_UPDATEUID dt_Month_Close = bco.GET_MONTH_CLOSE_DATA(ParameterList); #endregion int i_SignNum = 0;//沖正筆數 20110210 Rika新增 while ((s_FileLine = str.ReadLine()) != null) { #region 檢查條件 string s_Store = string.Empty;//店號 int i_Charge = 0;//手續費 string s_SIGN = s_FileLine.Substring(73, 1);//正負號資料 ArrayList arl_ConditionReturn = Check_Condition_FileLine(s_FileLine, dt_Month_Close, dt_Temp, out s_Store, out i_Charge); #endregion #region 檢查正確 if (arl_ConditionReturn[1].ToString() == string.Empty && s_SIGN == "+") { DataRow dr_Temp = dt_Temp.NewRow(); dr_Temp["ID"] = dt_Temp.Rows.Count + 1;//ID dr_Temp["STATUS"] = CAAComm.GetValueSetParameter("1", "int", false);//處理狀態(1:正常資料;2:錯誤資料;3:沖正資料) dr_Temp["DATASOURCE"] = CAAComm.GetValueSetParameter(arl_Return[3].ToString(), "string", false);//匯入檔案 dr_Temp["DATATYPE"] = CAAComm.GetValueSetParameter("1", "int", false);//資料類別(1:FILE TO TMP;2:TMP TO DB) dr_Temp["MEMO"] = CAAComm.GetValueSetParameter(string.Empty, "string", false);//說明 dr_Temp["STORE_ID"] = s_Store;//店號 dr_Temp["COLL_DATE"] = DateTime.ParseExact(Convert.ToString(int.Parse(s_FileLine.Substring(49, 7)) + 19110000), "yyyyMMdd", null);//交易日期 dr_Temp["COLL_SEQNO"] = CAAComm.GetValueSetParameter(s_FileLine.Substring(62, 10), "string", false);//交易序號 dr_Temp["COLL_TIME"] = DateTime.ParseExact(s_FileLine.Substring(56, 6), "HHmmss", null).ToString("HHmmss");//交易時間 dr_Temp["COLL_AMT"] = CAAComm.GetValueSetParameter(s_FileLine.Substring(34, 13), "int", false);//交易金額 dr_Temp["CHARGE"] = i_Charge;//手續費 dr_Temp["SAL_DATE"] = DateTime.ParseExact(Convert.ToString(int.Parse(s_FileLine.Substring(13, 7)) + 19110000), "yyyyMMdd", null);//營業日 dr_Temp["PAY_TYPE"] = CAAComm.GetValueSetParameter(s_FileLine.Substring(84, 1), "string", false);//繳款型態 dr_Temp["PAY_CHKNO"] = CAAComm.GetValueSetParameter(s_FileLine.Substring(20, 9), "string", false);//識別碼 dr_Temp["ACCTNO"] = Int64.Parse(s_FileLine.Substring(0, 12));//轉入帳號 dr_Temp["ACCT_CODE"] = CAAComm.GetValueSetParameter(s_FileLine.Substring(12, 1), "string", false);//帳務別 dr_Temp["MEMO_NO"] = CAAComm.GetValueSetParameter(s_FileLine.Substring(20, 14), "string", false);//註記一 dr_Temp["CREATEUID"] = CAAComm.GetValueSetParameter(Session["UID"].ToString(), "string", false); dr_Temp["CREATEDATE"] = CAAComm.GetValueSetParameter(d_Now.ToString(), "datetime", false); dr_Temp["UPDATEUID"] = CAAComm.GetValueSetParameter(string.Empty, "string", false); dr_Temp["UPDATEDATE"] = CAAComm.GetValueSetParameter(string.Empty, "string", false); dt_Temp.Rows.Add(dr_Temp); } #endregion #region 沖正資料處理 20110210 Rika 新增 else if (arl_ConditionReturn[1].ToString() == string.Empty && s_SIGN == "-") { string s_Filter_Expression = string.Empty; string i_COLL_AMT = CAAComm.GetValueSetParameter(s_FileLine.Substring(34, 13), "int", false).ToString();//交易金額 string i_COLL_DATE = DateTime.ParseExact(Convert.ToString(int.Parse(s_FileLine.Substring(49, 7)) + 19110000), "yyyyMMdd", null).ToString("yyyy/MM/dd"); #region 更新上一筆被沖正的資料狀態 // int i_ID = dt_Temp.Rows.Count -1 ; s_Filter_Expression = string.Format("COLL_AMT = '{0}' and COLL_DATE = #{1}# and STORE_ID = '{2}' and STATUS <> '3' ", i_COLL_AMT, i_COLL_DATE, s_Store); DataRow[] dr = dt_Temp.Select(s_Filter_Expression); int ID = dr.Length -1 ; int i_ID = Convert.ToInt32(dr[ID]["ID"].ToString()) -1 ; dt_Temp.Rows[i_ID]["STATUS"] = CAAComm.GetValueSetParameter("3", "int", false);//處理狀態(1:正常資料;2:錯誤資料;3:沖正資料) dt_Temp.Rows[i_ID]["MEMO"] = "此筆為被沖正資料";//說明 #endregion DataRow dr_Temp = dt_Temp.NewRow(); dr_Temp["ID"] = dt_Temp.Rows.Count + 1;//ID dr_Temp["STATUS"] = CAAComm.GetValueSetParameter("3", "int", false);//處理狀態(1:正常資料;2:錯誤資料;3:沖正資料) dr_Temp["DATASOURCE"] = CAAComm.GetValueSetParameter(arl_Return[3].ToString(), "string", false);//匯入檔案 dr_Temp["MEMO"] = "此筆為沖正資料";//說明 dr_Temp["CREATEUID"] = CAAComm.GetValueSetParameter(Session["UID"].ToString(), "string", false); dr_Temp["CREATEDATE"] = CAAComm.GetValueSetParameter(d_Now.ToString(), "datetime", false); dr_Temp["UPDATEUID"] = CAAComm.GetValueSetParameter(string.Empty, "string", false); dr_Temp["UPDATEDATE"] = CAAComm.GetValueSetParameter(string.Empty, "string", false); dt_Temp.Rows.Add(dr_Temp); } #endregion #region 檢查不正確 else { DataRow dr_Temp = dt_Temp.NewRow(); string s_ErrorMsg = string.Empty; s_ErrorMsg = arl_ConditionReturn[1].ToString().Replace("<br/>", string.Empty); dr_Temp["ID"] = dt_Temp.Rows.Count + 1;//ID dr_Temp["STATUS"] = CAAComm.GetValueSetParameter("2", "int", false);//處理狀態(1:正常資料;2:錯誤資料;3:沖正資料) dr_Temp["DATASOURCE"] = CAAComm.GetValueSetParameter(arl_Return[3].ToString(), "string", false);//匯入檔案 dr_Temp["MEMO"] = s_ErrorMsg;//說明 dr_Temp["CREATEUID"] = CAAComm.GetValueSetParameter(Session["UID"].ToString(), "string", false); dr_Temp["CREATEDATE"] = CAAComm.GetValueSetParameter(d_Now.ToString(), "datetime", false); dr_Temp["UPDATEUID"] = CAAComm.GetValueSetParameter(string.Empty, "string", false); dr_Temp["UPDATEDATE"] = CAAComm.GetValueSetParameter(string.Empty, "string", false); dt_Temp.Rows.Add(dr_Temp); } #endregion } str.Close(); str.Dispose(); #endregion #region 連結資料庫 if (dt_Temp.Rows.Count == 0) { this.ErrorMsgLabel.Text = "無匯入資料"; return; } else { #region 將資料寫入TempTable DataTable dt_Return = bco.FileToTmp(null, Session["UID"].ToString(), dt_Temp); #endregion #region 計算[總筆數][正常筆數][錯誤筆數] int i_Total_Count = 0;//總筆數 int i_Success_Count = 0;//正常筆數 int i_Failure_Count = 0;//錯誤筆數 int i_Reverse_Count = 0;//沖正筆數 string s_FilterExpression = string.Empty; s_FilterExpression = "STATUS ='1'";//1:正常資料; DataRow[] dr_Success = dt_Return.Select(s_FilterExpression); if (dr_Success.Length == 1) { i_Success_Count = int.Parse(dr_Success[0]["count"].ToString()) + i_SignNum; //沖正筆數 20110210 Rika新增 } s_FilterExpression = "STATUS ='2'";//2:錯誤資料; DataRow[] dr_Failure = dt_Return.Select(s_FilterExpression); if (dr_Failure.Length == 1) { i_Failure_Count = int.Parse(dr_Failure[0]["count"].ToString()); } s_FilterExpression = "STATUS ='3'";//3:沖正資料; DataRow[] dr_Reverse = dt_Return.Select(s_FilterExpression); if (dr_Reverse.Length == 1) { i_Reverse_Count = int.Parse(dr_Reverse[0]["count"].ToString()); } i_Total_Count = i_Success_Count + i_Failure_Count + i_Reverse_Count; this.UploadStatusPanel1.UploadSum = i_Total_Count;//上傳結果總筆數 this.UploadStatusPanel1.UploadOK = i_Success_Count;//上傳結果正常筆數 this.UploadStatusPanel1.UploadNG = i_Failure_Count;//上傳結果錯誤筆數 this.UploadStatusPanel1.ImportSum = 0;//匯入結果總筆數 this.UploadStatusPanel1.ImportOK = 0;//匯入結果正常筆數 this.UploadStatusPanel1.ImportNG = 0;//匯入結果錯誤筆數 #endregion #region 設定控制項 if ((i_Total_Count == (i_Success_Count + i_Reverse_Count)) && (i_Failure_Count == 0)) { //若沖正筆數=全部筆數則不用匯入 if (i_Reverse_Count != i_Total_Count) { this.but_Import.Enabled = true;//確定匯入 } //若有沖正資料則需要開啟檢視異常 if (i_Reverse_Count > 0) { this.but_Error.Enabled = true;//檢視異常 } else { this.but_Error.Enabled = false;//檢視異常 } } if (i_Failure_Count > 0) { this.but_Import.Enabled = false;//確定匯入 this.but_Error.Enabled = true;//檢視異常 } #endregion } #endregion #endregion } catch (Exception ex) { WaringLogProcess(ex.Message); this.ErrorMsgLabel.Text = ex.Message; } finally { #region 設定 TabContainer 的 ActiveTabIndex this.TabContainer1.ActiveTabIndex = 1; #endregion } }
/// <summary> /// 檢查文字檔條件 /// </summary> /// <param name="s_FileLine"></param> /// <param name="dt_Month_Close">月結的資料</param> /// <param name="dt_Temp">要寫入Temp Table VDS_CAA_COLL_TMP 的資料</param> /// <param name="s_Store">回傳[店號]</param> /// <param name="i_Charge">回傳[手續費]</param> /// <returns></returns> private ArrayList Check_Condition_FileLine(string s_FileLine, DataTable dt_Month_Close, DataTable dt_Temp, out string s_Store, out int i_Charge) { #region 規則 /* *交易日期 [COLL_DATE] :50~56 *交易序號 [COLL_SEQNO]:63~72 *交易時間 [COLL_TIME] :57~62 *交易金額 [COLL_AMT] :35~49 *營業日 [SAL_DATE] :14~20 *繳款型態 [PAY_TYPE] :85 *繳款識別碼[PAY_CHKNO] :21~29 *轉入帳號 [ACCTNO] :1~12 *帳務別 [ACCT_CODE] :13 *註記一 [MEMO_NO] :21~34 *銷帳代號:116~120 + 21~29 */ #endregion #region 宣告 BCO.CAACommon CAAComm = new BCO.CAACommon(); BCO.ImportCOLLPO bco = new BCO.ImportCOLLPO(ConntionDB); ArrayList arl_Return = new ArrayList(); arl_Return.Add(string.Empty);//該欄位放Focus欄位之ClientID arl_Return.Add(string.Empty);//該欄位放錯誤訊息 s_Store = string.Empty; i_Charge = 0; #endregion #region 檢查字串長度 //字串最長是用到取得[銷帳代號]120的位置,所以120之前都必須有值 if (s_FileLine.Length < 120) { arl_Return = CAAComm.ToMakeUp_Err_ArrayList(arl_Return, "字串長度不正確;", "1", string.Empty); } #endregion #region 如果檢查字串長度有誤,則Return if (arl_Return[1].ToString() != string.Empty) { return arl_Return; } #endregion #region 檢查數字格式 arl_Return = CAAComm.Check_Format_Int(s_FileLine.Substring(0, 12), "[轉入帳號]數字格式有誤;", "64", "1", string.Empty, arl_Return);//轉入帳號 arl_Return = CAAComm.Check_Format_Int(s_FileLine.Substring(13, 7), "[營業日]數字格式有誤;", "32", "1", string.Empty, arl_Return);//營業日 arl_Return = CAAComm.Check_Format_Int(s_FileLine.Substring(34, 15), "[交易金額]數字格式有誤;", "64", "1", string.Empty, arl_Return);//交易金額 arl_Return = CAAComm.Check_Format_Int(s_FileLine.Substring(49, 7), "[交易日期]數字格式有誤;", "32", "1", string.Empty, arl_Return);//交易日期 arl_Return = CAAComm.Check_Format_Int(s_FileLine.Substring(56, 6), "[交易時間]數字格式有誤;", "32", "1", string.Empty, arl_Return);//交易時間 #endregion #region 如果檢查數字格式有誤,則Return if (arl_Return[1].ToString() != string.Empty) { return arl_Return; } #endregion #region 檢查日期格式 try { DateTime.ParseExact(Convert.ToString(int.Parse(s_FileLine.Substring(13, 7)) + 19110000), "yyyyMMdd", null); } catch { arl_Return = CAAComm.ToMakeUp_Err_ArrayList(arl_Return, "[營業日]日期格式有誤;", "1", string.Empty); } try { DateTime.ParseExact(Convert.ToString(int.Parse(s_FileLine.Substring(49, 7)) + 19110000), "yyyyMMdd", null); } catch { arl_Return = CAAComm.ToMakeUp_Err_ArrayList(arl_Return, "[交易日期]日期格式有誤;", "1", string.Empty); } #endregion #region 檢查時間格式 try { DateTime.ParseExact(s_FileLine.Substring(56, 6), "HHmmss", null).ToString("HHmmss"); } catch { arl_Return = CAAComm.ToMakeUp_Err_ArrayList(arl_Return, "[交易時間]時間格式有誤;", "1", string.Empty); } #endregion #region 如果檢查日期&時間格式有誤,則Return if (arl_Return[1].ToString() != string.Empty) { return arl_Return; } #endregion #region 檢查該筆資料是否月結 string s_Month_Close = string.Empty; string s_Filter_Expression = string.Empty; s_Month_Close = DateTime.ParseExact(Convert.ToString(int.Parse(s_FileLine.Substring(13, 7)) + 19110000), "yyyyMMdd", null).ToString("yyyyMM");//[交易日期]取年月 //20110303 Rika改為 營業日期取年月 s_Filter_Expression = "MONTH_CLOSE ='" + s_Month_Close + "'"; DataRow[] dr_Month_Close = dt_Month_Close.Select(s_Filter_Expression); if (dr_Month_Close.Length > 0) { arl_Return = CAAComm.ToMakeUp_Err_ArrayList(arl_Return, "此代收年月:" + s_Month_Close + "己月結,不允許匯入;", "1", string.Empty); } #endregion #region 如果檢查該筆資料已月結,則Return if (arl_Return[1].ToString() != string.Empty) { return arl_Return; } #endregion #region 取得[店號] #region 規則 /* (1)抓取TXT檔中字元14~20並轉換資料前三碼(民國年,需轉換為西元年)。 EX:1911 + 民國年(097) =>存入資料為2008 (2)依店號(STORE)=TXT檔中字元23~28 + 流程(1)之資料介於有效起始日(MDC_START_DATE)及有效終止日(MDC_END_DATE),查詢門市檔(VDS_STM_STORE)之店號欄位,並判斷是否有值 (2.1)有值:STORE_ID=流程(2)取得之店號(STORE) (2.2)無值:抓取TXT檔中字元116~120 + 21~29 (2.2.1)依銷帳代號(PAY_ACCOUNT)=TXT檔中字元116~120 + 21~29且流程(1)之資料介於有效起始日(EFF_DATE_FROM)及有效終止日(EFF_DATE_TO),查詢帳務特性(VDS_STM_ACCOUNT_PROPERTY)之店號欄位,並判斷是否有值 (2.2.1.1)有值(一筆):STORE_ID=流程(2.2.1)取得之店號(STORE) (2.2.1.2)有值(多筆):依銷帳代號(PAY_ACCOUNT)=TXT檔中字元116~120 + 21~29且流程(1)之資料介於有效起始日(EFF_DATE_FROM)及有效終止日(EFF_DATE_TO)且STORE_TYPE=1(取總部店),查詢帳務特性(VDS_STM_ACCOUNT_PROPERTY)之店號欄位,並判斷是否有值 (A)有值:STORE_ID=流程(2.2.1.1)取得之店號(STORE) (B)無值:列為錯誤(多筆銷帳代號卻無總部店對應) (2.2.1.3)否:列為錯誤(店號不存在) */ #endregion string s_PAY_ACCOUNT = s_FileLine.Substring(115, 5) + s_FileLine.Substring(20, 9);//銷帳代號 string s_BUSINESS_DATE = DateTime.ParseExact(Convert.ToString(int.Parse(s_FileLine.Substring(13, 7)) + 19110000), "yyyyMMdd", null).ToString("yyyy/MM/dd");//營業日期 ParameterList.Clear(); ParameterList.Add(CAAComm.GetValueSetParameter(s_FileLine.Substring(22, 6), "string", false)); ParameterList.Add(CAAComm.GetValueSetParameter(s_BUSINESS_DATE, "date", false)); ParameterList.Add(CAAComm.GetValueSetParameter(Session["UID"].ToString(), "string", false));//V_LOG_UPDATEUID DataTable dt_Store_Information = bco.GET_STORE_INFORMATION(ParameterList); if (dt_Store_Information.Rows.Count == 0) { #region 使用銷帳代號取得店號 ParameterList.Clear(); ParameterList.Add(CAAComm.GetValueSetParameter(s_PAY_ACCOUNT, "string", false)); ParameterList.Add(CAAComm.GetValueSetParameter(s_BUSINESS_DATE, "date", false)); ParameterList.Add(CAAComm.GetValueSetParameter(Session["UID"].ToString(), "string", false));//V_LOG_UPDATEUID DataTable dt_Store_ID = bco.GET_STORE_FROM_ACCOUNTPROPERTY(ParameterList); #endregion #region 查詢結果-該銷帳代號無對應店號 if (dt_Store_ID.Rows.Count == 0) { arl_Return = CAAComm.ToMakeUp_Err_ArrayList(arl_Return, "[銷帳代號]:" + s_PAY_ACCOUNT + "查無對應的店號;", "1", string.Empty); } #endregion #region 查詢結果-該銷帳代號只對應到一筆店號 else if (dt_Store_ID.Rows.Count == 1) { ParameterList.Clear(); ParameterList.Add(CAAComm.GetValueSetParameter(dt_Store_ID.Rows[0]["STORE"].ToString(), "string", false)); ParameterList.Add(CAAComm.GetValueSetParameter(s_BUSINESS_DATE, "date", false)); ParameterList.Add(CAAComm.GetValueSetParameter(Session["UID"].ToString(), "string", false));//V_LOG_UPDATEUID dt_Store_Information = bco.GET_STORE_INFORMATION(ParameterList); if (dt_Store_Information.Rows.Count == 0) { arl_Return = CAAComm.ToMakeUp_Err_ArrayList(arl_Return, "[銷帳代號]:" + s_PAY_ACCOUNT + "對應的店號不存在於門市主檔;", "1", string.Empty); } else { s_Store = dt_Store_Information.Rows[0]["STORE"].ToString(); } } #endregion #region 查詢結果-該銷帳代號對應到多筆店號 else { s_Filter_Expression = "STORE_TYPE = '1'"; DataRow[] dr_Store_Array = dt_Store_ID.Select(s_Filter_Expression); if (dr_Store_Array.Length == 0) { arl_Return = CAAComm.ToMakeUp_Err_ArrayList(arl_Return, "[銷帳代號]:" + s_PAY_ACCOUNT + "對應到多筆店號卻無總部店對應;", "1", string.Empty); } else if (dr_Store_Array.Length == 1) { ParameterList.Clear(); ParameterList.Add(CAAComm.GetValueSetParameter(dr_Store_Array[0]["STORE"].ToString(), "string", false)); ParameterList.Add(CAAComm.GetValueSetParameter(s_BUSINESS_DATE, "date", false)); ParameterList.Add(CAAComm.GetValueSetParameter(Session["UID"].ToString(), "string", false));//V_LOG_UPDATEUID dt_Store_Information = bco.GET_STORE_INFORMATION(ParameterList); if (dt_Store_Information.Rows.Count == 0) { arl_Return = CAAComm.ToMakeUp_Err_ArrayList(arl_Return, "[銷帳代號]:" + s_PAY_ACCOUNT + "對應的店號不存在於門市主檔;", "1", string.Empty); } else { s_Store = dt_Store_Information.Rows[0]["STORE"].ToString(); } } else { arl_Return = CAAComm.ToMakeUp_Err_ArrayList(arl_Return, "[銷帳代號]:" + s_PAY_ACCOUNT + "對應到多筆店號;", "1", string.Empty); } } #endregion } else { s_Store = dt_Store_Information.Rows[0]["STORE"].ToString(); } #endregion #region 檢查是否為沖正資料 string s_SIGN = s_FileLine.Substring(73, 1);//正負號資料 string i_COLL_AMT = CAAComm.GetValueSetParameter(s_FileLine.Substring(34, 13), "int", false).ToString();//交易金額 string i_COLL_DATE = DateTime.ParseExact(Convert.ToString(int.Parse(s_FileLine.Substring(49, 7)) + 19110000), "yyyyMMdd", null).ToString("yyyy/MM/dd"); if (s_SIGN != "+") { //int i_NewestRow = dt_Temp.Rows.Count; //s_Filter_Expression = string.Format("COLL_AMT = '{0}' and COLL_DATE = #{1}# and STORE_ID = '{2}' and ID= '{3}'", i_COLL_AMT, i_COLL_DATE, s_Store, i_NewestRow); s_Filter_Expression = string.Format("COLL_AMT = '{0}' and COLL_DATE = #{1}# and STORE_ID = '{2}' and STATUS <> '3' ", i_COLL_AMT, i_COLL_DATE, s_Store); DataRow[] dr = dt_Temp.Select(s_Filter_Expression); if (dr.Length == 0) { arl_Return = CAAComm.ToMakeUp_Err_ArrayList(arl_Return, "沖正資料查無沖銷款項;", "1", string.Empty); } } #region 如果沖正資料查無沖銷款項,則Return if (arl_Return[1].ToString() != string.Empty) { return arl_Return; } #endregion #endregion #region 取得[手續費] if (s_Store != string.Empty) { #region 規則 /* 20100601秀玲異動規則 * 已經與使用者確認過,只要有相同資料,則第二筆以後的資料手續費就為零,不用去管第一筆資料的手續費是否為零。 * 檢查 Temp Table 中是否已有相同年月(營業日欄位取年月)+相同店號之資料 * 1.如果有則手續費直接回傳0元。 * 2.如果沒有則再去檢查 VDS_CAA_COLL_MAIN 中是否有相同年月(營業日欄位取年月)+相同店號之資料。 * (1)如果有則手續費直接回傳0元。 * (1)如果沒有則依照規則抓取手續費。 */ #endregion #region 檢查在dt_Temp中是否有相同年月(營業日欄位取年月)+相同店號之資料 string s_SAL_DATE_B = s_BUSINESS_DATE.Substring(0, 8) + "01"; string s_SAL_DATE_E = DateTime.Parse(s_SAL_DATE_B).AddMonths(1).AddDays(-1).ToString("yyyy/MM/dd"); s_Filter_Expression = string.Format("SAL_DATE >= #{0}# and SAL_DATE <= #{1}# and STORE_ID = '{2}'", s_SAL_DATE_B, s_SAL_DATE_E, s_Store); DataRow[] dr = dt_Temp.Select(s_Filter_Expression); if (dr.Length != 0) { i_Charge = 0; } #endregion #region 檢查在 VDS_CAA_COLL_MAIN 中是否有相同年月(營業日欄位取年月)+相同店號之資料 else { #region 傳入參數 ParameterList.Clear(); ParameterList.Add(CAAComm.GetValueSetParameter(s_Store, "string", false)); ParameterList.Add(CAAComm.GetValueSetParameter(s_BUSINESS_DATE, "date", false)); ParameterList.Add(CAAComm.GetValueSetParameter(Session["UID"].ToString(), "string", false));//V_LOG_UID #endregion #region 連結資料庫 DataTable dt_REPEAT_DATA = bco.CHECK_REPEAT_DATA(ParameterList); #endregion #region 檢查回傳資料 if (dt_REPEAT_DATA.Rows[0][0].ToString() == "0") { #region 取得手續費 #region 傳入參數 ParameterList.Clear(); ParameterList.Add(CAAComm.GetValueSetParameter(s_Store, "string", false)); ParameterList.Add(CAAComm.GetValueSetParameter(s_BUSINESS_DATE, "date", false)); ParameterList.Add(CAAComm.GetValueSetParameter(Session["UID"].ToString(), "string", false));//V_LOG_UPDATEUID #endregion #region 連結資料庫 DataTable dt_Charge_Information = bco.GET_CHARGE_INFORMATION(ParameterList); #endregion #region 規則 /* * 下面兩點已與秀玲確認過 * (1)因為匯入的資料中,有可能[店號]不存在於店主檔, * 當有這種情況資料必須匯入,手續費要帶0 * (2)VDS_STM_ACCOUNT_PROPERTY.FEET這一個欄位有可能是空值, * 在Package那邊會下nvl,使其不會為空值 * 當手續費欄位為空值,則代表手續費為0 */ #endregion if (dt_Charge_Information.Rows.Count == 0) { i_Charge = 0; } else if (dt_Charge_Information.Rows.Count == 1) { i_Charge = int.Parse(dt_Charge_Information.Rows[0]["FEET"].ToString()); } else { arl_Return = CAAComm.ToMakeUp_Err_ArrayList(arl_Return, "[店號]:" + s_Store + "對應到多筆手續費;", "1", string.Empty); } #endregion } else { i_Charge = 0; } #endregion } #endregion } #endregion return arl_Return; }