⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 personform.~cpp

📁 该源代码是一个关于电力设备和电力行业操作管理的管理系统
💻 ~CPP
📖 第 1 页 / 共 3 页
字号:
                Image1->Picture->Assign(p );
                break;
            }
        }
        catch(...)
        {
            ShowMessage("图像文件格式无效");
            break;
        }
        Datam->pople_qry->Next();
    }
     DBGrid1->Refresh();

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

void __fastcall TPersonFrm::DeleteDepartmentClick(TObject *Sender)
{
     AnsiString mSql;
     int i,j;
     AnsiString DeleStr;
     AnsiString Msg,Msg1;

     TAdd_partment *AddDep =new TAdd_partment(Application);
     Msg = "该部门可能存有人员信息,删除部门前最好先删除该部门人员,你确定删除该部门吗?";
//     Msg1 = "该部门可能存在下级部门,删除该部门将删除下级部门,你确定删除该部门吗?";
//     if(MessageBox(Handle,Msg1.c_str() ,"警告",MB_OKCANCEL)==IDOK)
     if(MessageBox(Handle,Msg.c_str() ,"警告",MB_OKCANCEL)==IDOK)
     {

         for(i=0;i<ListBox1->Items->Count;i++)
         {
             if(ListBox1->ItemIndex==i)
             {
                 DeleStr = ListBox1->Items->Strings[i];
                 ListBox1->Items->Delete(i);
                 mSql = "delete from tb_department where department_name='"+DeleStr+"'";

                 q_exesql(mSql);

                 for(j=0;j<ComboBox4->Items->Count;j++)
                 {
                     if(DeleStr==ComboBox4->Items->Strings[j])
                        ComboBox4->Items->Delete(j);
                        break;
                 }
                 for(j=0;j<AddDep->ComboBox1->Items->Count;j++)
                 {
                     if(DeleStr==AddDep->ComboBox1->Items->Strings[j])
                        AddDep->ComboBox1->Items->Delete(j);
                        break;
                 }

             }
         }
/*
         Datam->department_qry->Close();
         Datam->department_qry->SQL->Clear();
         Datam->department_qry->SQL->Add("delete from tb_department where parent_department_id='"+DeleStr+"'");
         Datam->department_qry->ExecSQL();
         Datam->department_qry->Open();
         Datam->department_qry->Close();
*/
        // String Record = DBGrid1->Columns->Items[DBGrid1->SelectedIndex]->Field->DataSet->FieldByName("employee_id")->AsString;
         Datam->pople_qry->Close();
         Datam->pople_qry->SQL->Clear();
         Datam->pople_qry->SQL->Add("delete from tb_employee where department_id='"+DeleStr+"'");
         Datam->pople_qry->Open();
         Datam->pople_qry->ExecSQL();
     }
     ComboBox4->Text = "----请选择----";
     GroupBox4->Caption = "所有人员信息";
     Datam->pople_qry->Close();
     Datam->pople_qry->SQL->Clear();
     Datam->pople_qry->SQL->Add("select * from tb_employee");
     Datam->pople_qry->Open();
     delete AddDep;
}
//---------------------------------------------------------------------------

void __fastcall TPersonFrm::Button1Click(TObject *Sender)
{
    OpenDialog1->Title = "请选择照片";
    OpenDialog1->InitialDir = "d:\\";
    if(OpenDialog1->Execute())
    {
        Image1->Picture->LoadFromFile(OpenDialog1->FileName);
        FileName = OpenDialog1->FileName;
        return;
    }
    else
        FileName = "";
}
//---------------------------------------------------------------------------

void __fastcall TPersonFrm::BBt_PrintClick(TObject *Sender)
{
     int LeftBlank = 1;
     int RightBlank = 1;
     int TopBlank = 1;
     int BottomBlank = 1;

     int PointX,PointY;
     int PointScale,PrintStep;
     int x,y,i;
     String Str;

     TPrinter *printer = Printer();
     PointX = GetDeviceCaps(printer->Handle,LOGPIXELSX)/2.54;
     PointY = GetDeviceCaps(printer->Handle,LOGPIXELSY)/2.54;
     PointScale = GetDeviceCaps(printer->Handle,LOGPIXELSX)/Screen->PixelsPerInch+0.5;

     printer->Orientation = poLandscape;
     printer->Canvas->Font->Name = "宋体";
     printer->Canvas->Font->Size = 10;
     Str = "谐波管理系统";
     PrintStep = printer->Canvas->TextHeight(Str)+16;

     x = PointX*LeftBlank;
     y = PointY*TopBlank;
     if(Datam->pople_qry->Active)
     {
        
        printer->BeginDoc();
        Datam->pople_qry->First();
        while(!Datam->pople_qry->Eof)
        {
             for(i=0;i<DBGrid1->FieldCount-1;i++)
             {
                if((x+DBGrid1->Columns->Items[i]->Width*PointScale)<=(printer->PageWidth-PointX*RightBlank))
                {
                     printer->Canvas->Rectangle(x,y,x+DBGrid1->Columns->Items[i]->Width*PointScale,y+PrintStep);
                     if(y==PointY*TopBlank)
                          printer->Canvas->TextOutA(x+8,y+8,DBGrid1->Columns->Items[i]->Title->Caption);
                     else
                          printer->Canvas->TextOutA(x+8,y+8,DBGrid1->Fields[i]->AsString);
                }
                x = x+DBGrid1->Columns->Items[i]->Width*PointScale;
             }
             if(y!=PointY*TopBlank)
                 Datam->pople_qry->Next();

             x = PointX*LeftBlank;
             y = y+PrintStep;
             if((y+PrintStep)>(printer->PageHeight-PointY*BottomBlank))
             {
                 printer->NewPage();
                 y = PointY*TopBlank;
             }
        }
        printer->EndDoc();
        Datam->pople_qry->First();
        MessageDlg("打印完成!",0,TMsgDlgButtons()<<mbOK,0);
    }

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








void __fastcall TPersonFrm::DateTimePicker2KeyDown(TObject *Sender,
      WORD &Key, TShiftState Shift)
{
    if (Key==VK_TAB)
    {
        ComboBox4->SetFocus();
    }
}
//---------------------------------------------------------------------------

void __fastcall TPersonFrm::DBNavigator1Click(TObject *Sender,
      TNavigateBtn Button)
{
     int row;
     String Sex;
     row = DBGrid1->SelectedIndex;
     Edit1->Text = DBGrid1->Columns->Items[row]->Field->DataSet->FieldByName("employee_id")->AsString;
     Edit2->Text = DBGrid1->Columns->Items[row]->Field->DataSet->FieldByName("name")->AsString;
     ComboBox2->Text = DBGrid1->Columns->Items[row]->Field->DataSet->FieldByName("sex")->AsString;
     Edit3->Text = DBGrid1->Columns->Items[row]->Field->DataSet->FieldByName("duty")->AsString;
     DateTimePicker1->Date = DBGrid1->Columns->Items[row]->Field->DataSet->FieldByName("birth")->AsDateTime;
     ComboBox1->Text = DBGrid1->Columns->Items[row]->Field->DataSet->FieldByName("education")->AsString;
     ComboBox4->Text = DBGrid1->Columns->Items[row]->Field->DataSet->FieldByName("department_id")->AsString;
     DateTimePicker2->Date = DBGrid1->Columns->Items[row]->Field->DataSet->FieldByName("join_date")->AsDateTime;
     ComboBox4->Text = DBGrid1->Columns->Items[row]->Field->DataSet->FieldByName("department_id")->AsString;
  /*
     Datam->Employee_qry->Close();
     Datam->Employee_qry->SQL->Clear();
     Datam->Employee_qry->SQL->Add("select * from tb_employee where id='"+Edit1->Text+"'");
     TGraphicField * p =  (TGraphicField*)Datam->Employee_qry->FieldByName("ph");
     Image1->Picture->Assign(p );
     Datam->Employee_qry->ExecSQL();
     Datam->Employee_qry->Close();
/**/
     while(!Datam->pople_qry->Eof)
     {
        try
        {
            //((TBlobField *) Query1->FieldByName("ph"))->SaveToFile("c:\\a.bmp");
            if(Edit1->Text==Datam->pople_qry->FieldByName("employee_id")->AsString)
            {
               // TGraphicField * p =  (TGraphicField*)Datam->pople_qry->FieldByName("photo");
                TBlobField * p =  (TBlobField*)Datam->pople_qry->FieldByName("photo");
                if( p->IsNull )
                {
                        Image1->Picture = NULL; //->Bitmap->FreeImage();
                }
                else
                Image1->Picture->Assign(p );
                break;
            }
        }
        catch(...)
        {
            ShowMessage("图像文件格式无效");
            break;
        }
        Datam->pople_qry->Next();
    }
}
//---------------------------------------------------------------------------



void __fastcall TPersonFrm::DBGrid1CellClick(TColumn *Column)
{
               int row;
     String Sex;
     row = DBGrid1->SelectedIndex;
     Edit1->Text = DBGrid1->Columns->Items[row]->Field->DataSet->FieldByName("employee_id")->AsString;
     Edit2->Text = DBGrid1->Columns->Items[row]->Field->DataSet->FieldByName("name")->AsString;
     ComboBox2->Text = DBGrid1->Columns->Items[row]->Field->DataSet->FieldByName("sex")->AsString;
     Edit3->Text = DBGrid1->Columns->Items[row]->Field->DataSet->FieldByName("duty")->AsString;
     DateTimePicker1->Date = DBGrid1->Columns->Items[row]->Field->DataSet->FieldByName("birth")->AsDateTime;
     ComboBox1->Text = DBGrid1->Columns->Items[row]->Field->DataSet->FieldByName("education")->AsString;
     ComboBox4->Text = DBGrid1->Columns->Items[row]->Field->DataSet->FieldByName("department_id")->AsString;
     DateTimePicker2->Date = DBGrid1->Columns->Items[row]->Field->DataSet->FieldByName("join_date")->AsDateTime;
     ComboBox4->Text = DBGrid1->Columns->Items[row]->Field->DataSet->FieldByName("department_id")->AsString;
  /*
     Datam->Employee_qry->Close();
     Datam->Employee_qry->SQL->Clear();
     Datam->Employee_qry->SQL->Add("select * from tb_employee where id='"+Edit1->Text+"'");
     TGraphicField * p =  (TGraphicField*)Datam->Employee_qry->FieldByName("ph");
     Image1->Picture->Assign(p );
     Datam->Employee_qry->ExecSQL();
     Datam->Employee_qry->Close();
/**/
     while(!Datam->pople_qry->Eof)
     {
        try
        {
            //((TBlobField *) Query1->FieldByName("ph"))->SaveToFile("c:\\a.bmp");
            if(Edit1->Text==Datam->pople_qry->FieldByName("employee_id")->AsString)
            {
               // TGraphicField * p =  (TGraphicField*)Datam->pople_qry->FieldByName("photo");
                TBlobField * p =  (TBlobField*)Datam->pople_qry->FieldByName("photo");
                if( p->IsNull )
                {
                        Image1->Picture = NULL; //->Bitmap->FreeImage();
                }
                else
                Image1->Picture->Assign(p );
                break;
            }
        }
        catch(...)
        {
            ShowMessage("图像文件格式无效");
            break;
        }
        Datam->pople_qry->Next();
    }
}
//---------------------------------------------------------------------------


void __fastcall TPersonFrm::N1Click(TObject *Sender)
{
      try
      {
           depxx = new Tdepxx(Application);
           depxx->ShowModal();
      }
      __finally
      {
           delete depxx;
      }
}
//---------------------------------------------------------------------------

void __fastcall TPersonFrm::Edit1KeyPress(TObject *Sender, char &Key)
{
    if (Key==VK_TAB)
    {
        ComboBox4->SetFocus();

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

void __fastcall TPersonFrm::Edit2KeyPress(TObject *Sender, char &Key)
{
    if (Key==VK_TAB)
    {
        ComboBox2->SetFocus();
    }        
}
//---------------------------------------------------------------------------

void __fastcall TPersonFrm::ComboBox2KeyPress(TObject *Sender, char &Key)
{
    if (Key==VK_TAB)
    {
        Edit3->SetFocus();
    }        
}
//---------------------------------------------------------------------------

void __fastcall TPersonFrm::Edit3KeyPress(TObject *Sender, char &Key)
{
    if (Key==VK_TAB)
    {
        DateTimePicker1->SetFocus();
    }        
}
//---------------------------------------------------------------------------

void __fastcall TPersonFrm::DateTimePicker1KeyPress(TObject *Sender,
      char &Key)
{
    if (Key==VK_TAB)
    {
        ComboBox1->SetFocus();
    }        
}
//---------------------------------------------------------------------------

void __fastcall TPersonFrm::ComboBox1KeyPress(TObject *Sender, char &Key)
{
    if (Key==VK_TAB)
    {
        DateTimePicker2->SetFocus();
    }
}
//---------------------------------------------------------------------------

void __fastcall TPersonFrm::DateTimePicker2KeyPress(TObject *Sender,
      char &Key)
{
    if (Key==VK_TAB)
    {
        ComboBox4->SetFocus();
    }
}
//---------------------------------------------------------------------------

void __fastcall TPersonFrm::Edit1KeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
    if (Key==VK_TAB)
    {
        ComboBox4->SetFocus();
    }
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -