Exemplo n.º 1
0
        private void fnMakeSendData_KICC(DataTable dtTmp, string CompanyID_Resort, string CompanyID_Van)
        {
            try
            {
                int cnt_tot_11 = 0; /*일반건수    */
                int amt_tot_11 = 0; /*일반합계    */
                int cnt_tot_12 = 0; /*일반취소건수*/
                int amt_tot_12 = 0; /*일반취소합계*/
                int cnt_tot_21 = 0; /*할부건수    */
                int amt_tot_21 = 0; /*할부합계    */
                int cnt_tot_22 = 0; /*할부취소건수*/
                int amt_tot_22 = 0; /*할부취소합계*/

                /*☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*/
                //EDI START RECORD
                /*☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*/

                string MakeFileDate = System.DateTime.Now.ToString("yyMMdd");

                string str_EDI_START_RECORD = SendFormat.MakeRecord_EDI_Start_Record(MakeFileDate,
                                                                                     CompanyID_Resort,
                                                                                     CompanyID_Van);

                if (System.IO.File.Exists(Log.FilePath + "\\" + Log.FileName))
                {
                    System.IO.File.Delete(Log.FilePath + "\\" + Log.FileName);
                }


                if (str_EDI_START_RECORD.Length != 150)
                {
                    throw new Exception("CHECK FORMAT PLZ[EDI_START_RECORD]\n\r" + str_EDI_START_RECORD.Length);
                }

                EDI.Log.Log.SaveLog(str_EDI_START_RECORD);


                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                // 매입사별로 Groupby
                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                DataSetHelper helper = new Cls.GroupByHelper.DataSetHelper();

                DataTable dtCardGroupBy = helper.SelectGroupByInto("CARD_GROUPBY", dtTmp, "COMPANY_ID , VAN_ID", "", "COMPANY_ID , VAN_ID");

                for (int iCardGroup = 0; iCardGroup < dtCardGroupBy.Rows.Count; iCardGroup++)
                {
                    string companyid = dtCardGroupBy.Rows[iCardGroup]["COMPANY_ID"].ToString().Trim();
                    string vanid     = dtCardGroupBy.Rows[iCardGroup]["VAN_ID"].ToString().Trim();

                    //매입사 사업자번호로 그룹을 했다.
                    //가져온 데이터 테이블에서 사업자 번호로 데이터를 가져온다.
                    DataTable dtHeaderRecord = Basic.GetdtSelect(dtTmp, "VAN_ID = '" + vanid + "'", "AGREE_DATE ASC");

                    string SaleFrom = DateTime.Parse(dtHeaderRecord.Compute("MIN(AGREE_DATE)", "VAN_ID = '" + vanid + "' ").ToString()).ToString("yyMMdd");
                    string SaleTo   = DateTime.Parse(dtHeaderRecord.Compute("MAX(AGREE_DATE)", "VAN_ID = '" + vanid + "' ").ToString()).ToString("yyMMdd");

                    /*☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*/
                    //  header
                    /*☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*/

                    string str_HEADER_RECORD = SendFormat.MakeRecord_Header_Record(MakeFileDate,
                                                                                   vanid,
                                                                                   "",
                                                                                   companyid,
                                                                                   SaleFrom,
                                                                                   SaleTo
                                                                                   );
                    if (str_HEADER_RECORD.Length != 150)
                    {
                        throw new Exception("CHECK FORMAT PLZ[HEADER_RECORD]\n\r" + str_HEADER_RECORD);
                    }
                    EDI.Log.Log.SaveLog(str_HEADER_RECORD);



                    /*☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*/
                    //  DataRecord
                    /*☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*/
                    //TatalRecord 에 사용할 변수선언
                    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                    int cnt_11 = 0; /*일반건수    */
                    int amt_11 = 0; /*일반합계    */
                    int cnt_12 = 0; /*일반취소건수*/
                    int amt_12 = 0; /*일반취소합계*/
                    int cnt_21 = 0; /*할부건수    */
                    int amt_21 = 0; /*할부합계    */
                    int cnt_22 = 0; /*할부취소건수*/
                    int amt_22 = 0; /*할부취소합계*/


                    for (int iheaderRecord = 0; iheaderRecord < dtHeaderRecord.Rows.Count; iheaderRecord++)
                    {
                        string recordkind = ""; /*레코드구분  */
                        string SaleCode   = ""; /*당초매출일자*/
                        string SaleKind   = ""; /*거래구분    */

                        if (dtHeaderRecord.Rows[iheaderRecord]["AGREE_YN"].ToString() == "Y" &&
                            dtHeaderRecord.Rows[iheaderRecord]["INSTALLMENT_CNT"].ToString() == "0")
                        {
                            //일반
                            recordkind = "11";
                            SaleCode   = "000000";
                            SaleKind   = "00";

                            cnt_11++;
                            amt_11 += int.Parse(dtHeaderRecord.Rows[iheaderRecord]["SALE_AMT"].ToString());

                            cnt_tot_11++;
                            amt_tot_11 += int.Parse(dtHeaderRecord.Rows[iheaderRecord]["SALE_AMT"].ToString());
                        }
                        else if (dtHeaderRecord.Rows[iheaderRecord]["AGREE_YN"].ToString() == "N" &&
                                 dtHeaderRecord.Rows[iheaderRecord]["INSTALLMENT_CNT"].ToString() == "0")
                        {
                            //일반취소
                            recordkind = "12";
                            SaleCode   = DateTime.Parse(dtHeaderRecord.Rows[iheaderRecord]["AGREE_DATE"].ToString().Trim()).ToString("yyMMdd");
                            SaleKind   = "00";

                            cnt_12++;
                            amt_12 += int.Parse(dtHeaderRecord.Rows[iheaderRecord]["SALE_AMT"].ToString());

                            cnt_tot_12++;
                            amt_tot_12 += int.Parse(dtHeaderRecord.Rows[iheaderRecord]["SALE_AMT"].ToString());
                        }
                        else if (dtHeaderRecord.Rows[iheaderRecord]["AGREE_YN"].ToString() == "Y" &&
                                 dtHeaderRecord.Rows[iheaderRecord]["INSTALLMENT_CNT"].ToString() != "0")
                        {
                            //할부
                            recordkind = "21";
                            SaleCode   = "000000";
                            SaleKind   = "02";

                            cnt_21++;
                            amt_21 += int.Parse(dtHeaderRecord.Rows[iheaderRecord]["SALE_AMT"].ToString());

                            cnt_tot_21++;
                            amt_tot_21 += int.Parse(dtHeaderRecord.Rows[iheaderRecord]["SALE_AMT"].ToString());
                        }
                        else if (dtHeaderRecord.Rows[iheaderRecord]["AGREE_YN"].ToString() == "N" &&
                                 dtHeaderRecord.Rows[iheaderRecord]["INSTALLMENT_CNT"].ToString() != "0")
                        {
                            //할부취소
                            recordkind = "22";
                            SaleKind   = "02";
                            SaleCode   = DateTime.Parse(dtHeaderRecord.Rows[iheaderRecord]["AGREE_DATE"].ToString().Trim()).ToString("yyMMdd");

                            cnt_22++;
                            amt_22 += int.Parse(dtHeaderRecord.Rows[iheaderRecord]["SALE_AMT"].ToString());

                            cnt_tot_22++;
                            amt_tot_22 += int.Parse(dtHeaderRecord.Rows[iheaderRecord]["SALE_AMT"].ToString());
                        }
                        else
                        {
                            throw new Exception("데이터가 / 일반 / 일반취소 / 할부 / 할부취소 범위에 속하지 않습니다.\n\r" +
                                                "승인번호 : [" + dtHeaderRecord.Rows[iheaderRecord]["AGREE_NO"].ToString().Trim() + "]\n\r" +
                                                "BILL NO  : [" + dtHeaderRecord.Rows[iheaderRecord]["BILL_NO"].ToString().Trim() + "]"
                                                );
                        }

                        string agreeno        = dtHeaderRecord.Rows[iheaderRecord]["AGREE_NO"].ToString().Trim();
                        string validThru      = dtHeaderRecord.Rows[iheaderRecord]["VALID_THRU"].ToString().Trim();
                        string agreedate      = DateTime.Parse(dtHeaderRecord.Rows[iheaderRecord]["AGREE_DATE"].ToString().Trim()).ToString("yyMMdd");
                        string saleamt        = dtHeaderRecord.Rows[iheaderRecord]["SALE_AMT"].ToString().Trim();
                        string installmentcnt = dtHeaderRecord.Rows[iheaderRecord]["INSTALLMENT_CNT"].ToString().Trim();
                        string posno          = dtHeaderRecord.Rows[iheaderRecord]["POS_NO"].ToString().Trim();
                        string billno         = dtHeaderRecord.Rows[iheaderRecord]["BILL_NO"].ToString().Trim();
                        string agreetime      = dtHeaderRecord.Rows[iheaderRecord]["AGREE_TIME"].ToString().Trim();
                        string keyinyn        = dtHeaderRecord.Rows[iheaderRecord]["KEYIN_YN"].ToString().Trim();
                        string cardno         = dtHeaderRecord.Rows[iheaderRecord]["CARD_NO"].ToString().Trim();


                        //전표번호가 8자리기때문에
                        //201107 0045 같은 전표 자리가 큰건을 예외처리 해주기위해서
                        //안넣어줘도 상관없을뜻한데
                        //안넣어주어서 에러가 발생할지 몰라서 넣어준다.
                        //edi 는 리얼데이터로 테스트를 해야되기때문에
                        //현재 운영중이므로 처리한다.
                        if (billno.Length > 8)
                        {
                            try{
                                string strf = billno.Substring(0, 6);
                                int    stre = int.Parse(billno.Substring(6, billno.Length - 6));

                                if (stre > 99)
                                {
                                    stre = 99;
                                }
                                billno = strf + stre.ToString();
                            }
                            catch {
                                billno = billno.Substring(0, 8);
                            }
                        }

                        if (billno.Length > 8)
                        {
                            billno = "3214";
                        }
                        string str_DATA_RECORD = SendFormat.MakeRecord_Data_Record(recordkind,
                                                                                   (iheaderRecord + 1).ToString(),
                                                                                   validThru,
                                                                                   agreedate,
                                                                                   SaleCode,
                                                                                   agreeno,
                                                                                   "0",
                                                                                   "0",
                                                                                   Math.Abs(int.Parse(saleamt)).ToString(),
                                                                                   installmentcnt,
                                                                                   posno,
                                                                                   billno,
                                                                                   SaleKind,
                                                                                   agreetime.Trim().Length != 4 ? agreetime : agreetime + "00",
                                                                                   keyinyn,
                                                                                   cardno
                                                                                   );



                        if (str_DATA_RECORD.Length != 150)
                        {
                            throw new Exception("CHECK FORMAT PLZ[DATA_RECORD]\n\r" + str_DATA_RECORD);
                        }
                        EDI.Log.Log.SaveLog(str_DATA_RECORD);
                    }
                    /*☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*/
                    //  Total Record
                    /*☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*/

                    /*
                     *
                     * 갯수 금액 검증
                     *
                     * -------------------------------------------------------------------------------------------------------------*/

                    /*일반건수    */
                    string check_cnt_11 = dtHeaderRecord.Compute("COUNT(AGREE_YN)", "AGREE_YN = 'Y' AND INSTALLMENT_CNT = 0").ToString();
                    /*일반합계    */
                    string check_amt_11 = dtHeaderRecord.Compute("SUM(SALE_AMT)", "AGREE_YN = 'Y' AND INSTALLMENT_CNT = 0").ToString();
                    check_amt_11 = check_amt_11 == "" ? "0" : check_amt_11;

                    /*일반취소건수*/
                    string check_cnt_12 = dtHeaderRecord.Compute("COUNT(AGREE_YN)", "AGREE_YN = 'N' AND INSTALLMENT_CNT = 0").ToString();
                    /*일반취소합계*/
                    string check_amt_12 = dtHeaderRecord.Compute("SUM(SALE_AMT)", "AGREE_YN = 'N' AND INSTALLMENT_CNT = 0").ToString();
                    check_amt_12 = check_amt_12 == "" ? "0" : check_amt_12;

                    /*할부건수    */
                    string check_cnt_21 = dtHeaderRecord.Compute("COUNT(AGREE_YN)", "AGREE_YN = 'Y' AND INSTALLMENT_CNT <> 0").ToString();
                    /*할부합계    */
                    string check_amt_21 = dtHeaderRecord.Compute("SUM(SALE_AMT)", "AGREE_YN = 'Y' AND INSTALLMENT_CNT <> 0").ToString();
                    check_amt_21 = check_amt_21 == "" ? "0" : check_amt_21;

                    /*할부취소건수*/
                    string check_cnt_22 = dtHeaderRecord.Compute("COUNT(SALE_AMT)", "AGREE_YN = 'N' AND INSTALLMENT_CNT <> 0").ToString();
                    /*할부취소합계*/
                    string check_amt_22 = dtHeaderRecord.Compute("SUM(SALE_AMT)", "AGREE_YN = 'N' AND INSTALLMENT_CNT <> 0").ToString();
                    check_amt_22 = check_amt_22 == "" ? "0" : check_amt_22;

                    /*-------------------------------------------------------------------------------------------------------------*/

                    if (cnt_11 != int.Parse(check_cnt_11))
                    {
                        throw new Exception("일반건수가 잘못되었습니다");
                    }
                    else if (amt_11 != int.Parse(check_amt_11))
                    {
                        throw new Exception("일반합계가 잘못되었습니다");
                    }
                    else if (cnt_12 != int.Parse(check_cnt_12))
                    {
                        throw new Exception("일반취소건수가 잘못되었습니다");
                    }
                    else if (amt_12 != int.Parse(check_amt_12))
                    {
                        throw new Exception("일반취소합계가 잘못되었습니다");
                    }
                    else if (cnt_21 != int.Parse(check_cnt_21))
                    {
                        throw new Exception("할부건수가 잘못되었습니다");
                    }
                    else if (amt_21 != int.Parse(check_amt_21))
                    {
                        throw new Exception("할부합계가 잘못되었습니다");
                    }
                    else if (cnt_22 != int.Parse(check_cnt_22))
                    {
                        throw new Exception("할부취소건수가 잘못되었습니다");
                    }
                    else if (amt_22 != int.Parse(check_amt_22))
                    {
                        throw new Exception("할부취소합계가 잘못되었습니다");
                    }

                    /*-------------------------------------------------------------------------------------------------------------*/

                    string str_Total_Record = SendFormat.MakeRecord_Totol_Record(
                        MakeFileDate,                                                              //0
                        cnt_11.ToString().Trim(),                                                  //1
                        amt_11.ToString().Trim(),                                                  //2
                        "0",
                        amt_11.ToString().Trim(),                                                  //4
                        cnt_12.ToString().Trim(),                                                  //5
                        Math.Abs(amt_12).ToString().Trim(),                                        //6
                        "0",
                        Math.Abs(amt_12).ToString().Trim(),
                        cnt_21.ToString().Trim(),
                        amt_21.ToString().Trim(),
                        cnt_22.ToString().Trim(),
                        Math.Abs(amt_22).ToString().Trim()

                        );

                    if (str_Total_Record.Length != 150)
                    {
                        throw new Exception("CHECK FORMAT PLZ[Total_Record]\n\r" + str_Total_Record);
                    }
                    EDI.Log.Log.SaveLog(str_Total_Record);
                }
                /*☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*/
                //  Total Record
                /*☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*/

                /*-------------------------------------------------------------------------------------------------------------
                * 갯수 금액 검증 [전체데이터 비교]
                *  -------------------------------------------------------------------------------------------------------------*/


                /*일반건수    */
                string check_cnt_tot_11 = dtTmp.Compute("COUNT(AGREE_YN)", "AGREE_YN = 'Y' AND INSTALLMENT_CNT = 0").ToString();
                /*일반합계    */
                string check_amt_tot_11 = dtTmp.Compute("SUM(SALE_AMT)", "AGREE_YN = 'Y' AND INSTALLMENT_CNT = 0").ToString();
                check_amt_tot_11 = check_amt_tot_11 == "" ? "0" : check_amt_tot_11;

                /*일반취소건수*/
                string check_cnt_tot_12 = dtTmp.Compute("COUNT(AGREE_YN)", "AGREE_YN = 'N' AND INSTALLMENT_CNT = 0").ToString();
                /*일반취소합계*/
                string check_amt_tot_12 = dtTmp.Compute("SUM(SALE_AMT)", "AGREE_YN = 'N' AND INSTALLMENT_CNT = 0").ToString();
                check_amt_tot_12 = check_amt_tot_12 == "" ? "0" : check_amt_tot_12;

                /*할부건수    */
                string check_cnt_tot_21 = dtTmp.Compute("COUNT(AGREE_YN)", "AGREE_YN = 'Y' AND INSTALLMENT_CNT <> 0").ToString();
                /*할부합계    */
                string check_amt_tot_21 = dtTmp.Compute("SUM(SALE_AMT)", "AGREE_YN = 'Y' AND INSTALLMENT_CNT <> 0").ToString();
                check_amt_tot_21 = check_amt_tot_21 == "" ? "0" : check_amt_tot_21;

                /*할부취소건수*/
                string check_cnt_tot_22 = dtTmp.Compute("COUNT(SALE_AMT)", "AGREE_YN = 'N' AND INSTALLMENT_CNT <> 0").ToString();
                /*할부취소합계*/
                string check_amt_tot_22 = dtTmp.Compute("SUM(SALE_AMT)", "AGREE_YN = 'N' AND INSTALLMENT_CNT <> 0").ToString();
                check_amt_tot_22 = check_amt_tot_22 == "" ? "0" : check_amt_tot_22;

                /*-------------------------------------------------------------------------------------------------------------*/

                if (cnt_tot_11 != int.Parse(check_cnt_tot_11))
                {
                    throw new Exception("일반건수가 잘못되었습니다. (Total)");
                }
                else if (amt_tot_11 != int.Parse(check_amt_tot_11))
                {
                    throw new Exception("일반합계가 잘못되었습니다. (Total)");
                }
                else if (cnt_tot_12 != int.Parse(check_cnt_tot_12))
                {
                    throw new Exception("일반취소건수가 잘못되었습니다. (Total)");
                }
                else if (amt_tot_12 != int.Parse(check_amt_tot_12))
                {
                    throw new Exception("일반취소합계가 잘못되었습니다. (Total)");
                }
                else if (cnt_tot_21 != int.Parse(check_cnt_tot_21))
                {
                    throw new Exception("할부건수가 잘못되었습니다. (Total)");
                }
                else if (amt_tot_21 != int.Parse(check_amt_tot_21))
                {
                    throw new Exception("할부합계가 잘못되었습니다. (Total)");
                }
                else if (cnt_tot_22 != int.Parse(check_cnt_tot_22))
                {
                    throw new Exception("할부취소건수가 잘못되었습니다. (Total)");
                }
                else if (amt_tot_22 != int.Parse(check_amt_tot_22))
                {
                    throw new Exception("할부취소합계가 잘못되었습니다. (Total)");
                }

                string str_EDI_END_RECORD = SendFormat.MakeRecord_EDI_End_Record(dtCardGroupBy.Rows.Count.ToString(),
                                                                                 cnt_tot_11.ToString(),
                                                                                 amt_tot_11.ToString(),
                                                                                 "0",
                                                                                 amt_tot_11.ToString(),
                                                                                 cnt_tot_12.ToString(),
                                                                                 Math.Abs(amt_tot_12).ToString(),
                                                                                 "0",
                                                                                 Math.Abs(amt_tot_12).ToString(),
                                                                                 cnt_tot_21.ToString(),
                                                                                 amt_tot_21.ToString(),
                                                                                 cnt_tot_22.ToString(),
                                                                                 Math.Abs(amt_tot_22).ToString()
                                                                                 );

                if (str_EDI_END_RECORD.Length != 150)
                {
                    throw new Exception("CHECK FORMAT PLZ[EDI_END_RECORD]\n\r" + str_EDI_END_RECORD);
                }
                EDI.Log.Log.SaveLog(str_EDI_END_RECORD);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                Basic.SetCursor(this, true);
            }
        }
Exemplo n.º 2
0
        private string fnMakeSendData(DataTable dtTmp, string CompanyID_Resort, string CompanyID_Van, string FolderPath, string FileName)
        {
            try
            {
                Log.FileName = FileName;
                Log.FilePath = FolderPath;

                string vRet = "";


                int cnt_tot_11 = 0; /*일반건수    */
                int amt_tot_11 = 0; /*일반합계    */
                int cnt_tot_12 = 0; /*일반취소건수*/
                int amt_tot_12 = 0; /*일반취소합계*/
                int cnt_tot_21 = 0; /*할부건수    */
                int amt_tot_21 = 0; /*할부합계    */
                int cnt_tot_22 = 0; /*할부취소건수*/
                int amt_tot_22 = 0; /*할부취소합계*/

                /*☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*/
                //EDI START RECORD
                /*☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*/

                string MakeFileDate = System.DateTime.Now.ToString("yyMMdd");

                string str_EDI_START_RECORD = SendFormat.MakeRecord_EDI_Start_Record(MakeFileDate,
                                                                                     CompanyID_Resort,
                                                                                     CompanyID_Van);

                if (System.IO.File.Exists(Log.FilePath + "\\" + Log.FileName + ".txt"))
                {
                    System.IO.File.Delete(Log.FilePath + "\\" + Log.FileName + ".txt");
                }

                EDI.Log.Log.SaveLog(str_EDI_START_RECORD);
                vRet += str_EDI_START_RECORD;

                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                // 매입사별로 Groupby
                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                DataSetHelper helper = new Cls.GroupByHelper.DataSetHelper();

                DataTable dtCardGroupBy = helper.SelectGroupByInto("CARD_GROUPBY", dtTmp, "COMPANY_ID , VAN_ID", "", "COMPANY_ID , VAN_ID");

                for (int iCardGroup = 0; iCardGroup < dtCardGroupBy.Rows.Count; iCardGroup++)
                {
                    string companyid = dtCardGroupBy.Rows[iCardGroup]["COMPANY_ID"].ToString().Trim();
                    string vanid     = dtCardGroupBy.Rows[iCardGroup]["VAN_ID"].ToString().Trim();

                    //매입사 사업자번호로 그룹을 했다.
                    //가져온 데이터 테이블에서 사업자 번호로 데이터를 가져온다.
                    DataTable dtHeaderRecord = Basic.GetdtSelect(dtTmp, "COMPANY_ID = '" + companyid + "'", "AGREE_DATE ASC");

                    string SaleFrom = DateTime.Parse(dtHeaderRecord.Compute("MIN(AGREE_DATE)", "").ToString()).ToString("yyMMdd");
                    string SaleTo   = DateTime.Parse(dtHeaderRecord.Compute("MAX(AGREE_DATE)", "").ToString()).ToString("yyMMdd");

                    /*☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*/
                    //  header
                    /*☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*/

                    string str_HEADER_RECORD = SendFormat.MakeRecord_Header_Record(MakeFileDate,
                                                                                   vanid,
                                                                                   "",
                                                                                   companyid,
                                                                                   SaleFrom,
                                                                                   SaleTo
                                                                                   );
                    EDI.Log.Log.SaveLog(str_HEADER_RECORD);
                    vRet += str_HEADER_RECORD;


                    /*☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*/
                    //  DataRecord
                    /*☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*/
                    //TatalRecord 에 사용할 변수선언
                    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                    int cnt_11 = 0; /*일반건수    */
                    int amt_11 = 0; /*일반합계    */
                    int cnt_12 = 0; /*일반취소건수*/
                    int amt_12 = 0; /*일반취소합계*/
                    int cnt_21 = 0; /*할부건수    */
                    int amt_21 = 0; /*할부합계    */
                    int cnt_22 = 0; /*할부취소건수*/
                    int amt_22 = 0; /*할부취소합계*/


                    for (int iheaderRecord = 0; iheaderRecord < dtHeaderRecord.Rows.Count; iheaderRecord++)
                    {
                        string recordkind = ""; /*레코드구분  */
                        string SaleCode   = ""; /*당초매출일자*/
                        string SaleKind   = ""; /*거래구분    */

                        if (dtHeaderRecord.Rows[iheaderRecord]["AGREE_YN"].ToString() == "Y" &&
                            dtHeaderRecord.Rows[iheaderRecord]["INSTALLMENT_CNT"].ToString() == "0")
                        {
                            //일반
                            recordkind = "11";
                            SaleCode   = "000000";
                            SaleKind   = "00";

                            cnt_11++;
                            amt_11 += int.Parse(dtHeaderRecord.Rows[iheaderRecord]["SALE_AMT"].ToString());

                            cnt_tot_11++;
                            amt_tot_11 += int.Parse(dtHeaderRecord.Rows[iheaderRecord]["SALE_AMT"].ToString());
                        }
                        else if (dtHeaderRecord.Rows[iheaderRecord]["AGREE_YN"].ToString() == "N" &&
                                 dtHeaderRecord.Rows[iheaderRecord]["INSTALLMENT_CNT"].ToString() == "0")
                        {
                            //일반취소
                            recordkind = "12";
                            SaleCode   = DateTime.Parse(dtHeaderRecord.Rows[iheaderRecord]["AGREE_DATE"].ToString().Trim()).ToString("yyMMdd");
                            SaleKind   = "00";

                            cnt_12++;
                            amt_12 += int.Parse(dtHeaderRecord.Rows[iheaderRecord]["SALE_AMT"].ToString());

                            cnt_tot_12++;
                            amt_tot_12 += int.Parse(dtHeaderRecord.Rows[iheaderRecord]["SALE_AMT"].ToString());
                        }
                        else if (dtHeaderRecord.Rows[iheaderRecord]["AGREE_YN"].ToString() == "Y" &&
                                 dtHeaderRecord.Rows[iheaderRecord]["INSTALLMENT_CNT"].ToString() != "0")
                        {
                            //할부
                            recordkind = "21";
                            SaleCode   = "000000";
                            SaleKind   = "02";

                            cnt_21++;
                            amt_21 += int.Parse(dtHeaderRecord.Rows[iheaderRecord]["SALE_AMT"].ToString());

                            cnt_tot_21++;
                            amt_tot_21 += int.Parse(dtHeaderRecord.Rows[iheaderRecord]["SALE_AMT"].ToString());
                        }
                        else if (dtHeaderRecord.Rows[iheaderRecord]["AGREE_YN"].ToString() == "N" &&
                                 dtHeaderRecord.Rows[iheaderRecord]["INSTALLMENT_CNT"].ToString() != "0")
                        {
                            //할부취소
                            recordkind = "22";
                            SaleKind   = "02";
                            SaleCode   = DateTime.Parse(dtHeaderRecord.Rows[iheaderRecord]["AGREE_DATE"].ToString().Trim()).ToString("yyMMdd");

                            cnt_22++;
                            amt_22 += int.Parse(dtHeaderRecord.Rows[iheaderRecord]["SALE_AMT"].ToString());

                            cnt_tot_22++;
                            amt_tot_22 += int.Parse(dtHeaderRecord.Rows[iheaderRecord]["SALE_AMT"].ToString());
                        }
                        else
                        {
                            throw new Exception("데이터가 / 일반 / 일반취소 / 할부 / 할부취소 범위에 속하지 않습니다.\n\r" +
                                                "승인번호 : [" + dtHeaderRecord.Rows[iheaderRecord]["AGREE_NO"].ToString().Trim() + "]\n\r" +
                                                "BILL NO  : [" + dtHeaderRecord.Rows[iheaderRecord]["BILL_NO"].ToString().Trim() + "]"
                                                );
                        }

                        string agreeno        = dtHeaderRecord.Rows[iheaderRecord]["AGREE_NO"].ToString().Trim();
                        string validThru      = dtHeaderRecord.Rows[iheaderRecord]["VALID_THRU"].ToString().Trim();
                        string agreedate      = DateTime.Parse(dtHeaderRecord.Rows[iheaderRecord]["AGREE_DATE"].ToString().Trim()).ToString("yyMMdd");
                        string saleamt        = dtHeaderRecord.Rows[iheaderRecord]["SALE_AMT"].ToString().Trim();
                        string installmentcnt = dtHeaderRecord.Rows[iheaderRecord]["INSTALLMENT_CNT"].ToString().Trim();
                        string posno          = dtHeaderRecord.Rows[iheaderRecord]["POS_NO"].ToString().Trim();
                        string billno         = dtHeaderRecord.Rows[iheaderRecord]["BILL_NO"].ToString().Trim();
                        string agreetime      = dtHeaderRecord.Rows[iheaderRecord]["AGREE_TIME"].ToString().Trim();
                        string keyinyn        = dtHeaderRecord.Rows[iheaderRecord]["KEYIN_YN"].ToString().Trim();
                        string cardno         = dtHeaderRecord.Rows[iheaderRecord]["CARD_NO"].ToString().Trim();

                        string str_DATA_RECORD = SendFormat.MakeRecord_Data_Record(recordkind,
                                                                                   (iheaderRecord + 1).ToString(),
                                                                                   validThru,
                                                                                   agreedate,
                                                                                   SaleCode,
                                                                                   agreeno,
                                                                                   "0",
                                                                                   "0",
                                                                                   Math.Abs(int.Parse(saleamt)).ToString(),
                                                                                   installmentcnt,
                                                                                   posno,
                                                                                   billno,
                                                                                   SaleKind,
                                                                                   agreetime,
                                                                                   keyinyn,
                                                                                   cardno
                                                                                   );



                        EDI.Log.Log.SaveLog(str_DATA_RECORD);
                        vRet += str_DATA_RECORD;
                    }
                    /*☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*/
                    //  Total Record
                    /*☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*/

                    /*
                     *
                     * 갯수 금액 검증
                     *
                     * -------------------------------------------------------------------------------------------------------------*/

                    /*일반건수    */
                    string check_cnt_11 = dtHeaderRecord.Compute("COUNT(AGREE_YN)", "AGREE_YN = 'Y' AND INSTALLMENT_CNT = 0").ToString();
                    /*일반합계    */
                    string check_amt_11 = dtHeaderRecord.Compute("SUM(SALE_AMT)", "AGREE_YN = 'Y' AND INSTALLMENT_CNT = 0").ToString();
                    check_amt_11 = check_amt_11 == "" ? "0" : check_amt_11;

                    /*일반취소건수*/
                    string check_cnt_12 = dtHeaderRecord.Compute("COUNT(AGREE_YN)", "AGREE_YN = 'N' AND INSTALLMENT_CNT = 0").ToString();
                    /*일반취소합계*/
                    string check_amt_12 = dtHeaderRecord.Compute("SUM(SALE_AMT)", "AGREE_YN = 'N' AND INSTALLMENT_CNT = 0").ToString();
                    check_amt_12 = check_amt_12 == "" ? "0" : check_amt_12;

                    /*할부건수    */
                    string check_cnt_21 = dtHeaderRecord.Compute("COUNT(AGREE_YN)", "AGREE_YN = 'Y' AND INSTALLMENT_CNT <> 0").ToString();
                    /*할부합계    */
                    string check_amt_21 = dtHeaderRecord.Compute("SUM(SALE_AMT)", "AGREE_YN = 'Y' AND INSTALLMENT_CNT <> 0").ToString();
                    check_amt_21 = check_amt_21 == "" ? "0" : check_amt_21;

                    /*할부취소건수*/
                    string check_cnt_22 = dtHeaderRecord.Compute("COUNT(SALE_AMT)", "AGREE_YN = 'N' AND INSTALLMENT_CNT <> 0").ToString();
                    /*할부취소합계*/
                    string check_amt_22 = dtHeaderRecord.Compute("SUM(SALE_AMT)", "AGREE_YN = 'N' AND INSTALLMENT_CNT <> 0").ToString();
                    check_amt_22 = check_amt_22 == "" ? "0" : check_amt_22;

                    /*-------------------------------------------------------------------------------------------------------------*/

                    if (cnt_11 != int.Parse(check_cnt_11))
                    {
                        Basic.ShowMessage(1, "일반건수가 잘못되었습니다.");
                        return("");
                    }
                    else if (amt_11 != int.Parse(check_amt_11))
                    {
                        Basic.ShowMessage(1, "일반합계가 잘못되었습니다.");
                        return("");
                    }
                    else if (cnt_12 != int.Parse(check_cnt_12))
                    {
                        Basic.ShowMessage(1, "일반취소건수가 잘못되었습니다.");
                        return("");
                    }
                    else if (amt_12 != int.Parse(check_amt_12))
                    {
                        Basic.ShowMessage(1, "일반취소합계가 잘못되었습니다.");
                        return("");
                    }
                    else if (cnt_21 != int.Parse(check_cnt_21))
                    {
                        Basic.ShowMessage(1, "할부건수가 잘못되었습니다.");
                        return("");
                    }
                    else if (amt_21 != int.Parse(check_amt_21))
                    {
                        Basic.ShowMessage(1, "할부합계가 잘못되었습니다.");
                        return("");
                    }
                    else if (cnt_22 != int.Parse(check_cnt_22))
                    {
                        Basic.ShowMessage(1, "할부취소건수가 잘못되었습니다.");
                        return("");
                    }
                    else if (amt_22 != int.Parse(check_amt_22))
                    {
                        Basic.ShowMessage(1, "할부취소합계가 잘못되었습니다.");
                        return("");
                    }

                    /*-------------------------------------------------------------------------------------------------------------*/

                    string str_Total_Record = SendFormat.MakeRecord_Totol_Record(
                        MakeFileDate,
                        cnt_11.ToString().Trim(),
                        "0",
                        "0",
                        amt_11.ToString().Trim(),
                        cnt_12.ToString().Trim(),
                        "0",
                        "0",
                        Math.Abs(amt_12).ToString().Trim(),
                        cnt_21.ToString().Trim(),
                        amt_21.ToString().Trim(),
                        cnt_22.ToString().Trim(),
                        Math.Abs(amt_22).ToString().Trim()

                        );


                    EDI.Log.Log.SaveLog(str_Total_Record);
                    vRet += str_Total_Record;
                }
                /*☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*/
                //  Total Record
                /*☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*/

                /*-------------------------------------------------------------------------------------------------------------
                * 갯수 금액 검증 [전체데이터 비교]
                *  -------------------------------------------------------------------------------------------------------------*/


                /*일반건수    */
                string check_cnt_tot_11 = dtTmp.Compute("COUNT(AGREE_YN)", "AGREE_YN = 'Y' AND INSTALLMENT_CNT = 0").ToString();
                /*일반합계    */
                string check_amt_tot_11 = dtTmp.Compute("SUM(SALE_AMT)", "AGREE_YN = 'Y' AND INSTALLMENT_CNT = 0").ToString();
                check_amt_tot_11 = check_amt_tot_11 == "" ? "0" : check_amt_tot_11;

                /*일반취소건수*/
                string check_cnt_tot_12 = dtTmp.Compute("COUNT(AGREE_YN)", "AGREE_YN = 'N' AND INSTALLMENT_CNT = 0").ToString();
                /*일반취소합계*/
                string check_amt_tot_12 = dtTmp.Compute("SUM(SALE_AMT)", "AGREE_YN = 'N' AND INSTALLMENT_CNT = 0").ToString();
                check_amt_tot_12 = check_amt_tot_12 == "" ? "0" : check_amt_tot_12;

                /*할부건수    */
                string check_cnt_tot_21 = dtTmp.Compute("COUNT(AGREE_YN)", "AGREE_YN = 'Y' AND INSTALLMENT_CNT <> 0").ToString();
                /*할부합계    */
                string check_amt_tot_21 = dtTmp.Compute("SUM(SALE_AMT)", "AGREE_YN = 'Y' AND INSTALLMENT_CNT <> 0").ToString();
                check_amt_tot_21 = check_amt_tot_21 == "" ? "0" : check_amt_tot_21;

                /*할부취소건수*/
                string check_cnt_tot_22 = dtTmp.Compute("COUNT(SALE_AMT)", "AGREE_YN = 'N' AND INSTALLMENT_CNT <> 0").ToString();
                /*할부취소합계*/
                string check_amt_tot_22 = dtTmp.Compute("SUM(SALE_AMT)", "AGREE_YN = 'N' AND INSTALLMENT_CNT <> 0").ToString();
                check_amt_tot_22 = check_amt_tot_22 == "" ? "0" : check_amt_tot_22;

                /*-------------------------------------------------------------------------------------------------------------*/

                if (cnt_tot_11 != int.Parse(check_cnt_tot_11))
                {
                    Basic.ShowMessage(1, "일반건수가 잘못되었습니다. (Total) ");
                    return("");
                }
                else if (amt_tot_11 != int.Parse(check_amt_tot_11))
                {
                    Basic.ShowMessage(1, "일반합계가 잘못되었습니다. (Total) ");
                    return("");
                }
                else if (cnt_tot_12 != int.Parse(check_cnt_tot_12))
                {
                    Basic.ShowMessage(1, "일반취소건수가 잘못되었습니다. (Total) ");
                    return("");
                }
                else if (amt_tot_12 != int.Parse(check_amt_tot_12))
                {
                    Basic.ShowMessage(1, "일반취소합계가 잘못되었습니다. (Total) ");
                    return("");
                }
                else if (cnt_tot_21 != int.Parse(check_cnt_tot_21))
                {
                    Basic.ShowMessage(1, "할부건수가 잘못되었습니다. (Total) ");
                    return("");
                }
                else if (amt_tot_21 != int.Parse(check_amt_tot_21))
                {
                    Basic.ShowMessage(1, "할부합계가 잘못되었습니다. (Total) ");
                    return("");
                }
                else if (cnt_tot_22 != int.Parse(check_cnt_tot_22))
                {
                    Basic.ShowMessage(1, "할부취소건수가 잘못되었습니다. (Total) ");
                    return("");
                }
                else if (amt_tot_22 != int.Parse(check_amt_tot_22))
                {
                    Basic.ShowMessage(1, "할부취소합계가 잘못되었습니다. (Total) ");
                    return("");
                }

                string str_EDI_END_RECORD = SendFormat.MakeRecord_EDI_End_Record(dtCardGroupBy.Rows.Count.ToString(),
                                                                                 cnt_tot_11.ToString(),
                                                                                 "0",
                                                                                 "0",
                                                                                 amt_tot_11.ToString(),
                                                                                 cnt_tot_12.ToString(),
                                                                                 "0",
                                                                                 "0",
                                                                                 Math.Abs(amt_tot_12).ToString(),
                                                                                 cnt_tot_21.ToString(),
                                                                                 amt_tot_21.ToString(),
                                                                                 cnt_tot_22.ToString(),
                                                                                 Math.Abs(amt_tot_22).ToString()
                                                                                 );


                EDI.Log.Log.SaveLog(str_EDI_END_RECORD);
                vRet += str_EDI_END_RECORD;
                return(vRet);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }