Exemple #1
0
    public void Begin2(string path, string sKind0, ErrorInfoModel errorInfo, string identityKey)
    {
        if (!string.IsNullOrEmpty(sKind0))
        {
            sKind0 = sKind0.ToUpper();
        }
        string[] sArr;
        using (SQL1 sqlAdapter = new SQL1())
        { sqlAdapter.ReturnArr(out sArr); }
        string sPaPartition = sArr[3];

        using (SQL1 sqlAdapter = new SQL1())
        {
            List <EinvoiceC0701Temp> tempData = new List <EinvoiceC0701Temp>();
            var query = sqlAdapter.Kind1SelectTbl2("*", "FILE_TEMP", " EINVOICE_TP='C0701' and IDENT_KEY = '" + identityKey + "'", "", "");
            if (query != null)
            {
                var rows = query.Table.Rows;
                for (int i = 0; i < rows.Count; i++)
                {
                    tempData.Add(new EinvoiceC0701Temp()
                    {
                        EinvoiceContent  = rows[i]["FILE_CONTENT"].ToString(),
                        EinvoiceFIlePath = rows[i]["FILE_NM"].ToString(),
                    });
                }
            }
            else
            {
                return;
            }
            string sPgSN = DateTime.Now.ToString("yyyyMMddHHmmssfff");

            sqlAdapter.GoLogsAll(sPgSN, ProcessName, "FILE_TEMP", "", "", 1);

            foreach (var data in tempData)
            {
                int    index          = tempData.IndexOf(data) + 1;
                string sourceFile     = data.EinvoiceFIlePath;
                string einvoiceNumber = string.Empty;
                string errorMsg       = string.Empty;

                try
                {
                    string           line             = "";
                    List <Hashtable> einvoiceDataList = new List <Hashtable>();

                    line = data.EinvoiceContent;
                    if (line.Trim() != "")
                    {
                        string[] CutS  = { sPaPartition };
                        string[] charA = line.Split(CutS, StringSplitOptions.None);
                        einvoiceNumber = charA[0].ToUpper();
                        //字串尾要分號//共9個分號
                        if (charA.Length == 9)
                        {
                            if (sqlAdapter.Kind1SelectTbl3("D0501SN", "CancelAllowanceNumber='" + charA[0].ToString() + "'", "D0501") == 0)
                            {
                                Console.WriteLine(string.Format("{0} 寫入正式資料庫 第{1}筆 發票號碼:{2}開始.", sKind0, index, einvoiceNumber));

                                Hashtable hashData  = SetEinvoiceToHashtable(charA, sourceFile);
                                string    insertMsg = sqlAdapter.InsertDataNonKey("D0501", hashData);

                                #region 寫入有錯誤之處理

                                if (!string.IsNullOrEmpty(insertMsg))
                                {
                                    errorMsg = "[正式][" + sKind0 + "]" + einvoiceNumber + "[TXT寫入正式資料庫發生錯誤,資料不寫入]" + insertMsg;
                                    sqlAdapter.GoLogsAll(sPgSN, ProcessName, sourceFile, errorMsg, index.ToString(), 51, false);
                                    EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg, 2, 51, ref errorInfo, ProcessName);
                                }
                                else
                                {
                                    Console.WriteLine(string.Format("{0} 寫入正式資料庫 第{1}筆 發票號碼:{2}結束.", sKind0, index, einvoiceNumber));
                                }

                                #endregion 寫入有錯誤之處理
                            }
                            else
                            {
                                errorMsg = "[正式][作廢折讓證明單號碼:" + einvoiceNumber + "][此發票號碼已存在,資料不寫入]";
                                sqlAdapter.GoLogsAll(sPgSN, ProcessName, sourceFile, errorMsg, index.ToString(), 11, false);
                                EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg, 3, 11, ref errorInfo, ProcessName);
                            }
                        }
                        else
                        {
                            errorMsg = "[正式][作廢折讓證明單號碼:" + einvoiceNumber + "][字串尾要分號,共9個分號]";
                            sqlAdapter.GoLogsAll(sPgSN, ProcessName, sourceFile, "[正式]", index.ToString(), 12);
                            EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg, 4, 12, ref errorInfo, ProcessName);
                        }
                    }
                }
                catch (Exception ex)
                {
                    errorMsg = "[正式][未知錯誤]";
                    sqlAdapter.GoLogsAll(sPgSN, ProcessName, sourceFile, errorMsg + ex.ToString(), "", 15, false);
                    EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg, 5, 15, ref errorInfo, ProcessName);
                }
            }
            sqlAdapter.GoLogsAll(sPgSN, ProcessName, "FILE_TEMP", "", "", 2);
        }
    }
