コード例 #1
0
ファイル: CAA101.aspx.cs プロジェクト: ChiangHanLung/PIC_VDS
    /// <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
        }
    }