Beispiel #1
0
        public ArrayList TmpToDB(string strLoginUser, string ConntionDB)
        {
            ArrayList arl_Return = new ArrayList();
            try
            {
                int iTotal = 0;
                int iRight = 0;
                ArrayList ParameterList = new ArrayList();
                CAA_38DBO DBO = new CAA_38DBO(ref USEDB);
                ParameterList.Clear();
                ParameterList.Add(strLoginUser);
                ParameterList.Add("");
                DataTable dt = DBO.QueryTmp(ParameterList);
                iTotal = dt.Rows.Count;

                string strCREATEUID = strLoginUser;

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string strID = dt.Rows[i]["ID"].ToString();
                    string strCUBE_NO = dt.Rows[i]["CUBE_NO"].ToString();
                    string strWASH_TYPE = dt.Rows[i]["WASH_TYPE"].ToString();
                    string strWASH_NO = dt.Rows[i]["WASH_NO"].ToString();
                    string strLINK_TYPE = dt.Rows[i]["LINK_TYPE"].ToString();
                    string strLINK_NO = dt.Rows[i]["LINK_NO"].ToString();
                    string s_DIFF_AMT = dt.Rows[i]["DIFF_AMT"].ToString();
                    string s_OTHER_DIFF = dt.Rows[i]["OTHER_DIFF"].ToString();
                    string s_REMIT_DIFF = dt.Rows[i]["REMIT_DIFF"].ToString();
                    string strWASH_AMT = dt.Rows[i]["WASH_AMT"].ToString();

                    int iDIFF_AMT = 0;

                    string strCREATEDATE = dt.Rows[i]["CREATEDATE"].ToString();

                    string strErrMsg = "";

                    //檢查該筆資料是否月結,若立沖帳已月結則不可進行次代轉ACCT沖帳處理
                    DateTime WASH_DATE = Convert.ToDateTime(dt.Rows[i]["WASH_DATE"]);
                    string strWASH_DATE = WASH_DATE.Year.ToString() + WASH_DATE.Month.ToString();

                    if (CheckClose(strWASH_DATE) == true)
                    {
                        strErrMsg += strWASH_DATE + "立沖帳已月結,";
                    }

                    if ((int.Parse(s_DIFF_AMT) != 0 || int.Parse(s_OTHER_DIFF) != 0 || int.Parse(s_REMIT_DIFF) != 0)
                        && (strWASH_TYPE == "1" || strWASH_TYPE == "2" || strWASH_TYPE == "3"))
                    {
                        iDIFF_AMT = int.Parse(s_DIFF_AMT) + int.Parse(s_OTHER_DIFF) + int.Parse(s_REMIT_DIFF);

                        int iCheckREMAIN_AMT_DIFF = CheckREMAIN_AMT(strWASH_NO, strWASH_TYPE, Convert.ToString(iDIFF_AMT * -1));


                        if (iCheckREMAIN_AMT_DIFF == 0)
                            strErrMsg += "找不到符合的沖帳號碼資料或該筆資料已結案,";
                        else if (iCheckREMAIN_AMT_DIFF == 1)
                            strErrMsg += "沖帳差異金額造成沖帳餘額不足,";
                    }

                    DataRow[] Find_C = dt.Select("[CUBE_NO]='" + strCUBE_NO + "'");

                    int sum_Wash_Amt_C = 0;

                    if (Find_C.Length > 1)
                    {
                        foreach (DataRow dr in Find_C)
                        {
                            sum_Wash_Amt_C += int.Parse(dr["WASH_AMT"].ToString());
                        }

                    }
                    else
                    {
                        sum_Wash_Amt_C = int.Parse(strWASH_AMT);
                    }

                    int iCheckREMAIN_AMT_C = CheckREMAIN_AMT(strCUBE_NO, "6", sum_Wash_Amt_C.ToString());
                    
                    if (iCheckREMAIN_AMT_C == 0)
                        strErrMsg += "找不到符合的發票號碼資料或該筆資料已結案,";
                    else if (iCheckREMAIN_AMT_C == 1)
                        strErrMsg += "發票餘額不足,";


                    DataRow[] FindDbls = dt.Select("[WASH_NO]='" + strWASH_NO + "'");

                    int sum_Wash_Amt=0;

                    if (FindDbls.Length > 1)
                    {
                        foreach (DataRow dr in FindDbls)
                        {
                            sum_Wash_Amt += int.Parse(dr["WASH_AMT"].ToString()) - int.Parse(dr["DIFF_AMT"].ToString()) -
                                               int.Parse(dr["OTHER_DIFF"].ToString()) - int.Parse(dr["REMIT_DIFF"].ToString());
                        }

                    }
                    else
                    {
                        sum_Wash_Amt = int.Parse(strWASH_AMT) - iDIFF_AMT;
                    }


                    int iCheckREMAIN_AMT_W = CheckREMAIN_AMT(strWASH_NO, strWASH_TYPE, Convert.ToString(sum_Wash_Amt));                   

                    if (iCheckREMAIN_AMT_W == 0)
                        strErrMsg += "找不到符合的沖帳號碼資料或該筆資料已結案,";
                    else if (iCheckREMAIN_AMT_W == 1)
                        strErrMsg += "沖帳餘額不足,";

                    string str_Chk = "";

                    if (strLINK_TYPE != "0")
                    {
                        str_Chk = DBO.Check_No(strLINK_NO, strLINK_TYPE).ToString();
                    }
                    else
                    {
                        str_Chk = DBO.Check_No(strLINK_NO, strWASH_TYPE).ToString();
                    }

                    if (str_Chk == "0")
                    {
                        strErrMsg += "找不到關連號碼或該關連號碼已結案,";
                    }

                    if (strErrMsg != "")
                    {
                        strErrMsg = strErrMsg.Substring(0, strErrMsg.Length - 1);//去除最後一個逗點
                        ParameterList.Clear();
                        ParameterList.Add(strID);
                        ParameterList.Add("2");
                        ParameterList.Add("1");
                        ParameterList.Add(strErrMsg);
                        ParameterList.Add(strCREATEUID);
                        DBO.Update_Tmp(ParameterList, null);
                    }
                }

                ParameterList.Clear();
                ParameterList.Add(strCREATEUID);
                DBO.CheckImport(ParameterList,null);

                ParameterList.Clear();
                ParameterList.Add(strCREATEUID);
                ParameterList.Add("");
                DataTable dtTmp = DBO.QueryTmp(ParameterList);

                DataRow[] FindRows;
                FindRows = dtTmp.Select("STATUS='2'");
                int iWrong = FindRows.Length;

                if (iWrong == 0)
                {
                    Conn = USEDB.CreateConnection();
                    Conn.Open();
                    DBT = Conn.BeginTransaction();

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        string strID = dt.Rows[i]["ID"].ToString();
                        string strWASH_DATE = dt.Rows[i]["WASH_DATE"].ToString();
                        string strCUBE_NO = dt.Rows[i]["CUBE_NO"].ToString();
                        string strWASH_TYPE = dt.Rows[i]["WASH_TYPE"].ToString();
                        string strWASH_NO = dt.Rows[i]["WASH_NO"].ToString();
                        string strLINK_TYPE = dt.Rows[i]["LINK_TYPE"].ToString();
                        string strLINK_NO = dt.Rows[i]["LINK_NO"].ToString();
                        string s_DIFF_AMT = dt.Rows[i]["DIFF_AMT"].ToString();
                        string s_OTHER_DIFF = dt.Rows[i]["OTHER_DIFF"].ToString();
                        string s_REMIT_DIFF = dt.Rows[i]["REMIT_DIFF"].ToString();
                        string strWASH_AMT = dt.Rows[i]["WASH_AMT"].ToString();
                        int iDIFF_AMT = 0;

                        
                        if ((int.Parse(s_DIFF_AMT) != 0 || int.Parse(s_OTHER_DIFF) != 0 || int.Parse(s_REMIT_DIFF) != 0)
                            && (strWASH_TYPE == "1" || strWASH_TYPE == "2" || strWASH_TYPE == "3"))
                        {
                            iDIFF_AMT = int.Parse(s_DIFF_AMT) + int.Parse(s_OTHER_DIFF) + int.Parse(s_REMIT_DIFF);
                        }

                        //Update Diff
                        if (iDIFF_AMT!=0)
                        {
                            ParameterList.Clear();
                            ParameterList.Add(strWASH_TYPE);
                            ParameterList.Add(strWASH_NO);
                            ParameterList.Add(s_DIFF_AMT);//尾差
                            ParameterList.Add(s_OTHER_DIFF);//其他差異
                            ParameterList.Add(s_REMIT_DIFF);//匯兌差異
                            ParameterList.Add(strCREATEUID);

                            DBO.UPDATE_DIFF(ParameterList, DBT);
                        }

                        //Update Remain Amt(cube)
                        {

                            ParameterList.Clear();
                            ParameterList.Add(strWASH_AMT);
                            ParameterList.Add("6");
                            ParameterList.Add(strCUBE_NO);
                            ParameterList.Add(strCREATEUID);
                            DBO.UPDATE_REMAIN_AMT(ParameterList, DBT);
                        }

                        //Update Remain Amt(wash)
                        {

                            ParameterList.Clear();
                            ParameterList.Add(strWASH_AMT);
                            ParameterList.Add(strWASH_TYPE);
                            ParameterList.Add(strWASH_NO);
                            ParameterList.Add(strCREATEUID);
                            DBO.UPDATE_REMAIN_AMT(ParameterList, DBT);
                        }
                        //CONNECT_MAIN
                        {
                            string V_CUBE_NO = "";
                            string V_CUBE_TYPE = "1";
                            string V_WASH_NO = "";
                            string V_WASH_TYPE = "";
                            string V_LINK_NO = "";
                            string V_LINK_TYPE = "";
                            string V_WASH_AMT = "";
                            string V_SOURCE_TYPE = "1";
                            string V_WASH_DATE = "";

                            V_CUBE_NO = strCUBE_NO;
                            V_WASH_NO = strWASH_NO;
                            V_WASH_TYPE = strWASH_TYPE;
                            V_LINK_TYPE = strLINK_TYPE;
                            V_LINK_NO = strLINK_NO;
                            V_WASH_AMT = strWASH_AMT;
                            V_WASH_DATE = strWASH_DATE;

                            ParameterList.Clear();
                            ParameterList.Add(V_WASH_DATE);
                            ParameterList.Add(V_CUBE_NO);
                            ParameterList.Add(V_CUBE_TYPE);
                            ParameterList.Add(V_WASH_NO);
                            ParameterList.Add(V_WASH_TYPE);
                            ParameterList.Add(V_LINK_NO);
                            ParameterList.Add(V_LINK_TYPE);
                            ParameterList.Add(V_WASH_AMT);
                            ParameterList.Add(V_SOURCE_TYPE);
                            ParameterList.Add(strCREATEUID);
                            DBO.Add_CONNECT(ParameterList, DBT);

                            ParameterList.Clear();
                            ParameterList.Add(strID);
                            ParameterList.Add("1");
                            ParameterList.Add("2");
                            ParameterList.Add("");
                            ParameterList.Add(strCREATEUID);
                            DBO.Update_Tmp(ParameterList, DBT);
                        }

                        iRight++;
                    }
                    DBT.Commit();
                    arl_Return.Add("TRUE");
                    arl_Return.Add(iTotal);
                    arl_Return.Add(iRight);
                    arl_Return.Add(iWrong);
                }
                else
                {
                    arl_Return.Add("TRUE");
                    arl_Return.Add(iTotal);
                    arl_Return.Add(iRight);
                    arl_Return.Add(iWrong);
                }
            }
            catch (Exception ex)
            {

                arl_Return.Add("FALSE");
                arl_Return.Add(ex.Message);
                //獨立呼叫Transcation失敗
                DBT.Rollback();
            }
            finally
            {

                if (Conn.State == ConnectionState.Connecting)
                {
                    Conn.Close();
                }


            }
            return arl_Return;
        }
Beispiel #2
0
 private int CheckREMAIN_AMT(string strSecond_NO, string strSOURCE_TYPE, string strWASH_AMT_TOT)
 {
     int iResult = 0; //0.無資料 1.沖帳總額不足 2.OK
     ArrayList ParameterList = new ArrayList();
     try
     {
         CAA_38DBO DBO = new CAA_38DBO(ref USEDB);
         ParameterList.Clear();
         ParameterList.Add(strSOURCE_TYPE);
         ParameterList.Add(strSecond_NO);
         DataTable dt = DBO.QueryREMAIN_AMT(ParameterList);
         if (dt.Rows.Count > 0)
         {
             if (int.Parse(dt.Rows[0]["REMAIN_AMT"].ToString()) < int.Parse(strWASH_AMT_TOT))
             {
                 iResult = 1;
             }
             else
             {
                 iResult = 2;
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return iResult;
 }
Beispiel #3
0
 public DataTable QueryTmp(ArrayList ParameterList)
 {
     try
     {
         CAA_38DBO DBO = new CAA_38DBO(ref USEDB);
         DataTable dt = DBO.QueryTmp(ParameterList);
         return dt;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #4
0
        public ArrayList FileToTmp(DataSet ds_Excel, DateTime d_CreateDate, string s_LoginUser, string s_DBConnString, string s_AP_FileName)
        {
            ArrayList arl_Return = new ArrayList();
            int i_FileToTemp_Total_count = 0;
            int ChkCount = 0;
            string strErrMsg = "";
            Int32 iErrCount = 0;
            int iVal;
            ArrayList ParameterList = new ArrayList();
            try
            {
                ParameterList.Clear();

                CAA_38DBO DBO = new CAA_38DBO(ref USEDB);

                #region 先清除前一次,同一使用者執行的匯入暫存資訊與錯誤資訊

                ParameterList.Clear();
                ParameterList.Add(s_LoginUser);
                DBO.DeleteTmp(ParameterList);

                #endregion

                Conn = USEDB.CreateConnection();
                Conn.Open();
                DBT = Conn.BeginTransaction();

                int i = 0;

                foreach (DataRow dRow in ds_Excel.Tables[0].Rows)
                {
                    iErrCount = 0;
                    i = i + 1;

                    int V_ID = i;
                    string V_STATUS = "";
                    string V_DATASOURCE = s_AP_FileName;
                    string V_DATATYPE = "1";
                    string V_ERRORMEMO = "";

                    string V_WASH_DATE = dRow["沖帳日期"].ToString().Trim();
                    string V_CUBE_NO = dRow["發票號碼"].ToString().Trim();
                    string V_WASH_NO = dRow["沖帳號碼"].ToString().Trim();
                    string V_LINK_NO = dRow["關連號碼"].ToString().Trim();
                    string s_DIFF_AMT = dRow["尾差"].ToString();
                    string s_OTHER_DIFF = dRow["其他差異"].ToString();
                    string s_REMIT_DIFF = dRow["匯兌損益"].ToString();
                    string V_WASH_AMT = dRow["沖帳金額"].ToString().Trim();

                    string V_WASH_TYPE = string.Empty;
                    string V_LINK_TYPE = string.Empty;

                    strErrMsg = "";

                    DateTime dtTEMP;//檢查日期格式用的 不會真正使用此變數

                    #region 沖帳日期檢核
                    if (V_WASH_DATE == string.Empty)
                    {
                        strErrMsg += "沖帳日期欄位為必填,";
                    }
                    else if (DateTime.TryParseExact(V_WASH_DATE, "yyyyMMdd", null, DateTimeStyles.None, out dtTEMP) == false)
                    {
                        strErrMsg += "沖帳日期格式錯誤,";
                        V_WASH_DATE = "";
                    }
                    else 
                    {
                        string V_WASH_MONTH = V_WASH_DATE.Substring(0, 6);

                        //檢查該筆資料是否月結,若立沖帳已月結則不可進行沖帳處理
                        if (CheckClose(V_WASH_MONTH) == true)
                        {
                            strErrMsg += V_WASH_MONTH + "立沖帳已月結,";
                        }

                        DateTime.TryParseExact(V_WASH_DATE, "yyyyMMdd", null, DateTimeStyles.None, out dtTEMP);

                        if (DateTime.Compare(dtTEMP, DateTime.Now) > 0)
                        {
                            strErrMsg += "沖帳日期不可大於系統日,";
                        }
                    }

                    #endregion

                    #region 發票號碼檢核
                    if (V_CUBE_NO == string.Empty)
                    {
                        strErrMsg += "發票號碼欄位為必填,";
                    }
                    else 
                    {
                        if (CheckLength(V_CUBE_NO, 14, "發票號碼", strErrMsg, iErrCount, out  strErrMsg, out  iErrCount) == false)
                        {
                            //超過DB欄位
                            V_CUBE_NO = SubStr(V_CUBE_NO, 0, 14);
                        }
                        else
                        {
                            string str_Chk = DBO.Check_No(V_CUBE_NO, "6").ToString();

                            if (str_Chk != "1")
                            {
                                strErrMsg += "找不到發票號碼或該發票號碼已結案/作廢,";
                            }
                        }

                    }

                    #endregion


                    #region 沖帳號碼檢核
                    if (V_WASH_NO == string.Empty)
                    {
                        strErrMsg += "沖帳號碼欄位為必填,";
                    }
                    else
                    {
                        if (CheckLength(V_WASH_NO, 14, "沖帳號碼", strErrMsg, iErrCount, out  strErrMsg, out  iErrCount) == false)
                        {
                            //超過DB欄位
                            V_WASH_NO = SubStr(V_WASH_NO, 0, 14);
                        }
                        else
                        {

                            if (V_WASH_NO.Substring(0, 2) == "CR")
                            {
                                V_WASH_TYPE = "1";
                            }
                            else if (V_WASH_NO.Substring(0, 2) == "BR")
                            {
                                V_WASH_TYPE = "2";
                            }
                            else if (V_WASH_NO.Substring(0, 2) == "DR")
                            {
                                V_WASH_TYPE = "3";
                            }
                            else if (V_WASH_NO.Substring(0, 2) == "TR")
                            {
                                V_WASH_TYPE = "5";
                            }
                            else if (SubStr(V_WASH_NO, 0, 1) == "W" || SubStr(V_WASH_NO, 0, 1) == "Z")
                            {
                                V_WASH_TYPE = "4";
                            }
                            else
                            {
                                V_WASH_TYPE = string.Empty;
                                strErrMsg += "沖帳單號錯誤,";
                            }

                            if (V_WASH_TYPE == "1" || V_WASH_TYPE == "2" || V_WASH_TYPE == "3")
                            {
                                if (V_WASH_NO != V_LINK_NO)
                                {
                                    strErrMsg += "沖帳單據為支票/代收/應收應付調整時關連號碼應與沖帳號碼相同,";
                                }
                            }
                            else if ( V_WASH_TYPE == "5")
                            {
                                if (V_WASH_NO == V_LINK_NO)
                                {
                                    strErrMsg += "沖帳單據為暫收時關連號碼不可與沖帳號碼相同,";
                                }                            
                            }
                            else if (V_WASH_TYPE == "4")
                            {
                                if (V_WASH_NO == V_LINK_NO)
                                {
                                    strErrMsg += "沖帳單據為折讓時關連號碼不可與沖帳號碼相同,";
                                }
                                else
                                {

                                    #region 憑證未回判斷

                                    int i_Check_Flg = 0;

                                    CAACommon CAAComm = new CAACommon();
                                    CAA_32DBO DBO1 = new CAA_32DBO(ref USEDB);

                                    ParameterList.Clear();
                                    ParameterList.Add(CAAComm.GetValueSetParameter(V_WASH_NO, "string", false));//[折讓單號]
                                    ParameterList.Add(CAAComm.GetValueSetParameter(s_LoginUser, "string", false));//[登入人員]

                                    i_Check_Flg = DBO1.CHECK_DISC_MAIN_FLG(ParameterList);

                                    if (i_Check_Flg != 1)
                                    { strErrMsg += "此筆貨找不到折讓資料或尚未憑證已回,故不允許匯入,"; }

                                    #endregion
                                
                                }
                            }
                        }

                        //若已經有來源別錯誤時可避免進入判斷造成系統錯誤
                        if (strErrMsg == "")
                        {
                            string str_Chk = DBO.Check_No(V_WASH_NO, V_WASH_TYPE).ToString();

                            if (str_Chk != "1")
                            {
                                strErrMsg += "找不到沖帳號碼或該沖帳號碼已結案/作廢/退票/轉暫收/轉其他收入,";
                            }
                        }

                    }
                    #endregion


                    #region 關連號碼檢核
                    if (V_LINK_NO == string.Empty)
                    {
                        strErrMsg += "關連號碼欄位為必填,";
                    }
                    else
                    {
                        if (CheckLength(V_LINK_NO, 14, "關連號碼", strErrMsg, iErrCount, out  strErrMsg, out  iErrCount) == false)
                        {
                            //超過DB欄位
                            V_LINK_NO = SubStr(V_LINK_NO, 0, 14);
                        }
                        else
                        {
                            if (V_WASH_TYPE == "4" || V_WASH_TYPE == "5")
                            {

                                if (V_LINK_NO.Substring(0, 2) == "CR")
                                {
                                    V_LINK_TYPE = "1";
                                }
                                else if (V_LINK_NO.Substring(0, 2) == "BR")
                                {
                                    V_LINK_TYPE = "2";
                                }
                                else if (V_LINK_NO.Substring(0, 2) == "DR")
                                {
                                    V_LINK_TYPE = "3";

                                    DataRow[] FindDbls = ds_Excel.Tables[0].Select("[發票號碼]='" + V_CUBE_NO + "' AND [關連號碼]='" + V_LINK_NO + "' AND [沖帳號碼]='" + V_LINK_NO + "'");
                                    if (FindDbls.Length !=1)
                                        strErrMsg += "缺少發票沖應收應付調整資料(請參考範例補上),";
                                }
                                else
                                {
                                    V_LINK_TYPE = string.Empty;
                                    strErrMsg += "關連單號錯誤,";
                                }
                            }
                            else
                            {
                                V_LINK_TYPE = "0";
                            }

                        }

                        //若已經有來源別錯誤時可避免進入判斷造成系統錯誤
                        if (strErrMsg == "")
                        {
                            string str_Chk = "0";

                            if (V_LINK_TYPE == "0")
                            {
                                //沖帳資料為支票/代收/應收應付時,沖帳號碼與關連號碼相同
                                str_Chk = DBO.Check_No(V_LINK_NO, V_WASH_TYPE).ToString();
                            }
                            else
                            {
                                str_Chk = DBO.Check_No(V_LINK_NO, V_LINK_TYPE).ToString();
                            }

                            if (str_Chk != "1")
                            {
                                strErrMsg += "找不到關連號碼或該關連號碼已結案/作廢/退票/轉暫收/轉其他收入,";
                            }
                        }

                    }
                    #endregion


                    #region 尾差

                    if (s_DIFF_AMT == string.Empty)
                    {
                        strErrMsg += "尾差欄位為必填且為數值型態,";
                        s_DIFF_AMT = "0";
                    }
                    else if (CheckLength(s_DIFF_AMT, 3, "尾差", strErrMsg, iErrCount, out  strErrMsg, out  iErrCount) == false)
                    {
                        //超過DB欄位
                        strErrMsg += "尾差數值過大,";
                        s_DIFF_AMT = "0";
                    }
                    else if (int.TryParse(s_DIFF_AMT, out iVal) == false)
                    {
                        strErrMsg += "尾差必須為數值型態,";
                        s_DIFF_AMT = "0";
                    }

                    #endregion

                    #region 其他差異

                    if (s_OTHER_DIFF == string.Empty)
                    {
                        strErrMsg += "其他差異欄位為必填且為數值型態,";
                        s_OTHER_DIFF = "0";
                    }
                    else if (CheckLength(s_OTHER_DIFF, 8, "其他差異", strErrMsg, iErrCount, out  strErrMsg, out  iErrCount) == false)
                    {
                        //超過DB欄位
                        strErrMsg += "其他差異數值過大,";
                        s_OTHER_DIFF = "0";
                    }
                    else if (int.TryParse(s_OTHER_DIFF, out iVal) == false)
                    {
                        strErrMsg += "其他差異必須為數值型態,";
                        s_OTHER_DIFF = "0";
                    }

                    #endregion

                    #region 匯兌損益

                    if (s_REMIT_DIFF == string.Empty)
                    {
                        strErrMsg += "匯兌損益欄位為必填且為數值型態,";
                        s_REMIT_DIFF = "0";
                    }
                    else if (CheckLength(s_REMIT_DIFF, 8, "匯兌損益", strErrMsg, iErrCount, out  strErrMsg, out  iErrCount) == false)
                    {
                        //超過DB欄位
                        strErrMsg += "匯兌損益數值過大,";
                        s_REMIT_DIFF = "0";
                    }
                    else if (int.TryParse(s_REMIT_DIFF, out iVal) == false)
                    {
                        strErrMsg += "匯兌損益必須為數值型態,";
                        s_REMIT_DIFF = "0";
                    }

                    #endregion

                    #region 沖帳金額檢核

                    if (V_WASH_AMT == string.Empty)
                    {
                        strErrMsg += "沖帳金額欄位為必填且為數值型態,";
                        V_WASH_AMT = "0";
                    }
                    else if (CheckLength(V_WASH_AMT, 12, "沖帳金額", strErrMsg, iErrCount, out  strErrMsg, out  iErrCount) == false)
                    {
                        //超過DB欄位
                        V_WASH_AMT = "0";
                        strErrMsg += "沖帳金額過大,";
                    }
                    else if (int.TryParse(V_WASH_AMT, out iVal) == false)
                    {
                        strErrMsg += "沖帳金額必須為數值型態,";
                        V_WASH_AMT = "0";
                    }
                    else if (int.Parse(V_WASH_AMT) <0)
                    {
                        strErrMsg += "沖帳金額必須為正整數,";
                        V_WASH_AMT = "0";
                    }

                    #endregion


                    #region 餘額檢核
                    if (strErrMsg == "")
                    {
                        int V_DIFF_AMT = 0;


                        if (int.Parse(s_DIFF_AMT) != 0 || int.Parse(s_OTHER_DIFF) != 0 || int.Parse(s_REMIT_DIFF) != 0)
                        {

                            if (V_WASH_TYPE == "1" || V_WASH_TYPE == "2" || V_WASH_TYPE == "3")
                            {
                                V_DIFF_AMT = int.Parse(s_DIFF_AMT) + int.Parse(s_OTHER_DIFF) + int.Parse(s_REMIT_DIFF);

                                int iCheckREMAIN_AMT_DIFF = CheckREMAIN_AMT(V_WASH_NO, V_WASH_TYPE, (V_DIFF_AMT * -1).ToString());
                                if (iCheckREMAIN_AMT_DIFF == 0)
                                    strErrMsg += "找不到符合的沖帳號碼或該號碼已結案,";
                                else if (iCheckREMAIN_AMT_DIFF == 1)
                                    strErrMsg += "差異金額對應沖帳號碼餘額不足,";
                            }
                            else
                            {
                                strErrMsg += "沖帳單據類型無法新增尾差/其他差異/匯兌損益,";

                                s_DIFF_AMT = "0";
                                s_OTHER_DIFF = "0";
                                s_REMIT_DIFF = "0";
                            }

                        }

                        int iCheckREMAIN_AMT = CheckREMAIN_AMT(V_CUBE_NO, "6", V_WASH_AMT);
                        if (iCheckREMAIN_AMT == 0)
                        {
                            strErrMsg += "找不到符合的發票號碼或該號碼已結案,";
                        }
                        else if (iCheckREMAIN_AMT == 1)
                        {
                            strErrMsg += "發票餘額不足,";
                        }

                        int jCheckREMAIN_AMT = CheckREMAIN_AMT(V_WASH_NO, V_WASH_TYPE, Convert.ToString(int.Parse(V_WASH_AMT) - V_DIFF_AMT));
                        if (jCheckREMAIN_AMT == 0)
                        {
                            strErrMsg += "找不到符合的沖帳號碼或該號碼已結案,";
                        }
                        else if (jCheckREMAIN_AMT == 1)
                        {
                            strErrMsg += "沖帳餘額不足,";
                        }


                    }

                    #endregion

                    #region 資料重覆判斷
                    DataRow[] FindDbls1 = ds_Excel.Tables[0].Select("[發票號碼]='" + V_CUBE_NO + "' AND [沖帳號碼]='" + V_WASH_NO + "' AND [關連號碼]='" + V_LINK_NO + "'");
                    if (FindDbls1.Length > 1)
                        strErrMsg += "有重覆資料,";
                    if (strErrMsg == "")
                    {
                        V_STATUS = "1";
                    }
                    else
                    {
                        V_STATUS = "2";
                        strErrMsg = strErrMsg.Substring(0, strErrMsg.Length - 1);//去除最後一個逗點
                    }

                    #endregion

                    V_ERRORMEMO = strErrMsg;
                    ParameterList.Clear();
                    ParameterList.Add(V_ID); //0.N_ID
                    ParameterList.Add(V_STATUS);        //1.V_STATUS     1:正常資料; 2:錯誤資料				
                    ParameterList.Add(V_DATASOURCE);    //2.V_DATASOURCE 匯入檔名/TMP檔名
                    ParameterList.Add(V_DATATYPE);      //3.V_DATATYPE  
                    ParameterList.Add(V_ERRORMEMO);     //4.V_ERRORMEMO 
                    ParameterList.Add(V_WASH_DATE);    //5.V_WASH_DATE  沖帳日期
                    ParameterList.Add(V_CUBE_NO);     
                    ParameterList.Add(V_WASH_NO);   
                    ParameterList.Add(V_WASH_TYPE);  
                    ParameterList.Add(V_LINK_NO);   
                    ParameterList.Add(V_LINK_TYPE);  						
                    ParameterList.Add(s_DIFF_AMT);      
                    ParameterList.Add(s_OTHER_DIFF); 
                    ParameterList.Add(s_REMIT_DIFF);  
                    ParameterList.Add(V_WASH_AMT);
                    ParameterList.Add(s_LoginUser);    

                    DBO.Add_Tmp(ParameterList, DBT);
                    i_FileToTemp_Total_count += 1;
                }

                ParameterList.Clear();
                ParameterList.Add(s_LoginUser);
                DBO.CheckImport(ParameterList,DBT);

                DBT.Commit();

                //取得匯入TMP 的資料
                int i_FileToTemp_Right_count = 0;
                int i_FileToTemp_Wrong_count = 0;

                ParameterList.Clear();
                ParameterList.Add(s_LoginUser);
                ParameterList.Add("");

                DataTable dtTmp = DBO.QueryTmp(ParameterList);

                DataRow[] FindRows;
                FindRows = dtTmp.Select("STATUS='1'");
                i_FileToTemp_Right_count = FindRows.Length;
                FindRows = dtTmp.Select("STATUS='2'");
                i_FileToTemp_Wrong_count = FindRows.Length;

                arl_Return.Add("TRUE");
                arl_Return.Add(i_FileToTemp_Total_count);
                arl_Return.Add(i_FileToTemp_Right_count);
                arl_Return.Add(i_FileToTemp_Wrong_count);
            }
            catch (Exception ex)
            {

                arl_Return.Add("FALSE");
                arl_Return.Add(ex.Message);
                //獨立呼叫Transcation失敗
                DBT.Rollback();
            }
            finally
            {

                if (Conn.State == ConnectionState.Connecting)
                {
                    Conn.Close();
                }


            }
            return arl_Return;
        }