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

📄 newspaperdata.cpp

📁 邮件管理系统... 方便的管理邮件数据库系统
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include "PostMain.h"
#include "Newspaperdata.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TNewspaperForm *NewspaperForm;
//---------------------------------------------------------------------------

static char cType[2]="~";

void __fastcall TNewspaperForm::DispalyOffice() //显示报社
{
String SqlString=String("select name from Office")
           +" where code like '"
           + String(cType) + "%'" + " group by name";

           ComboBox1->Items->Clear();


try{
        if ( MainForm->ExecuteSQL( SqlString, 1 ) > 0 ) //以前登记考试日期
        {
        int i=0;
                MainForm->ADOQuery1->DisableControls();
                while( ! MainForm->ADOQuery1->Eof )
                {
                if(i>99) break;
                ComboBox1->Items->Add(MainForm->ADOQuery1->FieldByName("name")->AsString);
                i++;
                MainForm->ADOQuery1->Next();
                }
                MainForm->ADOQuery1->EnableControls();
                }
        }

        catch (Exception &exception)
        {
        Application->ShowException(&exception);
        return ;
        }
        ComboBox1->ItemIndex=0;
}


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

__fastcall TNewspaperForm::TNewspaperForm(TComponent* Owner)
        : TForm(Owner)
{
ChangeName();
DispalyOffice();
}

void TNewspaperForm::ChangeName()
{
ComboBox2->Items->Clear();
if(RadioGroup1->ItemIndex){
        Label1->Caption="杂志名称";
        Label2->Caption="杂志编号";
        Label5->Caption="杂志社名";
        cType[0]='^';
        cType[1]=0;
        ComboBox2->Items->Add("月刊");
        ComboBox2->Items->Add("季刊");
        }
        else{
        Label1->Caption="报刊名称";
        Label2->Caption="报刊编号";
        Label5->Caption="报刊社名";
        cType[0]='~';
        cType[1]=0;
        ComboBox2->Items->Add("日报");
        ComboBox2->Items->Add("周报");
        }
ComboBox2->ItemIndex=0;
}

//---------------------------------------------------------------------------
void __fastcall TNewspaperForm::RadioGroup1Click(TObject *Sender)
{
ChangeName();
DispalyOffice();
}
//---------------------------------------------------------------------------


void __fastcall TNewspaperForm::Edit1Exit(TObject *Sender)
{
  Edit5->Text=ConvertHZToPY(Edit1->Text.c_str());
}
//---------------------------------------------------------------------------

void __fastcall TNewspaperForm::AddBitBtnClick(TObject *Sender)
{
String SqlString, sValues, tmp;

sValues="";
for(int i=0, j=0;i<ComponentCount;i++)  //遍历所有的Edit控件
    if (Components[i]->ClassNameIs("TEdit")){
        if( ((TEdit *)Components[i])->Text.IsEmpty() ) {
                ((TEdit *)Components[i])->SetFocus();
                ShowMessage("内容不能空!");
                return;
                }
                else {

                        if(j==1) tmp=cType + ((TEdit *)Components[i])->Text;
                                else
                                tmp=((TEdit *)Components[i])->Text;
                if(j) sValues=sValues +"', '" + tmp;
                     else sValues=" '" + tmp;
                }
                j++;
       }
       
       sValues=sValues + "', '" + ComboBox1->Text +"', '" + ComboBox2->Text +"'";

       SqlString="select * from Newspaper where Code='" + Edit2->Text +"'";

      try{
            if( MainForm->ExecuteSQL( SqlString, 1 ) > 0 )
            {
                MainForm->ADOQuery1->DisableControls();

                tmp=MainForm->ADOQuery1->FieldByName( "Code")->AsString;
                if(!tmp.IsEmpty() ){
                ShowMessage("该编号已存在!");
                Edit2->SetFocus();
                return;
                }
                MainForm->ADOQuery1->EnableControls();
              }
        }//try
        catch (Exception &exception)
        {
        Application->ShowException(&exception);
        return ;
        }

       SqlString="insert into newspaper Values(" + sValues + ")";
       //  ShowMessage(SqlString);

     try{
        if(MainForm->ExecuteSQL( SqlString, 0 ) < 0 ){
        Application->MessageBox( "增加失败 !", NULL, MB_OK | MB_ICONWARNING );
        }
     }//try

     catch(Exception &exception){
                Application->ShowException(&exception);
                return;
                }

   for(int i=0;i<ComponentCount;i++)
    if (Components[i]->ClassNameIs("TEdit"))
        ((TEdit *)Components[i])->Text="";
}
//---------------------------------------------------------------------------

void __fastcall TNewspaperForm::Edit3KeyPress(TObject *Sender, char &Key)
{

        switch(Key)
        {
        case VK_RETURN:
                SendMessage(this->Handle,WM_NEXTDLGCTL,0,0);
                break;
        case VK_BACK:
                break;
        case VK_TAB:
                break;
        case '.':
                if(Edit3->Text.Pos(".") || Edit3->Text.Length()==0) Key=0;
                break;
        default:
                if (!isdigit(char(Key)) ){
                         Key=0;
                         MainForm->WarnBeep();
                         }

        }



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


⌨️ 快捷键说明

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