Exemple #2
0
    public void Begin2(string path, string sKind0, ErrorInfoModel errorInfo, string identityKey)
    {
        if (!string.IsNullOrEmpty(sKind0))
        {
            sKind0 = sKind0.ToUpper();
        }
        string[] sArr;
        using (SQL1 sqlAdapter = new SQL1())
        { sqlAdapter.ReturnArr(out sArr); }
        string sPaPartition = sArr[3];

        using (SQL1 sqlAdapter = new SQL1())
        {
            List <EinvoiceB0401DTemp> tempData = new List <EinvoiceB0401DTemp>();
            var query = sqlAdapter.Kind1SelectTbl2("*", "FILE_TEMP", " EINVOICE_TP='B0401D' and IDENT_KEY = '" + identityKey + "'", "", "");
            if (query != null)
            {
                var rows = query.Table.Rows;
                for (int i = 0; i < rows.Count; i++)
                {
                    tempData.Add(new EinvoiceB0401DTemp()
                    {
                        EinvoiceContent  = rows[i]["FILE_CONTENT"].ToString(),
                        EinvoiceFIlePath = rows[i]["FILE_NM"].ToString(),
                    });
                }
            }
            else
            {
                return;
            }
            string sPgSN = DateTime.Now.ToString("yyyyMMddHHmmssfff");

            sqlAdapter.GoLogsAll(sPgSN, ProcessName, "FILE_TEMP", "", "", 1);
            //抓 B0401D*.* 的所有檔案
            foreach (var data in tempData)
            {
                int    index               = tempData.IndexOf(data) + 1;
                string sourceFile          = data.EinvoiceFIlePath;
                string einvoiceNumber      = string.Empty;
                string einvoiceDescription = string.Empty;
                string errorMsg            = string.Empty;

                try
                {
                    string           line             = "";
                    List <Hashtable> einvoiceDataList = new List <Hashtable>();

                    line = data.EinvoiceContent;
                    if (line.Trim() != "")
                    {
                        string[] CutS  = { sPaPartition };
                        string[] charA = line.Split(CutS, StringSplitOptions.None);
                        einvoiceNumber      = charA[0];
                        einvoiceDescription = charA[1];
                        //字串尾要分號//共13個分號
                        if (charA.Length == 13)
                        {
                            #region 檢查Head有無寫入資料 有的話不寫入明細

                            var chkHeadHasError = EinvoiceRepository.CheckHeadHasError(sKind0, einvoiceNumber, errorInfo);

                            if (chkHeadHasError)
                            {
                                errorMsg = "[正式][" + sKind0 + "]" + einvoiceNumber + "[折讓證明單Head寫入時有錯,明細資料不寫入]";
                                EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg, 1, 51, ref errorInfo, ProcessName, sourceFile, einvoiceDescription);
                                continue;
                            }

                            #endregion 檢查Head有無寫入資料 有的話不寫入明細

                            if (sqlAdapter.Kind1SelectTbl3("B0401DSN", "MAllowanceNumber='" + charA[0].ToString() + "' And DAllowanceSequenceNumber='" + charA[10].ToString() + "'", "B0401D") == 0)
                            {
                                if (charA[1].ToString().Trim() != "" && charA[2].ToString().Trim() != "")
                                {
                                    Console.WriteLine(string.Format("{0} 寫入正式資料庫 第{1}筆 發票號碼:{2}開始.", sKind0, index, einvoiceNumber));

                                    Hashtable hashTable = new Hashtable();
                                    hashTable["MAllowanceNumber"]        = charA[0].ToString().Trim();
                                    hashTable["DOriginalInvoiceDate"]    = charA[1].ToString().Trim();
                                    hashTable["DOriginalInvoiceNumber"]  = charA[2].ToString().Trim();
                                    hashTable["DOriginalSequenceNumber"] = charA[3].ToString().Trim();
                                    hashTable["DOriginalDescription"]    = charA[4].ToString().Trim();
                                    hashTable["DQuantity"]  = charA[5].ToString().Trim();
                                    hashTable["DUnit"]      = charA[6].ToString().Trim();
                                    hashTable["DUnitPrice"] = charA[7].ToString().Trim();
                                    hashTable["DAmount"]    = charA[8].ToString().Trim();
                                    hashTable["DTax"]       = charA[9].ToString().Trim();
                                    hashTable["DAllowanceSequenceNumber"] = charA[10].ToString().Trim();
                                    hashTable["DTaxType"]   = charA[11].ToString().Trim();
                                    hashTable["TxFileNmae"] = sourceFile;
                                    string insertMsg = sqlAdapter.InsertDataNonKey("B0401D", hashTable);

                                    #region 寫入有錯誤之處理

                                    if (!string.IsNullOrEmpty(insertMsg))
                                    {
                                        errorMsg = "[正式][" + sKind0 + "]" + einvoiceNumber + "[TXT寫入正式資料庫發生錯誤,資料不寫入]" + insertMsg;
                                        EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg, 2, 51, ref errorInfo, ProcessName, sourceFile, einvoiceDescription);
                                    }
                                    else
                                    {
                                        Console.WriteLine(string.Format("{0} 寫入正式資料庫 第{1}筆 發票號碼:{2}結束.", sKind0, index, einvoiceNumber));
                                    }

                                    #endregion 寫入有錯誤之處理
                                }
                                else
                                {
                                    errorMsg = "[MInvoiceNumber:" + charA[0].ToString().Trim() + "][明細排列序號:" + charA[10].ToString().Trim() + "]";
                                    EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg + "[必要欄位沒值!!][DOriginalInvoiceDate][DOriginalInvoiceNumber]", 3, 17, ref errorInfo, ProcessName, sourceFile, einvoiceDescription);
                                }
                            }
                            else
                            {
                                errorMsg = "[MInvoiceNumber:" + charA[0].ToString().Trim() + "][明細排列序號:" + charA[10].ToString().Trim() + "]";
                                EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg + "[匯入商品細項的文字檔發生錯誤/此商品已存在!!]", 3, 16, ref errorInfo, ProcessName, sourceFile, einvoiceDescription);
                            }
                        }
                        else
                        {
                            errorMsg = "[正式][折讓證明單號碼:" + einvoiceNumber + "][字串尾要分號,共10個分號]";
                            EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg, 4, 12, ref errorInfo, ProcessName, sourceFile, einvoiceDescription);
                        }
                    }
                    else
                    {
                        errorMsg = "[正式][折讓證明單號碼:" + einvoiceNumber + "][讀取資料內容為空白]";
                        EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg, 4, 12, ref errorInfo, ProcessName, sourceFile, einvoiceDescription);
                    }
                }
                catch (Exception ex)
                {
                    errorMsg = "[正式][未知錯誤]";
                    EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg, 5, 15, ref errorInfo, ProcessName, sourceFile, einvoiceDescription);
                }
            }
            sqlAdapter.GoLogsAll(sPgSN, ProcessName, "FILE_TEMP", "", "", 2);
            ValidDetailsHasError(errorInfo);
        }
    }
Exemple #3
0
    public void Begin2(string path, string sKind0, ErrorInfoModel errorInfo, string identityKey)
    {
        Dictionary <string, List <string> > pdfNumList = new Dictionary <string, List <string> >();

        if (!string.IsNullOrEmpty(sKind0))
        {
            sKind0 = sKind0.ToUpper();
        }
        string[] sArr;
        using (SQL1 sqlAdapter = new SQL1())
        { sqlAdapter.ReturnArr(out sArr); }

        string sPaPartition = sArr[3];

        using (var sqlAdapter = new SQL1())
        {
            List <EinvoiceA0401HTemp> tempData = new List <EinvoiceA0401HTemp>();
            var query = sqlAdapter.Kind1SelectTbl2("*", "FILE_TEMP", " EINVOICE_TP='A0401H' and IDENT_KEY = '" + identityKey + "'", "", "");
            if (query != null)
            {
                var rows = query.Table.Rows;
                for (int i = 0; i < rows.Count; i++)
                {
                    tempData.Add(new EinvoiceA0401HTemp()
                    {
                        EinvoiceContent  = rows[i]["FILE_CONTENT"].ToString(),
                        EinvoiceFIlePath = rows[i]["FILE_NM"].ToString(),
                    });
                }
            }
            else
            {
                return;
            }
            string sPgSN = DateTime.Now.ToString("yyyyMMddHHmmssfff");
            sqlAdapter.GoLogsAll(sPgSN, ProcessName, "FILE_TEMP", "", "", 1);

            foreach (var data in tempData)
            {
                int    index          = tempData.IndexOf(data) + 1;
                string sourceFile     = data.EinvoiceFIlePath;
                string einvoiceNumber = string.Empty;
                string errorMsg       = string.Empty;

                try
                {
                    string           line             = "";
                    List <Hashtable> einvoiceDataList = new List <Hashtable>();

                    line = data.EinvoiceContent;
                    if (line.Trim() != "")
                    {
                        string[] CutS  = { sPaPartition };
                        string[] charA = line.Split(CutS, StringSplitOptions.None);
                        einvoiceNumber = charA[0].ToUpper();
                        //字串尾要分號//共48個分號
                        if (charA.Length == 48)
                        {
                            if (sqlAdapter.Kind1SelectTbl3("A0401SN", "MInvoiceNumber='" + charA[0].ToString() + "'", "A0401H") == 0)
                            {
                                Console.WriteLine(string.Format("{0} 寫入正式資料庫 第{1}筆 發票號碼:{2}開始.", sKind0, index, einvoiceNumber));
                                Dictionary <bool, string> validErrorBuffer = ValidInvoiceData(charA);

                                if (validErrorBuffer.Count > 0 && validErrorBuffer.Keys.First() == false)
                                {
                                    errorMsg = validErrorBuffer.Values.First() + "[正式]驗證失敗,資料不寫入";
                                    sqlAdapter.GoLogsAll(sPgSN, ProcessName, sourceFile, errorMsg, index.ToString(), 11, false);
                                    EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg, 1, 11, ref errorInfo, ProcessName);
                                    continue;
                                }
                                Hashtable hashData  = SetEinvoiceToHashtable(charA, sourceFile);
                                string    insertMsg = sqlAdapter.InsertDataNonKey("A0401H", hashData);

                                #region 寫入有錯誤之處理

                                if (!string.IsNullOrEmpty(insertMsg))
                                {
                                    errorMsg = "[正式][" + sKind0 + "]" + einvoiceNumber + "[TXT寫入正式資料庫發生錯誤,資料不寫入]" + insertMsg;
                                    sqlAdapter.GoLogsAll(sPgSN, ProcessName, sourceFile, errorMsg, index.ToString(), 51, false);
                                    EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg, 2, 51, ref errorInfo, ProcessName);
                                    Console.WriteLine(errorMsg);
                                }
                                else
                                {
                                    if (!pdfNumList.ContainsKey(sKind0))
                                    {
                                        pdfNumList[sKind0] = new List <string>();
                                    }
                                    pdfNumList[sKind0].Add(einvoiceNumber);
                                    Console.WriteLine(string.Format("{0} 寫入正式資料庫 第{1}筆 發票號碼:{2}完成.", sKind0, index, einvoiceNumber));
                                }

                                #endregion 寫入有錯誤之處理
                            }
                            else
                            {
                                errorMsg = "[正式][發票號碼:" + einvoiceNumber + "][此發票號碼已存在,資料不寫入]";
                                sqlAdapter.GoLogsAll(sPgSN, ProcessName, sourceFile, errorMsg, index.ToString(), 11, false);
                                EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg, 3, 11, ref errorInfo, ProcessName);
                            }
                        }
                        else
                        {
                            errorMsg = "[正式][發票號碼:" + einvoiceNumber + "][字串尾要分號,共48個分號]";
                            sqlAdapter.GoLogsAll(sPgSN, ProcessName, sourceFile, "[正式]", index.ToString(), 12);
                            EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg, 4, 12, ref errorInfo, ProcessName);
                        }
                    }
                }
                catch (Exception ex)
                {
                    errorMsg = "[正式][未知錯誤]";
                    sqlAdapter.GoLogsAll(sPgSN, ProcessName, sourceFile, errorMsg + ex.ToString(), "", 15, false);
                    EinvoiceRepository.AddEinvoiceToErrorBuffer(sKind0, einvoiceNumber, errorMsg, 5, 15, ref errorInfo, ProcessName);
                }
            }
            sqlAdapter.GoLogsAll(sPgSN, ProcessName, "FILE_TEMP", "", "", 2);

            foreach (var inv in pdfNumList)
            {
                foreach (var item in inv.Value)
                {
                    Hashtable hashTable = new Hashtable();
                    hashTable["PRINT_METHOD"]   = inv.Key;
                    hashTable["PRINT_EINV_NUM"] = item;
                    //hashTable["MAKE_FILE_DATE"] = DateTime.UtcNow;
                    hashTable["WRITE_DATE"] = DateTime.UtcNow;
                    hashTable["IDEN_KEY"]   = identityKey;
                    string insertMsg = sqlAdapter.InsertDataNonKey("PRINT_TEMP", hashTable);
                }
            }
        }
    }