//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include "Math.h"
#include "Stdio.h"
#include "Unit2.h"

#include "Unit4.h"
#include "Unit5.h"
#include "Unit6.h"
#include "Unit8.h"
#include "string.h"
#include "iostream.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm6 *Form6;

AnsiString Main_Name;
AnsiString Other_Name[100];
AnsiString OpenDB_Name;
int DB_Mod = 1;
int DB_Num = 0;
AnsiString Auto_DBF_Loaction = "";
int ajs = 0;
int found = 0;
AnsiString str20[60][500];
AnsiString wx[60][200];
AnsiString elsyhd[60][200];
AnsiString yxhd[60][200];

String WellName[2000][2];
String str16[50][500];
String NumToLetter(int n);
int CountMainName(String s);
String Excel_Name = NULL;
int pos_start = 3;
void ResrtAll();        //重置变量
int Main_Count0 = 0;
int space3 = 0;
String daa073_auto_open_path = NULL;
int ss = 0;

AnsiString change_well_name6(AnsiString s);
AnsiString change_name6(AnsiString s);

int flag073 = -1;
AnsiString filename1 = NULL;
AnsiString filename2 = NULL;
AnsiString change_name_single(AnsiString s);

int out_put_mod = 1;
String NewName[1000];
String OldList[1000];
String NewWellName;
//---------------------------------------------------------------------------
__fastcall TForm6::TForm6(TComponent* Owner)
                    : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm6::FormCreate(TObject *Sender)
{
   Label1->Caption="  参 考 井  ";
   Label2->Caption="  目 标 井  ";
   ComboBox1->Text="";
   ComboBox2->Text="";
   turn=0;
}
//---------------------------------------------------------------------------

void __fastcall TForm6::N2Click(TObject *Sender)
{

     num=Form5->inum;
     Image1->Canvas->TextOutA(120,20,"所选井号共计  "+AnsiString(num)+"  口井");
     for(int i9=0;i9<Form5->inum;i9++)
     {
        ComboBox1->Items->Add(LowerCase(Form5->Jh1[Form5->ic[i9]]));
        sn[i9]=LowerCase(Form5->Jh1[Form5->ic[i9]]);
        Image1->Canvas->TextOutA(50,25*i9+40,sn[i9]);
     }
     turn=0;
}
//---------------------------------------------------------------------------

void __fastcall TForm6::Button1Click(TObject *Sender)
{
    ComboBox2->Clear();
    ComboBox2->Text="所有目标井";
    i2=0;
    for(int i1=0;i1<num;i1++)
     {
        if(ComboBox1->Text!=sn[i1])
        {
            ComboBox2->Items->Add(sn[i1]);
            sn1[i2]=sn[i1];
            i2++;
        }
     }
}
//---------------------------------------------------------------------------

void __fastcall TForm6::Button3Click(TObject *Sender)
{
   turn=1;
   Form5->inum=0;Form5->inum1=0;
   Form5->Show();
}
//---------------------------------------------------------------------------

void __fastcall TForm6::Button4Click(TObject *Sender)
{
    for(int i3=0;i3<i2;i3++)
    {
       if(ComboBox2->Text==sn1[i3])
       {
          /*if(i3==(i2-1))
          {
             i2=i2-1;
          }  */
          for(int i4=i3+1;i4<i2;i4++)
          {
              sn1[i3]=sn1[i4];
          }
          i2=i2-1;
       }
    }
    ComboBox2->Clear();
    ComboBox2->Text="所有目标井";
    for(int i1=0;i1<i2;i1++)
    {
       ComboBox2->Items->Add(sn1[i1]);
    }

}
//---------------------------------------------------------------------------

void __fastcall TForm6::Button5Click(TObject *Sender)
{
     int i0=0;AnsiString Str;
    Image1->Picture->Assign(NULL);
  OpenDialog1->Filter="加载Excel井名文件(*.xlsx)|*.xlsx|加载Excel井名文件(*.xls)|*.xls|加载TXT井名文件(*.txt)|*.txt|所有文件(*.*)|*.*";
 // Image1->Canvas->TextOutA(120,25,"批处理井名");
  if(OpenDialog1->Execute())
  {
    if(OpenDialog1->Filter!="加载Excel井名文件(*.xlsx)|*.xlsx|加载Excel井名文件(*.xls)|*.xls|所有文件(*.*)|*.*"){
    for(int I=0;I<OpenDialog1->Files->Count;I++)
    {
      int i2=0;AnsiString cc1;
      FILE *fp1;
      fp1=fopen(OpenDialog1->Files->Strings[I].c_str(),"r");
      if(fp1){
        //AnsiString StrFileName=OpenDialog1->Filter;
        cc1=OpenDialog1->Files->Strings[I];
        Variant ExcelApp;   //对象
        Variant WorkBook1;  //工作薄
        Variant WorkSheet1; //工作表
        try{
          ExcelApp=Variant::CreateObject("Excel.Application");
        }
        catch(...){
          MessageBox(Handle,"无法启动Excel！","信息提示",MB_ICONSTOP|MB_OK);
        return;
        }
        ExcelApp.OlePropertySet("Visible",false);//设置Excel为可见
        //打开指定的Excel文件,文件中最好只设定一个Sheet
        ExcelApp.OlePropertyGet("WorkBooks").OleProcedure("Open",cc1.c_str());

        WorkBook1=ExcelApp.OlePropertyGet("ActiveWorkBook");
        WorkSheet1=WorkBook1.OlePropertyGet("ActiveSheet");//获得当前默认的Sheet


        Variant aCol1=WorkSheet1.OlePropertyGet("Columns",1);
        Variant aCol2=WorkSheet1.OlePropertyGet("Columns",10);
        Variant aRow1=WorkSheet1.OlePropertyGet("Rows",1);
        Variant aRow2=WorkSheet1.OlePropertyGet("Rows",300);
        int nRow=WorkSheet1.OlePropertyGet("Range",aRow1,aRow2).OlePropertyGet("Rows").OlePropertyGet("Count");//行
        int nCol=WorkSheet1.OlePropertyGet("Range",aCol1,aCol2).OlePropertyGet("Columns").OlePropertyGet("Count");//列
        //int N=WorkSheet1.OlePropertyGet("UsedRange").OlePropertyGet("Cells").OlePropertyGet("Count");

        for(int i=1;i<=nRow;i++)
        {
            for(int j=1;j<=nCol;j++)
            {
                AnsiString Str;
                Str=WorkSheet1.OlePropertyGet("Cells",i,j).OlePropertyGet("Value");
                if(Str!=NULL && Str!="")
                {
                   sn[i0]=LowerCase(Str);
                   i0=i0+1;

                }

                       // Image1->Canvas->TextOutA(120,20*i+50,Str);

            }
        }
        num=i0;
        WorkBook1.OleProcedure("Close");//关闭表格
        ExcelApp.OleFunction("Quit");//退出Excel
      }
      fclose(fp1);
    }
  }else if(OpenDialog1->Filter!="加载txt井名文件(*.txt)|*.txt"){
        String fnm;
        TStringList* S = new TStringList();
        fnm=OpenDialog1->FileName;
        S->LoadFromFile(fnm);
        for(int n=0;n<S->Count;n++)
        {
           sn[n]=S->Strings[n];
          // Image1->Canvas->TextOutA(100,20*n+50,S->Strings[n]);
        }
        num=S->Count;
        delete S;
    }
  }
    Image1->Canvas->TextOutA(120,20,"所选井号共计  "+AnsiString(num)+"  口井");
     for(int i9=0;i9<num;i9++)
     {
        ComboBox1->Items->Add(LowerCase(sn[i9]));
        //sn[i9]=LowerCase(Form5->Jh1[Form5->ic[i9]]);
        Image1->Canvas->TextOutA(50,25*i9+40,sn[i9]);
     }
     turn=0;




   if(num > 0)
   Form6->ltx->Enabled = true;












 /*
  int i2=0;AnsiString cc1;int i0=0;AnsiString Str;
  FILE *fp1;
  OpenDialog1->Filter="加载Excel井名文件(*.xlsx)|*.xlsx|Word文件（*.DOCX)|*.DOCX|所有文件(*.*)|*.*";
 // Image1->Canvas->TextOutA(120,25,"批处理井名");

  if(OpenDialog1->Execute())
  {
  for(int I=0;I<OpenDialog1->Files->Count;I++)
     {
     fp1=fopen(OpenDialog1->Files->Strings[I].c_str(),"r");
     if(fp1){

   //AnsiString StrFileName=OpenDialog1->Filter;
   cc1=OpenDialog1->Files->Strings[I];
   Variant ExcelApp;   //对象
  Variant WorkBook1;  //工作薄
  Variant WorkSheet1; //工作表
  try
  {
    ExcelApp=Variant::CreateObject("Excel.Application");
  }
  catch(...)
  {
   MessageBox(Handle,"无法启动Excel！","信息提示",MB_ICONSTOP|MB_OK);
   return;
  }
  ExcelApp.OlePropertySet("Visible",false);//设置Excel为可见
  //打开指定的Excel文件,文件中最好只设定一个Sheet
  ExcelApp.OlePropertyGet("WorkBooks").OleProcedure("Open",cc1.c_str());

  WorkBook1=ExcelApp.OlePropertyGet("ActiveWorkBook");
  WorkSheet1=WorkBook1.OlePropertyGet("ActiveSheet");//获得当前默认的Sheet


  Variant aCol1=WorkSheet1.OlePropertyGet("Columns",1);
  Variant aCol2=WorkSheet1.OlePropertyGet("Columns",10);
  Variant aRow1=WorkSheet1.OlePropertyGet("Rows",1);
  Variant aRow2=WorkSheet1.OlePropertyGet("Rows",100);
  int nRow=WorkSheet1.OlePropertyGet("Range",aRow1,aRow2).OlePropertyGet("Rows").OlePropertyGet("Count");//行
  int nCol=WorkSheet1.OlePropertyGet("Range",aCol1,aCol2).OlePropertyGet("Columns").OlePropertyGet("Count");//列


  for(int i=1;i<=nRow;i++)
   {
     for(int j=1;j<=nCol;j++)
     {
        Str=WorkSheet1.OlePropertyGet("Cells",i,j).OlePropertyGet("Value");
        if(Str!=NULL && Str!="")
        {
          sn[i0]=LowerCase(Str);
          i0=i0+1;

        }

     }
   }

  WorkBook1.OleProcedure("Close");//关闭表格
  ExcelApp.OleFunction("Quit");//退出Excel
        }
        fclose(fp1);
    }
  }
     num=i0;
     Image1->Canvas->TextOutA(120,20,"所选井号共计  "+AnsiString(num)+"  口井");
     for(int i9=0;i9<num;i9++)
     {
        ComboBox1->Items->Add(LowerCase(sn[i9]));
        //sn[i9]=LowerCase(Form5->Jh1[Form5->ic[i9]]);
        Image1->Canvas->TextOutA(50,25*i9+40,sn[i9]);
     }
     turn=0;     */
}
//---------------------------------------------------------------------------
void __fastcall TForm6::Button2Click(TObject *Sender)
{
        //清空DBF
        /*
        FILE *fp1;
        fp1=fopen("D:\\二厂沉积单元智能对比\\二厂单元深度判别.DBF","r+");
        AnsiString cc1="D:\\二厂沉积单元智能对比\\二厂单元深度判别.DBF";
        Table1->TableName=cc1;
        Table1->EmptyTable();
        fclose(fp1);

        fp1=fopen("D:\\二厂沉积单元智能对比\\二厂单元顶深对比.DBF","r+");
        cc1="D:\\二厂沉积单元智能对比\\二厂单元顶深对比.DBF";
        Table1->TableName=cc1;
        Table1->EmptyTable();
        fclose(fp1);

        fp1=fopen("D:\\二厂沉积单元智能对比\\File_name.DBF","r+");
        cc1="D:\\二厂沉积单元智能对比\\File_name.DBF";
        Table1->TableName=cc1;
        Table1->EmptyTable();
        fclose(fp1);
        */

    if(i2>1)num=i2;
    ckjm=ComboBox1->Text;      //参考井名
    for(int i1=0;i1<num;i1++)
    {
       mbjm[i1]=sn1[i1];      //目标井名
    }
    Form1->Show();
    Form1->pcl(Sender);
}
//------------------------------------------------------------------------------------
void __fastcall TForm6::Func_A(TObject *Sender)    //储层连通   断层识别
{

}
//---------------------------------------------------------------------------
void __fastcall TForm6::open_074_Auto(TObject *Sender)
{
   int i=0,ia=0,j,i1,i2=0,i3,flag=0,flag1=0,n;
   AnsiString cc,Bzz,jjhh;
   //int totalnum = 0;
   FILE *fc,*fo;
   int count = 0;
   int open = 0;
   int path = 0;

   if(Auto_DBF_Loaction == "")
   {
        TStringList *lst = new TStringList();
        TSearchRec sr;
        int iAttributes = 0;
        if(FindFirst("D:\\二厂沉积单元智能对比\\daa074.DBF",iAttributes,sr) == 0)
        {
                path = 1;
                //File_name = ChangeFileExt(la_Name[js],"");
                Auto_DBF_Loaction = "D:\\二厂沉积单元智能对比\\daa074.DBF";
                //open = 1;
        }
        FindClose(sr);
   }

   if(Auto_DBF_Loaction == "" && path == 0)
   {
        AnsiString File_name=ChangeFileExt(la_Name[js],"");
        OpenDialog1->Filter="daa074（*.DBF)|*.DBF|所有文件(*.*)|*.*";
        OpenDialog1->Execute();
        open = 1;
   }
   if(open == 1)
   {
        fc=fopen(OpenDialog1->Files->Strings[0].c_str(),_T("r"));
        cc=OpenDialog1->Files->Strings[0].c_str();
        Auto_DBF_Loaction = cc;
        Table1->TableName=cc;
        Table1->Open();
        DBGrid1->DataSource=DataSource1;
        Table1->Active=true;

   }
   if(Auto_DBF_Loaction != "" && open == 0)
   {
        fc=fopen(Auto_DBF_Loaction.c_str(),_T("r"));
        cc=Auto_DBF_Loaction;
        Table1->TableName=cc;
        Table1->Open();
        DBGrid1->DataSource=DataSource1;
        Table1->Active=true;
        open = 1;
   }
   if(open == 1)
   {
        for(int I = 0;I < 1;I ++)
        {
                if(fc)
                {
                        Table1->First();
                        AnsiString Dynscxhc[300];
                        AnsiString Yxc[300];
                        AnsiString Elsydsc[300];
                        AnsiString Elsyhdc[300];
                        AnsiString Ylsydsc[300];
                        AnsiString Wxc[300];
                        for(int i = 0;i < 300;i ++)
                        {
                                Dynscxhc[i] = "";
                                Yxc[i] = "";
                                Elsydsc[i] = "";
                                Elsyhdc[i] = "";
                                Ylsydsc[i] = "";
                                Wxc[i] = "";
                        }


                        //AnsiString Elsyhdc[300];
                        AnsiString Yxhdc[300];
                        File_name = LowerCase(OpenDB_Name);
                        flag1 = 0;
                        found = 0;
                        while((flag1<1)&&(!Table1->Eof))
                        {
                                jjhh = Table1->FieldByName("Jh")->AsString;
                                jjhh = LowerCase(jjhh); //
                                if(jjhh==File_name)
                                {
                                        found = 1;
                                        do{
                                                jjhh = Table1->FieldByName("Jh")->AsString;
                                                jjhh = LowerCase(jjhh);
                                                flag1=1;
                                                //Xhc[ia]      = Table1->FieldByName("Xh")->Value;
                                                Jhc[ia]      = Table1->FieldByName("Jh")->AsString;      //加新井井名
                                                Yczmcc[ia]   = Table1->FieldByName("Yczmc")->AsString;  //油层组名称
                                                Dymcc[ia]    = Table1->FieldByName("Dymc")->AsString;  //单元名称
                                                Bzc[ia]      = Table1->FieldByName("Bz")->AsString;
                                                //===074===
                                                Dynscxhc[ia] = Table1->FieldByName("Dynscxh")->AsString;
                                                Yxc[ia]      = Table1->FieldByName("Yx")->AsString;
                                                Elsydsc[ia]  = Table1->FieldByName("Elsyds")->AsString;
                                                Elsyhdc[ia]  = Table1->FieldByName("Elsyhd")->AsString;
                                                Ylsydsc[ia]  = Table1->FieldByName("Ylsyds")->AsString;
                                                Wxc[ia]      = Table1->FieldByName("Wx")->AsString;
                                                Yxhdc[ia]    = Table1->FieldByName("Yxhd")->AsString;
                                                ia++;
                                                count ++;
                                                Table1->Next();
                                        }while((jjhh==File_name)&&(!Table1->Eof));
                                }
                                if((flag1<1)&&(!Table1->Eof))
                                        Table1->Next();
                        }
                        Table1->First();
                        int temp = 0;
                        int temp2 = 0;
                        if(found == 0)
                                break;

                        int last = -1;
                        for(int i = count - 1;i > 0;i --)
                        {
                                if(Elsydsc[i] != "0" && Elsydsc[i] != NULL && Elsydsc[i] != " ")
                                {
                                        last = i;
                                        break;
                                }

                        }


                        for(int i = 0;i <= last;i ++)
                        {
                                AnsiString temps1 = Yczmcc[i];
                                AnsiString temps2 = Elsydsc[i];

                                if(DB_Num < 1)
                                {
                                        if(temps1 == NULL)
                                                continue;
                                        if(temps1.IsEmpty())
                                                continue;
                                }
                                if(DB_Num >= 1 && temps2 == "")
                                        continue;
                                if(DB_Num >= 1 && temps2 == "0")
                                        continue;
                                if(DB_Num >= 1 && temps2.IsEmpty())
                                        continue;
                                str16[DB_Mod][temp] = Yczmcc[i] + "#" + Dymcc[i] + "#" +Dynscxhc[i];
                                if(Yczmcc[i] + Dymcc[i] != str20[DB_Mod][temp2 - 1])
                                {
                                        str20[DB_Mod][temp2] = Yczmcc[i] + "#" + Dymcc[i];
                                        temp2 ++;
                                }
                                wx[DB_Mod][temp] = Wxc[i].c_str();
                                float YXHD = 0;
                                float SYHD = 0;
                                SYHD = StrToFloat(Elsyhdc[i]);
                                YXHD = StrToFloat(Yxhdc[i]);
                                //yxhd[DB_Mod][temp] = Yxhdc[i].c_str();
                                for(int k = 1;k < 6;k ++)
                                {
                                        if(i + k > last)
                                        {
                                                //YXHD += StrToFloat(Yxhdc[i + k - 1]);
                                                //SYHD += StrToFloat(Elsyhdc[i + k - 1]);
                                                elsyhd[DB_Mod][temp] = FloatToStr(SYHD).c_str();
                                                yxhd[DB_Mod][temp] = FloatToStr(YXHD).c_str();
                                                break;
                                        }
                                        float tempyx = StrToFloat(Yxhdc[i + k]);
                                        if(tempyx > 0 && Dynscxhc[i + k] == "" && Yczmcc[i + k] == "" && Dymcc[i + k] == "")
                                        {
                                                YXHD += StrToFloat(tempyx);
                                        }
                                        if(StrToFloat(Elsyhdc[i + k]) > 0 && Dynscxhc[i + k] == "" && Yczmcc[i + k] == "" && Dymcc[i + k] == "")
                                        {
                                                SYHD += StrToFloat(Elsyhdc[i + k]);
                                        }
                                        elsyhd[DB_Mod][temp] = FloatToStr(SYHD).c_str();
                                        yxhd[DB_Mod][temp] = FloatToStr(YXHD).c_str();
                                        if(Dynscxhc[i + k + 1] != "" || Yczmcc[i + k + 1] != "" || Dymcc[i + 1] != "")
                                                break;

                                }
                                a21lj[DB_Mod][temp] = StrToFloat(Elsydsc[i]);
                                jhw[DB_Mod][temp] = Yczmcc[i] + Dymcc[i] + Dynscxhc[i];
                                xcw[DB_Mod][temp] = StrToFloat(Elsydsc[i]);
                                temp ++;
                        }

                }
        }
   Table1->First();
   Table1->Close();
   fclose(fc);
   ajs ++;
   }
   //Form3->N12->Visible = true;
   //Form3->N12->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm6::ltxClick(TObject *Sender)
{
   //ajs = num;
   int not_found = 0;
   if(num >= 2)
   {
        DB_Mod = 0;
        DB_Num = 0;
        Main_Name = ComboBox1->Text;
        OpenDB_Name = Main_Name;
        open_074_Auto(Sender);

        for(int i1=0;i1<num;i1++)
        {
                OpenDB_Name = sn1[i1];
                DB_Mod = i1 + 1 - not_found;
                DB_Num ++;
                open_074_Auto(Sender);
                if(found == 0)
                {
                        not_found ++;
                }
                else
                        Other_Name[i1 - not_found] = sn1[i1];
        }

   }
   ajs = num - not_found + 1;
   if(ajs > 50)
        ajs = 50;
   Func_B(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm6::Func_B(TObject *Sender)    //储层连通   断层识别
{
   int tw,dc,dcs=0,last=0,dcpd=0,flag=0,i7=0,tm=-1; //断层、断层数 、最后层 、断层判断    题目
   int t1=0,t2=0,countdc=0,to=0,to2=0,ts=0,ts2=0;  float fdeep1[400],fdeep2[400],fdeep3[400];
   FILE *fpdc,*fp1;
   String Dir="D:\\";
   float dp1=0.0;
   String st1[200],st2[200];
   //
   int Count_A = 0;                     //
   int Count_B = 0;                     //
   int result[200][60];                 //断层对比结果
   int result_A[200][60];                 //断层对比结果
   int result_B[200][60];                 //断层对比结果
   int Count_Num[60];                   //已加载井层位计数，上限[10]
   int Count_Fault[60];                 //已加载井断层计数，上限[10]
   int Fault_A = 0;                     //A井相对B井断层数
   int Fault_B = 0;                     //B井相对A井断层数
   int Last_A = 0;                      //A井最后一层在B井中的位置
   int Last_B = 0;                      //B井最后一层在A井中的位置
   int Count_Ex = 0;                    //额外层数差
   int Switch_Fault = 0;                //断层存在情况：1A,2B,3AB
   int all = 200;                       //层数上限
   int Last[2][60];                        //中心井最后一层序数差
   int space4 = 0;
   int space5 = 0;



   struct Group
   {
        String Name;
        int sand_num;
        String sand_name[5];
   };

   struct all_Group
   {
        Group well_group[200];
   };

   all_Group all_group[60];

        //group[200];

   String st4[200][10];
   int count_num_g[60];
//======================================================================================
   if(ajs >= 2)
   {
        for(int i = 0;i < 60;i ++)      Count_Num[i] = Count_Fault[i] = 0;
        for(int i = 0;i < ajs;i ++)
        {
                for(int j = 0;j < all;j ++)
                {
                        if(str16[i][j] != "")
                        {
                                Count_Num[i] ++;
                                Count_Fault[i] ++;
                        }
                }
        }
        ///
        struct Main_Group                                                       //中心井结构体
        {
                String Name[200][2];
                int Position[200];
                //String Full_Name[200];
        };
        struct Other_Group                                                      //连通井结构体
        {
                String Name[200];
                int sand_num[200];
                String sand_name[200][5];
                //int sand_name[200]
                int Position[200];
        };
        ///
        Main_Group main_group;
        Other_Group other_group[20];
        for(int i = 0;i < 200;i ++)
        {
                main_group.Name[i][0] = NULL;
                main_group.Name[i][1] = NULL;
                main_group.Position[i] = 0;
                for(int j = 0;j < 20;j ++)
                {
                        other_group[j].Name[i] = NULL;
                        other_group[j].sand_num[i] = 0;
                        other_group[j].sand_name[i][0] = NULL;
                        other_group[j].sand_name[i][1] = NULL;
                        other_group[j].sand_name[i][2] = NULL;
                        other_group[j].sand_name[i][3] = NULL;
                        other_group[j].sand_name[i][4] = NULL;
                        other_group[j].Position[i] = 0;

                }


        }




        ///                                                                     //中心井写入
        int sw = 0;
        for(int i = 0;i < Count_Num[0];i ++)
        {
                AnsiString temp_s = str16[0][i];
                std::auto_ptr<TStringList>sl(new TStringList);
                sl->Delimiter = '#';
                sl->DelimitedText = temp_s;
                AnsiString temp1 = sl->Strings[0].c_str();
                temp1 += sl->Strings[1].c_str();
                main_group.Name[i][0] = temp1;
                main_group.Position[i] = i;
                if(sl->Strings[2] != "")
                        main_group.Name[i][1] = sl->Strings[2].c_str();
                else
                        main_group.Name[i][1] = "0";

        }
        ///
        int count_s = 0;                                                        //油层单元个数
        for(int j = 1;j < ajs;j ++)
        {
                count_s = 0;
                for(int i = 0;i < Count_Num[j];i ++)
                {
                        std::auto_ptr<TStringList>sl(new TStringList);
                        AnsiString temp_s = str16[j][i];
                        sl->Delimiter = '#';
                        sl->DelimitedText = temp_s;
                        AnsiString temp1 = sl->Strings[0].c_str();
                        temp1 += sl->Strings[1].c_str();
                        if(i != 0 && temp1 != other_group[j].Name[count_s])
                        {
                                count_s ++;
                                other_group[j].Position[count_s] = i;
                                other_group[j].Name[count_s]= temp1;
                                if(sl->Strings[2] != "")
                                {
                                        other_group[j].sand_name[count_s][other_group[j].sand_num[count_s]] = sl->Strings[2].c_str();
                                        other_group[j].sand_num[count_s] ++;
                                }

                        }
                        else
                        {
                                if(i == 0)
                                        other_group[j].Name[0]= temp1;
                                if(sl->Strings[2] != "")
                                {
                                        //String temp0 = sl->Strings[2].c_str();
                                        //int num = StrToInt(temp0);
                                        //other_group[j].sand_name[i][num - 1] = sl->Strings[2].c_str();
                                        //other_group[j].sand_num[i] = num;
                                        //other_group[1].sand_num[count_s]  other_group[1].sand_name[i][num - 1]
                                        other_group[j].sand_name[count_s][other_group[j].sand_num[count_s]] = sl->Strings[2].c_str();
                                        other_group[j].sand_num[count_s] ++;
                                }
                        }
                }


        }

        OpenDialog1->Filter="加载Excel井名文件(*.xlsx)|*.xlsx|加载Excel井名文件(*.xls)|*.xls|加载TXT井名文件(*.txt)|*.txt|所有文件(*.*)|*.*";
        if(Excel_Name == NULL)
        {
            OpenDialog1->Execute();
            if(OpenDialog1->Filter!="加载Excel井名文件(*.xlsx)|*.xlsx|加载Excel井名文件(*.xls)|*.xls|所有文件(*.*)|*.*")
            {
                int i2=0;AnsiString cc1;
                Excel_Name = OpenDialog1->Files->Strings[0].c_str();
            }

        }
        if(Excel_Name != NULL)
        {
                for(int I=0;I<1;I++)
                {
                        int i2=0;AnsiString cc1;
                        FILE *fp1;
                        fp1=fopen(Excel_Name.c_str(),"r");
                        if(fp1)
                        {
                                cc1=OpenDialog1->Files->Strings[I];
                                Variant ExcelApp;   //对象
                                Variant WorkBook1;  //工作薄
                                Variant WorkSheet1; //工作表
                                try
                                {
                                        ExcelApp=Variant::CreateObject("Excel.Application");
                                }
                                catch(...)
                                {
                                        MessageBox(Handle,"无法启动Excel！","信息提示",MB_ICONSTOP|MB_OK);
                                        return;
                                }

                                ExcelApp.OlePropertySet("Visible",false);//设置Excel为可见
                                ExcelApp.OlePropertyGet("WorkBooks").OleProcedure("Open",cc1.c_str());
                                WorkBook1=ExcelApp.OlePropertyGet("ActiveWorkBook");
                                WorkSheet1=WorkBook1.OlePropertyGet("ActiveSheet");//获得当前默认的Sheet
                                char letter[26] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
                                for(int k = 0;k < ajs;k ++)
                                {
                                        int w1 = k*8;
                                        int w2 = k*8 + 7;
                                        AnsiString a1 = NumToLetter(w1);
                                        AnsiString a2 = NumToLetter(w2);

                                        AnsiString temps = a1 + "1:" + a2 + "1";
                                        Variant Range1 = WorkSheet1.OlePropertyGet("Range",temps.c_str());
                                        Range1.OleFunction("Merge",false);
                                        Range1.OlePropertySet("HorizontalAlignment",3);
                                        if(k == 0)
                                                WorkSheet1.OlePropertyGet("Cells",1,1).OlePropertySet("Value","主井");
                                        else
                                                WorkSheet1.OlePropertyGet("Cells",1,w1 + 1).OlePropertySet("Value","连通井");

                                }
                                /////////////////////////////////////////主井预留空位
                                int space[200][60];
                                int space2[200];
                                for(int i = 1;i < 200;i ++)
                                {
                                        for(int j = 1;j < 60;j ++)
                                                space[i][j] = 0;
                                }
                                        for(int k = 1;k < ajs;k ++)
                                        {
                                                for(int i = 1;i < Count_Num[0];i ++)
                                                {
                                                        if(main_group.Name[i][0] == NULL || main_group.Name[i][0] == "")
                                                                break;
                                                        for(int j = 0;j < 200;j ++)
                                                        {
                                                                if(main_group.Name[i][1] == "0" && main_group.Name[i][0] == other_group[k].Name[j])                //主井、连通井无砂层序号
                                                                {
                                                                        if(other_group[k].sand_num[j] == 0)
                                                                        {
                                                                                space[i][k] = 0;
                                                                                break;
                                                                        }
                                                                        else if(other_group[k].sand_num[j] != 0)
                                                                        {
                                                                                //space[j][k] = StrToInt(other_group[k].sand_num[j]);
                                                                                space[i][k] = other_group[k].sand_num[j];
                                                                                break;
                                                                        }
                                                                }
                                                        }
                                                }

                                        }
                                        

                                /////////////////////////////////////////
                                for(int I=0;I<OpenDialog1->Files->Count;I++)
                                {
                                        for(int k = 0;k < 1;k ++)
                                        {
                                                WorkSheet1.OlePropertyGet("Cells",2,8*k + 1).OlePropertySet("Value","jh");
                                                WorkSheet1.OlePropertyGet("Cells",2,8*k + 2).OlePropertySet("Value","yczmc");
                                                WorkSheet1.OlePropertyGet("Cells",2,8*k + 3).OlePropertySet("Value","dymc");
                                                WorkSheet1.OlePropertyGet("Cells",2,8*k + 4).OlePropertySet("Value","dynscxh");
                                                WorkSheet1.OlePropertyGet("Cells",2,8*k + 5).OlePropertySet("Value","wx");
                                                WorkSheet1.OlePropertyGet("Cells",2,8*k + 6).OlePropertySet("Value","elsyhd");
                                                WorkSheet1.OlePropertyGet("Cells",2,8*k + 7).OlePropertySet("Value","yxhd");
                                                WorkSheet1.OlePropertyGet("Cells",2,8*k + 8).OlePropertySet("Value","skqk");
                                                int pos = 0;
                                                int pos_up = 0;
                                                int pos_down = 0;


                                                for(int i = 0;i < Count_Num[0];i ++)
                                                {
                                                        int temp = 0;
                                                        for(int j = 0;j < 60;j ++)
                                                        {
                                                                if(space[i][j] > temp)
                                                                {
                                                                        temp = space[i][j] - 1;
                                                                        space3 += temp;
                                                                }

                                                        }
                                                        space2[i] = temp;

                                                        if(temp == 0)
                                                        {
                                                                WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,1).OlePropertySet("Value",Main_Name.c_str());
                                                                AnsiString temp_s = str16[0][i];
                                                                std::auto_ptr<TStringList>sl(new TStringList);
                                                                sl->Delimiter = '#';
                                                                sl->DelimitedText = temp_s;
                                                                for(int j = 0; j < 3; j++)
                                                                {
                                                                        WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,2 + j).OlePropertySet("Value",sl->Strings[j].c_str());
                                                                }
                                                                WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,5).OlePropertySet("Value",wx[0][i].c_str());
                                                                WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,6).OlePropertySet("Value",elsyhd[0][i].c_str());
                                                                WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,7).OlePropertySet("Value",yxhd[0][i].c_str());
                                                                space4 = i + pos_start + pos_up;
                                                        }
                                                        int pos_up = pos;
                                                        pos += temp;

                                                        if(temp > 0 && i > 0)
                                                        {
                                                                for(int j = 0;j < 7;j ++)
                                                                {
                                                                        AnsiString a1 = NumToLetter(j);
                                                                        AnsiString up = IntToStr(i + pos_up + pos_start);
                                                                        AnsiString down = IntToStr(i + pos + pos_start);
                                                                        AnsiString temps = a1 + up + ":" + a1 + down;
                                                                        Variant Range1 = WorkSheet1.OlePropertyGet("Range",temps.c_str());
                                                                        Range1.OleFunction("Merge",false);
                                                                        Range1.OlePropertySet("HorizontalAlignment",3);
                                                                }
                                                                WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos_up,1).OlePropertySet("Value",Main_Name.c_str());
                                                                AnsiString temp_s = str16[0][i];
                                                                std::auto_ptr<TStringList>sl(new TStringList);
                                                                sl->Delimiter = '#';
                                                                sl->DelimitedText = temp_s;
                                                                for(int k = 0; k < 2; k ++)
                                                                {
                                                                        WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos_up,2 + k).OlePropertySet("Value",sl->Strings[k].c_str());
                                                                }
                                                                WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos_up,5).OlePropertySet("Value",wx[0][i].c_str());
                                                                WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos_up,6).OlePropertySet("Value",elsyhd[0][i].c_str());
                                                                WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos_up,7).OlePropertySet("Value",yxhd[0][i].c_str());
                                                                space4 = i + pos_start + pos_up;
                                                        }

                                                }
                                        }
                                        for(int k = 1;k < ajs;k ++)
                                        {
                                                WorkSheet1.OlePropertyGet("Cells",2,8*k + 1).OlePropertySet("Value","jh");
                                                WorkSheet1.OlePropertyGet("Cells",2,8*k + 2).OlePropertySet("Value","yczmc");
                                                WorkSheet1.OlePropertyGet("Cells",2,8*k + 3).OlePropertySet("Value","dymc");
                                                WorkSheet1.OlePropertyGet("Cells",2,8*k + 4).OlePropertySet("Value","dynscxh");
                                                WorkSheet1.OlePropertyGet("Cells",2,8*k + 5).OlePropertySet("Value","wx");
                                                WorkSheet1.OlePropertyGet("Cells",2,8*k + 6).OlePropertySet("Value","elsyhd");
                                                WorkSheet1.OlePropertyGet("Cells",2,8*k + 7).OlePropertySet("Value","yxhd");
                                                WorkSheet1.OlePropertyGet("Cells",2,8*k + 8).OlePropertySet("Value","skqk");

                                                int pos = 0;
                                                AnsiString Last_Name;
                                                for(int i = 0;i < Count_Num[0];i ++)
                                                {
                                                        if(main_group.Name[i][0] == NULL || main_group.Name[i][0] == "")
                                                                break;
                                                        for(int j = 0;j < 200;j ++)
                                                        {
                                                                //AnsiString temp = *other_group[k].Name;
                                                                if(main_group.Name[i][1] == "0" && main_group.Name[i][0] == other_group[k].Name[j])                //主井、连通井无砂层序号
                                                                {
                                                                        int pos_remp = pos;

                                                                        int temp = 0;

                                                                        if(other_group[k].sand_num[j] == 0)             //连通井无砂层
                                                                        {
                                                                                for(int n = 0;n < 7;n ++)
                                                                                {
                                                                                        AnsiString a1 = NumToLetter(n + 8*k);
                                                                                        AnsiString up = IntToStr(i + pos + pos_start);
                                                                                        AnsiString down = IntToStr(i + pos + pos_start + space2[i]);
                                                                                        AnsiString temps = a1 + up + ":" + a1 + down;
                                                                                        Variant Range1 = WorkSheet1.OlePropertyGet("Range",temps.c_str());
                                                                                        Range1.OleFunction("Merge",false);
                                                                                        Range1.OlePropertySet("HorizontalAlignment",3);
                                                                                }
                                                                                if(wx[0][i] == "0" || wx[0][i].IsEmpty())
                                                                                        break;
                                                                                WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,8*k + 1).OlePropertySet("Value",Other_Name[k - 1].c_str());
                                                                                AnsiString temp_s = str16[0][i];
                                                                                std::auto_ptr<TStringList>sl(new TStringList);
                                                                                sl->Delimiter = '#';
                                                                                sl->DelimitedText = temp_s;
                                                                                AnsiString temp1 = sl->Strings[0].c_str();
                                                                                AnsiString temp2 = sl->Strings[1].c_str();
                                                                                WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,8*k + 2).OlePropertySet("Value",temp1.c_str());
                                                                                WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,8*k + 3).OlePropertySet("Value",temp2.c_str());


                                                                                WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,8*k + 5).OlePropertySet("Value",wx[k][other_group[k].Position[j]].c_str());
                                                                                WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,8*k + 6).OlePropertySet("Value",elsyhd[k][other_group[k].Position[j]].c_str());
                                                                                WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,8*k + 7).OlePropertySet("Value",yxhd[k][other_group[k].Position[j]].c_str());
                                                                                break;
                                                                        }
                                                                        else if(other_group[k].sand_num[j] != 0)
                                                                        {
                                                                                for(int m = 0;m < other_group[k].sand_num[j];m ++)
                                                                                {
                                                                                if(wx[0][i] == "0" || wx[0][i].IsEmpty())
                                                                                        break;
                                                                                WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,8*k + 1).OlePropertySet("Value",Other_Name[k - 1].c_str());
                                                                                AnsiString temp_s = str16[0][i];
                                                                                std::auto_ptr<TStringList>sl(new TStringList);
                                                                                sl->Delimiter = '#';
                                                                                sl->DelimitedText = temp_s;
                                                                                AnsiString temp1 = sl->Strings[0].c_str();
                                                                                AnsiString temp2 = sl->Strings[1].c_str();
                                                                                WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,8*k + 2).OlePropertySet("Value",temp1.c_str());
                                                                                WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,8*k + 3).OlePropertySet("Value",temp2.c_str());
                                                                                WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,8*k + 4).OlePropertySet("Value",(other_group[k].sand_name[j][m]).c_str());
                                                                                WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,8*k + 5).OlePropertySet("Value",wx[k][other_group[k].Position[j]].c_str());
                                                                                WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,8*k + 6).OlePropertySet("Value",elsyhd[k][other_group[k].Position[j] + m].c_str());
                                                                                WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,8*k + 7).OlePropertySet("Value",yxhd[k][other_group[k].Position[j] + m].c_str());
                                                                                pos ++;
                                                                                }
                                                                                pos = pos_remp;
                                                                                break;
                                                                        }


                                                                }
                                                                else if(main_group.Name[i][1] != "0" && main_group.Name[i][0] == other_group[k].Name[j])
                                                                {
                                                                        int pos_remp = pos;
                                                                        //other_group[1].sand_num[j]  other_group[1].Name[]
                                                                        if(other_group[k].Name[j] != 0 && other_group[k].sand_num[j] != 0)
                                                                        {
                                                                                for(int m = 0;m < other_group[k].sand_num[j];m ++)
                                                                                {
                                                                                if(main_group.Name[i][1] == (other_group[k].sand_name[j][m]).c_str())
                                                                                {
                                                                                        if(wx[0][i] == "0" || wx[0][i].IsEmpty())
                                                                                                break;
                                                                                        WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,8*k + 1).OlePropertySet("Value",Other_Name[k - 1].c_str());
                                                                                        AnsiString temp_s = str16[0][i];
                                                                                        std::auto_ptr<TStringList>sl(new TStringList);
                                                                                        sl->Delimiter = '#';
                                                                                        sl->DelimitedText = temp_s;
                                                                                        AnsiString temp1 = sl->Strings[0].c_str();
                                                                                        AnsiString temp2 = sl->Strings[1].c_str();
                                                                                        WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,8*k + 2).OlePropertySet("Value",temp1.c_str());
                                                                                        WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,8*k + 3).OlePropertySet("Value",temp2.c_str());
                                                                                        WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,8*k + 4).OlePropertySet("Value",(other_group[k].sand_name[j][m]).c_str());
                                                                                        WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,8*k + 5).OlePropertySet("Value",wx[k][other_group[k].Position[j]].c_str());
                                                                                        WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,8*k + 6).OlePropertySet("Value",elsyhd[k][other_group[k].Position[j] + m].c_str());
                                                                                        WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,8*k + 7).OlePropertySet("Value",yxhd[k][other_group[k].Position[j] + m].c_str());
                                                                                        pos ++;
                                                                                }
                                                                                }
                                                                                pos = pos_remp;
                                                                                break;
                                                                        }
                                                                        else if(other_group[k].Name[j] != 0 && other_group[k].sand_num[j] == 0)
                                                                        {
                                                                                if(wx[0][i] == "0" || wx[0][i].IsEmpty())
                                                                                        break;
                                                                                if(other_group[k].Name[j] == Last_Name)
                                                                                        break;
                                                                                int count = 0;
                                                                                for(int m = 0;m < 200;m ++)
                                                                                {
                                                                                        if(other_group[k].Name[j] == main_group.Name[m][0])
                                                                                        count ++;
                                                                                }
                                                                                for(int n = 0;n < 7;n ++)
                                                                                {

                                                                                        AnsiString a1 = NumToLetter(n + 8*k);
                                                                                        AnsiString up = IntToStr(i + pos + pos_start);
                                                                                        AnsiString down = IntToStr(i + pos + pos_start + count - 1);
                                                                                        AnsiString temps = a1 + up + ":" + a1 + down;
                                                                                        Variant Range1 = WorkSheet1.OlePropertyGet("Range",temps.c_str());
                                                                                        Range1.OleFunction("Merge",false);
                                                                                        Range1.OlePropertySet("HorizontalAlignment",3);
                                                                                }
                                                                                Last_Name = other_group[k].Name[j];
                                                                                WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,8*k + 1).OlePropertySet("Value",Other_Name[k - 1].c_str());
                                                                                AnsiString temp_s = str16[0][i];
                                                                                std::auto_ptr<TStringList>sl(new TStringList);
                                                                                sl->Delimiter = '#';
                                                                                sl->DelimitedText = temp_s;
                                                                                AnsiString temp1 = sl->Strings[0].c_str();
                                                                                AnsiString temp2 = sl->Strings[1].c_str();
                                                                                WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,8*k + 2).OlePropertySet("Value",temp1.c_str());
                                                                                WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,8*k + 3).OlePropertySet("Value",temp2.c_str());
                                                                                WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,8*k + 5).OlePropertySet("Value",wx[k][other_group[k].Position[j]].c_str());
                                                                                WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,8*k + 6).OlePropertySet("Value",elsyhd[k][other_group[k].Position[j]].c_str());
                                                                                WorkSheet1.OlePropertyGet("Cells",i + pos_start + pos,8*k + 7).OlePropertySet("Value",yxhd[k][other_group[k].Position[j]].c_str());
                                                                                break;
                                                                        }
                                                                }
                                                        }
                                                        int temp = 0;
                                                        for(int j = 0;j < 60;j ++)
                                                        {
                                                                if(space[i][j] > temp)
                                                                        temp = space[i][j] - 1;
                                                        }
                                                        pos += temp;
                                                }
                                        }
                                }


                                for(int i = 1;i < 200;i ++)
                                {
                                        space5 += space2[i];

                                }


                                AnsiString a1 = NumToLetter(ajs*8);
                                AnsiString down = IntToStr(space4 + 20);
                                AnsiString temps = "A1:" + a1 + down;
                                Variant Range1 = WorkSheet1.OlePropertyGet("Range",temps.c_str());
                                Range1.OlePropertySet("HorizontalAlignment",3);
                                for(int i = 0;i < ajs;i ++)
                                {
                                        WorkSheet1.OlePropertyGet("Columns",1 + 8*i).OlePropertySet("ColumnWidth",16);
                                }
                                //
                                fclose(fp1);
                                //ExcelApp.OlePropertySet("Visible",true);
                                WorkBook1.OleProcedure("Save");
                                //ExcelApp.OleFunction("Save");
                                WorkBook1.OleProcedure("Close");
                                ExcelApp.OleFunction("Quit");


                        }
                }



        }
        //pos_start += Count_Num[0];
        //pos_start += space3;
        pos_start += space5 + Count_Num[0] + 5;
   }
}

void __fastcall TForm6::N5Click(TObject *Sender)
{

   String temp = NumToLetter(52);

   int i0=0;AnsiString Str;
   Image1->Picture->Assign(NULL);
   OpenDialog1->Filter="加载Excel井名文件(*.xlsx)|*.xlsx|加载Excel井名文件(*.xls)|*.xls";
   if(OpenDialog1->Execute())
   {
        if(OpenDialog1->Filter!="加载Excel井名文件(*.xlsx)|*.xlsx|加载Excel井名文件(*.xls)|*.xls|所有文件(*.*)|*.*")
        {
        for(int I=0;I<OpenDialog1->Files->Count;I++)
        {
                int i2=0;AnsiString cc1;
                FILE *fp1;
                fp1=fopen(OpenDialog1->Files->Strings[I].c_str(),"r");
                if(fp1)
                {
                        cc1=OpenDialog1->Files->Strings[I];
                        Variant ExcelApp;   //对象
                        Variant WorkBook1;  //工作薄
                        Variant WorkSheet1; //工作表
                        try{
                                ExcelApp=Variant::CreateObject("Excel.Application");
                        }
                        catch(...){
                                MessageBox(Handle,"无法启动Excel！","信息提示",MB_ICONSTOP|MB_OK);
                                return;
                        }
                        ExcelApp.OlePropertySet("Visible",false);//设置Excel为可见
                        ExcelApp.OlePropertyGet("WorkBooks").OleProcedure("Open",cc1.c_str());

                        WorkBook1=ExcelApp.OlePropertyGet("ActiveWorkBook");
                        WorkSheet1=WorkBook1.OlePropertyGet("ActiveSheet");//获得当前默认的Sheet

                        Variant aCol1=WorkSheet1.OlePropertyGet("Columns",1);
                        Variant aCol2=WorkSheet1.OlePropertyGet("Columns",3);
                        Variant aRow1=WorkSheet1.OlePropertyGet("Rows",1);
                        Variant aRow2=WorkSheet1.OlePropertyGet("Rows",2000);
                        int nRow=WorkSheet1.OlePropertyGet("Range",aRow1,aRow2).OlePropertyGet("Rows").OlePropertyGet("Count");//行
                        int nCol=WorkSheet1.OlePropertyGet("Range",aCol1,aCol2).OlePropertyGet("Columns").OlePropertyGet("Count");//列
                        /*
                        for(int i=2;i<=nRow;i++)
                        {
                                for(int j=1;j<=nCol;j++)
                                {
                                        AnsiString Str;
                                        Str=WorkSheet1.OlePropertyGet("Cells",i,j).OlePropertyGet("Value");
                                        if(Str!=NULL && Str!="")
                                        {
                                                if(j == 1)
                                                        WellName[i][0] = LowerCase(Str);
                                                else if(j == 2)
                                                        WellName[i][1] = LowerCase(Str);

                                                sn[i0]=LowerCase(Str);
                                                i0=i0+1;
                                        }
                                }
                        }
                        */
                        int tcount1 = 1;
                        int tcount2 = 0;
                        for(int i=2;i<=nRow;i++)
                        {
                                for(int j=1;j<=nCol;j++)
                                {
                                        AnsiString Str;
                                        Str=WorkSheet1.OlePropertyGet("Cells",i,j).OlePropertyGet("Value");
                                        if(Str != NULL && Str != "")
                                        {
                                                for(int k = 2;k < 10;k ++)
                                                {
                                                        String tStr = WorkSheet1.OlePropertyGet("Cells",i,k).OlePropertyGet("Value");
                                                        if(tStr != NULL && tStr != "" && tStr != Str)
                                                        {
                                                                WellName[tcount1][0] = LowerCase(Str);
                                                                WellName[tcount1][1] = LowerCase(tStr);
                                                                tcount1 ++;
                                                        }

                                                }

                                                sn[i0]=LowerCase(Str);
                                                i0=i0+1;
                                        }
                                }
                        }
                        num=i0;
                        WorkBook1.OleProcedure("Close");//关闭表格
                        ExcelApp.OleFunction("Quit");//退出Excel
                }
                fclose(fp1);
        }
        }
   }
   //
   /*
   for(int i=2;i<=nRow;i++)
   {
        for(int j=1;j<=nCol;j++)
        {
                AnsiString Str;
                Str=WorkSheet1.OlePropertyGet("Cells",i,j).OlePropertyGet("Value");
                if(Str!=NULL && Str!="")
                {
                        if(j == 1)
                        WellName[i][0] = LowerCase(Str);
                        else if(j == 2)
                        WellName[i][1] = LowerCase(Str);

                        sn[i0]=LowerCase(Str);
                        i0=i0+1;
                }
        }
   }
   */
   //
   Image1->Canvas->TextOutA(120,20,"共  "+AnsiString(num)+"  组对比井");
   Image1->Canvas->TextOutA(200,200,"已完成  "+IntToStr(Main_Count0)+"  组");
   /*
   for(int i9=0;i9<num;i9++)
   {
        ComboBox1->Items->Add(LowerCase(sn[i9]));
        //sn[i9]=LowerCase(Form5->Jh1[Form5->ic[i9]]);
        Image1->Canvas->TextOutA(50,25*i9+10,sn[i9]);
   }
   */
   turn=0;
   if(num > 0)
        Form6->ltx->Enabled = true;

   ////////////////////////////////////////////////////
   String Main = "0";
   String fb = "0";
   String other[60];
   for(int i = 0;i < 2000;i ++)
   {
        if(WellName[i][0] == "" || WellName[i][0] == NULL || WellName[i][0].IsEmpty())
                continue;
        Main_Count0 ++;
        int Main_Count = 0;
        String Name0 = WellName[i][0];
        int Otheer_Count = 0;
        if(Name0 != Main && Name0 != NULL)
        {
                Main = Name0;
                Main_Count ++;
                for(int j = i;j < 2000;j ++)
                {
                        if(WellName[j][0] != Name0)
                                break;
                        other[Otheer_Count] = WellName[j][1];
                        Otheer_Count ++;

                }
        }


        int not_found = 0;
        if(Otheer_Count > 0)
        {
                DB_Mod = 0;
                DB_Num = 0;
                Main_Name = Main;
                OpenDB_Name = Main_Name;
                open_074_Auto(Sender);
                for(int i1 = 0;i1 < Otheer_Count;i1 ++)
                {
                        OpenDB_Name = other[i1];
                        DB_Mod = i1 + 1 - not_found;
                        DB_Num ++;
                        open_074_Auto(Sender);
                        if(found == 0)
                        {
                                not_found ++;
                        }
                        else
                                Other_Name[i1 - not_found] = other[i1];
                }

        }
        ajs = Otheer_Count - not_found + 1;

        if(ajs > 50)
                ajs = 50;
        if(fb != Main)
        {
                Func_B(Sender);
                fb = Main;
                ResrtAll();
        }
        Image1->Canvas->TextOutA(200,200,"已完成  "+IntToStr(Main_Count0)+"  组");


   }


}
//---------------------------------------------------------------------------
String NumToLetter(int n)
{
   int num = n;
   char letter[26] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
   AnsiString a1 = "";
   int temp0 = 0;
   temp0 = num/26;
   if(num < 26)
        a1 = letter[num%26];
   else if(num >= 26 && temp0 < 26)
   {
        a1 = letter[temp0 - 1];
        a1 += letter[(num)%26];
   }
   return a1;
}
int CountMainName(String s)
{
   /*
   String temp = s;
   int count = 0;
   for(int i = 0;i < 200;i ++)
   {
        if(s == main_group.Name[i][0])
                count ++;
   }
   return count;
   */
}
//---------------------------------------------------------------------------
void ResrtAll()
{
        /*
        AnsiString Main_Name;
        AnsiString Other_Name[100];
        AnsiString OpenDB_Name;
        int DB_Mod = 1;
        int DB_Num = 0;
        AnsiString Auto_DBF_Loaction = "";
        int ajs = 0;
        int found = 0;
        AnsiString str20[60][500];
        AnsiString wx[60][200];
        AnsiString elsyhd[60][200];
        AnsiString yxhd[60][200];
        */
        Main_Name = NULL;
        for(int i = 0;i < 100;i ++)
                Other_Name[0] = NULL;

        DB_Mod = 1;
        DB_Num = 0;
        Auto_DBF_Loaction = "";
        ajs = 0;
        found = 0;
        for(int i = 0;i < 60;i ++)
        {
                for(int j = 0;j < 200;j ++)
                {
                        wx[i][j] = NULL;
                        elsyhd[i][j] = NULL;
                        yxhd[i][j] = NULL;

                }
        }
        for(int i = 0;i < 50;i ++)
        {
                for(int j = 0;j < 500;j ++)
                {
                        //str16[i][j] = NULL;
                        str16[i][j] = NULL;

                }
        }





}

void __fastcall TForm6::N6Click(TObject *Sender)
{
   String temp = NumToLetter(52);
   Main_Count0 = 0;
   int i0=0;AnsiString Str;
   Image1->Picture->Assign(NULL);
   OpenDialog1->Filter="加载Excel井名文件(*.xlsx)|*.xlsx|加载Excel井名文件(*.xls)|*.xls";
   if(OpenDialog1->Execute())
   {
        if(OpenDialog1->Filter!="加载Excel井名文件(*.xlsx)|*.xlsx|加载Excel井名文件(*.xls)|*.xls|所有文件(*.*)|*.*")
        {
        for(int I=0;I<OpenDialog1->Files->Count;I++)
        {
                int i2=0;AnsiString cc1;
                FILE *fp1;
                fp1=fopen(OpenDialog1->Files->Strings[I].c_str(),"r");
                if(fp1)
                {
                        cc1=OpenDialog1->Files->Strings[I];
                        Variant ExcelApp;   //对象
                        Variant WorkBook1;  //工作薄
                        Variant WorkSheet1; //工作表
                        try{
                                ExcelApp=Variant::CreateObject("Excel.Application");
                        }
                        catch(...){
                                MessageBox(Handle,"无法启动Excel！","信息提示",MB_ICONSTOP|MB_OK);
                                return;
                        }
                        ExcelApp.OlePropertySet("Visible",false);//设置Excel为可见
                        ExcelApp.OlePropertyGet("WorkBooks").OleProcedure("Open",cc1.c_str());
                        WorkBook1=ExcelApp.OlePropertyGet("ActiveWorkBook");
                        WorkSheet1=WorkBook1.OlePropertyGet("ActiveSheet");//获得当前默认的Sheet
                        Variant aCol1=WorkSheet1.OlePropertyGet("Columns",1);
                        Variant aCol2=WorkSheet1.OlePropertyGet("Columns",3);
                        Variant aRow1=WorkSheet1.OlePropertyGet("Rows",1);
                        Variant aRow2=WorkSheet1.OlePropertyGet("Rows",2000);
                        int nRow=WorkSheet1.OlePropertyGet("Range",aRow1,aRow2).OlePropertyGet("Rows").OlePropertyGet("Count");//行
                        int nCol=WorkSheet1.OlePropertyGet("Range",aCol1,aCol2).OlePropertyGet("Columns").OlePropertyGet("Count");//列
                        for(int i=2;i<=nRow;i++)
                        {
                                for(int j=1;j<=nCol;j++)
                                {
                                        AnsiString Str;
                                        Str=WorkSheet1.OlePropertyGet("Cells",i,j).OlePropertyGet("Value");
                                        if(Str!=NULL && Str!="")
                                        {
                                                if(j == 1)
                                                {
                                                        WellName[i][0] = LowerCase(Str);
                                                        Main_Count0 ++;
                                                }
                                                else if(j == 2)
                                                        WellName[i][1] = LowerCase(Str);

                                                sn[i0]=LowerCase(Str);
                                                i0=i0+1;
                                        }
                                }
                        }
                        num=i0;
                        WorkBook1.OleProcedure("Close");//关闭表格
                        ExcelApp.OleFunction("Quit");//退出Excel
                }
                fclose(fp1);
        }
        }
   }
   Image1->Canvas->TextOutA(120,20,"共  "+ IntToStr(Main_Count0) + "  组对比井");
   //Image1->Canvas->TextOutA(200,200,"已完成  "+IntToStr(Main_Count0)+"  组");
   turn=0;

   ////////////////////////////////////////////////////
   String Main = "0";
   String fb = "0";

   int count = 0;
   String other[60];
   for(int i = 0;i < 2000;i ++)
   {
        if(WellName[i][0] == "" || WellName[i][0] == NULL || WellName[i][0].IsEmpty())
                continue;

        for(int i = 0;i < 5;i ++)
        {
                for(int j = 0;j < 200;j ++)
                        str20[i][j] = "";
        }



        js = 0;
        flag073 = 1;
        filename1 = WellName[i][0];
        open_073_Auto(Sender);
        newname[1] = WellName[i][0];

        //if(filename1 == "N8-2-F325" || filename1 == "n8-2-f325")
        //ShowMessage("0");


        flag073 = 2;
        filename2 = WellName[i][1];
        open_073_Auto(Sender);
        newname[2] = WellName[i][1];


        cclt(Sender);

        count ++;
        Image1->Canvas->TextOutA(200,200,"已完成  "+ IntToStr(count) +"  组");

   }


}
//---------------------------------------------------------------------------
void __fastcall TForm6::open_073_Auto(TObject *Sender)
{
   int i=0,ia=0,j,i1,i2=0,i3,flag=0,flag1=0,n;
   AnsiString cc,Bzz,jjhh;
   //int totalnum = 0;
   FILE *fc,*fo;
   int count = 0;
   AnsiString File_name;

   int pos_20 = 0;
   if(flag073 == 1)
   {
        pos_20 = 0;
        File_name = filename1;
   }
   if(flag073 == 2)
   {
        pos_20 = 1;
        File_name = filename2;
   }



   int path = 0;
   /*
   if(daa073_auto_open_path != NULL)
   {
        TStringList *lst = new TStringList();
        TSearchRec sr;
        int iAttributes = 0;
        if(FindFirst(daa073_auto_open_path,iAttributes,sr) == 0)
        {
                path = 1;
                File_name = ChangeFileExt(la_Name[js],"");
        }
        FindClose(sr);
   }
   */
   if(daa073_auto_open_path == NULL)
   {
        File_name = ChangeFileExt(la_Name[js],"");
        OpenDialog1->Filter="daa073（*.DBF)|*.DBF|所有文件(*.*)|*.*";
        OpenDialog1->Execute();
        daa073_auto_open_path = OpenDialog1->Files->Strings[0].c_str();
        path = 2;
   }


   if(path == 2 || daa073_auto_open_path != NULL)
   {
        for(int I=0;I<1;I++)
        {

                        fc = fopen(daa073_auto_open_path.c_str(),_T("r"));
                        cc = daa073_auto_open_path.c_str();

                if(fc)
                {
                        Table1->TableName=cc;
                        Table1->Open();
                        DBGrid1->DataSource=DataSource1;

                        Table1->Active=true;
                        Table1->First();

                        AnsiString Dynscxhc[300];
                        AnsiString Yxc[300];
                        AnsiString Elsydsc[300];
                        AnsiString Elsyhdc[300];
                        AnsiString Ylsydsc[300];
                        AnsiString Dydsc[300];

                        if(flag073 == 1)
                        {
                                pos_20 = 0;
                                File_name = filename1;
                        }
                        if(flag073 == 2)
                        {
                                pos_20 = 1;
                                File_name = filename2;
                        }

                        while((flag1<1)&&(!Table1->Eof))
                        {
                                jjhh = Table1->FieldByName("JH")->AsString;
                                jjhh = LowerCase(jjhh); //
                                if(jjhh == File_name)
                                {
                                        do{
                                                jjhh = Table1->FieldByName("JH")->AsString;
                                                jjhh = LowerCase(jjhh);flag1=1;

                                                Xhc[ia]      = Table1->FieldByName("XH")->Value;
                                                Jhc[ia]      = Table1->FieldByName("JH")->AsString;      //加新井井名
                                                Yczmcc[ia]   = Table1->FieldByName("YCZMC")->AsString;  //油层组名称
                                                Dymcc[ia]    = Table1->FieldByName("DYMC")->AsString;  //单元名称
                                                Bzc[ia]      = Table1->FieldByName("BZ")->AsString;
                                                Dydsc[ia]    = Table1->FieldByName("DYDS")->AsString;
                                                ia++;
                                                count ++;
                                                Table1->Next();
                                        }while((jjhh==File_name)&&(!Table1->Eof));
                                        //totalnum[js]=count-1;
                                        js ++;
                                }
                                if((flag1<1)&&(!Table1->Eof))
                                        Table1->Next();
                        }
                        Table1->First();
                        //totalnum=i-1;
                        int temp = 0;
                        for(int i = 0;i < count - 1;i ++)
                        {

                                if(Dydsc[i] == "0" || Dydsc[i] == "")
                                        continue;

                                str20[pos_20 + 1][temp] = Yczmcc[i] + Dymcc[i];
                                a21lj[pos_20 + 1][temp] = StrToFloat(Dydsc[i]);
                                jhw[pos_20 + 1][temp] = str20[pos_20 + 1][temp];
                                dsw[pos_20 + 1][temp] = a21lj[pos_20 + 1][temp];
                                /*
                                jhw[js][temp] = Yczmcc[i] + Dymcc[i] + Dynscxhc[i];
                                xcw[js][temp] = StrToFloat(Elsydsc[i]);
                                */
                                temp ++;
                        }
                }
        }
   ss++;
   }

   Table1->First();
   Table1->Close();
   fclose(fc);
}
//---------------------------------------------------------------------------
void __fastcall TForm6::cclt(TObject *Sender)    //储层连通   断层识别
{
   int tw,dc,dcs=0,last=0,dcpd=0,flag=0,i7=0,tm=-1; //断层、断层数 、最后层 、断层判断    题目
   int t1=0,t2=0,countdc=0,to=0,to2=0,ts=0,ts2=0;  float fdeep1[400],fdeep2[400],fdeep3[400];
   FILE *fpdc,*fp1;
   String Dir="D:\\二厂储层对比项目\\断层识别\\";

   float dp1=0.0;
   String st1[200],st2[200];

   //
   int max = 0,min = 0;
   int Count_Max = 0;
   int Count_Min = 0;
   int Count_A = 0;                     //
   int Count_B = 0;                     //
   int result[200][20];                 //断层对比结果
   int Count_Num[10];                   //已加载井层位计数，上限[10]
   int Count_Fault[10];                 //已加载井断层计数，上限[10]
   int Fault_A = 0;                     //A井相对B井断层数
   int Fault_B = 0;                     //B井相对A井断层数
   int Last_A = 0;                      //A井最后一层在B井中的位置
   int Last_B = 0;                      //B井最后一层在A井中的位置
   int Count_Ex = 0;                    //额外层数差
   int Switch_Fault = 0;                //断层存在情况：1A,2B,3AB
   //
   int left_px[10];
   for(int i1=1;i1<js;i1++)
   {
        tw=dj*(i1-1)+2+trackwidth+50+trackwidth;
        left_px[i1] = dj*(i1-1)+2+trackwidth+50+trackwidth;
        int i2=0;
   }

   if(js >= 2)
   {
                int i1 = js - 1;
                for(int i = 0;i < 10;i ++)      Count_Num[i] = Count_Fault[i] = 0;
                for(int i = 0;i < 200;i ++)
                {
                        if(str20[js - 1][i] != "")
                                Count_Num[js - 1] ++;
                        if(str20[js][i] != "")
                                Count_Num[js] ++;
                }
                max = Count_Num[js];
                min = Count_Num[js - 1];
                if(Count_Num[js - 1] > max)
                {
                        max = Count_Num[js - 1];
                        min = Count_Num[js];
                }
                for(int i = 0;i < 200;i ++)
                {
                        for(int j = 0;j < 20;j ++)
                        result[i][j] = 0;
                }
                Count_Fault[js] = Count_Num[js];
                Count_Fault[js - 1] = Count_Num[js - 1];
                for(int i = 0;i < Count_Num[js];i ++)
                {
                        result[i][js] = i;
                        for(int j = 0;j < Count_Num[js - 1];j ++)
                        {
                                if(str20[js][i] == str20[js - 1][j])
                                {
                                        result[i][js - 1] = j;
                                        result[i][0] = 1;
                                        Count_Fault[js] --;
                                        break;
                                }
                                //if(str20[js][180])
                        }
                }
                //
                for(int i = 0;i < Count_Num[js - 1];i ++)
                {
                        result[i][js - 1 + 10] = i;
                        for(int j = 0;j < Count_Num[js];j ++)
                        {
                                if(str20[js - 1][i] == str20[js][j])
                                {
                                        result[i][js + 10] = j;
                                        result[i][10] = 1;
                                        Count_Fault[js - 1] --;
                                        break;
                                }
                        }

                }
                //
                for(int j = 1;j < 100;j ++)
                {
                        int temp = 0;
                        Last_A = j - 1;
                        for(int i = Count_Num[js];i > 0;i --)
                        {
                                if(str20[js - 1][Count_Num[js - 1] - j] != str20[js][i] && str20[js][i] != "")
                                        Last_A ++;
                                if(str20[js - 1][Count_Num[js - 1] - j] == str20[js][i] && str20[js][i] != "")
                                {
                                        temp = 1;
                                        Last_A = j- 1;
                                        break;
                                }
                        }
                        if(temp == 1)
                                break;

                }
                for(int j = 1;j < 100;j ++)
                {
                        int temp = 0;
                        Last_B = j - 1;
                        for(int i = Count_Num[js - 1];i > 0;i --)
                        {
                                if(str20[js][Count_Num[js] - j] != str20[js - 1][i] && str20[js - 1][i] != "")
                                        Last_B ++;
                                if(str20[js][Count_Num[js] - j] == str20[js - 1][i] && str20[js - 1][i] != "")
                                {
                                        temp = 1;
                                        Last_B = j - 1;
                                        break;
                                }
                        }
                        if(temp == 1)
                                break;
                }
                Count_Ex = Last_A;
                Count_Fault[js - 1] = Count_Fault[js - 1] - Last_A;
                Count_Fault[js] = Count_Fault[js] - Last_B;
        /*
                if(Last_A > Last_B + 20)     //A最后层位深度>B最后层位深度 Last_B = 额外层位数差 , A更深
                {
                        Count_Ex = Last_B;
                        Count_Fault[js - 1] = Count_Fault[js - 1] - Count_Ex;
                }
                else if(Last_B > Last_A + 20)     //B最后层位深度>A最后层位深度 Last_A = 额外层位数差 , B更深
                {
                        Count_Ex = Last_A;
                        Count_Fault[js] = Count_Fault[js] - Count_Ex;
                }
                else     //B最后层位深度>A最后层位深度 Last_A = 额外层位数差 , B更深
                {
                        Count_Ex = Last_A;
                        Count_Fault[js - 1] = Count_Fault[js - 1] - Last_A;
                        Count_Fault[js] = Count_Fault[js] - Last_B;
                }
        */
                //
                if(js >= 2 && Count_Fault[js] > 0 && Count_Fault[js - 1] > 0)   //A、B都存在断层
                        Switch_Fault = 3;
                if(js >= 2 && Count_Fault[js] > 0 && Count_Fault[js - 1] == 0)  //A都存在断层
                        Switch_Fault = 1;
                if(js >= 2 && Count_Fault[js] == 0 && Count_Fault[js - 1] > 0)  //B都存在断层
                        Switch_Fault = 2;
                //JS == 2 计数真断层
                        int fA = Count_Fault[js - 1];
                        int fB = Count_Fault[js];
                        int temp = fB;

                //连续断层计数处理
                int end_A = Count_Num[js - 1];
                int end_B = Count_Num[js];
                for(int i = 199 ;i > 0; i --)
                {
                        if(result[i][js - 1] != 0)
                        {
                                end_A = i;
                                break;
                        }
                }
                for(int i = 199 ;i > 0; i --)
                {
                        if(result[i][js + 10] != 0)
                        {
                                end_B = i;
                                break;
                        }
                }
                if(Count_Fault[js] > 0)
                {
                        for(int j = 0;j < end_A;j ++)
                        {
                                if(result[j][0] == 0 && result[j + 1][0] == 0 && result[j][js] > 0 && Count_Fault[js] > 0)//连续断层
                                        Count_Fault[js] --;
                        }

                }
                if(Count_Fault[js - 1] > 0)
                {
                        for(int j = 0;j < end_B ;j ++)
                        {
                                if(result[j][10] == 0 && result[j + 1][10] == 0 && result[j][10 + js - 1] > 0 && Count_Fault[js - 1] > 0)//连续断层
                                        Count_Fault[js - 1] --;
                        }
                }
                //output
                if(Switch_Fault != 0 && js >= 2 && Switch_Fault != 2)
                {
                        String File_name_A = ChangeFileExt(newname[js - 1],"");
                        String File_name_B = ChangeFileExt(newname[js],"");
                        String d1 = "";
                        if(out_put_mod == 2)
                        {
                                d1 = File_name_A + " - " + File_name_B + ".txt";
                        }
                        else if(out_put_mod == 3)
                        {
                                TDateTime date;
                                date = Now();
                                AnsiString st = date.DateTimeString();
                                st = StringReplace(st,"/","-", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
                                st = StringReplace(st,":","'", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
                                d1 = File_name_A + " - " + st + ".txt";
                        }
                        else
                        {
                                d1 = File_name_A + ".txt";
                        }
                        String fname_A = Dir + d1;
                        //A========================================================================================================
                        fpdc = fopen(fname_A.c_str(),"w+t");
                        fprintf(fpdc,"%d\n",Count_Fault[js]);
                        int last_pos = 0;
                        for(int ic = 0;ic < Count_Fault[js];ic ++)
                        {
                                //int LastOne = (Count_Num[js - 1] > Count_Num[js])? Count_Num[js - 1]:Count_Num[js];
                                for(int j = 0;j < (Count_Num[js - 1] > Count_Num[js])? Count_Num[js - 1]:Count_Num[js];j ++)
                                {
                                        if(result[j][0] == 0 && result[j + 1][0] > 0 && j > last_pos)//单断层
                                        {
                                                /*
                                                int flag = 0;
                                                for(int m = 0;m < Count_Num[js - 1];m ++)
                                                {
                                                        if(result[m][12] == j && result[j + 1][10] > 0)
                                                        {
                                                                flag = 1;
                                                                break;
                                                        }

                                                }
                                                if(flag != 1)
                                                        continue;
                                                        */
                                                float A = 0;
                                                float B = 0;
                                                float fault_depth = a21lj[js - 1][result[j - 1][js - 1]] + (a21lj[js][result[j][js]] - a21lj[js][result[j - 1][js]]);
                                                if(fault_depth > a21lj[js - 1][result[j - 1][js - 1] + 1])
                                                        fault_depth = (a21lj[js - 1][result[j - 1][js - 1] + 1] + a21lj[js - 1][result[j - 1][js - 1]])/2;
                                                fprintf(fpdc,"%6.1f\n",fault_depth - 1);
                                                fprintf(fpdc,"%6.1f\n",fault_depth);
                                                fprintf(fpdc,"%6.1f米\n",fault_depth);
                                                fprintf(fpdc,"%s井\n",change_well_name6(newname[js]));

                                                for(int k = 0;k < 200;k ++)
                                                {
                                                        if(str20[js][j] == jhw[js][k])
                                                        {
                                                                A = dsw[js][k];
                                                                B = dsw[js][k + 1];
                                                                break;
                                                        }
                                                }
                                                //B = A;
                                                /*
                                                for(int m = 0;m < 200;m ++)
                                                {
                                                        if(str20[js][j] == jhw[js][m])
                                                                B += hdw[js][m];
                                                }
                                                */
                                                if(A == 0)
                                                {
                                                        A = a21lj[js][result[j][js] + 1];
                                                        B = a21lj[js][result[j][js] + 1];
                                                }
                                                fprintf(fpdc,"%6.1f - ",A);
                                                fprintf(fpdc,"%6.1f米\n",B);
                                                AnsiString str_temp = str20[js][j];
                                                str_temp = change_name_single(str_temp);
                                                fprintf(fpdc,"%s\n",str_temp);
                                                fprintf(fpdc,"%4.1f米\n",B - A);
                                                result[j][0] = 2;
                                                last_pos = j;
                                                j++;
                                                break;
                                        }
                                        else if(result[j][0] == 0 && result[j + 1][0] == 0 && result[j + 1][js] > 0 && j > last_pos)//连续断层
                                        {
                                                float A = 0;
                                                float B = 0;
                                                int topA = j;
                                                int k = j;
                                                for(;k < Count_Num[js];k ++)
                                                {
                                                        if(result[k + 1][0] == 0)
                                                                j++;
                                                        else if(result[k + 1][0] == 1)
                                                                break;
                                                }
                                                float fault_depth = 0;
                                                fault_depth = a21lj[js - 1][result[topA - 1][js - 1]] + (a21lj[js][result[topA][js]] - a21lj[js][result[topA - 1][js]]);
                                                fprintf(fpdc,"%6.1f\n",fault_depth - 1);
                                                fprintf(fpdc,"%6.1f\n",fault_depth);
                                                fprintf(fpdc,"%6.1f米\n",fault_depth);
                                                fprintf(fpdc,"%s井\n",change_well_name6(newname[js]));
                                                A = a21lj[js][result[topA][js]];
                                                B = a21lj[js][result[j][js]];
                                                fprintf(fpdc,"%6.1f - ",A);
                                                fprintf(fpdc,"%6.1f米\n",B);
                                                AnsiString str_temp = str20[js][topA];
                                                str_temp = change_name6(str_temp);
                                                fprintf(fpdc,"%s - ",str_temp);
                                                str_temp = str20[js][j];
                                                str_temp = change_name6(str_temp);
                                                fprintf(fpdc,"%s\n",str_temp);
                                                fprintf(fpdc,"%4.1f米\n",B - A);
                                                result[j][0] = 2;
                                                last_pos = j;
                                                j++;
                                                break;
                                        }
                                }
                        }
                        fclose(fpdc);
                }
                if(Switch_Fault >= 2 && js >= 2)//B========================================================================================================
                {

                        String File_name_A = ChangeFileExt(newname[js - 1],"");
                        String File_name_B = ChangeFileExt(newname[js],"");
                        String d1 = "";
                        if(out_put_mod == 2)
                        {
                                d1 = File_name_B + " - " + File_name_A + ".txt";
                        }
                        else if(out_put_mod == 3)
                        {
                                TDateTime date;
                                date = Now();
                                AnsiString st = date.DateTimeString();
                                st = StringReplace(st,"/","-", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
                                st = StringReplace(st,":","'", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
                                d1 = File_name_B + " - " + st + ".txt";
                        }
                        else
                        {
                                d1 = File_name_B + ".txt";
                        }
                        String fname_B = Dir + d1;
                        int last_pos2 = 0;
                        fpdc = fopen(fname_B.c_str(),"w+t");
                        fprintf(fpdc,"%d\n",Count_Fault[js - 1]);
                        for(int ic = 0;ic < Count_Fault[js - 1];ic ++)
                        {
                                for(int j = 0;j < (Count_Num[js - 1] > Count_Num[js])? Count_Num[js - 1]:Count_Num[js];j ++)
                                {
                                        if(result[j][10] == 0 && result[j + 1][10] > 0 && j > last_pos2)//单断层
                                        {
                                                float A = 0;
                                                float B = 0;
                                                float fault_depth = a21lj[js][result[j - 1][js + 10]] + (a21lj[js - 1][result[j][js + 10 - 1]] - a21lj[js - 1][result[j - 1][js + 10 - 1]]);
                                                if(fault_depth > a21lj[js][result[j - 1][js + 10] + 1])
                                                        fault_depth = (a21lj[js][result[j - 1][js + 10]] + a21lj[js][result[j - 1][js + 10] + 1])/2;


                                                fprintf(fpdc,"%6.1f\n",fault_depth - 1);
                                                fprintf(fpdc,"%6.1f\n",fault_depth);
                                                fprintf(fpdc,"%6.1f米\n",fault_depth);
                                                fprintf(fpdc,"%s井\n",change_well_name6(newname[js - 1]));
                                                for(int k = 0;k < 200;k ++)
                                                {
                                                        if(str20[js - 1][j] == jhw[js - 1][k])
                                                        {
                                                                A = dsw[js - 1][k];
                                                                B = dsw[js - 1][k + 1];
                                                                break;
                                                        }
                                                }
                                                //B = A;
                                                /*
                                                for(int m = 0;m < 200;m ++)
                                                {
                                                        if(str20[js - 1][j] == jhw[js - 1][m])
                                                                B += hdw[js - 1][m];
                                                }
                                                */
                                                if(A == 0)
                                                {
                                                        A = a21lj[js][result[j][js] + 1];
                                                        B = a21lj[js][result[j][js] + 1];
                                                }
                                                fprintf(fpdc,"%6.1f - ",A);
                                                fprintf(fpdc,"%6.1f米\n",B);
                                                AnsiString str_temp = str20[js - 1][j];
                                                str_temp = change_name_single(str_temp);
                                                fprintf(fpdc,"%s\n",str_temp);
                                                fprintf(fpdc,"%3.1f米\n",B - A);
                                                result[j][0] = 2;
                                                last_pos2 = j;
                                                j++;
                                                break;
                                        }
                                        else if(result[j][10] == 0 && result[j + 1][10] == 0 && result[j + 1][js - 1 + 10] > 0 && j > last_pos2)//连续断层
                                        {
                                                int topB = j;
                                                float A = 0;
                                                float B = 0;
                                                for(int k = j;k < Count_Num[js - 1];k ++)
                                                {
                                                        if(result[k + 1][10] == 0)
                                                                j++;
                                                        if(result[k + 1][10] == 1)
                                                                break;
                                                }
                                                //
                                                float fault_depth = a21lj[js][result[topB - 1][js + 10]] + (a21lj[js - 1][result[topB][js + 10 - 1]] - a21lj[js - 1][result[topB - 1][js + 10 - 1]]);
                                                fprintf(fpdc,"%6.1f\n",fault_depth - 1);
                                                fprintf(fpdc,"%6.1f\n",fault_depth);
                                                fprintf(fpdc,"%6.1f米\n",fault_depth);
                                                fprintf(fpdc,"%s井\n",change_well_name6(newname[js - 1]));
                                                A = a21lj[js - 1][result[topB][js - 1 + 10]];
                                                B = a21lj[js - 1][result[j][js - 1 + 10]];
                                                fprintf(fpdc,"%6.1f - ",A);
                                                fprintf(fpdc,"%6.1f米\n",B);
                                                AnsiString str_temp = str20[js - 1][topB];
                                                str_temp = change_name6(str_temp);
                                                fprintf(fpdc,"%s - ",str_temp);
                                                str_temp = str20[js - 1][j];
                                                str_temp = change_name6(str_temp);
                                                fprintf(fpdc,"%s\n",str_temp);
                                                fprintf(fpdc,"%4.1f米\n",B - A);
                                                result[j][0] = 2;
                                                last_pos2 = j;
                                                j++;
                                                break;
                                        }

                                }
                        }
                        fclose(fpdc);
                }

   }

}
//---------------------------------------------------------------------------
AnsiString change_name6(AnsiString s)
{
        //AnsiString full_name = AnsiString s;
        int length = s.Length();
        AnsiString full_name = s.SubString(1,2);
        AnsiString str0 = "";
        int sw = 0;
        if(s.SubString(length,length) == "a")
        {
                str0 = "顶";
                sw = 1;
        }
        else if(s.SubString(length,length) == "b")
        {
                str0 = "中";
                sw = 2;
        }
        else if(s.SubString(length,length) == "c" || s.SubString(length,length) == "d")
        {
                str0 = "底";
                sw = 3;
        }
        else
        {
                str0 = "顶";
                sw = 4;
        }

        if(full_name == "S1" || full_name == "s1")
                full_name = "萨Ⅰ";
        if(full_name == "S2" || full_name == "s2")
                full_name = "萨Ⅱ";
        if(full_name == "S3" || full_name == "s3")
                full_name = "萨Ⅲ";
        if(full_name == "P1" || full_name == "p1")
                full_name = "葡Ⅰ";
        if(full_name == "P2" || full_name == "p2")
                full_name = "葡Ⅱ";
        if(full_name == "P3" || full_name == "p3")
                full_name = "葡Ⅲ";
        if(full_name == "G1" || full_name == "g1")
                full_name = "高Ⅰ";
        if(full_name == "G2" || full_name == "g2")
                full_name = "高Ⅱ";
        if(full_name == "G3" || full_name == "g3")
                full_name = "高Ⅲ";
        if(full_name == "G4" || full_name == "g4")
                full_name = "高Ⅳ";
        AnsiString temp = s.c_str();
        length = temp.Length();
        if(sw == 1)
        {
                temp =  temp.SubString(3,int(length - 1));
                full_name = full_name + temp;
                full_name = StringReplace(full_name,"a","顶", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
        }
        if(sw == 2)
        {
                temp =  s.SubString(3,length - 1);
                full_name = full_name + temp;
                full_name = StringReplace(full_name,"b","中", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
        }
        if(sw == 3)
        {
                temp =  s.SubString(3,length - 1);
                full_name = full_name + temp;
                full_name = StringReplace(full_name,"c","底", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
                full_name = StringReplace(full_name,"d","底", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
        }
        if(sw == 4)
                full_name = full_name + s.SubString(3,length) + "顶";
        //String sNewStr1 =StringReplace(wj,"n","南", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
        return full_name;
}
//---------------------------------------------------------------------------
AnsiString change_name_single(AnsiString s)
{
        //AnsiString full_name = AnsiString s;
        int length = s.Length();
        AnsiString full_name = s.SubString(1,2);
        AnsiString str0 = "";
        int sw = 0;
        if(s.SubString(length,length) == "a")
        {
                str0 = "顶";
                sw = 1;
        }
        else if(s.SubString(length,length) == "b")
        {
                str0 = "中";
                sw = 2;
        }
        else if(s.SubString(length,length) == "c" || s.SubString(length,length) == "d")
        {
                str0 = "底";
                sw = 3;
        }
        else
        {
                str0 = "顶";
                sw = 4;
        }

        if(full_name == "S1" || full_name == "s1")
                full_name = "萨Ⅰ";
        if(full_name == "S2" || full_name == "s2")
                full_name = "萨Ⅱ";
        if(full_name == "S3" || full_name == "s3")
                full_name = "萨Ⅲ";
        if(full_name == "P1" || full_name == "p1")
                full_name = "葡Ⅰ";
        if(full_name == "P2" || full_name == "p2")
                full_name = "葡Ⅱ";
        if(full_name == "P3" || full_name == "p3")
                full_name = "葡Ⅲ";
        if(full_name == "G1" || full_name == "g1")
                full_name = "高Ⅰ";
        if(full_name == "G2" || full_name == "g2")
                full_name = "高Ⅱ";
        if(full_name == "G3" || full_name == "g3")
                full_name = "高Ⅲ";
        if(full_name == "G4" || full_name == "g4")
                full_name = "高Ⅳ";
        //full_name = full_name + s.SubString(3,length) + str0;

        AnsiString temp = s.c_str();
        length = temp.Length();

        if(sw == 1)
        {
                AnsiString ts = full_name;
                full_name = full_name + s.SubString(3,length) + " - ";
                full_name = StringReplace(full_name,"a","顶", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
                full_name = full_name + ts + s.SubString(3,length);
                full_name = StringReplace(full_name,"a","底", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
        }
        if(sw == 2)
        {
                AnsiString ts = full_name;
                full_name = full_name + s.SubString(3,length) + " - ";
                full_name = StringReplace(full_name,"b","中", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
                full_name = full_name + ts + s.SubString(3,length);
                full_name = StringReplace(full_name,"b","底", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
        }
        if(sw == 3)
        {
                AnsiString ts = full_name;
                full_name = full_name + s.SubString(3,length) + " - ";
                full_name = StringReplace(full_name,"c","中", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
                full_name = StringReplace(full_name,"d","中", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
                full_name = full_name + ts + s.SubString(3,length);
                full_name = StringReplace(full_name,"d","底", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
                full_name = StringReplace(full_name,"c","底", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
        }
        if(sw == 4)
                full_name = full_name + s.SubString(3,length) + "顶 - " + full_name + s.SubString(3,length) + "底";
        //String sNewStr1 =StringReplace(wj,"n","南", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
        return full_name;
}
//---------------------------------------------------------------------------
AnsiString change_well_name6(AnsiString s)
{
        int length = s.Length();
        AnsiString well_name = s;
        well_name = StringReplace(well_name,"n","南", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
        well_name = StringReplace(well_name,"-p","-P", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
        well_name = StringReplace(well_name,"-sp","-斜P", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
        well_name = StringReplace(well_name,"-d","-丁", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
        well_name = StringReplace(well_name,"-f","-更", TReplaceFlags()<<rfReplaceAll<<rfIgnoreCase);
        return well_name;
}

void __fastcall TForm6::RadioButton2Click(TObject *Sender)
{
out_put_mod = 2;
}
//---------------------------------------------------------------------------

void __fastcall TForm6::RadioButton1Click(TObject *Sender)
{
out_put_mod = 1;
}
//---------------------------------------------------------------------------

void __fastcall TForm6::RadioButton3Click(TObject *Sender)
{
out_put_mod = 3;
}
//---------------------------------------------------------------------------

void __fastcall TForm6::N7Click(TObject *Sender)
{
   Form8->Show();
   Form8->RadioButton1Click(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm6::Func_C(TObject *Sender)
{
   int i0=0;AnsiString Str;
   if(Form8->LAB1.Length() > 3)
   {
        for(int I=0;I<1;I++)
        {
                int i2=0;AnsiString cc1;
                FILE *fp1;
                fp1=fopen(Form8->LAB1.c_str(),"r");
                if(fp1)
                {
                        cc1=Form8->LAB1;
                        Variant ExcelApp;   //对象
                        Variant WorkBook1;  //工作薄
                        Variant WorkSheet1; //工作表
                        try{
                          ExcelApp=Variant::CreateObject("Excel.Application");
                        }
                        catch(...){
                          MessageBox(Handle,"无法启动Excel！","信息提示",MB_ICONSTOP|MB_OK);
                        return;
                        }
                        ExcelApp.OlePropertySet("Visible",false);//设置Excel为可见
                        //打开指定的Excel文件,文件中最好只设定一个Sheet
                        ExcelApp.OlePropertyGet("WorkBooks").OleProcedure("Open",cc1.c_str());
                        WorkBook1=ExcelApp.OlePropertyGet("ActiveWorkBook");
                        WorkSheet1=WorkBook1.OlePropertyGet("ActiveSheet");//获得当前默认的Sheet
                        Variant aCol1=WorkSheet1.OlePropertyGet("Columns",1);
                        Variant aCol2=WorkSheet1.OlePropertyGet("Columns",10);
                        Variant aRow1=WorkSheet1.OlePropertyGet("Rows",1);
                        Variant aRow2=WorkSheet1.OlePropertyGet("Rows",100);
                        int nRow=WorkSheet1.OlePropertyGet("Range",aRow1,aRow2).OlePropertyGet("Rows").OlePropertyGet("Count");//行
                        int nCol=WorkSheet1.OlePropertyGet("Range",aCol1,aCol2).OlePropertyGet("Columns").OlePropertyGet("Count");//列
                        for(int i = 1;i <= 1000;i++)
                        {
                                for(int j = 1;j <= nCol;j++)
                                {
                                        AnsiString Str;
                                        Str=WorkSheet1.OlePropertyGet("Cells",i,j).OlePropertyGet("Value");
                                        if(Str!=NULL && Str!="")
                                        {
                                                sn[i0]=LowerCase(Str);
                                                i0=i0+1;
                                        }
                                        num=i0;
                                }
                        }
                        WorkBook1.OleProcedure("Close");//关闭表格
                        ExcelApp.OleFunction("Quit");//退出Excel
                        fclose(fp1);
                }
        }

   }
   //Image1->Canvas->TextOutA(120,20,"共  "+ IntToStr(Main_Count0) + "  组对比井");
   //Image1->Canvas->TextOutA(200,200,"已完成  "+IntToStr(Main_Count0)+"  组");
   turn=0;
   ////////////////////////////////////////////////////
   for(int i = 0;i < 300;i ++)
   {
        if(sn[i] == "" || sn[i] == NULL || sn[i].IsEmpty())
                continue;
        for(int i = 0;i < 5;i ++)
        {
                for(int j = 0;j < 200;j ++)
                        str20[i][j] = "";
        }
        js = 0;
        NewWellName = sn[i];
        open_073_NEW(Sender);
        SelectWell();
        if(OldList[0] == "")
                continue;
        open_073_OLD(Sender);
        newname[1] = sn[i];
        //newname[2] = WellName[i][1];
        js = 2;
        cclt(Sender);
        //Image1->Canvas->TextOutA(200,200,"已完成  "+ IntToStr(count) +"  组");
   }
   /*
   String Main = "0";
   String fb = "0";
   int count = 0;
   String other[60];
   for(int i = 0;i < 2000;i ++)
   {
        if(WellName[i][0] == "" || WellName[i][0] == NULL || WellName[i][0].IsEmpty())
                continue;
        for(int i = 0;i < 5;i ++)
        {
                for(int j = 0;j < 200;j ++)
                        str20[i][j] = "";
        }
        js = 0;
        flag073 = 1;
        filename1 = WellName[i][0];
        open_073_Auto(Sender);
        newname[1] = WellName[i][0];
        flag073 = 2;
        filename2 = WellName[i][1];
        open_073_Auto(Sender);
        newname[2] = WellName[i][1];
        cclt(Sender);
        count ++;
        Image1->Canvas->TextOutA(200,200,"已完成  "+ IntToStr(count) +"  组");
   }
   */
}
//---------------------------------------------------------------------------
void __fastcall TForm6::open_073_NEW(TObject *Sender)
{
   int i=0,ia=0,j,i1,i2=0,i3,flag=0,flag1=0,n;
   AnsiString cc,Bzz,jjhh;
   //int totalnum = 0;
   FILE *fc,*fo;
   int count = 0;
   AnsiString File_name;
   int pos_20 = 0;
   int path = 0;
   if(Form8->LAB2.Length() > 3)
   {
        for(int I=0;I<1;I++)
        {
                fc = fopen(Form8->LAB2.c_str(),_T("r"));
                cc = Form8->LAB2.c_str();
                if(fc)
                {
                        String JHName = "";
                        int JHCount = 0;
                        Table1->TableName=cc;
                        Table1->Open();
                        DBGrid1->DataSource=DataSource1;
                        Table1->Active=true;
                        Table1->First();
                        AnsiString Dynscxhc[300];
                        AnsiString Yxc[300];
                        AnsiString Elsydsc[300];
                        AnsiString Elsyhdc[300];
                        AnsiString Ylsydsc[300];
                        AnsiString Wxc[300];
                        AnsiString Dydsc[300];
                        while((flag1<1)&&(!Table1->Eof))
                        {
                                jjhh = Table1->FieldByName("JH")->AsString;
                                jjhh = LowerCase(jjhh); //
                                if(jjhh == LowerCase(NewWellName) && NewWellName != "")
                                {
                                        found = 1;
                                        do{
                                                jjhh = Table1->FieldByName("JH")->AsString;
                                                jjhh = LowerCase(jjhh); //
                                                flag1=1;
                                                Jhc[ia]      = Table1->FieldByName("Jh")->AsString;      //加新井井名
                                                Yczmcc[ia]   = Table1->FieldByName("Yczmc")->AsString;  //油层组名称
                                                Dymcc[ia]    = Table1->FieldByName("Dymc")->AsString;  //单元名称
                                                Bzc[ia]      = Table1->FieldByName("Bz")->AsString;
                                                Dydsc[ia]    = Table1->FieldByName("DYDS")->AsString;
                                                ia++;
                                                count ++;
                                                Table1->Next();

                                        }while(jjhh == LowerCase(NewWellName)&&(!Table1->Eof));
                                                break;
                                }
                                else if((flag1<1)&&(!Table1->Eof))
                                        Table1->Next();

                        }
                        Table1->First();
                        if(found == 0)
                                break;
                        else
                        {
                                JHName = jjhh;
                                NewName[JHCount] = jjhh;
                                JHCount ++;
                        }

                        int last = 196;
                        int temp = 0;
                        for(int i = 0;i < last - 1;i ++)
                        {
                                if(Dydsc[i] == "0" || Dydsc[i] == "")
                                        continue;
                                str20[pos_20 + 1][temp] = Yczmcc[i] + Dymcc[i];
                                a21lj[pos_20 + 1][temp] = StrToFloat(Dydsc[i]);
                                jhw[pos_20 + 1][temp] = str20[pos_20 + 1][temp];
                                dsw[pos_20 + 1][temp] = a21lj[pos_20 + 1][temp];
                                temp ++;
                        }
                }
        }
   }
   Table1->First();
   Table1->Close();
   fclose(fc);
}
//---------------------------------------------------------------------------
void __fastcall TForm6::open_073_OLD(TObject *Sender)
{
   int i=0,ia=0,j,i1,i2=0,i3,flag=0,flag1=0,n;
   AnsiString cc,Bzz,jjhh;
   //int totalnum = 0;
   FILE *fc,*fo;
   int count = 0;
   int open = 0;
   int path = 0;
   int pos_20 = 1;
   if(Form8->LAB3.Length() > 3)
   {
        fc = fopen(Form8->LAB3.c_str(),_T("r"));
        cc = Form8->LAB3.c_str();
        int Unit = 0;
        int UnitCount = 0;
        int range = 50;
        if(Form8->SearchRange == 1)
                range = 300;
        for(int I = 0;I < range;I ++)
        {
                i=0,ia=0,j,i1,i2=0,i3;
                if(fc && OldList[I] != "")
                {
                        Table1->TableName = Form8->LAB3;
                        Table1->Open();
                        Table1->Active = true;
                        Table1->First();
                        AnsiString Dynscxhc[300];
                        AnsiString Yxc[300];
                        AnsiString Elsydsc[300];
                        AnsiString Elsyhdc[300];
                        AnsiString Ylsydsc[300];
                        AnsiString Wxc[300];
                        AnsiString Dydsc[300];
                        //AnsiString Elsyhdc[300];
                        AnsiString Yxhdc[300];
                        File_name = LowerCase(OpenDB_Name);
                        flag1 = 0;
                        found = 0;
                        while((flag1<1)&&(!Table1->Eof))
                        {
                                jjhh = Table1->FieldByName("Jh")->AsString;
                                jjhh = LowerCase(jjhh); //

                                if(jjhh == OldList[I] && OldList[I] != "")
                                {
                                        found = 1;
                                        UnitCount = 0;
                                        do{
                                                jjhh = Table1->FieldByName("Jh")->AsString;
                                                jjhh = LowerCase(jjhh);
                                                flag1=1;
                                                //Xhc[ia]      = Table1->FieldByName("Xh")->Value;
                                                Jhc[ia]      = Table1->FieldByName("Jh")->AsString;      //加新井井名
                                                Yczmcc[ia]   = Table1->FieldByName("Yczmc")->AsString;  //油层组名称
                                                Dymcc[ia]    = Table1->FieldByName("Dymc")->AsString;  //单元名称
                                                Bzc[ia]      = Table1->FieldByName("Bz")->AsString;
                                                Dydsc[ia]    = Table1->FieldByName("DYDS")->AsString;
                                                //if(Dydsc[ia] != NULL && Dydsc[ia] != "" && Dydsc[ia] != "0")
                                                if(Dydsc[ia].Length() > 2)
                                                        UnitCount ++;
                                                ia++;
                                                count ++;
                                                Table1->Next();
                                        }while((jjhh==OldList[I])&&(!Table1->Eof));
                                }
                                if((flag1<1)&&(!Table1->Eof))
                                        Table1->Next();
                        }
                        Table1->First();
                        int temp = 0;
                        int temp2 = 0;

                        if(found == 0)
                                break;

                        int last = 196;
                        /*
                        for(int i = 299;i > 0;i --)
                        {
                                if(Dydsc[i] != "0" && Dydsc[i] != NULL && Dydsc[i] != " ")
                                {
                                        last = i;
                                        break;
                                }

                        }
                        */
                        UnitCount --;
                        if(UnitCount <= Unit)
                                continue;
                        else
                        {
                                Unit = UnitCount;
                                newname[2] = OldList[I];
                        }

                        for(int i = 0;i < last - 1;i ++)
                        {
                                AnsiString temps1 = Yczmcc[i];
                                AnsiString temps2 = Dydsc[i];
                                if(Dydsc[i] == "0" || Dydsc[i] == "")
                                        continue;
                                /*
                                if(DB_Num >= 1 && temps2 == "")
                                        continue;
                                if(DB_Num >= 1 && temps2 == "0")
                                        continue;
                                if(DB_Num >= 1 && temps2.IsEmpty())
                                        continue;
                                str16[DB_Mod][temp] = Yczmcc[i] + "#" + Dymcc[i];
                                if(Yczmcc[i] + Dymcc[i] != str20[DB_Mod][temp2 - 1])
                                {
                                        str20[DB_Mod][temp2] = Yczmcc[i] + "#" + Dymcc[i];
                                        temp2 ++;
                                }
                                */
                                /*
                                wx[DB_Mod][temp] = Wxc[i].c_str();
                                elsyhd[DB_Mod][temp] = Dydsc[i].c_str();
                                //yxhd[DB_Mod][temp] = Yxhdc[i].c_str();
                                a21lj[DB_Mod][temp] = StrToFloat(Dydsc[i]);
                                jhw[DB_Mod][temp] = Yczmcc[i] + Dymcc[i];
                                xcw[DB_Mod][temp] = StrToFloat(Dydsc[i]);
                                temp ++;
                                */

                                str20[pos_20 + 1][temp] = Yczmcc[i] + Dymcc[i];
                                a21lj[pos_20 + 1][temp] = StrToFloat(Dydsc[i]);
                                jhw[pos_20 + 1][temp] = str20[pos_20 + 1][temp];
                                dsw[pos_20 + 1][temp] = a21lj[pos_20 + 1][temp];
                                /*
                                jhw[js][temp] = Yczmcc[i] + Dymcc[i] + Dynscxhc[i];
                                xcw[js][temp] = StrToFloat(Elsydsc[i]);
                                */
                                temp ++;
                        }


                }
        }
   Table1->First();
   Table1->Close();
   fclose(fc);
   ajs ++;
   }
}
//---------------------------------------------------------------------------
void __fastcall TForm6::SelectWell()
{
   String wellname = NewWellName;
   int j,i3,flag1=0,n;
   AnsiString cc,Bzz,jjhh;
   FILE *fc,*fp;
   AnsiString File_name;
   int path = 0;
   //
   String Jhc[300];

   if(Form8->LAB3.Length() > 3)
   {
        for(int I=0;I<1;I++)
        {
                fc = fopen(Form8->LAB3.c_str(),_T("r"));
                cc = Form8->LAB3.c_str();
                String strtemp = "";
                if(fc)
                {
                        Table1->TableName = cc;
                        Table1->Open();
                        Table1->Active=true;
                        Table1->First();
                        //
                        String Wrong = "";
                        Table1->Last();
                        for(int t = 0;t < 200;t ++)
                                Table1->Prior();
                        String LastName = Table1->FieldByName("JH")->AsString;
                        Table1->First();
                        String sc0 = "";
                        int Ocount = 0;
                        String NameTemp = "";
                        while((flag1<1)&&(!Table1->Eof))
                        {
                                jjhh = Table1->FieldByName("JH")->AsString;
                                jjhh = LowerCase(jjhh); //

                                Table1->FieldByName("YCZMC")->AsString;  //油层组名称
                                Table1->FieldByName("DYMC")->AsString;  //单元名称
                                Table1->FieldByName("DYDS")->AsString;

                                if(Table1->Eof || LowerCase(Wrong) == LowerCase(LastName) || LowerCase(jjhh) == LowerCase(LastName))
                                {
                                        Table1->First();
                                        break;
                                }

                                if(LowerCase(jjhh) == LowerCase(Wrong) || jjhh.Length() < 7)
                                {
                                        Table1->Next();
                                        continue;
                                }

                                std::auto_ptr<TStringList>sl1(new TStringList);
                                sl1->Delimiter = '-';
                                sl1->DelimitedText = LowerCase(jjhh);
                                AnsiString NameS1 = sl1->Strings[0].c_str();
                                AnsiString NameS2 = sl1->Strings[1].c_str();
                                AnsiString NameS3 = sl1->Strings[2].c_str();

                                std::auto_ptr<TStringList>sl2(new TStringList);
                                sl2->Delimiter = '-';
                                sl2->DelimitedText = LowerCase(NewWellName);
                                AnsiString NameT1 = sl2->Strings[0].c_str();
                                AnsiString NameT2 = sl2->Strings[1].c_str();
                                AnsiString NameT3 = sl2->Strings[2].c_str();

                                if(Form8->SearchRange == 0 && (NameS1 == NameT1 && NameS2 == NameT2 && LowerCase(jjhh) != LowerCase(NewWellName)) || (NameS1 == NameT1 && NameS3 == NameT3 && LowerCase(jjhh) != LowerCase(NewWellName)) && (LowerCase(jjhh) != LowerCase(NameTemp)))
                                {
                                        if(Ocount > 0 && jjhh != OldList[Ocount - 1])
                                        {
                                                OldList[Ocount] = jjhh;
                                                NameTemp = jjhh;
                                                Ocount ++;
                                                Table1->Next();
                                        }
                                        else if(Ocount == 0)
                                        {
                                                OldList[Ocount] = jjhh;
                                                NameTemp = jjhh;
                                                Ocount ++;
                                                Table1->Next();
                                        }
                                        else
                                        Table1->Next();
                                }
                                else if(Form8->SearchRange == 1 && NameS1 == NameT1 && LowerCase(jjhh) != LowerCase(NewWellName))
                                {
                                        if(Ocount > 0 && jjhh != OldList[Ocount - 1])
                                        {
                                                OldList[Ocount] = jjhh;
                                                NameTemp = jjhh;
                                                Ocount ++;
                                                Table1->Next();
                                        }
                                        else if(Ocount == 0)
                                        {
                                                OldList[Ocount] = jjhh;
                                                NameTemp = jjhh;
                                                Ocount ++;
                                                Table1->Next();
                                        }
                                        else
                                        Table1->Next();
                                }
                                else
                                        Table1->Next();
                        }
                Table1->First();
                Table1->Close();
                fclose(fc);
                }
        }
   }

}
void __fastcall TForm6::RadioButton4Click(TObject *Sender)
{
Form1->MOD = 1;
}
//---------------------------------------------------------------------------

void __fastcall TForm6::RadioButton5Click(TObject *Sender)
{
Form1->MOD = 2;
}
//---------------------------------------------------------------------------

void __fastcall TForm6::N4Click(TObject *Sender)
{
    Form6->Button2Click(Sender);    
}
//---------------------------------------------------------------------------


