Beispiel #1
0
        private void btnFoxFile_Click(object sender, EventArgs e)
        {
            try
            {
                this.lblCount.Text = "Plase wait...";
                this.Enabled = false;
                OpenFileDialog op = new OpenFileDialog();
                op.Filter = "*.dbf|*.dbf|All Files|*.*";
                if (op.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    dataGridView1.DataSource = "";
                    txtFoxFile.Text = op.FileName;
                    jolParseDBF.DBF myDbf = new jolParseDBF.DBF();
                    DataTable T = myDbf.parse(txtFoxFile.Text);

                    //DataView foxDataView = T.DefaultView; //new DataView(T);
                    //foxDataView.Sort = "V0BATCHNUM,V0SEQUENCE";
                    //dataGridView1.DataSource = foxDataView;

                    lblTotal.Text = T.Rows.Count.ToString("###,###,##0");
                    myDbf = null;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Enabled = true;
                this.lblCount.Text = "0";
            }
        }
Beispiel #2
0
 public DataTable getData(string foxFile, bool parseDB)
 {
     DataTable T = null;
     jolParseDBF.DBF parsedbf = new jolParseDBF.DBF();
     try {
         T = parsedbf.parse(foxFile);
         Message = "Done...";
     }catch(Exception e) {
         Message = e.Message;
     }
     parsedbf = null;
     return T;
 }
Beispiel #3
0
        public void loadData(string txtFoxFile, System.Windows.Forms.Label lblTotal, System.Windows.Forms.DataGridView dataGridView1)
        {
            dataGridView1.DataSource = "";

            jolParseDBF.DBF myDbf = new jolParseDBF.DBF();
            DataTable T = myDbf.parse(txtFoxFile);

            DataView foxDataView = T.DefaultView; //new DataView(T);
            foxDataView.Sort = "V0BATCHNUM,V0SEQUENCE";
            dataGridView1.DataSource = foxDataView;

            lblTotal.Text = T.Rows.Count.ToString("###,###,##0");
            myDbf = null;
        }
Beispiel #4
0
        public void run(string pdfFile, string txtFileOutPut, String MembidDummy, String tblSubscribers, String whatIsTable, String tblProvider, String pay_name1_117, System.Windows.Forms.Label lblTotal, System.Windows.Forms.Label lblCount, ToolStripProgressBar Bar, ToolStripStatusLabel Label,System.Windows.Forms.DataGridView dgview,String sCount)
        {
            //Para MMM y PMC 837i

            jolParseDBF.DBF foxCnn = null;

            String Images = null;
            String sqlCnnString = null;
            findData.Search myFindData = null;

            DataSet mySqlDataSet = null;

            header myHeader = null;
            detail myDetail = null;
               //         createString.create myCreateFile = null;
             //       writeFile.file myWriteFile = null;
            Int32 iCC = 0; //Contador de la categoria
            String TMPcc = null;

            try
            {

                myFindData = new findData.Search();

                mySqlDataSet = new DataSet();

                myHeader = new header();
                myDetail = new detail();

                StringBuilder sHDOut = new StringBuilder();

                string file2 = txtFileOutPut.Substring(0, txtFileOutPut.IndexOf("."));
                file2 += ".dtl"; //

                if (File.Exists(txtFileOutPut.Trim()))
                    File.Delete(txtFileOutPut.Trim());

                if (File.Exists(file2.Trim()))
                    File.Delete(file2.Trim());

                sqlCnnString = _sqlCnnString;

                foxCnn = new jolParseDBF.DBF();
                DataTable foxTable = foxCnn.parse(pdfFile); // TODO: New Parse

                lblTotal.Text =  String.Format("{0:0,0}",  foxTable.Select("V1PAGINA <> '99'").Length.ToString()); //String.Format("{0:0,0}", foxCmd.ExecuteScalar());
                int totalrecord = foxTable.Select("V1PAGINA <> '99'").Length;                                      //Convert.ToInt16(foxCmd.ExecuteScalar());

                Bar.Maximum = totalrecord;

                System.Windows.Forms.Application.DoEvents();

                string V1SUSCRIID = null;
                string V156NPI = null;
                String V1FEDTAXNO = null;
                string V276NPI = null;
                //string V276NPILegaci = null;

                string  V2OPERANPI = null;
                //string V2OPERANPILegaci = null;

                string  V278NPI = null;
                //string V278NPILegaci = null;

                string V279NPI = null;
                //string V279NPILegaci = null;

                bool isNotGoodV276NPI = false;
                bool isNotGoodV2OPERANPI = false;
                bool isNotGoodV278NPI = false;
                bool isNotGoodV279NPI = false;
                bool isNotGoodV156NPI = false;

                int intClaim_no_2 = 0;
                Int64 myCount = 0;

                foreach (System.Data.DataRow foxDR in foxTable.Select("V1PAGINA <> '99'", "V0DOCUMENT"))//TODO: Star loop
                {
                    myHeader = null;
                    myDetail = null;

                    myHeader = new header();
                    myDetail = new detail();

                        Bar.Value++;
                        Double iP = Bar.Value;
                        iP = iP / Bar.Maximum;
                        Label.Text = String.Format("{0:0%}", iP);
                        Application.DoEvents();

                        myCount++;
                        lblCount.Text = String.Format("{0:0,0}", myCount);
                        System.Windows.Forms.Application.DoEvents();

                        isNotGoodV276NPI = false;
                        isNotGoodV2OPERANPI = false;
                        isNotGoodV278NPI = false;
                        isNotGoodV279NPI = false;

                        intClaim_no_2++;
                        Images = foxDR["V0IFNAME01"].ToString().Trim();

                        V156NPI = foxDR["V156NPI"].ToString();

                        V276NPI = foxDR["V276NPI"].ToString();

                        V2OPERANPI = foxDR["V2OPERANPI"].ToString();

                        V278NPI = foxDR["V278NPI"].ToString();

                        V279NPI = foxDR["V279NPI"].ToString();

                        V1FEDTAXNO = foxDR["V1FEDTAXNO"].ToString();
                        //TODO V279NPI **
                        if (V279NPI.Trim().Length == 0)
                        {
                            V279NPI = new String(' ', 10);
                            isNotGoodV279NPI = true;
                        }
                        else
                        {
                            if (!check_digit_NPI.isValidNPI(V279NPI.Trim()))
                            {
                                V279NPI = new String(' ', 10);
                                isNotGoodV279NPI = true;
                            }
                            else
                            {
                                string count = Program.MySqlbusqueda(sqlCnnString, "select count(*) from  " + tblProvider + " where (npi ='" + V279NPI + "') or (PAYEE_NPI ='" + V279NPI + "')");
                                if (count == "0")
                                {
                                    V279NPI = "9999999995";
                                    isNotGoodV279NPI = true;
                                }
                                else
                                {
                                    isNotGoodV279NPI = false;
                                }
                            }
                        }

                        //TODO V278NPI **
                        if (V278NPI.Trim().Length == 0)
                        {
                            V278NPI = new string(' ', 10);
                            isNotGoodV278NPI = true;
                        }
                        else
                        {
                            if (!check_digit_NPI.isValidNPI(V278NPI.Trim()))
                            {
                                V278NPI = new string(' ', 10);
                                isNotGoodV278NPI = true;
                            }
                            else
                            {
                                string count = Program.MySqlbusqueda(sqlCnnString, "select count(*) from  " + tblProvider + " where (npi ='" + V278NPI + "') or (PAYEE_NPI ='" + V278NPI + "')");
                                if (count == "0")
                                {
                                    V278NPI = "9999999995";
                                    isNotGoodV278NPI = true;
                                }
                                else
                                {
                                    isNotGoodV278NPI = false;
                                }
                            }
                        }

                        //TODO V2OPERANPI **
                        if (V2OPERANPI.Trim().Length == 0)
                        {
                            V2OPERANPI = new string(' ', 10);
                            isNotGoodV2OPERANPI = true;
                        }
                        else
                        {
                            if (!check_digit_NPI.isValidNPI(V2OPERANPI.Trim()))
                            {
                                V2OPERANPI = new string(' ', 10);
                                isNotGoodV2OPERANPI = true;
                            }
                            else
                            {
                                string count = Program.MySqlbusqueda(sqlCnnString, "select count(*) from  " + tblProvider + " where (npi ='" + V2OPERANPI + "') or (PAYEE_NPI ='" + V2OPERANPI + "')");
                                if (count == "0")
                                {
                                    V2OPERANPI = "9999999995";
                                    isNotGoodV2OPERANPI = true;
                                }
                                else
                                {
                                    isNotGoodV2OPERANPI = false;
                                }
                            }
                        }
                        //TODO V276NPI **
                        if (V276NPI.Trim().Length == 0)
                        {
                            V276NPI = new string(' ', 10);
                            isNotGoodV276NPI = true;
                        }
                        else
                        {
                            if (!check_digit_NPI.isValidNPI(V276NPI.Trim()))
                            {
                                V276NPI = new string(' ', 10);
                                isNotGoodV276NPI = true;
                            }
                            else
                            {
                                string count = Program.MySqlbusqueda(sqlCnnString, "select count(*) from  " + tblProvider + " where (npi ='" + V276NPI + "') or (PAYEE_NPI ='" + V276NPI + "')");
                                if (count == "0")
                                {
                                    V276NPI = "9999999995";
                                    isNotGoodV276NPI = true;
                                }
                                else
                                {
                                    isNotGoodV276NPI = false;
                                }

                            }
                        }
                        //TODO V156NPI
                        if (V156NPI.Trim().Length == 0)
                        {
                            V156NPI = "9999999995";

                        }
                        else
                        {
                            if (!check_digit_NPI.isValidNPI(V156NPI.Trim()))
                            {
                                V156NPI = "9999999995";

                            }
                            else
                            {
                                string count = Program.MySqlbusqueda(sqlCnnString, "select count(*) from  " + tblProvider + " where (npi ='" + V156NPI + "')");

                                if (count == "0")
                                {
                                    V156NPI = "9999999995";
                                    isNotGoodV156NPI = true;

                                }
                                else
                                {
                                    isNotGoodV156NPI = false;
                                }
                            }
                        }

                        V1SUSCRIID = foxDR["V1SUSCRIID"].ToString().Trim();

                        if (V1SUSCRIID.Trim().Length == 0)
                        {
                            V1SUSCRIID = MembidDummy;
                        }
                        else
                        {
                            string count = Program.MySqlbusqueda(sqlCnnString, "select membid from " +
                                tblSubscribers + " where (membid = '" + V1SUSCRIID + "')");
                            if (count.Trim().Length == 0)
                            {//or (membid2 = '" + V1SUSCRIID + "')"
                                string count2 = Program.MySqlbusqueda(sqlCnnString, "select membid from " +
                                    tblSubscribers + " where (membid2 = '" + V1SUSCRIID + "')");
                                if (count2.Trim().Length == 0)
                                {
                                    V1SUSCRIID = MembidDummy;
                                }
                                else
                                {
                                    V1SUSCRIID = count2;
                                }
                            }
                            else
                            {
                                V1SUSCRIID = count;
                            }
                        }
                        if (V1FEDTAXNO.Trim().Length == 0)
                        {
                            V1FEDTAXNO = "999999999";
                        }
                        else
                        {
                            string count = Program.MySqlbusqueda(sqlCnnString, "select count(*) from  " + tblProvider + " where vendor ='" + V1FEDTAXNO + "'");

                            if (count == "0")
                            {
                                V1FEDTAXNO = "999999999";
                            }
                        }
                        //TODO: /////////////////////////// header //////////////
                        myHeader.uniquekey_1= (new string(' ', 60));

                        myHeader.claim_no_2 = ( intClaim_no_2.ToString("00000000000000#"));
                        {// Nota nopuede estar en blanco
                            myHeader.prov_name_3 = ( Program.MySqlbusqueda(sqlCnnString, "select  SUBSTRING([LASTNAME],1,CHARINDEX (' ',[LASTNAME],1)) AS LASTNAME from " + tblProvider + " where (payee_npi ='" + V156NPI + "') or (npi='" + V156NPI + "')"));
                            if(myHeader.prov_name_3.ToString().Trim().Length == 0 )
                            {
                                myHeader.prov_name_3 = (Program.MySqlbusqueda(sqlCnnString, "select LASTNAME from " + tblProvider + " where (payee_npi ='" + V156NPI + "') or (npi='" + V156NPI + "')"));
                            }
                            myHeader.prov_addrs_4 = (Program.MySqlbusqueda(sqlCnnString, "select  rtrim(ltrim(STREET)) as Add1   from " + tblProvider + " where (payee_npi ='" + V156NPI + "') or (npi='" + V156NPI + "')"));

                            if (myHeader.prov_addrs_4.ToString().Trim().Length  == 0 )
                            {
                                myHeader.prov_addrs_4 = ("Dummy");

                            }

                            if(myHeader.prov_addrs_4.ToString().Trim().ToUpper().Contains("BOX"))
                            {
                                myHeader.prov_addrs_4 = ("Dummy");
                            }

                            myHeader.prov_csz_5 = (Program.MySqlbusqueda(sqlCnnString,   "select  rtrim(lTRIM(City)) from " + tblProvider + " where (payee_npi ='" + V156NPI + "') or (npi='" + V156NPI + "')"));

                            myHeader.prov_state_5 = (Program.MySqlbusqueda(sqlCnnString, "select  rtrim(lTRIM(State)) From " + tblProvider + " where (payee_npi ='" + V156NPI + "') or (npi='" + V156NPI + "')"));
                            myHeader.prov_zipcode_5 = (Program.MySqlbusqueda(sqlCnnString, "select rtrim(lTRIM(Zip)) from " + tblProvider + " where (payee_npi ='" + V156NPI + "') or (npi='" + V156NPI + "')"));

                            if (myHeader.prov_zipcode_5.ToString().Trim().Length >0)
                            {
                                if (myHeader.prov_zipcode_5.ToString().Trim().Length<9) {
                                    myHeader.prov_zipcode_5 += (new string('9', 9 - myHeader.prov_zipcode_5.ToString().Trim().Length));
                                }
                            }else {
                                myHeader.prov_zipcode_5 = ("999999999");
                            }

                            myHeader.prov_phone_6 = ("7879999999");//Program.MySqlbusqueda(sqlCnnString, "select  ContactTelephone from tblProvider where NPI = '" + V156NPI + "'");
                            myHeader.provpaynam_7 = ( Program.MySqlbusqueda(sqlCnnString, "select SUBSTRING([LASTNAME],1,CHARINDEX (' ',[LASTNAME],1)) + ' ' +  FIRSTNAME  from " + tblProvider + " where (payee_npi ='" + V156NPI + "') or (npi='" + V156NPI + "')"));
                            myHeader.prov_contac = myHeader.provpaynam_7;
                        }
                        {
                            myHeader.prov_name_3 = (myHeader.prov_name_3.ToString().Trim());
                            if (myHeader.prov_name_3.Length > 33)
                            {
                                myHeader.prov_name_3 = ( myHeader.prov_name_3.ToString().Substring(0, 33));
                            }
                        }

                        myHeader.provpayadr_8 = (" "); //myHeader.prov_addrs_4;
                        myHeader.provpaycsz_9 = (" ");//myHeader.prov_csz_5;
                        myHeader.provpayphn_10 = (" ");// myHeader.prov_phone_6;
                        myHeader.two_1_11 = (new string(' ', 37));
                        myHeader.two_2_12 = (new string(' ', 37));
                        {
                            myHeader.pat_id_13 =  (foxDR["V1PATCNTRL"].ToString());
                            if (myHeader.pat_id_13.ToString().Trim().Length == 0)
                            {
                                myHeader.pat_id_13 = ("0");
                            }
                        }
                        myHeader.med_rec_no_14 = (foxDR["V1MEDREC"].ToString());
                        myHeader.batch_type_15 = (foxDR["V1TYOFBILL"].ToString());
                        myHeader.clam_freq = (" ");
                        myHeader.fedtaxid_16 = (V1FEDTAXNO.Trim()); ;  //foxDR["V1FEDTAXNO"].ToString();
                        myHeader.from_date_17 = (Program.setFecha(foxDR["V1STDATE1"].ToString(), Images));
                        myHeader.thru_date_18 = (Program.setFecha(foxDR["V1STDATE2"].ToString(), Images));
                        {
                            String fl_7_19 = foxDR["V1ADMIDATE"].ToString().Trim();
                            if (fl_7_19.Trim().Length == 0)
                            {
                                fl_7_19 = myHeader.from_date_17.ToString().Trim();
                            }

                            if (fl_7_19.Length < 6)
                            {
                                throw new Exception("Error en la fecha V1ADMIDATE -->" + fl_7_19 + " -->Imagen-->" + Images);
                            }
                            if (fl_7_19.Length == 0)
                            {

                                myHeader.fl_7_19 = ( Program.setFecha(Images.Substring(0, 6), Images));

                            }
                            else
                            {
                                try
                                {
                                    String imgDate = "20" + Images.Substring(4, 2) +
                                                     Images.Substring(0, 2) +
                                                     Images.Substring(2, 2);
                                    fl_7_19 = "20" + fl_7_19.Substring(4, 2) +
                                                    fl_7_19.Substring(0, 2) +

                                                    fl_7_19.Substring(2, 2);

                                    string dateNow = System.DateTime.Today.ToString("yyMMdd");

                                    if (Convert.ToInt32(fl_7_19) > Convert.ToInt32(dateNow))
                                    {
                                        myHeader.fl_7_19 = (Program.setFecha(Images.Substring(0, 6), Images));
                                    }
                                    else
                                    {
                                        myHeader.fl_7_19 = (Program.setFecha(foxDR["V1ADMIDATE"].ToString(), Images));
                                    }
                                }
                                catch (Exception ex)
                                {
                                    throw new Exception(ex.ToString() + " --fl_7_19");
                                }

                            }
                        }
                        myHeader.cov_d_20 = (new string(' ', 10));
                        myHeader.ncd_21 = (new string(' ', 10));
                        myHeader.cid_22 = (new string(' ', 10));
                        myHeader.lrd_23 = (new string(' ', 10));
                        myHeader.eleven_1_24 = (new string(' ', 16));
                        myHeader.eleven_2_25 = (new string(' ', 16));

                        myHeader.pat_lname_26 = (Program.MySqlbusqueda(sqlCnnString, "select SUBSTRING([LastNM],1,CHARINDEX (' ',[LastNM],1)) AS LASTNAME from " + tblSubscribers + " where (membid = '" + V1SUSCRIID + "') or (membid2 = '" + V1SUSCRIID + "')"));
                        if (myHeader.pat_lname_26.ToString().Trim().Length == 0)
                        {
                            myHeader.pat_lname_26 = (Program.MySqlbusqueda(sqlCnnString, "select LastNM from " + tblSubscribers + " where (membid = '" + V1SUSCRIID + "') or (membid2 = '" + V1SUSCRIID + "')"));

                        }

                        myHeader.pat_fname_27 = (Program.MySqlbusqueda(sqlCnnString, "select FirstNM from " + tblSubscribers + " where (membid = '" + V1SUSCRIID + "') or (membid2 = '" + V1SUSCRIID + "')"));
                        myHeader.pat_mname_28 = (Program.MySqlbusqueda(sqlCnnString, "select MI from " + tblSubscribers + " where (membid = '" + V1SUSCRIID + "') or (membid2 = '" + V1SUSCRIID + "')"));
                        myHeader.pat_nmsfx_29 = (new string(' ', 10));
                        myHeader.pat_addrs_30 = (Program.MySqlbusqueda(sqlCnnString, "select Street from " + tblSubscribers + " where (membid = '" + V1SUSCRIID + "') or (membid2 = '" + V1SUSCRIID + "')"));
                        myHeader.pat_city_31 = (Program.MySqlbusqueda(sqlCnnString, "select City from " + tblSubscribers + "  where (membid = '" + V1SUSCRIID + "') or (membid2 = '" + V1SUSCRIID + "')"));
                        myHeader.pat_state_32 = (Program.MySqlbusqueda(sqlCnnString, "select State from " + tblSubscribers + "  where (membid = '" + V1SUSCRIID + "') or (membid2 = '" + V1SUSCRIID + "')"));
                        {
                            myHeader.pat_zip_33 = (Program.MySqlbusqueda(sqlCnnString, "select Zip from " + tblSubscribers + "  where (membid = '" + V1SUSCRIID + "') or (membid2 = '" + V1SUSCRIID + "')"));
                            if (myHeader.pat_zip_33.ToString().Trim().Length > 0)
                            {
                                if (myHeader.pat_zip_33.ToString().Trim().Length >= 5)
                                {
                                    myHeader.pat_zip_33 = (myHeader.pat_zip_33.ToString().Trim().Substring(0, 5));
                                }
                                else
                                {
                                    myHeader.pat_zip_33 = ("99999");
                                }
                            }
                            else
                            {
                                myHeader.pat_zip_33 = ("99999");
                            }

                        }
                        {
                            myHeader.pat_bd_34 = (Program.MySqlbusqueda(sqlCnnString, "select Birth from " + tblSubscribers + "  where (membid = '" + V1SUSCRIID + "') or (membid2 = '" + V1SUSCRIID + "')"));
                            if (myHeader.pat_bd_34.ToString().Trim().Length == 10)
                            {
                                try
                                {
                                    System.DateTime Dt = System.DateTime.Parse(myHeader.pat_bd_34.ToString());
                                    myHeader.pat_bd_34 = ( Dt.ToString("yyyyMMdd"));
                                }
                                catch (Exception ex)
                                {
                                    throw new Exception(ex.Message + "--pat_bd_34-->" + myHeader.pat_bd_34);
                                }
                            }
                            else
                            {
                                try
                                {//Dummy
                                    System.DateTime Dt = System.DateTime.Parse("01/01/1901");

                                    myHeader.pat_bd_34 = (Dt.ToString("yyyyMMdd"));
                                }
                                catch (Exception ex)
                                {
                                    throw new Exception(ex.Message + "--pat_bd_34-->" + myHeader.pat_bd_34);
                                }

                            }
                        }
                        myHeader.pat_sex_35 = (Program.MySqlbusqueda(sqlCnnString, "select sex from " + tblSubscribers + "  where (membid = '" + V1SUSCRIID + "') or (membid2 = '" + V1SUSCRIID + "')"));

                        myHeader.pat_ms_36 = (new string(' ', 1));
                        {
                            if (foxDR["V1ADMIDATE"].ToString().Trim().Length != 0)
                            {
                                myHeader.adm_date_37 = (Program.setFecha(foxDR["V1ADMIDATE"].ToString(), Images));
                            }
                            else
                            {
                                myHeader.adm_date_37 = ( myHeader.from_date_17.ToString().Trim());
                            }
                        }
                        {
                            myHeader.adm_hour_38 = (foxDR["V1ADMIHOUR"].ToString());
                            try
                            {
                                //Int32 adm_hour_38 = Convert.ToInt32(myHeader.adm_hour_38);
                                string HH = myHeader.adm_hour_38.ToString().Trim().Substring(0, 2);
                                string MM = myHeader.adm_hour_38.ToString().Trim().Substring(2, 2);
                                int iHH = int.Parse(HH);
                                int iMM = int.Parse(MM);

                                if ((iHH > 24))
                                {
                                    HH = "24";
                                }
                                if (iMM > 59)
                                {
                                    MM = "00";
                                }

                                myHeader.adm_hour_38 = (HH + MM);
                            }
                            catch
                            {

                                myHeader.adm_hour_38 = ("2400");
                            }
                        }
                        {
                            Int32 itype_39 = Int32.Parse(foxDR["V1ADMITYPE"].ToString());

                            if ((itype_39 > 0) && (itype_39 < 5))
                            {
                                myHeader.adm_type_39 = (itype_39.ToString());
                            }
                            else
                            {
                                myHeader.adm_type_39 = ("9");
                            }
                        }
                        {
                            Int32 iadm_src_40 = Int32.Parse(foxDR["V1ADMSOURC"].ToString());
                            //1 2 4 6 7 8

                            switch (iadm_src_40)
                            {
                                case 1:
                                    myHeader.adm_src_40 = (iadm_src_40.ToString());
                                    break;
                                case 2:
                                    myHeader.adm_src_40 = (iadm_src_40.ToString());
                                    break;
                                case 4:
                                    myHeader.adm_src_40 = (iadm_src_40.ToString());
                                    break;
                                case 6:
                                    myHeader.adm_src_40 = (iadm_src_40.ToString());
                                    break;
                                case 7:
                                    myHeader.adm_src_40 = (iadm_src_40.ToString());
                                    break;
                                case 8:
                                    myHeader.adm_src_40 = (iadm_src_40.ToString());
                                    break;
                                default:
                                    myHeader.adm_src_40 = ("9");
                                    break;
                            }
                        }
                        myHeader.d_hr_41 = (foxDR["V1DHR"].ToString());
                        myHeader.stat_42 = (foxDR["V1PATSTATU"].ToString());
                        myHeader.cond_1_43 = (foxDR["V1CONCOD18"].ToString());
                        myHeader.cond_2_44 = (foxDR["V1CONCOD19"].ToString());
                        myHeader.cond_3_45 = (foxDR["V1CONCOD20"].ToString());
                        myHeader.cond_4_46 = (foxDR["V1CONCOD21"].ToString());
                        myHeader.cond_5_47 = (foxDR["V1CONCOD22"].ToString());
                        myHeader.cond_6_48 = (foxDR["V1CONCOD23"].ToString());
                        myHeader.cond_7_49 = (foxDR["V1CONCOD24"].ToString());
                        myHeader.cond_8_50 = (foxDR["V1CONCOD25"].ToString());
                        myHeader.cond_9_51 = (foxDR["V1CONCOD26"].ToString());
                        myHeader.cond_10_52 = (foxDR["V1CONCOD27"].ToString());
                        myHeader.cond_11_53 = (foxDR["V1CONCOD28"].ToString());
                        myHeader.acdt_st_54 = (new string(' ', 2));
                        myHeader.thirty1_55 = (new string(' ', 10));
                        myHeader.thirty_56 = (new string(' ', 10));
                        myHeader.occ_code1_57 = (new string(' ', 2));
                        myHeader.occ_date1_58 = (new string(' ', 8));
                        myHeader.occ_code2_59 = (new string(' ', 2));
                        myHeader.occ_date2_60 = (new string(' ', 8));
                        myHeader.occ_code3_61 = (new string(' ', 2));
                        myHeader.occ_date3_62 = (new string(' ', 8));
                        myHeader.occ_code4_63 = (new string(' ', 2));
                        myHeader.occ_date4_64 = (new string(' ', 8));
                        myHeader.occ_spanc1_65 = (new string(' ', 2));
                        myHeader.occ_spanf1_66 = (new string(' ', 8));
                        myHeader.occ_spant1_67 = (new string(' ', 8));
                        myHeader.occ_spanc2_68 = (new string(' ', 2));
                        myHeader.occ_spanf2_69 = (new string(' ', 8));
                        myHeader.occ_spant2_70 = (new string(' ', 8));
                        myHeader.occ_code5_71 = (new string(' ', 2));
                        myHeader.occ_date5_72 = (new string(' ', 8));
                        myHeader.occ_code6_73 = (new string(' ', 2));
                        myHeader.occ_date6_74 = (new string(' ', 8));
                        myHeader.occ_code7_75 = (new string(' ', 2));
                        myHeader.occ_date7_76 = (new string(' ', 8));
                        myHeader.occ_code8_77 = (new string(' ', 2));
                        myHeader.occ_date8_78 = (new string(' ', 8));
                        myHeader.occ_spanc3_79 = (new string(' ', 2));
                        myHeader.occ_spanf3_80 = (new string(' ', 8));
                        myHeader.occ_spant3_81 = (new string(' ', 8));
                        myHeader.occ_span4_82 = (new string(' ', 2));
                        myHeader.occ_spanf4_83 = (new string(' ', 8));
                        myHeader.occ_spant4_84 = (new string(' ', 8));
                        myHeader.a_37_85 = (new string(' ', 28));
                        myHeader.b_37_86 = (new string(' ', 28));
                        myHeader.c_37_87 = (new string(' ', 29));
                        myHeader.a_38_88 = (new string(' ', 50));
                        myHeader.LNAME_38 = (" ");
                        myHeader.FNAME_38 = (" ");
                        myHeader.MNAME_38 = (" ");
                        myHeader.NAMESFX_38 = (" ");
                        myHeader.b_38_89 = (new string(' ', 50));
                        myHeader.c_38_90  = (new string(' ', 50));
                        myHeader.CITY_38  = ( " ");
                        myHeader.STATE_38 = (" ");
                        myHeader.ZIP_38 = (" ");
                        myHeader.d_38_91 = (new string(' ', 50));
                        myHeader.e_38_92 = (" "); //new string(' ', 50);
                        {
                            try
                            {
                                myHeader.val_code1_93 = (foxDR["V1VALUCO39"].ToString());

                                if (myHeader.val_code1_93.ToString().Trim() == "00")
                                {

                                    myHeader.val_code1_93 = (" ");
                                }
                            }
                            catch
                            {
                                throw new Exception("Error con val_code1_93 [V1VALUCO39]:" + myHeader.val_code1_93);
                            }
                        }
                        myHeader.val_code1_93 = ( " "); // esto es temporero pues esta esta mal
                        {
                            myHeader.val_code2_94 = (foxDR["V1VALUCO40"].ToString());

                            if (myHeader.val_code2_94.ToString().Trim() == "00")
                            {
                                myHeader.val_code2_94 = ( " ");
                            }

                        }

                        myHeader.val_code2_94 = (" "); // esto es temporero pues esta mal

                        myHeader.val_code3_95 = ( new string(' ', 2));
                        myHeader.val_code4_96 = (new string(' ', 2));
                        myHeader.val_code5_97 = ( new string(' ', 2));
                        myHeader.val_code6_98  = ( new string(' ', 2));
                        myHeader.val_code7_99  = (new string(' ', 2));
                        myHeader.val_code8_100  = ( new string(' ', 2));
                        myHeader.val_code9_101  = ( new string(' ', 2));
                        myHeader.val_code10_102  = ( new string(' ', 2));
                        myHeader.val_code11_103  = ( new string(' ', 2));
                        myHeader.val_code12_104  = ( new string(' ', 2));
                        {
                            myHeader.val_amt1_105 = (foxDR["V1AMOUNT39"].ToString());

                            if (myHeader.val_amt1_105.ToString() == "00")
                            {
                                myHeader.val_amt1_105 = ( " ");
                            }

                            myHeader.val_amt1_105 = ( " "); // esto es temporero pues esta mal

                            myHeader.val_amt2_106 = ( foxDR["V1AMOUNT40"].ToString());

                            if (myHeader.val_amt2_106.ToString() == "00")
                            {
                                myHeader.val_amt2_106 = (" ");
                            }
                            myHeader.val_amt2_106 = (" "); // esto es temporero pues esta mal

                        }
                        myHeader.val_amt3_107  = (new string(' ', 12));
                        myHeader.val_amt4_108  = (new string(' ', 12));
                        myHeader.val_amt5_109  = (new string(' ', 12));
                        myHeader.val_amt6_110  = (new string(' ', 12));
                        myHeader.val_amt7_111  = (new string(' ', 12));
                        myHeader.val_amt8_112  = (new string(' ', 12));
                        myHeader.val_amt9_113  = (new string(' ', 12));
                        myHeader.val_amt10_114  = (new string(' ', 12));
                        myHeader.val_amt11_115  = (new string(' ', 12));
                        myHeader.val_amt12_116  = (new string(' ', 12));
                        myHeader.pay_name1_117  = ( pay_name1_117);
                        myHeader.pay_name2_118  = (new string(' ', 31));
                        myHeader.pay_name3_119  = (new string(' ', 31));
                        myHeader.pay_id1_120 = ( "660610220"); //MMM ID
                        myHeader.pay_id2_121  = (new string(' ', 20));
                        myHeader.pay_id3_122  = (new string(' ', 20));
                        {
                            if (isNotGoodV156NPI)
                            {
                                myHeader.prov_npi56_123 = ( foxDR["V156NPI"].ToString());
                            }
                            else
                            {
                                myHeader.prov_npi56_123 = ( V156NPI);
                            }
                        }
                        myHeader.prov_no1_124  = (new string(' ', 16));
                        myHeader.prov_no2_125  = (new string(' ', 16));
                        myHeader.prov_no3_126  = (new string(' ', 16));
                        myHeader.rel_info1_127  = ( "N" + new string(' ', 9));
                        myHeader.rel_info2_128  = (new string(' ', 10));
                        myHeader.rel_info3_129  = (new string(' ', 10));
                        myHeader.asg_ben1_130  = ( "Y");// new string(' ', 10));
                        myHeader.asg_ben2_131  = (new string(' ', 10));
                        myHeader.asg_ben3_132  = (new string(' ', 10));
                        myHeader.prior_pay1_133  = (new string(' ', 12));
                        myHeader.prior_pay2_134  = (new string(' ', 12));
                        myHeader.prior_pay3_135  = (new string(' ', 12));
                        myHeader.prior_pay4_136  = (new string(' ', 12));
                        myHeader.est_due1_137  = (new string(' ', 12));
                        myHeader.est_due2_138  = (new string(' ', 12));
                        myHeader.est_due3_139  = (new string(' ', 12));
                        myHeader.est_due4_140  = (new string(' ', 12));
                        myHeader.a_56_141  = (new string(' ', 18));        //V1BILLPROV;// new string(' ', 18));
                        myHeader.b_56_142  = (new string(' ', 18));
                        myHeader.c_56_143  = (new string(' ', 18));
                        myHeader.d_56_144  = (new string(' ', 18));
                        myHeader.e_56_145  = (new string(' ', 18));
                        myHeader.a_57_146  = (new String(' ', 34)); //V1BILLPROV;

                        // SI NO ESTA LE PONGO 99999
                        myHeader.ins_name1_147 = ( Program.MySqlbusqueda(sqlCnnString, "select  " +
                            " rtrim(ltrim(SUBSTRING([LastNM],1,CHARINDEX (' ',[LastNM],1)))) + ',' + rtrim(ltrim(FirstNM)) as name  from " +
                            tblSubscribers + "  where (membid = '" + V1SUSCRIID + "') or (membid2 = '" + V1SUSCRIID + "')"));

                        myHeader.ins_lname1  = ( Program.MySqlbusqueda(sqlCnnString, "select  SUBSTRING([LastNM],1,CHARINDEX (' ',[LastNM],1)) AS LASTNAME from " + tblSubscribers + "  where (membid = '" + V1SUSCRIID + "') or (membid2 = '" + V1SUSCRIID + "')").Trim());
                        if (myHeader.ins_lname1.ToString ().Trim().Length == 0)
                        {
                            myHeader.ins_lname1  = ( Program.MySqlbusqueda(sqlCnnString, "select  LastNM from " + tblSubscribers + "  where (membid = '" + V1SUSCRIID + "') or (membid2 = '" + V1SUSCRIID + "')").Trim());

                        }
                        myHeader.ins_fname1  = ( Program.MySqlbusqueda(sqlCnnString, "select  rtrim(ltrim(FirstNM)) from " + tblSubscribers + "  where (membid = '" + V1SUSCRIID + "') or (membid2 = '" + V1SUSCRIID + "')"));
                        myHeader.ins_mname1  = ( " ");
                        myHeader.ins_namesfx1  = ( " ");
                        myHeader.ins_name2_148  = ( "");    // Program.busqueda(sqlCnnString, "select LastName2 from " + tblSubscribers + "  where SubscriberID = '" + V1SUSCRIID + "'");
                        myHeader.ins_lname2  = ( " ");
                        myHeader.ins_fname2  = ( " ");
                        myHeader.ins_mname2  = ( " ");
                        myHeader.ins_namesfx2  = ( " ");
                        myHeader.ins_name3_149  = ( "");   //Program.busqueda(sqlCnnString, "select FirstName from " + tblSubscribers + "  where SubscriberID = '" + V1SUSCRIID + "'");
                        myHeader.ins_lname3  = ( " ");
                        myHeader.ins_fname3  = ( " ");
                        myHeader.ins_mname3  = ( " ");
                        myHeader.ins_namesfx3  = ( " ");
                        myHeader.p_relat1_150  = ( "18"); // Ref:18 PPO: 001 (18), 011(01), other(24)
                        myHeader.p_relat2_151  = ( new string(' ', 3));
                        myHeader.p_relat3_152  = ( new string(' ', 3));
                        myHeader.crt1_153  = ( V1SUSCRIID); //foxDR["V1SUSCRIID"].ToString();     // new string(' ',24);
                        //Program.busqueda(sqlCnnString, "select GenderCode from " + tblSubscribers + "  where SuscriberID = '" + V1SUSCRIID + "'");
                        myHeader.crt2_154  = ( new string(' ', 24));
                        myHeader.crt3_155  = ( new string(' ', 24));
                        myHeader.group1_156  = (new string(' ', 20));
                        myHeader.group2_157  = ( new string(' ', 20));
                        myHeader.group3_158  = ( new string(' ', 20));
                        myHeader.ins_group1_159  = (new string(' ', 21));
                        myHeader.ins_group2_160  = (new string(' ', 21));
                        myHeader.ins_group3_161  = (new string(' ', 21));
                        myHeader.treat_cod1_162  = ( foxDR["V1TREATAUT"].ToString());
                        myHeader.treat_cod2_163  = ( new string(' ', 22));
                        myHeader.treat_cod3_164  = ( new string(' ', 22));
                        myHeader.esc1_165  = ( new string(' ', 2));
                        myHeader.esc2_166  = ( new string(' ', 2));
                        myHeader.esc3_167  = ( new string(' ', 2));
                        myHeader.doc_ctrl1_168  = ( new string(' ', 20));
                        myHeader.doc_ctrl2_169  = ( new string(' ', 20));
                        myHeader.doc_ctrl3_170  = ( new string(' ', 20));
                        myHeader.emp_name1_171  = ( new string(' ', 30));
                        myHeader.emp_name2_172  = ( new string(' ', 30));
                        myHeader.emp_name3_173  = ( new string(' ', 30));
                        myHeader.emp_loc1_174  = ( new string(' ', 43));
                        myHeader.emp_loc2_175  = ( new string(' ', 43));
                        myHeader.emp_loc3_176  = ( new string(' ', 43));

                        {//mydbMMM.tblDiagnosisCodes
                            myHeader.diag1_177 = ( foxDR["V2PRINDIAG"].ToString().ToString().Trim());
                            if (myHeader.diag1_177.Length == 0)
                            {
                                myHeader.diag1_177 = ("99999");
                            }
                            else
                            {
                                String count = Program.MySqlbusqueda(sqlCnnString,
                                    "select count(*) from tblDiagnosisCodes where code='" + myHeader.diag1_177 + "';");
                                if (count == "0")
                                {
                                    myHeader.diag1_177 = ("99999");
                                }
                            }
                        }
                        myHeader.diag2_178  = (foxDR["V267ACOD"].ToString());
                        myHeader.diag3_179  = (foxDR["V267BCOD"].ToString());
                        myHeader.diag4_180  = (foxDR["V267CCOD"].ToString());
                        myHeader.diag5_181  = (foxDR["V267DCOD"].ToString());
                        myHeader.diag6_182  = (foxDR["V267ECOD"].ToString());

                        myHeader.diag7_183  = (foxDR["V267FCOD"].ToString());
                        myHeader.diag8_184  = (foxDR["V267GCOD"].ToString());
                        myHeader.diag9_185  = (foxDR["V267HCOD"].ToString());
                        myHeader.diag10_186  = (foxDR["V267ICOD"].ToString());
                        myHeader.diag11_187  = (foxDR["V267JCOD"].ToString());
                        myHeader.diag12_188  = (foxDR["V267KCOD"].ToString());
                        myHeader.diag13_189  = (foxDR["V267LCOD"].ToString());
                        myHeader.diag14_190  = (foxDR["V267MCOD"].ToString());
                        myHeader.diag15_191  = (foxDR["V267NCOD"].ToString());
                        myHeader.diag16_192  = (foxDR["V267OCOD"].ToString());
                        myHeader.diag17_193  = (foxDR["V267PCOD"].ToString());
                        myHeader.diag18_194  = (foxDR["V267QCOD"].ToString());

                        myHeader.adm_diag_195  = (foxDR["V2ADMDIACD"].ToString());
                        myHeader.e_code1_196  = (foxDR["V2PATIENDX"].ToString());
                        myHeader.e_code2_197  = ( new string(' ', 8));
                        myHeader.e_code3_198  = (new string(' ', 8));
                        myHeader.pat_rdx1_199  = ( new string(' ', 8));
                        myHeader.pat_rdx2_200  = (new string(' ', 8));
                        myHeader.pat_rdx3_201  = ( new string(' ', 8));
                        myHeader.pps_code  = ( " ");
                        myHeader.a_73_202  = ( new string(' ', 10));

                        {
                            myHeader.proc_cod1_203  = (foxDR["V2CODE74"].ToString());
                            myHeader.proc_cod2_204  = (foxDR["V2CODE74A"].ToString());
                            myHeader.proc_cod3_205  = (foxDR["V2CODE74B"].ToString());
                            myHeader.proc_cod4_206  = (foxDR["V2CODE74C"].ToString());
                            myHeader.proc_cod5_207  = (foxDR["V2CODE74D"].ToString());
                            myHeader.proc_cod6_208  = (foxDR["V2CODE74E"].ToString());

                            if (myHeader.proc_cod1_203.ToString ().Trim().Length > 0)
                            {
                                myHeader.proc_date1_209  = ( GetDate2(foxDR["V2DATE74"].ToString()));
                                if (myHeader.proc_date1_209.ToString().Trim().Length == 0)
                                {
                                    myHeader.proc_date1_209 = myHeader.from_date_17;
                                }
                            }
                            else
                            {
                                myHeader.proc_date1_209 = ( new string(' ', 8));
                            }

                            if (myHeader.proc_cod2_204.ToString().Trim().Length > 0)
                            {
                                myHeader.proc_date2_210 = ( GetDate2(foxDR["V2DATE74A"].ToString()));
                                if (myHeader.proc_date2_210.ToString().Trim().Length == 0)
                                {
                                    myHeader.proc_date2_210 = myHeader.from_date_17;
                                }
                            }
                            else
                            {
                                myHeader.proc_date2_210  = ( new string(' ', 8));
                            }

                            if (myHeader.proc_cod3_205.ToString ().Trim().Length > 0)
                            {
                                myHeader.proc_date3_211  = ( GetDate2(foxDR["V2DATE74B"].ToString()));
                                if (myHeader.proc_date3_211.ToString().Trim().Length == 0)
                                {
                                    myHeader.proc_date3_211 = myHeader.from_date_17;
                                }
                            }
                            else
                            {
                                myHeader.proc_date3_211  = ( new string(' ', 8));
                            }

                            if (myHeader.proc_cod4_206.ToString().Trim().Length > 0)
                            {
                                myHeader.proc_date4_212  = (GetDate2(foxDR["V2DATE74C"].ToString()));
                                if (myHeader.proc_date4_212.ToString().Trim().Length == 0)
                                {
                                    myHeader.proc_date4_212 = myHeader.from_date_17;
                                }
                            }
                            else
                            {
                                myHeader.proc_date4_212  = ( new string(' ', 8));
                            }

                            if (myHeader.proc_cod5_207.ToString ().Trim().Length > 0)
                            {
                                myHeader.proc_date5_213  = ( GetDate2(foxDR["V2DATE74D"].ToString()));
                                if (myHeader.proc_date5_213.ToString().Trim().Length == 0)
                                {
                                    myHeader.proc_date5_213 = myHeader.from_date_17;
                                }
                            }
                            else
                            {
                                myHeader.proc_date5_213 = ( new string(' ', 8));
                            }

                            if (myHeader.proc_cod6_208.ToString().Trim().Length > 0)
                            {
                                myHeader.proc_date6_214  = ( GetDate2(foxDR["V2DATE74E"].ToString()));
                                if (myHeader.proc_date6_214.ToString().Trim().Length == 0)
                                {
                                    myHeader.proc_date6_214 = myHeader.from_date_17;
                                }
                            }
                            else
                            {
                                myHeader.proc_date6_214 = ( new string(' ', 8));
                            }
                        }
                        //
                        myHeader.att_phyln_215  = ( Program.MySqlbusqueda(sqlCnnString, "select  SUBSTRING([LASTNAME],1,CHARINDEX (' ',[LASTNAME],1)) AS LASTNAME from " + tblProvider + " where (NPI = '" + V276NPI + "') or (payee_npi ='" + V276NPI + "')")); //LASTNAME FIRSTNAME

                        if (myHeader.att_phyln_215.ToString().Trim().Length ==0)
                        {
                            myHeader.att_phyln_215 = (Program.MySqlbusqueda(sqlCnnString, "select LASTNAME from " + tblProvider + " where (NPI = '" + V276NPI + "') or (payee_npi ='" + V276NPI + "')")); //LASTNAME FIRSTNAME
                        }

                        myHeader.att_phyfn_216 = ( Program.MySqlbusqueda(sqlCnnString, "select  FIRSTNAME from " + tblProvider + " where (NPI = '" + V276NPI + "') or (payee_npi='" + V276NPI + "')"));
                        myHeader.att_phymn  = ( " ");
                        myHeader.att_physfx  = ( " ");
                        //***********************************************************************************
                        //TODO Write 217, 218,219 ** V276NPI

                        if (V276NPI == "9999999995")
                        {
                            myHeader.att_phynpi_217  = (foxDR["V276NPI"].ToString());

                            if (myHeader.att_phynpi_217.ToString().Trim().Length == 0)
                            {
                                myHeader.att_phynpi_217  = ( V276NPI);
                            }
                            myHeader.att_phyidq_218  = ( new string(' ', 3));
                            myHeader.att_phyid_219  = ( new string(' ', 15));
                        }
                        else
                        {
                            myHeader.att_phynpi_217  = ( V276NPI);
                            if (!isNotGoodV276NPI)
                            {
                                myHeader.att_phyidq_218  = ( new string(' ', 3));
                                myHeader.att_phyid_219 = (new string(' ', 15));
                            }
                            else
                            {
                                myHeader.att_phyidq_218  = ( new string(' ', 3));
                                myHeader.att_phyid_219 = (new string(' ', 15));
                            }
                        }

                        myHeader.op_phyln_220  = ( Program.MySqlbusqueda(sqlCnnString, "select  SUBSTRING([LASTNAME],1,CHARINDEX (' ',[LASTNAME],1)) AS LASTNAME from " + tblProvider + " where (NPI = '" + V2OPERANPI + "') or (payee_npi='" + V2OPERANPI + "')")); //LASTNAME FIRSTNAME

                        if (myHeader.op_phyln_220.ToString().Trim().Length == 0)
                        {
                            myHeader.op_phyln_220  = ( Program.MySqlbusqueda(sqlCnnString, "select  LASTNAME from " + tblProvider + " where (NPI = '" + V2OPERANPI + "') or (payee_npi='" + V2OPERANPI + "')")); //LASTNAME FIRSTNAME

                        }

                        myHeader.op_phyfn_221 = ( Program.MySqlbusqueda(sqlCnnString, "select  FIRSTNAME from " + tblProvider + " where (NPI = '" + V2OPERANPI + "') or (payee_npi='" + V2OPERANPI + "')")); //LASTNAME FIRSTNAME
                        myHeader.op_phymn  = ( " ");
                        myHeader.op_physfx  = (" ");
                        // Write 222, 223,224 ** V2OPERANPI
                        if (V2OPERANPI == "9999999995")
                        {
                            myHeader.op_phy_npi_222  = ( foxDR["V2OPERANPI"].ToString());
                            myHeader.op_phyidq_223  = ( new string(' ', 3));
                            myHeader.op_phyid_224  = ( new string(' ', 15));
                        }
                        else
                        {
                            myHeader.op_phy_npi_222  = ( V2OPERANPI);
                            if (!isNotGoodV2OPERANPI)
                            {
                                myHeader.op_phyidq_223  = ( new string(' ', 3));
                                myHeader.op_phyid_224  = ( new string(' ', 15));
                            }
                            else
                            {
                                myHeader.op_phyidq_223  = ( new string(' ', 3));
                                myHeader.op_phyid_224  = ( new string(' ', 15));
                            }
                        }

                        myHeader.ot_phy1ln_225  = ( Program.MySqlbusqueda(sqlCnnString, "select  SUBSTRING([LASTNAME],1,CHARINDEX (' ',[LASTNAME],1)) AS LASTNAME from " + tblProvider + " where (NPI = '" + V278NPI + "') or (payee_npi='" + V278NPI + "')")); //LASTNAME FIRSTNAME
                        if (myHeader.ot_phy1ln_225.ToString().Trim().Length == 0)
                        {
                            myHeader.ot_phy1ln_225  = ( Program.MySqlbusqueda(sqlCnnString, "select  LASTNAME from " + tblProvider + " where (NPI = '" + V278NPI + "') or (payee_npi='" + V278NPI + "')")); //LASTNAME FIRSTNAME
                        }
                        myHeader.ot_phy1fn_226 = (Program.MySqlbusqueda(sqlCnnString, "select  FIRSTNAME from " + tblProvider + " where (NPI = '" + V278NPI + "') or (payee_npi='" + V278NPI + "')")); //LASTNAME FIRSTNAME

                        // Write 227, 228,229 ** V278NPI
                        if (V278NPI == "9999999995")
                        {
                            myHeader.ot_phy1npi_227  = ( foxDR["V278NPI"].ToString());
                            myHeader.ot_phy1idq_228  = ( new string(' ', 3));
                            myHeader.ot_phy1id_229  = ( new string(' ', 15));
                        }
                        else
                        {
                            myHeader.ot_phy1npi_227  = ( V278NPI);
                            if (isNotGoodV278NPI == false)
                            {
                                myHeader.ot_phy1idq_228  = (new string(' ', 3));
                                myHeader.ot_phy1id_229 = (new string(' ', 15));
                            }
                            else
                            {
                                myHeader.ot_phy1idq_228  = ( new string(' ', 3));
                                myHeader.ot_phy1id_229  = ( new string(' ', 15));
                            }
                        }

                        myHeader.ot_phy2ln_230  = ( Program.MySqlbusqueda(sqlCnnString, "select  SUBSTRING([LASTNAME],1,CHARINDEX (' ',[LASTNAME],1)) AS LASTNAME from " + tblProvider + " where (NPI = '" + V279NPI + "') or (payee_npi='" + V279NPI + "')")); //LASTNAME FIRSTNAME
                        if (myHeader.ot_phy2ln_230.ToString().Trim().Length == 0)
                        {
                            myHeader.ot_phy2ln_230  = ( Program.MySqlbusqueda(sqlCnnString, "select LASTNAME from " + tblProvider + " where (NPI = '" + V279NPI + "') or (payee_npi='" + V279NPI + "')")); //LASTNAME FIRSTNAME

                        }
                        myHeader.ot_phy2fn_231 = (Program.MySqlbusqueda(sqlCnnString, "select  FIRSTNAME from " + tblProvider + " where (NPI = '" + V279NPI + "') or (payee_npi='" + V279NPI + "')")); //LASTNAME FIRSTNAME

                        // Write 232, 233,234 ** V279NPI
                        if (V279NPI == "9999999995")
                        {
                            myHeader.ot_phy2npi_232 = (foxDR["V279NPI"].ToString());
                            myHeader.ot_phy2idq_233 = (new string(' ', 3));
                            myHeader.ot_phy2id_234 = ( new string(' ', 15));
                        }
                        else
                        {
                            myHeader.ot_phy2npi_232  = ( V279NPI);
                            if (!isNotGoodV279NPI)
                            {
                                myHeader.ot_phy2idq_233  = ( new string(' ', 3));
                                myHeader.ot_phy2id_234 = (new string(' ', 15));
                            }
                            else
                            {
                                myHeader.ot_phy2idq_233  = ( new string(' ', 3));
                                myHeader.ot_phy2id_234 = (new string(' ', 15));
                            }
                        }
                        //***************************************************************************************

                        myHeader.remarks1_235  = ( foxDR["V2REMARKS"].ToString());
                        myHeader.remarks2_236  = ( new string(' ', 58));
                        myHeader.remarks3_237  = (new string(' ', 58));
                        myHeader.remarks4_238  = ( new string(' ', 58));
                        myHeader.prov_rep_239  = ( new string(' ', 26));
                        myHeader.prov_rp_dt_240  = ( new string(' ', 15));
                        myHeader.fl81a_1_241  = ( new string(' ', 2));
                        myHeader.fl81a_2_242  = ( new string(' ', 10));
                        myHeader.fl81a_3_243  = ( new string(' ', 12));
                        myHeader.fl81b_1_244  = ( new string(' ', 2));
                        myHeader.fl81b_2_245  = ( new string(' ', 10));
                        myHeader.fl81b_3_246  = ( new string(' ', 12));
                        myHeader.fl81c_1_247  = ( new string(' ', 2));
                        myHeader.fl81c_2_248  = ( new string(' ', 10));
                        myHeader.fl81c_3_249  = ( new string(' ', 12));
                        myHeader.fl81d_1_250  = ( new string(' ', 2));
                        myHeader.fl81d_2_251  = ( new string(' ', 10));
                        myHeader.fl81d_3_252 = (new string(' ', 12));
                        myHeader.poa1_253  = (foxDR["V2COD1"].ToString());
                        myHeader.poa2_254  = ( foxDR["V2COD2"].ToString());
                        myHeader.poa3_255  = ( foxDR["V2COD3"].ToString());
                        myHeader.poa4_256  = ( foxDR["V2COD4"].ToString());
                        myHeader.poa5_257  = ( foxDR["V2COD5"].ToString());
                        myHeader.poa6_258  = ( foxDR["V2COD6"].ToString());

                        {
                            // Estrututa de la image file : MMDDYY CC BBBB SEQDOC.TIF
                            //**** Icn ejemplo: CCNNNNMMMDD`YY Nota:CC es el numero de la CATEGORIA
                            //NNNN numero de la Seq no usal LA DE LA IMAGEN hay que calcularlo Cadave q cabies de Categoria regresa a uno,
                            //MMM es el Nombre del mes, DD es el dia,YY es el ano

                            String img = Images;
                            String CC = img.Substring(6, 2);

                                if (TMPcc == CC)
                                {
                                    iCC++;
                                }
                                else
                                {
                                    if (CC == "97")
                                    {
                                        iCC = int.Parse(sCount);
                                        iCC++;
                                    }
                                    else
                                    {
                                        iCC = 1;
                                    }
                                    TMPcc = CC;
                                }

                            String NNNN = iCC.ToString("000#");
                            String MMM = img.Substring(0, 2);
                            String DD = img.Substring(2, 2);
                            String YY = img.Substring(4, 2);

                            switch (MMM)
                            {
                                case "01":
                                    MMM = "JAN";
                                    break;
                                case "02":
                                    MMM = "FEB";
                                    break;
                                case "03":
                                    MMM = "MAR";
                                    break;
                                case "04":
                                    MMM = "APR";
                                    break;
                                case "05":
                                    MMM = "MAY";
                                    break;
                                case "06":
                                    MMM = "JUN";
                                    break;
                                case "07":
                                    MMM = "JUL";
                                    break;
                                case "08":
                                    MMM = "AUG";
                                    break;
                                case "09":
                                    MMM = "SEP";
                                    break;
                                case "10":
                                    MMM = "OCT";
                                    break;
                                case "11":
                                    MMM = "NOV";
                                    break;
                                case "12":
                                    MMM = "DEC";
                                    break;
                            }

                            myHeader.icn_259 = ( CC + NNNN + MMM.Substring(0, 3) + DD + "'" + YY);
                        }

                        myHeader.bht_260 = ( Images.Substring(0, 2) + "/" + Images.Substring(2, 2) + "/20" + Images.Substring(4, 2));  // mm/dd/ccyy

                        if (myHeader.prov_addrs_4.ToString().Trim().Length == 0)
                        {
                            myHeader.prov_addrs_4  = ( "DUMMY ADDRESS");
                        }

                        if (myHeader.pat_addrs_30.ToString().Trim().Length == 0)
                        {
                            myHeader.pat_addrs_30 = ("DUMMY ADDRESS");
                        }
                        if (myHeader.diag1_177.ToString().Trim().Length == 0)
                        {
                            myHeader.diag1_177  = ( "99999");
                        }
                        if (myHeader.adm_diag_195.ToString().Trim().Length == 0)
                        {
                            myHeader.adm_diag_195  = ( "99999");
                        }

                        //////////////////////////////////////////////////////////////////////////////////////////////////
                        using (StreamWriter fs = File.AppendText(txtFileOutPut.Trim()))
                        {
                            sHDOut.Clear();
                            //myHeader.uniquekey_1 + "|" +
                            sHDOut.Append(myHeader.claim_no_2 ); sHDOut.Append("|");
                            sHDOut.Append(myHeader.prov_name_3); sHDOut.Append("|");
                            sHDOut.Append(myHeader.prov_addrs_4.ToString().Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.prov_csz_5.ToString().Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.prov_state_5.ToString().Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.prov_zipcode_5.ToString().Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.prov_phone_6); sHDOut.Append("|");
                            sHDOut.Append(myHeader.prov_contac); sHDOut.Append("|");
                            //sHDOut.Append(myHeader.provpayadr_8.Trim()); sHDOut.Append("|");
                            //sHDOut.Append(myHeader.provpaycsz_9.Trim()); sHDOut.Append("|");
                            //sHDOut.Append(myHeader.provpayphn_10); sHDOut.Append("|");
                            sHDOut.Append(myHeader.two_1_11); sHDOut.Append("|");
                            sHDOut.Append(myHeader.two_2_12); sHDOut.Append("|");
                            sHDOut.Append(myHeader.pat_id_13); sHDOut.Append("|");
                            sHDOut.Append(myHeader.med_rec_no_14); sHDOut.Append("|");
                            sHDOut.Append(myHeader.batch_type_15); sHDOut.Append("|");
                            sHDOut.Append(myHeader.clam_freq); sHDOut.Append("|");
                            sHDOut.Append(myHeader.fedtaxid_16); sHDOut.Append("|");
                            sHDOut.Append(myHeader.from_date_17); sHDOut.Append("|");
                            sHDOut.Append(myHeader.thru_date_18); sHDOut.Append("|");
                            sHDOut.Append(myHeader.fl_7_19); sHDOut.Append("|");
                            sHDOut.Append(myHeader.cov_d_20); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ncd_21); sHDOut.Append("|");
                            sHDOut.Append(myHeader.cid_22); sHDOut.Append("|");
                            sHDOut.Append(myHeader.lrd_23); sHDOut.Append("|");
                            sHDOut.Append(myHeader.eleven_1_24); sHDOut.Append("|");
                            sHDOut.Append(myHeader.eleven_2_25); sHDOut.Append("|");
                            sHDOut.Append(myHeader.pat_lname_26); sHDOut.Append("|");
                            sHDOut.Append(myHeader.pat_fname_27); sHDOut.Append("|");
                            sHDOut.Append(myHeader.pat_mname_28); sHDOut.Append("|");
                            sHDOut.Append(myHeader.pat_nmsfx_29); sHDOut.Append("|");
                            sHDOut.Append(myHeader.pat_addrs_30); sHDOut.Append("|");
                            sHDOut.Append(myHeader.pat_city_31); sHDOut.Append("|");
                            sHDOut.Append(myHeader.pat_state_32); sHDOut.Append("|");
                            sHDOut.Append(myHeader.pat_zip_33); sHDOut.Append("|");
                            sHDOut.Append(myHeader.pat_bd_34); sHDOut.Append("|");
                            sHDOut.Append(myHeader.pat_sex_35); sHDOut.Append("|");
                            sHDOut.Append(myHeader.pat_ms_36); sHDOut.Append("|");
                            sHDOut.Append(myHeader.adm_date_37); sHDOut.Append("|");
                            sHDOut.Append(myHeader.adm_hour_38); sHDOut.Append("|");
                            sHDOut.Append(myHeader.adm_type_39); sHDOut.Append("|");
                            sHDOut.Append(myHeader.adm_src_40); sHDOut.Append("|");
                            sHDOut.Append(myHeader.d_hr_41); sHDOut.Append("|");
                            sHDOut.Append(myHeader.stat_42); sHDOut.Append("|");
                            sHDOut.Append(myHeader.cond_1_43); sHDOut.Append("|");
                            sHDOut.Append(myHeader.cond_2_44); sHDOut.Append("|");
                            sHDOut.Append(myHeader.cond_3_45); sHDOut.Append("|");
                            sHDOut.Append(myHeader.cond_4_46); sHDOut.Append("|");
                            sHDOut.Append(myHeader.cond_5_47); sHDOut.Append("|");
                            sHDOut.Append(myHeader.cond_6_48); sHDOut.Append("|");
                            sHDOut.Append(myHeader.cond_7_49); sHDOut.Append("|");
                            sHDOut.Append(myHeader.cond_8_50); sHDOut.Append("|");
                            sHDOut.Append(myHeader.cond_9_51); sHDOut.Append("|");
                            sHDOut.Append(myHeader.cond_10_52); sHDOut.Append("|");
                            sHDOut.Append(myHeader.cond_11_53); sHDOut.Append("|");
                            sHDOut.Append(myHeader.acdt_st_54); sHDOut.Append("|");
                            sHDOut.Append(myHeader.thirty1_55); sHDOut.Append("|");
                            sHDOut.Append(myHeader.thirty_56); sHDOut.Append("|");
                            sHDOut.Append(myHeader.occ_code1_57); sHDOut.Append("|");
                            sHDOut.Append(myHeader.occ_date1_58); sHDOut.Append("|");
                            sHDOut.Append(myHeader.occ_code2_59); sHDOut.Append("|");
                            sHDOut.Append(myHeader.occ_date2_60); sHDOut.Append("|");
                            sHDOut.Append(myHeader.occ_code3_61); sHDOut.Append("|");
                            sHDOut.Append(myHeader.occ_date3_62); sHDOut.Append("|");
                            sHDOut.Append(myHeader.occ_code4_63); sHDOut.Append("|");
                            sHDOut.Append(myHeader.occ_date4_64); sHDOut.Append("|");
                            sHDOut.Append(myHeader.occ_spanc1_65); sHDOut.Append("|");
                            sHDOut.Append(myHeader.occ_spanf1_66); sHDOut.Append("|");
                            sHDOut.Append(myHeader.occ_spant1_67); sHDOut.Append("|");
                            sHDOut.Append(myHeader.occ_spanc2_68); sHDOut.Append("|");
                            sHDOut.Append(myHeader.occ_spanf2_69); sHDOut.Append("|");
                            sHDOut.Append(myHeader.occ_spant2_70); sHDOut.Append("|");
                            sHDOut.Append(myHeader.occ_code5_71); sHDOut.Append("|");
                            sHDOut.Append(myHeader.occ_date5_72); sHDOut.Append("|");
                            sHDOut.Append(myHeader.occ_code6_73); sHDOut.Append("|");
                            sHDOut.Append(myHeader.occ_date6_74); sHDOut.Append("|");
                            sHDOut.Append(myHeader.occ_code7_75); sHDOut.Append("|");
                            sHDOut.Append(myHeader.occ_date7_76); sHDOut.Append("|");
                            sHDOut.Append(myHeader.occ_code8_77); sHDOut.Append("|");
                            sHDOut.Append(myHeader.occ_date8_78); sHDOut.Append("|");
                            sHDOut.Append(myHeader.occ_spanc3_79); sHDOut.Append("|");
                            sHDOut.Append(myHeader.occ_spanf3_80); sHDOut.Append("|");
                            sHDOut.Append(myHeader.occ_spant3_81); sHDOut.Append("|");
                            sHDOut.Append(myHeader.occ_span4_82); sHDOut.Append("|");
                            sHDOut.Append(myHeader.occ_spanf4_83); sHDOut.Append("|");
                            sHDOut.Append(myHeader.occ_spant4_84); sHDOut.Append("|");
                            sHDOut.Append(myHeader.a_37_85); sHDOut.Append("|");
                            sHDOut.Append(myHeader.b_37_86); sHDOut.Append("|");
                            sHDOut.Append(myHeader.c_37_87); sHDOut.Append("|");
                            sHDOut.Append(myHeader.a_38_88); sHDOut.Append("|");
                            sHDOut.Append(myHeader.LNAME_38.ToString().Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.FNAME_38.ToString().Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.MNAME_38.ToString().Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.NAMESFX_38.ToString().Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.b_38_89); sHDOut.Append("|");
                            sHDOut.Append(myHeader.c_38_90); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CITY_38.ToString().Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.STATE_38.ToString().Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ZIP_38.ToString().Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.d_38_91); sHDOut.Append("|");
                            // sHDOut.Append(myHeader.e_38_92); sHDOut.Append("|");
                            sHDOut.Append(myHeader.val_code1_93); sHDOut.Append("|");
                            sHDOut.Append(myHeader.val_code2_94); sHDOut.Append("|");
                            sHDOut.Append(myHeader.val_code3_95); sHDOut.Append("|");
                            sHDOut.Append(myHeader.val_code4_96); sHDOut.Append("|");
                            sHDOut.Append(myHeader.val_code5_97); sHDOut.Append("|");
                            sHDOut.Append(myHeader.val_code6_98); sHDOut.Append("|");
                            sHDOut.Append(myHeader.val_code7_99); sHDOut.Append("|");
                            sHDOut.Append(myHeader.val_code8_100); sHDOut.Append("|");
                            sHDOut.Append(myHeader.val_code9_101); sHDOut.Append("|");
                            sHDOut.Append(myHeader.val_code10_102); sHDOut.Append("|");
                            sHDOut.Append(myHeader.val_code11_103); sHDOut.Append("|");
                            sHDOut.Append(myHeader.val_code12_104); sHDOut.Append("|");
                            sHDOut.Append(myHeader.val_amt1_105); sHDOut.Append("|");
                            sHDOut.Append(myHeader.val_amt2_106); sHDOut.Append("|");
                            sHDOut.Append(myHeader.val_amt3_107); sHDOut.Append("|");
                            sHDOut.Append(myHeader.val_amt4_108); sHDOut.Append("|");
                            sHDOut.Append(myHeader.val_amt5_109); sHDOut.Append("|");
                            sHDOut.Append(myHeader.val_amt6_110); sHDOut.Append("|");
                            sHDOut.Append(myHeader.val_amt7_111); sHDOut.Append("|");
                            sHDOut.Append(myHeader.val_amt8_112); sHDOut.Append("|");
                            sHDOut.Append(myHeader.val_amt9_113); sHDOut.Append("|");
                            sHDOut.Append(myHeader.val_amt10_114); sHDOut.Append("|");
                            sHDOut.Append(myHeader.val_amt11_115); sHDOut.Append("|");
                            sHDOut.Append(myHeader.val_amt12_116); sHDOut.Append("|");
                            sHDOut.Append(myHeader.pay_name1_117); sHDOut.Append("|");
                            sHDOut.Append(myHeader.pay_name2_118); sHDOut.Append("|");
                            sHDOut.Append(myHeader.pay_name3_119); sHDOut.Append("|");
                            sHDOut.Append(myHeader.pay_id1_120); sHDOut.Append("|");
                            sHDOut.Append(myHeader.pay_id2_121); sHDOut.Append("|");
                            sHDOut.Append(myHeader.pay_id3_122); sHDOut.Append("|");
                            sHDOut.Append(myHeader.prov_npi56_123); sHDOut.Append("|");
                            sHDOut.Append(myHeader.prov_no1_124); sHDOut.Append("|");
                            sHDOut.Append(myHeader.prov_no2_125); sHDOut.Append("|");
                            sHDOut.Append(myHeader.prov_no3_126); sHDOut.Append("|");
                            sHDOut.Append(myHeader.rel_info1_127); sHDOut.Append("|");
                            sHDOut.Append(myHeader.rel_info2_128); sHDOut.Append("|");
                            sHDOut.Append(myHeader.rel_info3_129); sHDOut.Append("|");
                            sHDOut.Append(myHeader.asg_ben1_130); sHDOut.Append("|");
                            sHDOut.Append(myHeader.asg_ben2_131); sHDOut.Append("|");
                            sHDOut.Append(myHeader.asg_ben3_132); sHDOut.Append("|");
                            sHDOut.Append(myHeader.prior_pay1_133); sHDOut.Append("|");
                            sHDOut.Append(myHeader.prior_pay2_134); sHDOut.Append("|");
                            sHDOut.Append(myHeader.prior_pay3_135); sHDOut.Append("|");
                            sHDOut.Append(myHeader.prior_pay4_136); sHDOut.Append("|");
                            sHDOut.Append(myHeader.est_due1_137); sHDOut.Append("|");
                            sHDOut.Append(myHeader.est_due2_138); sHDOut.Append("|");
                            sHDOut.Append(myHeader.est_due3_139); sHDOut.Append("|");
                            sHDOut.Append(myHeader.est_due4_140); sHDOut.Append("|");
                            sHDOut.Append(myHeader.a_56_141); sHDOut.Append("|");
                            sHDOut.Append(myHeader.b_56_142); sHDOut.Append("|");
                            sHDOut.Append(myHeader.c_56_143); sHDOut.Append("|");
                            sHDOut.Append(myHeader.d_56_144); sHDOut.Append("|");
                            sHDOut.Append(myHeader.e_56_145); sHDOut.Append("|");
                            sHDOut.Append(myHeader.a_57_146); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ins_name1_147); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ins_lname1.ToString().Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ins_fname1.ToString().Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ins_mname1.ToString().Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ins_namesfx1.ToString().Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ins_name2_148); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ins_lname2.ToString().Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ins_fname2.ToString().Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ins_mname2.ToString().Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ins_namesfx2.ToString().Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ins_name3_149); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ins_lname3.ToString().Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ins_fname3.ToString().Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ins_mname3.ToString().Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ins_namesfx3.ToString().Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.p_relat1_150); sHDOut.Append("|");
                            sHDOut.Append(myHeader.p_relat2_151); sHDOut.Append("|");
                            sHDOut.Append(myHeader.p_relat3_152); sHDOut.Append("|");
                            sHDOut.Append(myHeader.crt1_153); sHDOut.Append("|");
                            sHDOut.Append(myHeader.crt2_154); sHDOut.Append("|");
                            sHDOut.Append(myHeader.crt3_155); sHDOut.Append("|");
                            sHDOut.Append(myHeader.group1_156); sHDOut.Append("|");
                            sHDOut.Append(myHeader.group2_157); sHDOut.Append("|");
                            sHDOut.Append(myHeader.group3_158); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ins_group1_159); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ins_group2_160); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ins_group3_161); sHDOut.Append("|");
                            sHDOut.Append(myHeader.treat_cod1_162); sHDOut.Append("|");
                            sHDOut.Append(myHeader.treat_cod2_163); sHDOut.Append("|");
                            sHDOut.Append(myHeader.treat_cod3_164); sHDOut.Append("|");
                            sHDOut.Append(myHeader.esc1_165); sHDOut.Append("|");
                            sHDOut.Append(myHeader.esc2_166); sHDOut.Append("|");
                            sHDOut.Append(myHeader.esc3_167); sHDOut.Append("|");
                            sHDOut.Append(myHeader.doc_ctrl1_168); sHDOut.Append("|");
                            sHDOut.Append(myHeader.doc_ctrl2_169); sHDOut.Append("|");
                            sHDOut.Append(myHeader.doc_ctrl3_170); sHDOut.Append("|");
                            sHDOut.Append(myHeader.emp_name1_171); sHDOut.Append("|");
                            sHDOut.Append(myHeader.emp_name2_172); sHDOut.Append("|");
                            sHDOut.Append(myHeader.emp_name3_173); sHDOut.Append("|");
                            sHDOut.Append(myHeader.emp_loc1_174); sHDOut.Append("|");
                            sHDOut.Append(myHeader.emp_loc2_175); sHDOut.Append("|");
                            sHDOut.Append(myHeader.emp_loc3_176); sHDOut.Append("|");
                            sHDOut.Append(myHeader.diag1_177); sHDOut.Append("|");
                            sHDOut.Append(myHeader.diag2_178); sHDOut.Append("|");
                            sHDOut.Append(myHeader.diag3_179); sHDOut.Append("|");
                            sHDOut.Append(myHeader.diag4_180); sHDOut.Append("|");
                            sHDOut.Append(myHeader.diag5_181); sHDOut.Append("|");
                            sHDOut.Append(myHeader.diag6_182); sHDOut.Append("|");
                            sHDOut.Append(myHeader.diag7_183); sHDOut.Append("|");
                            sHDOut.Append(myHeader.diag8_184); sHDOut.Append("|");
                            sHDOut.Append(myHeader.diag9_185); sHDOut.Append("|");
                            sHDOut.Append(myHeader.diag10_186); sHDOut.Append("|");
                            sHDOut.Append(myHeader.diag11_187); sHDOut.Append("|");
                            sHDOut.Append(myHeader.diag12_188); sHDOut.Append("|");
                            sHDOut.Append(myHeader.diag13_189); sHDOut.Append("|");
                            sHDOut.Append(myHeader.diag14_190); sHDOut.Append("|");
                            sHDOut.Append(myHeader.diag15_191); sHDOut.Append("|");
                            sHDOut.Append(myHeader.diag16_192); sHDOut.Append("|");
                            sHDOut.Append(myHeader.diag17_193); sHDOut.Append("|");
                            sHDOut.Append(myHeader.diag18_194); sHDOut.Append("|");
                            sHDOut.Append(myHeader.adm_diag_195); sHDOut.Append("|");
                            sHDOut.Append(myHeader.e_code1_196); sHDOut.Append("|");
                            sHDOut.Append(myHeader.e_code2_197); sHDOut.Append("|");
                            sHDOut.Append(myHeader.e_code3_198); sHDOut.Append("|");
                            sHDOut.Append(myHeader.pat_rdx1_199); sHDOut.Append("|");
                            sHDOut.Append(myHeader.pat_rdx2_200); sHDOut.Append("|");
                            sHDOut.Append(myHeader.pps_code.ToString().Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.pat_rdx3_201); sHDOut.Append("|");
                            sHDOut.Append(myHeader.a_73_202); sHDOut.Append("|");
                            sHDOut.Append(myHeader.proc_cod1_203); sHDOut.Append("|");
                            sHDOut.Append(myHeader.proc_cod2_204); sHDOut.Append("|");
                            sHDOut.Append(myHeader.proc_cod3_205); sHDOut.Append("|");
                            sHDOut.Append(myHeader.proc_cod4_206); sHDOut.Append("|");
                            sHDOut.Append(myHeader.proc_cod5_207); sHDOut.Append("|");
                            sHDOut.Append(myHeader.proc_cod6_208); sHDOut.Append("|");
                            sHDOut.Append(myHeader.proc_date1_209); sHDOut.Append("|");
                            sHDOut.Append(myHeader.proc_date2_210); sHDOut.Append("|");
                            sHDOut.Append(myHeader.proc_date3_211); sHDOut.Append("|");
                            sHDOut.Append(myHeader.proc_date4_212); sHDOut.Append("|");
                            sHDOut.Append(myHeader.proc_date5_213); sHDOut.Append("|");
                            sHDOut.Append(myHeader.proc_date6_214); sHDOut.Append("|");
                            sHDOut.Append(myHeader.att_phyln_215); sHDOut.Append("|");
                            sHDOut.Append(myHeader.att_phyfn_216); sHDOut.Append("|");
                            sHDOut.Append(myHeader.att_phymn.ToString().Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.att_physfx.ToString().Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.att_phynpi_217); sHDOut.Append("|");
                            sHDOut.Append(myHeader.att_phyidq_218); sHDOut.Append("|");
                            sHDOut.Append(myHeader.att_phyid_219); sHDOut.Append("|");
                            sHDOut.Append(myHeader.op_phyln_220); sHDOut.Append("|");
                            sHDOut.Append(myHeader.op_phyfn_221); sHDOut.Append("|");
                            sHDOut.Append(myHeader.op_phymn.ToString().Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.op_physfx.ToString().Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.op_phy_npi_222); sHDOut.Append("|");
                            sHDOut.Append(myHeader.op_phyidq_223); sHDOut.Append("|");
                            sHDOut.Append(myHeader.op_phyid_224); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ot_phy1ln_225); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ot_phy1fn_226); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ot_phy1npi_227); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ot_phy1idq_228); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ot_phy1id_229); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ot_phy2ln_230); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ot_phy2fn_231); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ot_phy2npi_232); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ot_phy2idq_233); sHDOut.Append("|");
                            sHDOut.Append(myHeader.ot_phy2id_234); sHDOut.Append("|");
                            sHDOut.Append(myHeader.remarks1_235); sHDOut.Append("|");
                            sHDOut.Append(myHeader.remarks2_236); sHDOut.Append("|");
                            sHDOut.Append(myHeader.remarks3_237); sHDOut.Append("|");
                            sHDOut.Append(myHeader.remarks4_238); sHDOut.Append("|");
                            sHDOut.Append(myHeader.prov_rep_239); sHDOut.Append("|");
                            sHDOut.Append(myHeader.prov_rp_dt_240); sHDOut.Append("|");
                            sHDOut.Append(myHeader.fl81a_1_241); sHDOut.Append("|");
                            sHDOut.Append(myHeader.fl81a_2_242); sHDOut.Append("|");
                            sHDOut.Append(myHeader.fl81a_3_243); sHDOut.Append("|");
                            sHDOut.Append(myHeader.fl81b_1_244); sHDOut.Append("|");
                            sHDOut.Append(myHeader.fl81b_2_245); sHDOut.Append("|");
                            sHDOut.Append(myHeader.fl81b_3_246); sHDOut.Append("|");
                            sHDOut.Append(myHeader.fl81c_1_247); sHDOut.Append("|");
                            sHDOut.Append(myHeader.fl81c_2_248); sHDOut.Append("|");
                            sHDOut.Append(myHeader.fl81c_3_249); sHDOut.Append("|");
                            sHDOut.Append(myHeader.fl81d_1_250); sHDOut.Append("|");
                            sHDOut.Append(myHeader.fl81d_2_251); sHDOut.Append("|");
                            sHDOut.Append(myHeader.fl81d_3_252); sHDOut.Append("|");
                            sHDOut.Append(myHeader.poa1_253);
                            sHDOut.Append(myHeader.poa2_254);
                            sHDOut.Append(myHeader.poa3_255);
                            sHDOut.Append(myHeader.poa4_256);
                            sHDOut.Append(myHeader.poa5_257);
                            sHDOut.Append(myHeader.poa6_258); sHDOut.Append("|");
                            sHDOut.Append(myHeader.icn_259); sHDOut.Append("|");
                            sHDOut.Append(myHeader.bht_260);

                            fs.WriteLine(sHDOut.ToString());
                            sHDOut.Clear();
                        }
                        // write heder //
                        //myWriteFile.setString = myCreateFile.getString;
                        //myWriteFile.write(txtFileOutPut);
                        //myWriteFile = null;
                        /////////////// Detail ////////////////////////////////////////////////////////////////////////////
                        int i = 3;
                        int j = 1;
                        String strJ = null;
                        string strI = null;
                        //myWriteFile = new writeFile.file();
                       // myCreateFile.setStringLen = 138;

                        while (i < 23)
                        {
                            if (i > 9)
                            {
                                switch (i)
                                {
                                    case 10:
                                        strI = "a";
                                        break;
                                    case 11:
                                        strI = "b";
                                        break;
                                    case 12:
                                        strI = "c";
                                        break;
                                    case 13:
                                        strI = "d";
                                        break;
                                    case 14:
                                        strI = "e";
                                        break;
                                    case 15:
                                        strI = "f";
                                        break;
                                    case 16:
                                        strI = "g";
                                        break;
                                    case 17:
                                        strI = "h";
                                        break;
                                    case 18:
                                        strI = "i";
                                        break;
                                    case 19:
                                        strI = "j";
                                        break;
                                    case 20:
                                        strI = "k";
                                        break;
                                    case 21:
                                        strI = "l";
                                        break;
                                    case 22:
                                        strI = "M";
                                        break;
                                }
                            }
                            else
                            {
                                strI = i.ToString();
                            }
                            String REVENUCD = null;
                            String SERVICID = null;
                            String SERVIDAT = null;
                            String SERUNTCO = null;
                            String CHARGAMT = null;

                            j = 1;
                            while (j < 6)
                            {
                                if (j == 1)
                                {
                                    strJ = "";
                                    REVENUCD = "REVENUCD";
                                    SERVICID = "SERVICID";
                                    SERVIDAT = "SERVIDAT";
                                    SERUNTCO = "SERUNTCO";
                                    CHARGAMT = "CHARGAMT";
                                }
                                else
                                {
                                    strJ = j.ToString();
                                    REVENUCD = "REVENUC";
                                    SERVICID = "SERVICI";
                                    SERVIDAT = "SERVIDA";
                                    SERUNTCO = "SERUNTC";
                                    CHARGAMT = "CHARGAM";
                                }
                                if (foxDR["V" + strI + REVENUCD + strJ].ToString().Trim() != "0000")
                                {
                                    myDetail.claim_no_1 = myHeader.claim_no_2.ToString();
                                    myDetail.rev_cd_2 = foxDR["V" + strI + REVENUCD + strJ].ToString(); //falta taba revcode
                                    myDetail.descr_3 = new string(' ', 30);
                                    {
                                        myDetail.hcps_4 = foxDR["V" + strI + SERVICID + strJ].ToString().Trim();

                                        if (myDetail.hcps_4.Trim().Length == 0)
                                        {
                                            myDetail.hcps_4 = new String(' ', 5);
                                        }
                                        else
                                        {
                                            String count = Program.MySqlbusqueda(sqlCnnString,
                                                "select count(*) from tblServiceCodes where serviceCode='" + myDetail.hcps_4.Trim() + "';");
                                            if (count == "0")
                                            {
                                                myDetail.hcps_4 = "99999";
                                            }

                                        }
                                    }
                                    {/////////////////////// mydbMMM.tbtMod //////////////////////////////
                                        if (j == 3)
                                        {
                                            myDetail.hcps_mode1_5 = foxDR["V" + strI + "MODF1" + strJ].ToString().Trim();

                                        }
                                        else
                                        {
                                            myDetail.hcps_mode1_5 = foxDR["V" + strI + "MODIF1" + strJ].ToString().Trim();
                                        }
                                        myDetail.hcpcs_mode2_6 = foxDR["V" + strI + "MODIF2" + strJ].ToString().Trim();
                                        myDetail.hcpcs_mode3_7 = foxDR["V" + strI + "MODIF3" + strJ].ToString().Trim();
                                        myDetail.hcpcs_mode4_8 = foxDR["V" + strI + "MODIF4" + strJ].ToString().Trim();
                                        ////////////////////// hcps_mode1_5 /////////////////////////////
                                        if (myDetail.hcps_mode1_5.Trim().Length == 0)
                                        {
                                            myDetail.hcps_mode1_5 = new String(' ', 2);
                                        }
                                        else
                                        {
                                            String count = Program.MySqlbusqueda(sqlCnnString,
                                                "select count(*) from tbtMod where code='" + myDetail.hcps_mode1_5 + "';");
                                            if (count == "0")
                                            {
                                                myDetail.hcps_mode1_5 = "MD";
                                            }
                                        }
                                        ////////////////////// hcps_mode2_6 ////////////////////////
                                        if (myDetail.hcpcs_mode2_6.Trim().Length == 0)
                                        {
                                            myDetail.hcpcs_mode2_6 = new String(' ', 2);
                                        }
                                        else
                                        {
                                            String count = Program.MySqlbusqueda(sqlCnnString,
                                                "select count(*) from tbtMod where code='" + myDetail.hcpcs_mode2_6 + "';");
                                            if (count == "0")
                                            {
                                                myDetail.hcpcs_mode2_6 = "MD";
                                            }

                                        }
                                        /////////////// hcps_mode3_7 ///////////////////////////////
                                        if (myDetail.hcpcs_mode3_7.Trim().Length == 0)
                                        {
                                            myDetail.hcpcs_mode3_7 = new string(' ', 2);
                                        }
                                        else
                                        {
                                            String count = Program.MySqlbusqueda(sqlCnnString,
                                                "select count(*) from tbtMod where code='" + myDetail.hcpcs_mode3_7 + "';");
                                            if (count == "0")
                                            {
                                                myDetail.hcpcs_mode3_7 = "MD";
                                            }

                                        }
                                        ///////////////// hcps_mode4_8 ///////////////////////////////
                                        if (myDetail.hcpcs_mode4_8.Trim().Length == 0)
                                        {
                                            myDetail.hcpcs_mode4_8 = new String(' ', 2);
                                        }
                                        else
                                        {
                                            String count = Program.MySqlbusqueda(sqlCnnString,
                                                "select count(*) from tbtMod where code='" + myDetail.hcpcs_mode4_8 + "';");
                                            if (count == "0")
                                            {
                                                myDetail.hcpcs_mode4_8 = "MD";
                                            }

                                        }
                                        ///////////////////////////////////////////////////////////////////////
                                    }
                                    {
                                        string serv_date_9 = foxDR["V" + strI + SERVIDAT + strJ].ToString().Trim();

                                        if (serv_date_9.Length < 6)
                                        {
                                            //   throw new Exception("Error con la fecha V" + strI + "SERVIDAT -->Imagen-->" + Images);
                                            myDetail.serv_date_9 = myHeader.fl_7_19.ToString();
                                        }

                                        if (serv_date_9.Length == 0)
                                        {
                                            myDetail.serv_date_9 = myHeader.fl_7_19.ToString();
                                        }
                                        else
                                        {
                                            try
                                            {
                                                serv_date_9 = "20" + foxDR["V" + strI + SERVIDAT + strJ].ToString().Trim().Substring(4, 2) +
                                                              foxDR["V" + strI + SERVIDAT + strJ].ToString().Trim().Substring(0, 2) +
                                                              foxDR["V" + strI + SERVIDAT + strJ].ToString().Trim().Substring(2, 2);
                                            }
                                            catch
                                            {
                                                serv_date_9 = myHeader.fl_7_19.ToString();

                                            }

                                            string imgDate = "20" + Images.Substring(4, 2) +
                                                             Images.Substring(0, 2) +
                                                             Images.Substring(2, 2);

                                            if (Convert.ToInt32(serv_date_9) > Convert.ToInt32(imgDate))
                                            {
                                                myDetail.serv_date_9 = myHeader.fl_7_19.ToString();
                                            }
                                            else
                                            {
                                                try
                                                {
                                                    myDetail.serv_date_9 = Program.setFecha(foxDR["V" + strI + SERVIDAT + strJ].ToString(), Images);
                                                }
                                                catch
                                                {
                                                    myDetail.serv_date_9 = myHeader.fl_7_19.ToString();

                                                }
                                            }
                                        }
                                    }
                                    {
                                        myDetail.serv_units_10 = foxDR["V" + strI + SERUNTCO + strJ].ToString().Trim();
                                        Int32 serv_units_10 = Convert.ToInt32(myDetail.serv_units_10);
                                        if (serv_units_10 == 0)
                                        {
                                            serv_units_10 = 1 * 10;
                                        }
                                        else
                                        {
                                            serv_units_10 = serv_units_10 * 10;
                                        }
                                        myDetail.serv_units_10 = serv_units_10.ToString("000000000#");
                                    }
                                    {
                                        myDetail.total_chgs_11 = foxDR["V" + strI + CHARGAMT + strJ].ToString();
                                    }
                                    myDetail.noncv_chgs_12 = new string(' ', 13);
                                    myDetail.a49_13 = new string(' ', 6);
                                    using (StreamWriter fs = File.AppendText(file2.Trim()))
                                    {
                                        sHDOut.Clear();
                                        sHDOut.Append(myDetail.claim_no_1); sHDOut.Append("|");
                                        sHDOut.Append(myDetail.rev_cd_2); sHDOut.Append("|" );
                                        sHDOut.Append(myDetail.descr_3); sHDOut.Append("|" );
                                        sHDOut.Append(myDetail.hcps_4); sHDOut.Append("|" );
                                        sHDOut.Append(myDetail.hcps_mode1_5); sHDOut.Append("|" );
                                        sHDOut.Append(myDetail.hcpcs_mode2_6); sHDOut.Append("|" );
                                        sHDOut.Append(myDetail.hcpcs_mode3_7); sHDOut.Append("|" );
                                        sHDOut.Append(myDetail.hcpcs_mode4_8); sHDOut.Append("|" );
                                        sHDOut.Append(myDetail.serv_date_9); sHDOut.Append("|" );
                                        sHDOut.Append(myDetail.serv_units_10); sHDOut.Append("|" );
                                        sHDOut.Append(myDetail.total_chgs_11); sHDOut.Append("|" );
                                        sHDOut.Append(myDetail.noncv_chgs_12); sHDOut.Append("|");
                                        sHDOut.Append(myDetail.a49_13);

                                        fs.WriteLine(sHDOut.ToString().Trim());

                                        //clear
                                        myDetail = null;
                                        myDetail = new detail();

                                        // write  Detail
                                     //   myWriteFile.setString = myCreateFile.getString;
                                      //  myWriteFile.write(file2 + ".dtl");
                                    }
                                }
                                j++;
                            }//end loop while (j <6)
                            i++;
                        }// end loop while (i < 23)
                    }//end loop  foreach (System.Data.DataRow foxDR in myTable.Rows)

                   // myWriteFile = null;

                    /////////////// Detail ////////////////////////////////////////////////////////////////////////////

                //MessageBox.Show("Done...");

            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            finally
            {
                foxCnn = null;
                //foxCmd = null;
            }
        }
Beispiel #5
0
        public void run(string txtFox,string txtFileOutPut,  String MembIdDummy, 
            String tblMemberMMM, String whatIsTable, String tblProvider, 
            String PAY_NAME_200, System.Windows.Forms.Label lblTotal, 
            System.Windows.Forms.Label lblCount, ToolStripProgressBar Bar, ToolStripStatusLabel Label, String PAY_ID1_300, System.Windows.Forms.DataGridView dataGridView1,ref  int iCount_97)
        {
            jolParseDBF.DBF foxCnn = null;

            SqlDataAdapter foxDataAdapter = null;
            System.Data.DataSet foxDataSet = null;

            String Images = null;
            String sqlCnnString = null;
            findData.Search myFindData = null;
            DataSet mySqlDataSet = null;
            header837P  myHeader = null;
            detail837P myDetail = null;
            //            createString.create myCreateFile = null;
            //            writeFile.file myWriteFile = null;
            Int32 iCC = 0; //Contador de la categoria
            String TMPcc = null;

            try
            {
                foxCnn = new jolParseDBF.DBF();
                DataTable foxTable = foxCnn.parse(txtFox);
              //  foxCmd = new SqlCommand();
                //////////////////////////////////
                foxDataAdapter = new SqlDataAdapter();
                foxDataSet = new DataSet();
                //////////////////////////////////

                myFindData = new findData.Search();
                mySqlDataSet = new DataSet();

                myHeader = new header837P();
                myDetail = new detail837P();

                //myCreateFile = new createString.create();
                //myWriteFile = new writeFile.file();
                //myCreateFile.setStringLen = 14895;
                //myWriteFile.createFile(txtFileOutPut); // header
                StringBuilder sHDOut = new StringBuilder();

                string file2 = txtFileOutPut.Substring(0, txtFileOutPut.IndexOf("."));
                file2 += ".dtl";

                if (File.Exists(txtFileOutPut.Trim()))
                    File.Delete(txtFileOutPut.Trim());

                if (File.Exists(file2.Trim()))
                    File.Delete(file2.Trim());

                //myWriteFile.createFile(file2 + ".dtl"); //

                sqlCnnString = _sqlCnnString;

                lblTotal.Text = String.Format("{0:0,0}", foxTable.Select("V1PAGINA <> '99'").Length.ToString());// lblTotal.Text =String.Format("{0:0,0}", foxCmd.ExecuteScalar());

                int totalrecord = foxTable.Select("V1PAGINA <> '99'").Length;//Convert.ToInt16( foxCmd.ExecuteScalar());

                Bar.Maximum = totalrecord;
                System.Windows.Forms.Application.DoEvents();

                int intClaim_no_2 = 0;
                Int64 myCount = 0;

                foreach (System.Data.DataRow foxDR in foxTable.Select("V1PAGINA <> '99'", "V0DOCUMENT"))
                {
                    {
                        Bar.Value++;
                        Double iP = Bar.Value;
                        iP = iP / Bar.Maximum;
                        Label.Text = String.Format("{0:0%}", iP);
                        Application.DoEvents();

                        myCount++;
                        lblCount.Text = String.Format("{0:0,0}", myCount);
                        System.Windows.Forms.Application.DoEvents();

                        //myWriteFile = new writeFile.file();
                        //myCreateFile.setStringLen = 14895;
                        intClaim_no_2++;
                        Images = foxDR["V0IFNAME01"].ToString().Trim();

                        myHeader.CLAIM_NO_100 = intClaim_no_2.ToString("00000000000#");
                        //////////////////////////////////////////////////////////////////////////////////////////////////
                        myHeader.PAY_NAME_200 = PAY_NAME_200;//MMM or PMC
                        myHeader.PAY_ID1_300 = PAY_ID1_300;  // MMM =660588600 PMC =660592131
                        myHeader.PAY_ID2_400 = new string(' ', 20);
                        myHeader.PAY1_SEQNC_500 = new string(' ', 1);
                        myHeader.PAY_ADD1_600 = new string(' ', 50);
                        myHeader.PAY_ADD2_700 = new string(' ', 50);
                        myHeader.PAY_CITY_800 = new string(' ', 30);
                        myHeader.PAY_ST_900 = new string(' ', 2);
                        myHeader.PAY_ZIP_1000 = new string(' ', 9);
                        myHeader.B1_TYPE_1100 = new string(' ', 2);
                        myHeader.B1_CLMFIND_1200 = "CI";
                        myHeader.PAY2_ID1_1300 = new string(' ', 20);
                        myHeader.PAY2_ID2_1400 = new string(' ', 20);
                        myHeader.PAY2_SEQNC_1500 = new string(' ', 1);
                        myHeader.PAY2_NAME_1600 = new string(' ', 50);
                        myHeader.PAY2_ADD1_1700 = new string(' ', 50);
                        myHeader.PAY2_ADD2_1800 = new string(' ', 50);
                        myHeader.PAY2_CITY_1900 = new string(' ', 30);
                        myHeader.PAY2_ST_2000 = new string(' ', 2);
                        myHeader.PAY2_ZIP_2100 = new string(' ', 9);
                        myHeader.PAY2_TYPE_2200 = new string(' ', 2);
                        myHeader.PAY2_CFIND_2300 = new string(' ', 2);

                        {//Primera Regla de Negocio ***************** MembId or MembId2 ************************************

                            myHeader.B1A_ID_2400 = foxDR["V1INSURED"].ToString().Trim();

                            if (myHeader.B1A_ID_2400.Trim().Length == 0)
                            {
                                myHeader.B1A_ID_2400 = MembIdDummy;
                            }

                            String tmpB1A_ID_2400 =
                                Program.MySqlbusqueda(sqlCnnString, "select MembId from " + tblMemberMMM + " where MembId='" + myHeader.B1A_ID_2400.Trim() + "';");

                            if (tmpB1A_ID_2400.Trim().Length == 0)
                            {
                                tmpB1A_ID_2400 =
                                    Program.MySqlbusqueda(sqlCnnString, "select MembId from " + tblMemberMMM + " where MembId2='" + myHeader.B1A_ID_2400.Trim() + "';");
                                if (tmpB1A_ID_2400.Trim().Length == 0)
                                {
                                    myHeader.B1A_ID_2400 = MembIdDummy;
                                }
                                else
                                {
                                    myHeader.B1A_ID_2400 = tmpB1A_ID_2400;
                                }
                            }
                            else
                            {
                                myHeader.B1A_ID_2400 = tmpB1A_ID_2400;
                            }
                        }// ***************** MembId or MembId2 ************************************
                        // Esto es de La Base de Datos de MMM (SQL 0 MySql) TODO Falta
                        myHeader.B2_LAST_2500 = Program.MySqlbusqueda(sqlCnnString, "select LastNM from " + tblMemberMMM + " where MembId='" + myHeader.B1A_ID_2400.Trim() + "';");
                        {
                            myHeader.B2_LAST_2500 = myHeader.B2_LAST_2500.Trim();
                            if (myHeader.B2_LAST_2500.Length > 33)
                            {
                                myHeader.B2_LAST_2500 = myHeader.B2_LAST_2500.Substring(0, 33);
                            }

                        }

                        myHeader.B2_FIRST_2600 = Program.MySqlbusqueda(sqlCnnString, "select FirstNM from " + tblMemberMMM + " where MembId='" + myHeader.B1A_ID_2400.Trim() + "';");
                        myHeader.B2_MI_2700 = Program.MySqlbusqueda(sqlCnnString, "select MI from " + tblMemberMMM + " where MembId='" + myHeader.B1A_ID_2400.Trim() + "';");
                        myHeader.B3_DOB_2800 = Program.MySqlbusqueda(sqlCnnString, "select Birth from " + tblMemberMMM + " where MembId='" + myHeader.B1A_ID_2400.Trim() + "';");
                        myHeader.B3_SEX_2900 = Program.MySqlbusqueda(sqlCnnString, "select Sex from " + tblMemberMMM + " where MembId='" + myHeader.B1A_ID_2400.Trim() + "';");
                        myHeader.B4_LAST_3000 = myHeader.B2_LAST_2500;
                        myHeader.B4_FIRST_3100 = myHeader.B2_FIRST_2600;
                        myHeader.B4_MI_3200 = myHeader.B2_MI_2700;
                        myHeader.B5_ADD_3300 = Program.MySqlbusqueda(sqlCnnString, "select Street from " + tblMemberMMM + " where MembId='" + myHeader.B1A_ID_2400.Trim() + "';"); // Falta Rutina para que busque la direccion si no la encuentra
                        myHeader.B5_CITY_3400 = Program.MySqlbusqueda(sqlCnnString, "select City from " + tblMemberMMM + " where MembId='" + myHeader.B1A_ID_2400.Trim() + "';");
                        myHeader.B5_STATE_3500 = Program.MySqlbusqueda(sqlCnnString, "select State from " + tblMemberMMM + " where MembId='" + myHeader.B1A_ID_2400.Trim() + "';");
                        {
                            myHeader.B5_ZIP_3600 = Program.MySqlbusqueda(sqlCnnString, "select Zip from " + tblMemberMMM + " where MembId='" + myHeader.B1A_ID_2400.Trim() + "';");
                            if (myHeader.B5_ZIP_3600.Trim().Length > 0)
                            {
                                if (myHeader.B5_ZIP_3600.Trim().Length >= 5)
                                {
                                    myHeader.B5_ZIP_3600 = myHeader.B5_ZIP_3600.Trim().Substring(0, 5);
                                }
                                else
                                {
                                    myHeader.B5_ZIP_3600 = "99999";
                                }
                            }
                            else
                            {
                                myHeader.B5_ZIP_3600 = "99999";
                            }
                        }
                        myHeader.B5_PHONE_3700 = "7879999999"; //Program.MySqlbusqueda(sqlCnnString, "select  from tblMemberMMM where MembId='" + myHeader.B1A_ID_2400.Trim() + "';");
                        ///////////////////////////////////////////////////////////////
                        myHeader.B6_REL_3800 = "18";
                        //sale de Base de Datos...
                        myHeader.B7_ADD_3900 = myHeader.B5_ADD_3300;
                        myHeader.B7_CITY_4000 = myHeader.B5_CITY_3400;
                        myHeader.B7_STATE_4100 = myHeader.B5_STATE_3500;
                        myHeader.B7_ZIP_4200 = myHeader.B5_ZIP_3600;
                        myHeader.B7_PHONE_4300 = myHeader.B5_PHONE_3700;
                        ///////////////////////////////////////////////////
                        myHeader.B8_STAT_4400 = new string(' ', 1);
                        myHeader.B8_EMP_4500 = new string(' ', 1);
                        myHeader.B9_LAST_4600 = myHeader.B2_LAST_2500;
                        myHeader.B9_FIRST_4700 = myHeader.B2_FIRST_2600;
                        myHeader.B9_MI_4800 = myHeader.B2_MI_2700;
                        myHeader.B9_INSID2_4900 = new string(' ', 25);
                        myHeader.B9_PATREL2_5000 = new string(' ', 2);
                        myHeader.B9A_POL_5100 = new string(' ', 20);
                        myHeader.B9B_DOB_5200 = new string(' ', 10);
                        myHeader.B9B_SEX_5300 = new string(' ', 1);
                        myHeader.B9C_EMP_5400 = new string(' ', 33);
                        myHeader.B9D_PLN_5500 = new string(' ', 33);
                        myHeader.B10A_EMP_5600 = new string(' ', 1);
                        myHeader.B10B_AUT_5700 = "N";
                        myHeader.B10B_ST_5800 = new string(' ', 2);
                        myHeader.B10C_ACC_5900 = new string(' ', 1);
                        myHeader.B10D_LOCAL_6000 = new string(' ', 15);
                        myHeader.B11_POL_6100 = new string(' ', 20);
                        myHeader.B11A_DOB_6200 = myHeader.B3_DOB_2800;// peticion de bob
                        myHeader.B11A_SEX_6300 = myHeader.B3_SEX_2900;// peticion de bob
                        myHeader.B11B_EMP_6400 = new string(' ', 33);
                        myHeader.B11C_PLN_6500 = new string(' ', 33);
                        myHeader.B11D_APL_6600 = new string(' ', 1);
                        myHeader.B12_SIGN_6700 = "Y";
                        myHeader.B12_DATE_6800 = new string(' ', 10);
                        myHeader.B13_SIGN_6900 = "Y";
                        //myHeader.B13_DATE_7000 = new string(' ', 10);
                        {//TODO:**** si la fecha es futura (mayor a la del dia de procesamiento.) cambiar a los 6 digitos de la imagen.
                            //080607
                            Int64 B13_DATE_7000 = 0;
                            Int64 iV2DATETO = 0;
                            String img = foxDR["V0ifname01"].ToString().Trim();
                            String V2DATETO = null;
                            myHeader.B13_DATE_7000 = foxDR["V2DATEFROM"].ToString().Trim();//V2DATEFROM ->Rutina de Fecha MMDDCCYY
                            V2DATETO = foxDR["V2DATETO"].ToString().Trim();//Rutina de Fecha MMDDCCYY
                            if (myHeader.B13_DATE_7000.Trim().Length > 0)
                            {
                                String tmp = "20" + myHeader.B13_DATE_7000.Trim().Substring(4, 2) +
                                    myHeader.B13_DATE_7000.Trim().Substring(0, 2) + myHeader.B13_DATE_7000.Trim().Substring(2, 2);
                                B13_DATE_7000 = Convert.ToInt64(tmp);
                            }
                            if (V2DATETO.Trim().Length > 0)
                            {
                                String tmp = "20" + V2DATETO.Trim().Substring(4, 2) +
                                    V2DATETO.Trim().Substring(0, 2) + V2DATETO.Trim().Substring(2, 2);
                                iV2DATETO = Convert.ToInt64(tmp);
                            }

                            //   System.Console.Out.WriteLine("iV2DATETO:" + iV2DATETO + "<  B13_DATE_7000:" + B13_DATE_7000);
                            if (iV2DATETO < B13_DATE_7000)
                            {// Estrututa de la image file : MMDDYY CC BBBB SEQDOC.TIF
                                //                                    throw new Exception("Error en las Fechas:" + img);

                                // throw new Exception("Error con la Fecha: " + "V2DATEFROM ->ImgName:" + img.Trim());

                                iV2DATETO = B13_DATE_7000;

                            }
                            String sFechaRecivido = img.Trim().Substring(0, 6);
                            String tmpFechaRecivido = "20" + sFechaRecivido.Substring(4, 2) +
                                sFechaRecivido.Substring(0, 2) + sFechaRecivido.Substring(2, 2);
                            Int64 iFechaRecivido = Convert.ToInt64(tmpFechaRecivido);

                            if (iV2DATETO >= iFechaRecivido)
                            {// Estrututa de la image file : MMDDYY CC BBBB SEQDOC.TIF
                                String MM = img.Substring(0, 2);
                                String DD = img.Substring(2, 2);
                                String YY = img.Substring(4, 2);
                                myHeader.B13_DATE_7000 = MM + DD + YY;
                                V2DATETO = MM + DD + YY;
                            }

                            if (myHeader.B13_DATE_7000.Trim().Length == 6)
                            {
                                String MM = myHeader.B13_DATE_7000.Trim().Substring(0, 2);
                                String DD = myHeader.B13_DATE_7000.Trim().Substring(2, 2);
                                String YY = myHeader.B13_DATE_7000.Trim().Substring(4, 2);
                                myHeader.B13_DATE_7000 = MM + "/" + DD + "/20" + YY;
                            }
                            else
                            {
                                throw new Exception("Error con la Fecha: " + "V2DATEFROM ->ImgName:" + img.Trim());
                            }
                            if (V2DATETO.Trim().Length == 6)
                            {
                                String MM = V2DATETO.Trim().Substring(0, 2);
                                String DD = V2DATETO.Trim().Substring(2, 2);
                                String YY = V2DATETO.Trim().Substring(4, 2);
                                V2DATETO = MM + "/" + DD + "/20" + YY;
                            }
                            else
                            {
                                V2DATETO = myHeader.B13_DATE_7000;
                            }
                        }//////////////////////////////////////////////////////////////////////////
                        myHeader.B14_DT_QAL_7100 = new string(' ', 3);
                        myHeader.B14_DATE_7200 = new string(' ', 10);
                        myHeader.B15_DATE_7300 = new string(' ', 10);
                        myHeader.B16_FROM_7400 = new string(' ', 10);
                        myHeader.B16_TO_7500 = new string(' ', 10);

                        {
                            myHeader.B17A_NPI_7900 = foxDR["V117NPI"].ToString().Trim(); // todo rutina del chekdig
                            String count = Program.MySqlbusqueda(sqlCnnString,
                                "SELECT count(*) FROM " + tblProvider + " where NPI ='" + foxDR["V117NPI"].ToString().Trim() + "';");

                            if (count == "0")
                            {
                                myHeader.B17_REF_LAST_7600 = "Dummy";
                                myHeader.B17_REF_7620 = "Dummy";
                                myHeader.B17_REF_MID_7630 = "Dummy";
                                /*
                                switch (foxDR["V117NPI"].ToString().Trim().Length)
                                {
                                    case 10:
                                        if (check_digit_NPI.isValidNPI(foxDR["V117NPI"].ToString().Trim()))
                                        {
                                            myHeader.B17_REF_LAST_7600 = "Dummy";
                                            myHeader.B17_REF_7620 = "Dummy";
                                            myHeader.B17_REF_MID_7630 = "Dummy";
                                        }
                                        else
                                        {
                                            myHeader.B17A_NPI_7900 = new String(' ', 10);
                                            myHeader.B17_REF_LAST_7600 = new string(' ', 25);
                                            myHeader.B17_REF_7620 = new string(' ', 25);
                                            myHeader.B17_REF_MID_7630 = new string(' ', 10);
                                        }
                                        break;
                                    default:
                                        myHeader.B17A_NPI_7900 = new String(' ', 10);
                                        myHeader.B17_REF_LAST_7600 = new string(' ', 25);
                                        myHeader.B17_REF_7620 = new string(' ', 25);
                                        myHeader.B17_REF_MID_7630 = new string(' ', 10);
                                        break;
                                }*/
                            }
                            else
                            {
                                myHeader.B17_REF_LAST_7600 = Program.MySqlbusqueda(sqlCnnString,
                                    "SELECT LASTNAME FROM " + tblProvider + " where NPI ='" + foxDR["V117NPI"].ToString().Trim() + "';");
                                myHeader.B17_REF_7620 = Program.MySqlbusqueda(sqlCnnString,
                                    "SELECT FIRSTNAME FROM " + tblProvider + " where NPI ='" + foxDR["V117NPI"].ToString().Trim() + "';");
                                myHeader.B17_REF_MID_7630 = Program.MySqlbusqueda(sqlCnnString,
                                    "SELECT MI FROM " + tblProvider + " where NPI ='" + foxDR["V117NPI"].ToString().Trim() + "';");
                            }
                        }

                        {
                            myHeader.B17_REF_LAST_7600 = myHeader.B17_REF_LAST_7600.Trim();
                            if (myHeader.B17_REF_LAST_7600.Length > 33)
                            {
                                myHeader.B17_REF_LAST_7600 = myHeader.B17_REF_LAST_7600.Substring(0, 33);
                            }
                        }

                        myHeader.B17A_ID_7700 = new string(' ', 15);

                        myHeader.B17A_IDQAL_7800 = new string(' ', 2);

                        myHeader.B17A_PRV_1_7920 = new string(' ', 3);
                        myHeader.B17A_PRV_3_7930 = new string(' ', 10);
                        myHeader.B18_FROM_8000 = new string(' ', 10);
                        myHeader.B18_TO_8100 = new string(' ', 10);
                        myHeader.B19_NAV_8200 = foxDR["V119RESERV"].ToString().Trim(); //V119RESERV
                        myHeader.B20_LAB_8300 = new string(' ', 1);
                        myHeader.B20_CHGS_8400 = new string(' ', 9);
                        {//TODO: Regla de Negocio #6 Tabla Diagniticos tblDiagnosisCodes

                            myHeader.B21_D1_8500 = foxDR["V1DIAGN1"].ToString().Trim(); //V1DIAGN1	V1DIAGN2	V1DIAGN3	V1DIAGN4

                            string[] dataDiag = null;

                            if (myHeader.B21_D1_8500.Trim().Length > 0)
                            {
                                String tmpB21_D1_8500 = Program.MySqlbusqueda(sqlCnnString, "select Code from tblDiagnosisCodes where Code='" + myHeader.B21_D1_8500 + "';");

                                if (tmpB21_D1_8500.Trim().Length == 0)
                                {
                                    myHeader.B21_D1_8500 = "99999";
                                }
                            }
                            else
                            {
                                myHeader.B21_D1_8500 = "99999";
                            }

                            myHeader.B21_D2_8600 = foxDR["V1DIAGN2"].ToString().Trim();

                            if (myHeader.B21_D2_8600.Trim().Length > 0)
                            {

                                String tmpB21_D2_8600 = Program.MySqlbusqueda(sqlCnnString, "select Code from tblDiagnosisCodes where Code='" + myHeader.B21_D2_8600 + "';");
                                if (tmpB21_D2_8600.Trim().Length == 0)
                                {
                                    myHeader.B21_D2_8600 = "99999";
                                }
                            }
                            else
                            {
                                myHeader.B21_D2_8600 = new String(' ', 6);
                            }

                            myHeader.B21_D3_8700 = foxDR["V1DIAGN3"].ToString().Trim();

                            if (myHeader.B21_D3_8700.Trim().Length > 0)
                            {

                                String tmpB21_D3_8700 = Program.MySqlbusqueda(sqlCnnString, "select Code from tblDiagnosisCodes where Code='" + myHeader.B21_D3_8700 + "';");
                                if (tmpB21_D3_8700.Trim().Length == 0)
                                {
                                    myHeader.B21_D3_8700 = "99999";

                                }
                            }
                            else
                            {
                                myHeader.B21_D3_8700 = new String(' ', 6);
                            }

                            myHeader.B21_D4_8800 = foxDR["V1DIAGN4"].ToString().Trim();

                            if (myHeader.B21_D4_8800.Trim().Length > 0)
                            {

                                String tmpB21_D4_8800 =Program.MySqlbusqueda(sqlCnnString, "select Code from tblDiagnosisCodes where Code='" + myHeader.B21_D4_8800 + "';");
                                if (tmpB21_D4_8800.Trim().Length == 0)
                                {
                                    myHeader.B21_D4_8800 = "99999";
                                }
                            }
                            else
                            {
                                myHeader.B21_D4_8800 = new String(' ', 6);
                            }
                            ///////////////////// codigo Nuevo ////////////////////
                            //V1DIAGN5
                            myHeader.B21_D5_8810 = foxDR["V1DIAGN5"].ToString().Trim();

                            if (myHeader.B21_D5_8810.Trim().Length > 0)
                            {

                                String tmpB21_D5_8810 = Program.MySqlbusqueda(sqlCnnString, "select Code from tblDiagnosisCodes where Code='" + myHeader.B21_D5_8810 + "';");
                                if (tmpB21_D5_8810.Trim().Length == 0)
                                {
                                    myHeader.B21_D5_8810 = "99999";
                                }
                            }
                            else
                            {
                                myHeader.B21_D5_8810 = new String(' ', 6);
                            }
                            /// V1DIAGN6
                            myHeader.B21_D6_8820 = foxDR["V1DIAGN6"].ToString().Trim();

                            if (myHeader.B21_D6_8820.Trim().Length > 0)
                            {

                                String tmpB21_D6_8820 = Program.MySqlbusqueda(sqlCnnString, "select Code from tblDiagnosisCodes where Code='" + myHeader.B21_D6_8820 + "';");
                                if (tmpB21_D6_8820.Trim().Length == 0)
                                {
                                    myHeader.B21_D6_8820 = "99999";
                                }
                            }
                            else
                            {
                                myHeader.B21_D6_8820 = new String(' ', 6);
                            }
                            /// V1DIAGN7
                            myHeader.B21_D7_8830 = foxDR["V1DIAGN7"].ToString().Trim();

                            if (myHeader.B21_D7_8830.Trim().Length > 0)
                            {

                                String tmpB21_D7_8830 =  Program.MySqlbusqueda(sqlCnnString, "select Code from tblDiagnosisCodes where Code='" + myHeader.B21_D7_8830 + "';");
                                if (tmpB21_D7_8830.Trim().Length == 0)
                                {
                                    myHeader.B21_D7_8830 = "99999";
                                }
                            }
                            else
                            {
                                myHeader.B21_D7_8830 = new String(' ', 6);
                            }
                            /// V1DIAGN8
                            myHeader.B21_D8_8840 = foxDR["V1DIAGN8"].ToString().Trim();

                            if (myHeader.B21_D8_8840.Trim().Length > 0)
                            {

                                String tmpB21_D8_8840 = Program.MySqlbusqueda(sqlCnnString, "select Code from tblDiagnosisCodes where Code='" + myHeader.B21_D8_8840 + "';");
                                if (tmpB21_D8_8840.Trim().Length == 0)
                                {
                                    myHeader.B21_D8_8840 = "99999";
                                }
                            }
                            else
                            {
                                myHeader.B21_D8_8840 = new String(' ', 6);
                            }

                            // este es un truco para sortial los diagnotico  junio del 2012
                            myHeader.B21_D2_8600 = myHeader.B21_D2_8600.Trim().Length>0?"08_" + myHeader.B21_D2_8600:" ";

                            myHeader.B21_D3_8700 = myHeader.B21_D3_8700.Trim().Length>0?"07_" + myHeader.B21_D3_8700:" ";

                            myHeader.B21_D4_8800 = myHeader.B21_D4_8800.Trim().Length>0? "06_" + myHeader.B21_D4_8800:" ";

                            myHeader.B21_D5_8810 =myHeader.B21_D5_8810.Trim().Length>0? "05_" + myHeader.B21_D5_8810: " ";

                            myHeader.B21_D6_8820 = myHeader.B21_D6_8820.Trim().Length>0?"04_" + myHeader.B21_D6_8820: " " ;

                            myHeader.B21_D7_8830 =myHeader.B21_D7_8830.Trim().Length>0?"03_" + myHeader.B21_D7_8830:" ";

                            myHeader.B21_D8_8840 =myHeader.B21_D8_8840.Trim().Length>0? "02_" + myHeader.B21_D8_8840:" ";

                            dataDiag = new string[] {myHeader.B21_D2_8600,myHeader.B21_D3_8700,myHeader.B21_D4_8800,
                                                     myHeader.B21_D5_8810,myHeader.B21_D6_8820,myHeader.B21_D7_8830,myHeader.B21_D8_8840 };

                            var sortDataDiag = from data in dataDiag orderby data descending select data;

                            {
                                myHeader.B21_D2_8600 = sortDataDiag.ElementAt(0).Trim().Length > 0 ? sortDataDiag.ElementAt(0).Trim().Substring(3) : " ";
                                myHeader.B21_D3_8700 = sortDataDiag.ElementAt(1).Trim().Length > 0 ? sortDataDiag.ElementAt(1).Trim().Substring(3) : " ";
                                myHeader.B21_D4_8800 = sortDataDiag.ElementAt(2).Trim().Length > 0 ? sortDataDiag.ElementAt(2).Trim().Substring(3) : " ";
                                myHeader.B21_D5_8810 = sortDataDiag.ElementAt(3).Trim().Length > 0 ? sortDataDiag.ElementAt(3).Trim().Substring(3) : " ";
                                myHeader.B21_D6_8820 = sortDataDiag.ElementAt(4).Trim().Length > 0 ? sortDataDiag.ElementAt(4).Trim().Substring(3):" ";
                                myHeader.B21_D7_8830 = sortDataDiag.ElementAt(5).Trim().Length > 0 ? sortDataDiag.ElementAt(5).Trim().Substring(3) : " ";
                                myHeader.B21_D8_8840 = sortDataDiag.ElementAt(6).Trim().Length > 0 ? sortDataDiag.ElementAt(6).Trim().Substring(3) : " ";
                            }

                            ///
                        }
                        myHeader.B22_CODE_8900 = new string(' ', 20);
                        {
                            // Estrututa de la image file : MMDDYY CC BBBB SEQDOC.TIF
                            //**** falta rutina para Icn ejemplo: CCNNNNMMMDD`YY Nota:CC es el numero de la CATEGORIA
                            //NNNN numero de la Seq no usal LA DE LA IMAGEN hay que calcularlo Cadave q cabies de Categoria regresa a uno,
                            //MMM es el Nombre del mes, DD es el dia,YY es el ano
                            String img = Images;
                            String CC = img.Substring(6, 2);
                            if (TMPcc == CC)
                            {
                                iCC++;
                            }
                            else
                            {
                                iCC = 1;
                                TMPcc = CC;
                            }
                            if (CC == "97")
                            {
                                iCount_97 = iCC;
                            }

                            String NNNN = iCC.ToString("000#");
                            String MMM = img.Substring(0, 2);
                            String DD = img.Substring(2, 2);
                            String YY = img.Substring(4, 2);

                            switch (MMM)
                            {
                                case "01":
                                    MMM = "JAN";
                                    break;
                                case "02":
                                    MMM = "FEB";
                                    break;
                                case "03":
                                    MMM = "MAR";
                                    break;
                                case "04":
                                    MMM = "APR";
                                    break;
                                case "05":
                                    MMM = "MAY";
                                    break;
                                case "06":
                                    MMM = "JUN";
                                    break;
                                case "07":
                                    MMM = "JUL";
                                    break;
                                case "08":
                                    MMM = "AUG";
                                    break;
                                case "09":
                                    MMM = "SEP";
                                    break;
                                case "10":
                                    MMM = "OCT";
                                    break;
                                case "11":
                                    MMM = "NOV";
                                    break;
                                case "12":
                                    MMM = "DEC";
                                    break;
                            }

                            myHeader.B22_OREF_9000 = CC + NNNN + MMM.Substring(0, 3) + DD + "'" + YY;
                        }
                        myHeader.B23_AUTH_9100 = foxDR["V123AUTORI"].ToString().Trim();  //V123AUTORI
                        myHeader.B23_CLIA_9200 = new string(' ', 30);

                        {// Regla de Negocio #3 Tabala provedores tblProvider
                            myHeader.B25_FTID_9300 = foxDR["V1FEDTAXID"].ToString().Trim();
                            if (myHeader.B25_FTID_9300.Trim().Length > 0)
                            {
                                String tmpB25_FTID_9300 =
                                Program.MySqlbusqueda(sqlCnnString, "select VENDOR from " + tblProvider + " where VENDOR='" + myHeader.B25_FTID_9300 + "';");
                                if (tmpB25_FTID_9300.Trim().Length == 0)
                                {
                                    myHeader.B25_FTID_9300 = "999999999";
                                }
                                else
                                {//V1NPIBILLI  PAYEE_NPI
                                    String V1NPIBILLI = foxDR["V1NPIBILLI"].ToString().Trim();
                                    String PAYEE_NPI =
                                        Program.MySqlbusqueda(sqlCnnString, "select PAYEE_NPI from " + tblProvider + " where VENDOR='" + myHeader.B25_FTID_9300 + "';");
                                    if (V1NPIBILLI.Trim() != PAYEE_NPI)
                                    {
                                        myHeader.B25_FTID_9300 = "999999999";
                                    }
                                }
                            }
                            else
                            {
                                myHeader.B25_FTID_9300 = "999999999";
                            }

                        }
                        myHeader.B25_TYPE_9400 = "EI";// foxDR["V1SSNEIN"].ToString().Trim();//V1SSNEIN

                        {
                            myHeader.B26_PAN_9500 = foxDR["V1PATCONTR"].ToString().Trim();//V1PATCONTR
                            if (myHeader.B26_PAN_9500.Trim().Length == 0)
                            {
                                myHeader.B26_PAN_9500 = "0";
                            }
                        }

                        {//V127ACCEPT // 1=A,2=B, Blanco = C
                            myHeader.B27_ASSN_9600 = foxDR["V127ACCEPT"].ToString().Trim();
                            if (foxDR["V127ACCEPT"].ToString().Trim().Length == 0)
                            {
                                myHeader.B27_ASSN_9600 = "C";
                            }
                            else
                            {
                                switch (foxDR["V127ACCEPT"].ToString().Trim())
                                {
                                    case "1":
                                        myHeader.B27_ASSN_9600 = "A";
                                        break;
                                    case "2":
                                        myHeader.B27_ASSN_9600 = "B";
                                        break;
                                    default:
                                        myHeader.B27_ASSN_9600 = "C";
                                        break;
                                }
                            }
                        }
                        myHeader.B28_TOT_9700 = foxDR["V128TOTAL"].ToString().Trim(); // V128TOTAL
                        myHeader.B29_AP_9800 = new string(' ', 9);
                        myHeader.B30_BAL_9900 = new string(' ', 9);

                        {//**** si la fecha es futura (mayor a la del dia de procesamiento.) cambiar a los 6 digitos de la imagen.
                            //080607
                            Int64 B24A_FDT_100200 = 0;
                            Int64 B24A_TDT_100300 = 0;
                            String img = foxDR["V0ifname01"].ToString().Trim();
                            myDetail.B24A_FDT_100200 = foxDR["V2DATEFROM"].ToString().Trim();//V2DATEFROM ->Rutina de Fecha MMDDCCYY
                            myDetail.B24A_TDT_100300 = foxDR["V2DATETO"].ToString().Trim();//Rutina de Fecha MMDDCCYY
                            if (myDetail.B24A_FDT_100200.Trim().Length > 0)
                            {
                                String tmp = "20" + myDetail.B24A_FDT_100200.Trim().Substring(4, 2) +
                                    myDetail.B24A_FDT_100200.Trim().Substring(0, 2) + myDetail.B24A_FDT_100200.Trim().Substring(2, 2);
                                B24A_FDT_100200 = Convert.ToInt64(tmp);
                            }
                            if (myDetail.B24A_TDT_100300.Trim().Length > 0)
                            {
                                String tmp = "20" + myDetail.B24A_TDT_100300.Trim().Substring(4, 2) +
                                    myDetail.B24A_TDT_100300.Trim().Substring(0, 2) + myDetail.B24A_TDT_100300.Trim().Substring(2, 2);
                                B24A_TDT_100300 = Convert.ToInt64(tmp);
                            }
                            if (B24A_TDT_100300 < B24A_FDT_100200)
                            {// Estrututa de la image file : MMDDYY CC BBBB SEQDOC.TIF
                                //                                    throw new Exception("Error en las Fechas:" + img);
                                //throw new Exception("Error con la Fecha: " + "V2DATEFROM ->ImgName:" + img.Trim());
                                B24A_TDT_100300 = B24A_FDT_100200;
                            }
                            String sFechaRecivido = img.Trim().Substring(0, 6);
                            String tmpFechaRecivido = "20" + sFechaRecivido.Substring(4, 2) +
                                sFechaRecivido.Substring(0, 2) + sFechaRecivido.Substring(2, 2);
                            Int64 iFechaRecivido = Convert.ToInt64(tmpFechaRecivido);

                            if (B24A_FDT_100200 >= iFechaRecivido)
                            {// Estrututa de la image file : MMDDYY CC BBBB SEQDOC.TIF
                                String MM = img.Substring(0, 2);
                                String DD = img.Substring(2, 2);
                                String YY = img.Substring(4, 2);
                                myDetail.B24A_FDT_100200 = MM + DD + YY;
                                myDetail.B24A_TDT_100300 = MM + DD + YY;
                            }

                            if (myDetail.B24A_FDT_100200.Trim().Length == 6)
                            {
                                String MM = myDetail.B24A_FDT_100200.Trim().Substring(0, 2);
                                String DD = myDetail.B24A_FDT_100200.Trim().Substring(2, 2);
                                String YY = myDetail.B24A_FDT_100200.Trim().Substring(4, 2);
                                myDetail.B24A_FDT_100200 = MM + "/" + DD + "/20" + YY;
                            }
                            else
                            {
                                throw new Exception("Error con la Fecha: " + "V2DATEFROM ->ImgName:" + img.Trim());
                            }
                            if (myDetail.B24A_TDT_100300.Trim().Length == 6)
                            {
                                String MM = myDetail.B24A_TDT_100300.Trim().Substring(0, 2);
                                String DD = myDetail.B24A_TDT_100300.Trim().Substring(2, 2);
                                String YY = myDetail.B24A_TDT_100300.Trim().Substring(4, 2);
                                myDetail.B24A_TDT_100300 = MM + "/" + DD + "/20" + YY;
                            }
                            else
                            {
                                myDetail.B24A_TDT_100300 = myDetail.B24A_FDT_100200;
                            }
                            myHeader.B31_DATE_10300 = myDetail.B24A_FDT_100200; //V2DATEFROM ->Rutina de Fecha MMDDCCYY
                        }//////////////////////////////////////////////////////////

                        myHeader.B31_PRV_1_10310 = new string(' ', 2);
                        myHeader.B31_PRV_3_10320 = new string(' ', 10);
                        {// Regla de Negocio: Tabla Provedor
                            myHeader.B31_NPI_10330 = foxDR["V2NPI24J"].ToString().Trim(); //TODO:****si es invalido 9999999995
                            if (myHeader.B31_NPI_10330.Trim().Length > 0)
                            {
                                String tmpB31_NPI_10330 =
                                Program.MySqlbusqueda(sqlCnnString, "select NPI from " + tblProvider + " where NPI='" + myHeader.B31_NPI_10330 + "';");
                                if (tmpB31_NPI_10330.Trim().Length == 0)
                                {
                                    myHeader.B31_NPI_10330 = "9999999995";
                                }
                                else
                                {
                                    String V1NPIBILLI = foxDR["V1NPIBILLI"].ToString().Trim();
                                    if (V1NPIBILLI.Trim().Length > 0)
                                    {
                                        String Count =
                                        Program.MySqlbusqueda(sqlCnnString, "select count(*) from " + tblProvider + " where NPI='" + myHeader.B31_NPI_10330 +
                                                                                                               "' and PAYEE_NPI='" + V1NPIBILLI.Trim() + "';");
                                        if (Count == "0")
                                        {
                                            myHeader.B31_NPI_10330 = "9999999995";
                                        }
                                    }
                                    else
                                    {
                                        myHeader.B31_NPI_10330 = "9999999995";
                                    }
                                }
                            }
                            else
                            {
                                myHeader.B31_NPI_10330 = "9999999995";
                            }

                            {
                                myHeader.B31_FIRS_10000 = Program.MySqlbusqueda(sqlCnnString,
                                    "SELECT FIRSTNAME FROM " + tblProvider + " where NPI ='" + myHeader.B31_NPI_10330 + "';");
                                myHeader.B31_MI_10100 = Program.MySqlbusqueda(sqlCnnString,
                                    "SELECT MI FROM " + tblProvider + " where NPI ='" + myHeader.B31_NPI_10330 + "';");
                                myHeader.B31_LAST_10200 = Program.MySqlbusqueda(sqlCnnString,
                                    "SELECT LASTNAME FROM " + tblProvider + " where NPI ='" + myHeader.B31_NPI_10330 + "';");
                            }
                            {
                                myHeader.B31_FIRS_10000 = myHeader.B31_FIRS_10000.Trim();
                                if (myHeader.B31_FIRS_10000.Length > 33)
                                {
                                    myHeader.B31_FIRS_10000 = myHeader.B31_FIRS_10000.Substring(0, 33);
                                }
                            }
                            {
                                myHeader.B31_LAST_10200 = myHeader.B31_LAST_10200.Trim();
                                if (myHeader.B31_LAST_10200.Length > 33)
                                {
                                    myHeader.B31_LAST_10200 = myHeader.B31_LAST_10200.Substring(0, 33);
                                }
                            }
                        }
                        myHeader.B31_REFQAL_10340 = new string(' ', 3);
                        myHeader.B31_REF_10350 = new string(' ', 15);
                        myHeader.B32_ID_11000 = new string(' ', 15);
                        myHeader.B32_IDQAL_11100 = new string(' ', 2);
                        {//todo chkDig
                            myHeader.B32_NPI_11200 = foxDR["V1NPISERVI"].ToString().Trim();//V1NPISERVI

                            String count = Program.MySqlbusqueda(sqlCnnString,
                                "Select count(*) from " + tblProvider + " where NPI='" + myHeader.B32_NPI_11200 + "';");

                            if (count == "0")
                            {
                                switch (myHeader.B32_NPI_11200.Length)
                                {//TODO: B32_ZIP_10900 22 de feb de 2012
                                    case 10:
                                        if (check_digit_NPI.isValidNPI(myHeader.B32_NPI_11200))
                                        {//9999999995 Los Record Dummy
                                            myHeader.B32_NAME_10400 = Program.MySqlbusqueda(sqlCnnString, "Select lastname from " + tblProvider + " where NPI='9999999995';");
                                            myHeader.B32_ADD1_10500 = Program.MySqlbusqueda(sqlCnnString, "Select street from " + tblProvider + " where NPI='9999999995';");
                                            myHeader.B32_ADD2_10600 = Program.MySqlbusqueda(sqlCnnString, "Select street2 from " + tblProvider + " where NPI='9999999995';");
                                            myHeader.B32_CITY_10700 = Program.MySqlbusqueda(sqlCnnString, "Select city from " + tblProvider + " where NPI='9999999995';");
                                            myHeader.B32_ST_10800 = Program.MySqlbusqueda(sqlCnnString, "Select state from " + tblProvider + " where NPI='9999999995';");
                                            myHeader.B32_ZIP_10900 = Program.MySqlbusqueda(sqlCnnString, "Select zip from " + tblProvider + " where NPI='9999999995';");
                                            if (myHeader.B32_ZIP_10900.Trim().Length < 9) {
                                                myHeader.B32_ZIP_10900 += new string('9', 9-myHeader.B32_ZIP_10900.Trim().Length);
                                            }else if (myHeader.B32_ZIP_10900.Trim().Length >9) {
                                                myHeader.B32_ZIP_10900 = myHeader.B32_ZIP_10900.Trim().Substring(0, 9);
                                            }
                                        }
                                        else
                                        {
                                            myHeader.B32_NPI_11200 = new String(' ', 10);
                                            myHeader.B32_NAME_10400 = new string(' ', 33);
                                            myHeader.B32_ADD1_10500 = new string(' ', 30);
                                            myHeader.B32_ADD2_10600 = new string(' ', 30);
                                            myHeader.B32_CITY_10700 = new string(' ', 20);
                                            myHeader.B32_ST_10800 = new string(' ', 2);
                                            myHeader.B32_ZIP_10900 = new string(' ', 9);
                                        }
                                        break;
                                    default:
                                        myHeader.B32_NPI_11200 = new String(' ', 10);
                                        myHeader.B32_NAME_10400 = new string(' ', 33);
                                        myHeader.B32_ADD1_10500 = new string(' ', 30);
                                        myHeader.B32_ADD2_10600 = new string(' ', 30);
                                        myHeader.B32_CITY_10700 = new string(' ', 20);
                                        myHeader.B32_ST_10800 = new string(' ', 2);
                                        myHeader.B32_ZIP_10900 = new string(' ', 9);
                                        break;
                                }
                            }
                            else
                            {
                                myHeader.B32_NAME_10400 = Program.MySqlbusqueda(sqlCnnString,
                                                         "SELECT LASTNAME FROM " + tblProvider + " where NPI ='" + myHeader.B32_NPI_11200 + "';");
                                myHeader.B32_ADD1_10500 = Program.MySqlbusqueda(sqlCnnString,
                                                         "SELECT STREET FROM " + tblProvider + " where NPI ='" + myHeader.B32_NPI_11200 + "';");
                                myHeader.B32_ADD2_10600 = Program.MySqlbusqueda(sqlCnnString,
                                                         "SELECT STREET2 FROM " + tblProvider + " where NPI ='" + myHeader.B32_NPI_11200 + "';");
                                myHeader.B32_CITY_10700 = Program.MySqlbusqueda(sqlCnnString,
                                                         "SELECT CITY FROM " + tblProvider + " where NPI ='" + myHeader.B32_NPI_11200 + "';");
                                myHeader.B32_ST_10800 = Program.MySqlbusqueda(sqlCnnString,
                                                         "SELECT STATE FROM " + tblProvider + " where NPI ='" + myHeader.B32_NPI_11200 + "';");
                                myHeader.B32_ZIP_10900 = Program.MySqlbusqueda(sqlCnnString,
                                                         "SELECT ZIP FROM " + tblProvider + " where NPI ='" + myHeader.B32_NPI_11200 + "';");
                                {
                                    if (myHeader.B32_ZIP_10900.Trim().Length > 0)
                                    {
                                        if (myHeader.B32_ZIP_10900.Trim().Length >= 5)
                                        {
                                            if (myHeader.B32_ZIP_10900.Trim().Length < 9)
                                            {
                                                myHeader.B32_ZIP_10900 += new string('9', 9 - myHeader.B32_ZIP_10900.Trim().Length);
                                            }
                                            else if (myHeader.B32_ZIP_10900.Trim().Length > 9)
                                            {
                                                myHeader.B32_ZIP_10900 = myHeader.B32_ZIP_10900.Trim().Substring(0, 9);
                                            }
                                        }
                                        else
                                        {
                                            myHeader.B32_ZIP_10900 = "999999999";
                                        }
                                    }
                                    else
                                    {
                                        myHeader.B32_ZIP_10900 = "999999999";
                                    }
                                }
                            }
                        }//End Modificado 22 de feb de 2012 //////////////////////////////////////////////////////////////////////////////////
                        {
                            if (myHeader.B32_NAME_10400.Trim().Length > 33)
                            {
                                myHeader.B32_NAME_10400 = myHeader.B32_NAME_10400.Trim().Substring(0, 33);
                            }
                            else
                            {
                                myHeader.B32_NAME_10400 = myHeader.B32_NAME_10400.Trim();
                            }
                        }

                        myHeader.B33_PRV_1_11210 = new string(' ', 3);
                        myHeader.B33_PRV_3_11220 = new string(' ', 10);// foxDR["V1FEDTAXID"].ToString().Trim();

                        {//Tabala de Provedores
                            myHeader.BILL_NPI_12600 = foxDR["V1NPIBILLI"].ToString().Trim();//TODO:**** si es invalido 9999999995
                            if (myHeader.BILL_NPI_12600.Trim().Length > 0)
                            {
                                String tmpBILL_NPI_12600 =
                                Program.MySqlbusqueda(sqlCnnString, "select PAYEE_NPI from " + tblProvider + " where PAYEE_NPI='" + myHeader.BILL_NPI_12600 + "';");
                                if (tmpBILL_NPI_12600.Trim().Length == 0)
                                {
                                    myHeader.BILL_NPI_12600 = "9999999995";
                                }
                            }
                            else
                            {
                                myHeader.BILL_NPI_12600 = "9999999995";
                            }
                        }
                        {
                            myHeader.B33_GRLN_11300 = Program.MySqlbusqueda(sqlCnnString, "select LASTNAME from " + tblProvider + " where PAYEE_NPI='" + myHeader.BILL_NPI_12600 + "';");
                            myHeader.B33_FIRS_11400 = Program.MySqlbusqueda(sqlCnnString, "select FIRSTNAME from " + tblProvider + " where PAYEE_NPI='" + myHeader.BILL_NPI_12600 + "';");
                            myHeader.B33_MI_11500 = " "; //Program.MySqlbusqueda(sqlCnnString, "select MI from " + tblProvider + " where PAYEE_NPI='" + myHeader.BILL_NPI_12600 + "';");
                        }
                        {
                            myHeader.B33_GRLN_11300 = myHeader.B33_GRLN_11300.Trim();
                            if (myHeader.B33_GRLN_11300.Length > 33)
                            {
                                myHeader.B33_GRLN_11300 = myHeader.B33_GRLN_11300.Substring(0, 33);
                            }
                        }
                        {////// Base de datos SQL
                            myHeader.B33_ADD1_11600 =
                            Program.MySqlbusqueda(sqlCnnString, "select STREET from " + tblProvider + " where PAYEE_NPI='" + myHeader.BILL_NPI_12600 + "';");

                            if (myHeader.B33_ADD1_11600.Trim().Length == 0) {
                                myHeader.B33_ADD1_11600 = "Dummy";
                            }
                            if (myHeader.B33_ADD1_11600.Trim().ToUpper().Contains("BOX"))
                            {
                                myHeader.B33_ADD1_11600 = "Dummy";
                            }
                            myHeader.B33_ADD2_11700 =
                            Program.MySqlbusqueda(sqlCnnString, "select STREET2 from " + tblProvider + " where PAYEE_NPI='" + myHeader.BILL_NPI_12600 + "';");

                            if (myHeader.B33_ADD2_11700.Trim().Length == 0)
                            {
                                myHeader.B33_ADD2_11700 = "Dummy";
                            }
                            if (myHeader.B33_ADD2_11700.Trim().ToUpper().Contains("BOX"))
                            {
                                myHeader.B33_ADD2_11700 = "Dummy";
                            }

                            myHeader.B33_CITY_11800 =
                            Program.MySqlbusqueda(sqlCnnString, "select CITY from " + tblProvider + " where PAYEE_NPI='" + myHeader.BILL_NPI_12600 + "';");

                            myHeader.B33_ST_11900 =
                            Program.MySqlbusqueda(sqlCnnString, "select STATE from " + tblProvider + " where PAYEE_NPI='" + myHeader.BILL_NPI_12600 + "';");

                            myHeader.B33_ZIP_12000 =
                            Program.MySqlbusqueda(sqlCnnString, "select ZIP from " + tblProvider + " where PAYEE_NPI='" + myHeader.BILL_NPI_12600 + "';");
                            if (myHeader.B33_ZIP_12000.Trim().Length > 0)
                            {
                                if (myHeader.B33_ZIP_12000.Trim().Length >= 5)
                                {
                                    myHeader.B33_ZIP_12000 += new string('9', 9 - myHeader.B33_ZIP_12000.Trim().Length); //myHeader.B33_ZIP_12000.Trim().Substring(0, 5);
                                }
                                else
                                {
                                    myHeader.B33_ZIP_12000 = "999999999";
                                }

                            }
                            else
                            {
                                myHeader.B33_ZIP_12000 = "999999999";
                            }

                            myHeader.B33_TELE_12100 = new string(' ', 2);
                        }
                        myHeader.B33_PIN_12200 = new string(' ', 16);
                        myHeader.B33_PINQAL_12300 = new string(' ', 2);
                        myHeader.B33_GRP_12400 = myHeader.BILL_NPI_12600;
                        myHeader.B33_GRPQAL_12500 = "XX";

                        myHeader.PRIMGEN_12700 = new string(' ', 20);
                        myHeader.MAKEDATE_12800 = new string(' ', 10);
                        myHeader.AMT_PAYPRV_12900 = new string(' ', 9);
                        myHeader.DTP_PAID_13000 = new string(' ', 10);
                        myHeader.AMT_ALLOWD_13100 = new string(' ', 9);
                        myHeader.clm_05_03_13150 = "1";
                        myHeader.COB_CAS101_13200 = new string(' ', 2);
                        myHeader.COB_CAS102_13300 = new string(' ', 3);
                        myHeader.COB_CAS103_13400 = new string(' ', 9);
                        myHeader.COB_CAS104_13500 = new string(' ', 4);
                        myHeader.COB_CAS105_13600 = new string(' ', 3);
                        myHeader.COB_CAS106_13700 = new string(' ', 9);
                        myHeader.COB_CAS107_13800 = new string(' ', 4);
                        myHeader.COB_CAS201_13900 = new string(' ', 2);
                        myHeader.COB_CAS202_14000 = new string(' ', 3);
                        myHeader.COB_CAS203_14100 = new string(' ', 9);
                        myHeader.COB_CAS204_14200 = new string(' ', 4);
                        myHeader.COB_CAS205_14300 = new string(' ', 3);
                        myHeader.COB_CAS206_14400 = new string(' ', 9);
                        myHeader.COB_CAS207_14500 = new string(' ', 4);
                        myHeader.CLM_05_03_14550 = new string(' ', 1);
                        myHeader.CR1_01_14600 = new string(' ', 2);
                        myHeader.CR1_02_14700 = new string(' ', 10);
                        myHeader.CR1_03_14800 = new string(' ', 1);
                        myHeader.CR1_04_14900 = new string(' ', 1);
                        myHeader.CR1_05_15000 = new string(' ', 2);
                        myHeader.CR1_06_15100 = new string(' ', 15);
                        myHeader.CR1_07_15200 = new string(' ', 55);
                        myHeader.CR1_08_15300 = new string(' ', 55);
                        myHeader.CR1_09_15400 = new string(' ', 80);
                        myHeader.CR1_10_15500 = new string(' ', 80);
                        myHeader.CRC_01_15600 = new string(' ', 2);
                        myHeader.CRC_02_15700 = new string(' ', 1);
                        myHeader.CRC_03_15800 = new string(' ', 2);
                        myHeader.CRC_04_15900 = new string(' ', 2);
                        myHeader.CRC_05_16000 = new string(' ', 2);
                        myHeader.CRC_06_16100 = new string(' ', 2);
                        myHeader.CRC_07_16200 = new string(' ', 2);
                        myHeader.CR2_01_16300 = new string(' ', 9);
                        myHeader.CR2_02_16400 = new string(' ', 15);
                        myHeader.CR2_03_16500 = new string(' ', 3);
                        myHeader.CR2_04_16600 = new string(' ', 3);
                        myHeader.CR2_05_16700 = new string(' ', 2);
                        myHeader.CR2_06_16800 = new string(' ', 15);
                        myHeader.CR2_07_16900 = new string(' ', 15);
                        myHeader.CR2_08_17000 = new string(' ', 1);
                        myHeader.CR2_09_17100 = new string(' ', 1);
                        myHeader.CR2_10_17200 = new string(' ', 80);
                        myHeader.CR2_11_17300 = new string(' ', 80);
                        myHeader.CR2_12_17400 = new string(' ', 8);
                        myHeader.BHT_04_17500 = Images.Substring(0, 2) + "/" + Images.Substring(2, 2) + "/20" + Images.Substring(4, 2);  // mm/dd/ccyy

                        using (StreamWriter fs = File.AppendText(txtFileOutPut.Trim()))
                        {
                            sHDOut.Clear();

                            sHDOut.Append(myHeader.CLAIM_NO_100.Trim());  sHDOut.Append("|");
                            sHDOut.Append(myHeader.PAY_NAME_200.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.PAY_ID1_300.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.PAY_ID2_400.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.PAY1_SEQNC_500.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.PAY_ADD1_600.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.PAY_ADD2_700.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.PAY_CITY_800.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.PAY_ST_900.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.PAY_ZIP_1000.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B1_TYPE_1100.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B1_CLMFIND_1200.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.PAY2_ID1_1300.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.PAY2_ID2_1400.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.PAY2_SEQNC_1500.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.PAY2_NAME_1600.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.PAY2_ADD1_1700.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.PAY2_ADD2_1800.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.PAY2_CITY_1900.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.PAY2_ST_2000.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.PAY2_ZIP_2100.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.PAY2_TYPE_2200.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.PAY2_CFIND_2300.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B1A_ID_2400.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B2_LAST_2500.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B2_FIRST_2600.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B2_MI_2700.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B3_DOB_2800.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B3_SEX_2900.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B4_LAST_3000.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B4_FIRST_3100.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B4_MI_3200.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B5_ADD_3300.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B5_CITY_3400.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B5_STATE_3500.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B5_ZIP_3600.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B5_PHONE_3700.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B6_REL_3800.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B7_ADD_3900.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B7_CITY_4000.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B7_STATE_4100.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B7_ZIP_4200.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B7_PHONE_4300.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B8_STAT_4400.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B8_EMP_4500.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B9_LAST_4600.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B9_FIRST_4700.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B9_MI_4800.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B9_INSID2_4900.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B9_PATREL2_5000.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B9A_POL_5100.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B9B_DOB_5200.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B9B_SEX_5300.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B9C_EMP_5400.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B9D_PLN_5500.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B10A_EMP_5600.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B10B_AUT_5700.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B10B_ST_5800.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B10C_ACC_5900.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B10D_LOCAL_6000.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B11_POL_6100.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B11A_DOB_6200.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B11A_SEX_6300.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B11B_EMP_6400.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B11C_PLN_6500.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B11D_APL_6600.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B12_SIGN_6700.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B12_DATE_6800.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B13_SIGN_6900.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B13_DATE_7000.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B14_DT_QAL_7100.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B14_DATE_7200.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B15_DATE_7300.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B16_FROM_7400.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B16_TO_7500.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B17_REF_LAST_7600.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B17_REF_7620.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B17_REF_MID_7630.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B17A_ID_7700.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B17A_IDQAL_7800.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B17A_NPI_7900.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B17A_PRV_1_7920.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B17A_PRV_3_7930.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B18_FROM_8000.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B18_TO_8100.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B19_NAV_8200.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B20_LAB_8300.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B20_CHGS_8400.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B21_D1_8500.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B21_D2_8600.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B21_D3_8700.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B21_D4_8800.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B21_D5_8810.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B21_D6_8820.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B21_D7_8830.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B21_D8_8840.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B22_CODE_8900.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B22_OREF_9000.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B23_AUTH_9100.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B23_CLIA_9200.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B25_FTID_9300.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B25_TYPE_9400.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B26_PAN_9500.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B27_ASSN_9600.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B28_TOT_9700.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B29_AP_9800.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B30_BAL_9900.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B31_FIRS_10000.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B31_MI_10100.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B31_LAST_10200.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B31_DATE_10300.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B31_PRV_1_10310.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B31_PRV_3_10320.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B31_NPI_10330.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B31_REFQAL_10340.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B31_REF_10350.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B32_NAME_10400.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B32_ADD1_10500.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B32_ADD2_10600.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B32_CITY_10700.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B32_ST_10800.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B32_ZIP_10900.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B32_ID_11000.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B32_IDQAL_11100.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B32_NPI_11200.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B33_PRV_1_11210.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B33_PRV_3_11220.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B33_GRLN_11300.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B33_FIRS_11400.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B33_MI_11500.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B33_ADD1_11600.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B33_ADD2_11700.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B33_CITY_11800.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B33_ST_11900.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B33_ZIP_12000.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B33_TELE_12100.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B33_PIN_12200.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B33_PINQAL_12300.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B33_GRP_12400.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.B33_GRPQAL_12500.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.BILL_NPI_12600.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.PRIMGEN_12700.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.MAKEDATE_12800.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.AMT_PAYPRV_12900.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.DTP_PAID_13000.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.AMT_ALLOWD_13100.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.clm_05_03_13150.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.COB_CAS101_13200.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.COB_CAS102_13300.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.COB_CAS103_13400.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.COB_CAS104_13500.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.COB_CAS105_13600.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.COB_CAS106_13700.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.COB_CAS107_13800.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.COB_CAS201_13900.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.COB_CAS202_14000.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.COB_CAS203_14100.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.COB_CAS204_14200.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.COB_CAS205_14300.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.COB_CAS206_14400.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.COB_CAS207_14500.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CLM_05_03_14550.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CR1_01_14600.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CR1_02_14700.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CR1_03_14800.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CR1_04_14900.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CR1_05_15000.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CR1_06_15100.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CR1_07_15200.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CR1_08_15300.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CR1_09_15400.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CR1_10_15500.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CRC_01_15600.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CRC_02_15700.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CRC_03_15800.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CRC_04_15900.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CRC_05_16000.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CRC_06_16100.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CRC_07_16200.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CR2_01_16300.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CR2_02_16400.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CR2_03_16500.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CR2_04_16600.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CR2_05_16700.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CR2_06_16800.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CR2_07_16900.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CR2_08_17000.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CR2_09_17100.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CR2_10_17200.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CR2_11_17300.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.CR2_12_17400.Trim()); sHDOut.Append("|");
                            sHDOut.Append(myHeader.BHT_04_17500.Trim());

                            fs.WriteLine(sHDOut.ToString().Trim());
                            sHDOut.Clear();
                        }
                        // write heder //
                        //myWriteFile.setString = myCreateFile.getString.Trim();
                        //myWriteFile.write(txtFileOutPut);
                        //myWriteFile = null;
                        /////////////// Detail ////////////////////////////////////////////////////////////////////////////
                        int i = 2;
                        string strI = null;
                        //myWriteFile = new writeFile.file();
                        //myCreateFile.setStringLen = 14895;
                        long SEQ_NO_100100 = 0;

                        while (i < 31)   //(1 < 14)  old (i>8)
                        {
                            switch (i)
                            {
                                case 10:
                                    strI = "A";
                                    break;
                                case 11:
                                    strI = "B";
                                    break;
                                case 12:
                                    strI = "C";
                                    break;
                                case 13:
                                    strI = "D";
                                    break;
                                case 14:
                                    strI = "E";
                                    break;
                                case 15:
                                    strI = "F";
                                    break;
                                case 16:
                                    strI = "G";
                                    break;
                                case 17:
                                    strI = "H";
                                    break;
                                case 18:
                                    strI = "I";
                                    break;
                                case 19:
                                    strI = "J";
                                    break;
                                case 20:
                                    strI = "K";
                                    break;
                                case 21:
                                    strI = "L";
                                    break;
                                case 22:
                                    strI = "M";
                                    break;
                                case 23:
                                    strI = "N";
                                    break;
                                case 24:
                                    strI = "O";
                                    break;
                                case 25:
                                    strI = "P";
                                    break;
                                case 26:
                                    strI = "Q";
                                    break;
                                case 27:
                                    strI = "R";
                                    break;
                                case 28:
                                    strI = "S";
                                    break;
                                case 29:
                                    strI = "T";
                                    break;
                                case 30:
                                    strI = "U";
                                    break;
                                case 31:
                                    strI = "V";
                                    break;
                                default:
                                    strI = i.ToString();
                                    break;
                            }

                            if (foxDR["V" + strI + "DATETO"].ToString().Trim().Length != 0)
                            {
                                myDetail.CLAIM_NO_100000 = myHeader.CLAIM_NO_100;

                                SEQ_NO_100100++;
                                myDetail.SEQ_NO_100100 = SEQ_NO_100100.ToString("0#"); //Cuantas lineas de serv hay en la reclamacion

                                {// si la fecha es futura (mayor a la del dia de procesamiento.) cambiar a los 6 digitos de la imagen.
                                    //080607
                                    Int64 B24A_FDT_100200 = 0;
                                    Int64 B24A_TDT_100300 = 0;
                                    String img = foxDR["V0ifname01"].ToString().Trim();
                                    myDetail.B24A_FDT_100200 = foxDR["V" + strI + "DATEFROM"].ToString().Trim();//V2DATEFROM ->Rutina de Fecha MMDDCCYY
                                    myDetail.B24A_TDT_100300 = foxDR["V" + strI + "DATETO"].ToString().Trim();//Rutina de Fecha MMDDCCYY
                                    if (myDetail.B24A_FDT_100200.Trim().Length > 0)
                                    {
                                        String tmp = "20" + myDetail.B24A_FDT_100200.Trim().Substring(4, 2) +
                                            myDetail.B24A_FDT_100200.Trim().Substring(0, 2) + myDetail.B24A_FDT_100200.Trim().Substring(2, 2);
                                        B24A_FDT_100200 = Convert.ToInt64(tmp);
                                    }
                                    if (myDetail.B24A_TDT_100300.Trim().Length > 0)
                                    {
                                        String tmp = "20" + myDetail.B24A_TDT_100300.Trim().Substring(4, 2) +
                                            myDetail.B24A_TDT_100300.Trim().Substring(0, 2) + myDetail.B24A_TDT_100300.Trim().Substring(2, 2);
                                        B24A_TDT_100300 = Convert.ToInt64(tmp);
                                    }
                                    if (B24A_TDT_100300 < B24A_FDT_100200)
                                    {// Estrututa de la image file : MMDDYY CC BBBB SEQDOC.TIF
                                        //                                    throw new Exception("Error en las Fechas:" + img);
                                        // throw new Exception("Error con la Fecha: " + "V" + strI + "DATEFROM ->ImgName:" + img.Trim());
                                        B24A_TDT_100300 = B24A_FDT_100200;

                                    }
                                    String sFechaRecivido = img.Trim().Substring(0, 6);
                                    String tmpFechaRecivido = "20" + sFechaRecivido.Substring(4, 2) +
                                        sFechaRecivido.Substring(0, 2) + sFechaRecivido.Substring(2, 2);
                                    Int64 iFechaRecivido = Convert.ToInt64(tmpFechaRecivido);

                                    if (B24A_FDT_100200 >= iFechaRecivido)
                                    {// Estrututa de la image file : MMDDYY CC BBBB SEQDOC.TIF
                                        String MM = img.Substring(0, 2);
                                        String DD = img.Substring(2, 2);
                                        String YY = img.Substring(4, 2);
                                        myDetail.B24A_FDT_100200 = MM + DD + YY;
                                        myDetail.B24A_TDT_100300 = MM + DD + YY;
                                    }

                                    if (myDetail.B24A_FDT_100200.Trim().Length == 6)
                                    {
                                        String MM = myDetail.B24A_FDT_100200.Trim().Substring(0, 2);
                                        String DD = myDetail.B24A_FDT_100200.Trim().Substring(2, 2);
                                        String YY = myDetail.B24A_FDT_100200.Trim().Substring(4, 2);
                                        myDetail.B24A_FDT_100200 = MM + "/" + DD + "/20" + YY;
                                    }
                                    else
                                    {
                                        throw new Exception("Error con la Fecha: " + "V" + strI + "DATEFROM ->ImgName:" + img.Trim());
                                    }
                                    if (myDetail.B24A_TDT_100300.Trim().Length == 6)
                                    {
                                        String MM = myDetail.B24A_TDT_100300.Trim().Substring(0, 2);
                                        String DD = myDetail.B24A_TDT_100300.Trim().Substring(2, 2);
                                        String YY = myDetail.B24A_TDT_100300.Trim().Substring(4, 2);
                                        myDetail.B24A_TDT_100300 = MM + "/" + DD + "/20" + YY;
                                    }
                                    else
                                    {
                                        myDetail.B24A_TDT_100300 = myDetail.B24A_FDT_100200;
                                    }
                                }

                                {//Tabla DP mydbMMM.tblPlace
                                    //**** si es invalido DP
                                    myDetail.B24B_POS_100400 = foxDR["V" + strI + "PLACEOF"].ToString().Trim();//V2PLACEOF

                                    if (myDetail.B24B_POS_100400.Trim().Length > 0)
                                    {
                                        String tmpB24B_POS_100400 =
                                            Program.MySqlbusqueda(sqlCnnString, "select * from tblPlace where code='" + myDetail.B24B_POS_100400.Trim() + "';");
                                        if (tmpB24B_POS_100400.Trim().Length == 0)
                                        {
                                            myDetail.B24B_POS_100400 = "DP";
                                        }
                                    }
                                    else
                                    {
                                        myDetail.B24B_POS_100400 = "DP";
                                    }

                                }//////////////////////////////////////////////////

                                myDetail.B24C_TOP_100500 = new string(' ', 2);

                                {//Table Procedimiento tblServiceCodes
                                    myDetail.B24D_PC_100600 = foxDR["V" + strI + "PROCEDIM"].ToString().Trim();// si esta invalido 99999
                                    if (myDetail.B24D_PC_100600.Trim().Length > 0)
                                    {
                                        String tmpB24D_PC_100600 =
                                        Program.MySqlbusqueda(sqlCnnString, "select serviceCode from tblServiceCodes where serviceCode='" + myDetail.B24D_PC_100600 + "';");
                                        if (tmpB24D_PC_100600.Trim().Length == 0)
                                        {
                                            myDetail.B24D_PC_100600 = "99999";
                                        }
                                    }
                                    else
                                    {
                                        myDetail.B24D_PC_100600 = new String('9', 5);
                                    }
                                }

                                {// Tabla de Midificadore mydbMMM.tbtMod
                                    //**** si es invalido DM
                                    myDetail.B24D_MOD1_100700 = foxDR["V" + strI + "MOD1"].ToString().Trim();//V2MOD1
                                    if (myDetail.B24D_MOD1_100700.Trim().Length > 0)
                                    {
                                        String tmpB24D_MOD1_100700 =
                                        Program.MySqlbusqueda(sqlCnnString, "select * from tbtMod where code='" + myDetail.B24D_MOD1_100700.Trim() + "';");
                                        if (tmpB24D_MOD1_100700.Trim().Length == 0)
                                        {
                                            myDetail.B24D_MOD1_100700 = "DM";
                                        }
                                    }
                                    else
                                    {
                                        myDetail.B24D_MOD1_100700 = new String(' ', 2);
                                    }

                                    myDetail.B24D_MOD2_100800 = foxDR["V" + strI + "MOD2"].ToString().Trim();

                                    if (myDetail.B24D_MOD2_100800.Trim().Length > 0)
                                    {
                                        String B24D_MOD2_100800 =
                                        Program.MySqlbusqueda(sqlCnnString, "select * from tbtMod where code='" + myDetail.B24D_MOD2_100800.Trim() + "';");
                                        if (B24D_MOD2_100800.Trim().Length == 0)
                                        {
                                            myDetail.B24D_MOD2_100800 = "DM";
                                        }
                                    }
                                    else
                                    {
                                        myDetail.B24D_MOD2_100800 = new String(' ', 2);
                                    }

                                    myDetail.B24D_MOD3_100900 = foxDR["V" + strI + "MOD3"].ToString().Trim();

                                    if (myDetail.B24D_MOD3_100900.Trim().Length > 0)
                                    {
                                        String B24D_MOD3_100900 =
                                        Program.MySqlbusqueda(sqlCnnString, "select * from tbtMod where code='" + myDetail.B24D_MOD3_100900.Trim() + "';");
                                        if (B24D_MOD3_100900.Trim().Length == 0)
                                        {
                                            myDetail.B24D_MOD3_100900 = "DM";
                                        }
                                    }
                                    else
                                    {
                                        myDetail.B24D_MOD3_100900 = new String(' ', 2);
                                    }

                                    myDetail.B24D_MOD4_101000 = foxDR["V" + strI + "MOD4"].ToString().Trim();

                                    if (myDetail.B24D_MOD4_101000.Trim().Length > 0)
                                    {
                                        String B24D_MOD4_101000 =
                                        Program.MySqlbusqueda(sqlCnnString, "select * from tbtMod where code='" + myDetail.B24D_MOD4_101000.Trim() + "';");
                                        if (B24D_MOD4_101000.Trim().Length == 0)
                                        {
                                            myDetail.B24D_MOD4_101000 = "DM";
                                        }
                                    }
                                    else
                                    {
                                        myDetail.B24D_MOD4_101000 = new String(' ', 2);
                                    }
                                }////////////////////////////////////////////////////////

                                // CDIAG 9 de julio de 2012
                                {
                                    string myDiag = foxDR["V" + strI + "CDIAG1"].ToString().Trim();
                                    if (myDiag.Trim().Length > 0)
                                    {
                                        int imyDiag = int.Parse(myDiag.Trim());
                                        if (imyDiag < 5 )
                                        {
                                            switch(imyDiag)
                                            {
                                                case 1:
                                                    myDetail.B24E_DCP1_101100 = "1";
                                                    break;
                                                case 2:
                                                    if (myHeader.B21_D2_8600.Trim().Length > 0)
                                                    {
                                                        myDetail.B24E_DCP1_101100 = "2";
                                                    }else
                                                    {
                                                        myDetail.B24E_DCP1_101100 = "1";
                                                    }
                                                    break;
                                                case 3:
                                                    if ( myHeader.B21_D3_8700.Trim().Length > 0 )
                                                    {
                                                        myDetail.B24E_DCP1_101100 = "3";
                                                    }else
                                                    {
                                                        myDetail.B24E_DCP1_101100 = "1";
                                                    }
                                                    break;
                                                case 4:
                                                    if (myHeader.B21_D4_8800.Trim().Length >0)
                                                    {
                                                        myDetail.B24E_DCP1_101100 = "4";
                                                    }else
                                                    {
                                                        myDetail.B24E_DCP1_101100 = "1";
                                                    }
                                                    break;
                                                default:
                                                    myDetail.B24E_DCP1_101100 = "1";
                                                    break;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        myDetail.B24E_DCP1_101100 = "1";
                                    }
                                }
                                ///////////// End CDIAG ///////// Modificado el 2 de julio de 2012 ////////////////////

                                myDetail.N24F_CHG_101500 = foxDR["V" + strI + "CHARGES"].ToString().Trim();//V2CHARGES

                                {// Rutina el largo es 9 en el output. y si es 0000 = 0001
                                    myDetail.B24G_DOU_101600 = foxDR["V" + strI + "DAYUNIT"].ToString().Trim();
                                    int tmpB24G_DOU_101600 = Convert.ToInt32(myDetail.B24G_DOU_101600.Trim());
                                    if (tmpB24G_DOU_101600 == 0)
                                    {
                                        myDetail.B24G_DOU_101600 = "000000001";
                                    }
                                    else
                                    {
                                        myDetail.B24G_DOU_101600 = tmpB24G_DOU_101600.ToString("00000000#");
                                    }
                                }//////////////////////////////////////////////////////////////////////////

                                myDetail.B24H_EPS_101700 = new string(' ', 4);
                                {//V2EMG rutina el largo es de 4 en el output.
                                    myDetail.B24I_EMG_101800 = new string(' ', 4); // foxDR["V" + strI + "EMG"].ToString().Trim();
                                    // int myLen = myDetail.B24I_EMG_101800.Trim().Length;
                                    //myDetail.B24I_EMG_101800 = new String(' ', 4 - myLen) + myDetail.B24I_EMG_101800;
                                }
                                myDetail.B24J_COB_101900 = new string(' ', 4);
                                myDetail.B24K_REF_102000 = new string(' ', 20);
                                myDetail.B24REFQAL_102100 = new string(' ', 2);
                                myDetail.B24K_REF2_102200 = new string(' ', 20);
                                myDetail.B24REFQAL2_102300 = new string(' ', 2);
                                myDetail.B24K_NPI_102400 = myHeader.B31_NPI_10330;    //foxDR["V" + strI + "NPI24J"].ToString().Trim();//V2NPI24J
                                myDetail.B24_NAR_102500 = new string(' ', 100);
                                myDetail.B24_CLIA_102600 = new string(' ', 30);
                                myDetail.AMT_PAYPRV_102900 = new string(' ', 9);
                                myDetail.DTP_PAID_103000 = new string(' ', 10);
                                myDetail.DCOB_CAS101_103100 = new string(' ', 2);
                                myDetail.DCOB_CAS102_103200 = new string(' ', 3);
                                myDetail.DCOB_CAS103_103300 = new string(' ', 9);
                                myDetail.DCOB_CAS104_103400 = new string(' ', 4);
                                myDetail.DCOB_CAS105_103500 = new string(' ', 3);
                                myDetail.DCOB_CAS106_103600 = new string(' ', 9);
                                myDetail.DCOB_CAS107_103700 = new string(' ', 4);
                                myDetail.DCOB_CAS201_103800 = new string(' ', 2);
                                myDetail.DCOB_CAS202_103900 = new string(' ', 3);
                                myDetail.DCOB_CAS203_104000 = new string(' ', 9);
                                myDetail.DCOB_CAS204_104100 = new string(' ', 4);
                                myDetail.DCOB_CAS205_104200 = new string(' ', 3);
                                myDetail.DCOB_CAS206_104300 = new string(' ', 9);
                                myDetail.DCOB_CAS207_104400 = new string(' ', 5);
                                //myDetail.Line_104500 = new string(' ', 20);
                                using (StreamWriter fs = File.AppendText(file2.Trim()))
                                {
                                    sHDOut.Clear();
                                    sHDOut.Append(myDetail.CLAIM_NO_100000.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.SEQ_NO_100100.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.B24A_FDT_100200.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.B24A_TDT_100300.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.B24B_POS_100400.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.B24C_TOP_100500.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.B24D_PC_100600.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.B24D_MOD1_100700.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.B24D_MOD2_100800.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.B24D_MOD3_100900.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.B24D_MOD4_101000.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.B24E_DCP1_101100.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.B24E_DCP2_101200.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.B24E_DCP3_101300.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.B24E_DCP4_101400.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.N24F_CHG_101500.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.B24G_DOU_101600.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.B24H_EPS_101700.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.B24I_EMG_101800.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.B24J_COB_101900.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.B24K_REF_102000.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.B24REFQAL_102100.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.B24K_REF2_102200.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.B24REFQAL2_102300.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.B24K_NPI_102400.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.B24_NAR_102500.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.B24_CLIA_102600.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.AMT_PAYPRV_102900.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.DTP_PAID_103000.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.DCOB_CAS101_103100.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.DCOB_CAS102_103200.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.DCOB_CAS103_103300.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.DCOB_CAS104_103400.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.DCOB_CAS105_103500.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.DCOB_CAS106_103600.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.DCOB_CAS107_103700.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.DCOB_CAS201_103800.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.DCOB_CAS202_103900.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.DCOB_CAS203_104000.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.DCOB_CAS204_104100.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.DCOB_CAS205_104200.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.DCOB_CAS206_104300.Trim()); sHDOut.Append("|");
                                    sHDOut.Append(myDetail.DCOB_CAS207_104400.Trim()); sHDOut.Append("||");

                                    fs.WriteLine(sHDOut.ToString().Trim());
                                    //Clear
                                    myDetail = null;
                                    myDetail = new detail837P();

                                }
                                // write  Detail
                                //myWriteFile.setString = myCreateFile.getString.Trim();
                                //myWriteFile.write(file2 + ".dtl");
                            }
                            i++;
                        }// end loop
                        //myWriteFile = null;
                        /////////////// Detail ////////////////////////////////////////////////////////////////////////////
                    }
                }//end Main Loop
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            finally
            {
                foxCnn = null;
                //foxCmd = null;
            }
        }
Beispiel #6
0
        private void btnGetFoxInfo_Click(object sender, EventArgs e)
        {
            try
            {
                jolParseDBF.DBF readPDF = new jolParseDBF.DBF();
                DataTable T = null;
                T = readPDF.parse(txtFoxDbf.Text.Trim());

                lsbFild.Items.Clear();
                foreach (DataColumn C in T.Rows[0].Table.Columns)
                {
                    lsbFild.Items.Add(C.ColumnName);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }