📄 cxkb.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <stdio.h>
#include "CXKB.h"
#include "zu.h"
#include "tjse.h"
#include <stdlib.h>
int lo1=0,ro1=0,ld1=0;
int lo3=0,ro3=0,ld3=0;
int pd=0;
int msq=-1;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm6 *Form6;
//---------------------------------------------------------------------------
__fastcall TForm6::TForm6(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm6::Button1Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm6::RadioGroup1Click(TObject *Sender)
{
if( RadioGroup1->ItemIndex ==0){
lo1=0;
ro1=0;
Label3->Caption="";
ComboBox3->Visible=false;
Label4->Visible=false;
ComboBox1->Visible=true;
Label1->Visible=true;
ComboBox2->Visible=false;
Label2->Visible=false;
}
else if(RadioGroup1->ItemIndex ==1){
lo1=0;
ro1=0;
Label3->Caption="";
ComboBox3->Visible=false;
Label4->Visible=false;
ComboBox2->Visible=true;
Label2->Visible=true;
ComboBox1->Visible=false;
Label1->Visible=false;
}
else if(RadioGroup1->ItemIndex ==2){
lo1=0;
ro1=0;
ComboBox3->Visible=true;
Label4->Visible=true;
ComboBox2->Visible=false;
Label2->Visible=false;
ComboBox1->Visible=false;
Label1->Visible=false;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm6::Button2Click(TObject *Sender)
{
if(ComboBox4->Visible==true){
ComboBox4->Visible=false;
Label5->Visible=false;
ComboBox5->Visible=false;
Label6->Visible=false;
RadioGroup1->Visible=true;
char *ssd;
//char xxxq[]="新学校的99学年第一学期";
ssd=new char[250];
Set<TMsgDlgBtn,0,8>temp_set;
temp_set<<mbYes<<mbNo;
sprintf(ssd,"%s老师:\n 由于%s老师%s,\n请你代(%s)%s的%s课。 \n %s ",ComboBox4->Text.c_str(),ComboBox2->Text.c_str(),ComboBox5->Text.c_str(),StringGrid1->Cells[lo3][ro3].SubString(ld3+1,8).c_str(),AnsiString("星期"+AnsiString(lo3)+"第"+AnsiString(ro3)+"节").c_str(),StringGrid1->Cells[lo3][ro3].SubString(1,ld3).c_str(),DateToStr(Date()));
switch(MessageBox(Handle,ssd,"代课通知单",MB_YESNOCANCEL | MB_ICONQUESTION))
{
case mrNo:
break;
case mrYes:
Table1->Active = true;
Table1->AppendRecord(ARRAYOFCONST((ComboBox4->Text,ComboBox2->Text,DateToStr(Date()),StringGrid1->Cells[lo3][ro3].SubString(1,ld3),ComboBox5->Text,StringGrid1->Cells[lo3][ro3].SubString(ld3+1,8),AnsiString("星期"+AnsiString(lo3)+"第"+AnsiString(ro3)+"节")))); //代,原。时间,课程,原因,班,节次
}
delete ssd;
}
else if( RadioGroup1->ItemIndex ==0){
Label3->Caption="";
msq=0;
Form2->Table3->IndexName="BJMC";
Form2->Table3->Active = true;
if(Form2->Table3->FindKey(ARRAYOFCONST((ComboBox1->Text)))){
INSB();
char *qwe,*fg,*td;
qwe=new char[20];
td=new char[20];
fg=new char[5];
for(int cl=0;cl<=41;cl++){
strcpy(qwe,"KCMC");
strcpy(td,"TXM");
itoa(cl+1, fg, 10);
strcat(qwe,fg);
strcat(td,fg);
StringGrid1->Cells[cl/7+1][cl%7+1]=Form2->Table3->FieldByName(qwe)->AsString+Form2->Table3->FieldByName(td)->AsString;
}
delete qwe;
delete fg;
delete td;
}
}
else if( RadioGroup1->ItemIndex ==1){
msq=1;
Form2->Table3->IndexName="BJMC";
Form2->Table3->Active = true;
INSB();
char *qwe,*fg,*td;
qwe=new char[20];
td=new char[20];
fg=new char[5];
Form2->Table3->First();
while(!Form2->Table3->Eof){
for(int i=0;i<=41;i++){
strcpy(qwe,"TXM");
strcpy(td,"KCMC");
itoa(i+1, fg, 10);
strcat(qwe,fg);
strcat(td,fg);
if(Form2->Table3->FieldByName(qwe)->AsString==ComboBox2->Text){
StringGrid1->Cells[i/7+1][i%7+1]=Form2->Table3->FieldByName(td)->AsString+Form2->Table3->FieldByName("BJMC")->AsString;
}
}
Form2->Table3->Next();
}
delete qwe;
delete fg;
delete td;
}
else if( RadioGroup1->ItemIndex ==2){
msq=2;
if(Label3->Caption==""){
Form2->Table3->IndexName="BJMC";
Form2->Table3->Active = true;
Form2->Table3->First();
INSB();
char *ow;
char mb[4];
int kf;
ow=new char[256];
for(kf=0;kf<=41;kf++){
strcpy(ow,"KCMC");
itoa(kf+1, mb, 10);
strcat(ow,mb);
int ad1=0;
bool ad2=false;
while(!Form2->Table3->Eof&&ComboBox3->Text!=""){
if(Form2->Table3->FieldByName(ow)->AsString==ComboBox3->Text){
ad1++;
ad2=true;
}
Form2->Table3->Next();
}
Form2->Table3->First();
if(ad2){
StringGrid1->Cells[kf/7+1][kf%7+1]=ComboBox3->Text+AnsiString(ad1)+"节";
}
}
delete ow;
}
else{
Form2->Table3->IndexName="BJMC";
Form2->Table3->Active = true;
Form2->Table3->FindKey(ARRAYOFCONST((ComboBox1->Text)));
INSB();
char *ow,*nv;
char mb[4];
int kf;
ow=new char[256];
nv=new char[256];
for(kf=0;kf<=41;kf++){
strcpy(ow,"KCMC");
strcpy(nv,"TXM");
itoa(kf+1, mb, 10);
strcat(ow,mb);
strcat(nv,mb);
if(Form2->Table3->FieldByName(ow)->AsString==ComboBox3->Text&&ComboBox3->Text!=""){
StringGrid1->Cells[kf/7+1][kf%7+1]=ComboBox3->Text+Form2->Table3->FieldByName(nv)->AsString;
}
}
delete ow,nv;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm6::FormActivate(TObject *Sender)
{
INSB();
}
//---------------------------------------------------------------------------
void __fastcall TForm6::INSB(void)
{
for(int i=1;i<=7;i++)
StringGrid1->Cells[0][i]=i;
StringGrid1->Cells[1][0]="星期一";
StringGrid1->Cells[2][0]="星期二";
StringGrid1->Cells[3][0]="星期三";
StringGrid1->Cells[4][0]="星期四";
StringGrid1->Cells[5][0]="星期五";
StringGrid1->Cells[6][0]="星期六";
for(int i=0;i<=41;i++)
StringGrid1->Cells[i/7+1][i%7+1]="";
}
void __fastcall TForm6::N1Click(TObject *Sender)
{
if(lo1!=0&&ro1!=0){
int lo2,ro2;
char *ow1,*nv1,*ow2,*nv2;
char mb[4];
int kf;
kf=(lo1-1)*7+ro1;
ow1=new char[256];
nv1=new char[256];
ow2=new char[256];
nv2=new char[256];
strcpy(ow1,"TXM");
itoa(kf, mb, 10);
strcpy(nv1,"KCMC");
strcat(nv1,mb);
strcat(ow1,mb);
ComboBox2->Text=Form2->Table3->FieldByName(ow1)->AsString;
ld1=Form2->Table3->FieldByName(nv1)->AsString.Length();
lo2=StringGrid1->Col;
ro2=StringGrid1->Row;
kf=(lo2-1)*7+ro2;
itoa(kf, mb, 10);
strcpy(nv2,"KCMC");
strcat(nv2,mb);
int ld2;
ld2=Form2->Table3->FieldByName(nv2)->AsString.Length();
strcpy(ow2,"TXM");
strcat(ow2,mb);
Form2->Table3->Active = false;
Form2->Table3->IndexName="BJMC";
Form2->Table3->Active = true;
Form2->Table3->First();
bool ad1=true;
while(!Form2->Table3->Eof&&ad1&&ComboBox2->Text!=""){
if(Form2->Table3->FieldByName(ow2)->AsString==ComboBox2->Text){
ad1=false;
}
Form2->Table3->Next();
}
Form2->Table3->First();
bool ad2=true;
while(!Form2->Table3->Eof&&ad2&&StringGrid1->Cells[lo2][ro2].SubString(ld2+1,8)!=""){
if(Form2->Table3->FieldByName(ow1)->AsString==StringGrid1->Cells[lo2][ro2].SubString(ld2+1,8)){
ad2=false;
}
Form2->Table3->Next();
}
//Table3->RecNo=mbc; SubString(int index, int count)
Form2->Table3->FindKey(ARRAYOFCONST((ComboBox1->Text)));
if(ad1&&ad2&&pd==0){
Form2->Table3->Edit();
Form2->Table3->FieldByName(nv1)->AsString =StringGrid1->Cells[lo2][ro2].SubString(1,ld2);
Form2->Table3->FieldByName(ow1)->AsString =StringGrid1->Cells[lo2][ro2].SubString(ld2+1,8);
Form2->Table3->FieldByName(nv2)->AsString =StringGrid1->Cells[lo1][ro1].SubString(1,ld1);
Form2->Table3->FieldByName(ow2)->AsString =StringGrid1->Cells[lo1][ro1].SubString(ld1+1,8);
StringGrid1->Cells[lo1][ro1]=Form2->Table3->FieldByName(nv1)->AsString+Form2->Table3->FieldByName(ow1)->AsString;
StringGrid1->Cells[lo2][ro2]=Form2->Table3->FieldByName(nv2)->AsString+Form2->Table3->FieldByName(ow2)->AsString;
Form2->Table3->Post();
}
else if(ad1&&ad2&&pd==1){
pd=0;
char *ssd;
ssd=new char[250];
Set<TMsgDlgBtn,0,8>temp_set;
temp_set<<mbYes<<mbNo;
sprintf(ssd,"%s老师:\n 由于%s老师%s,\n(%s)%s的%s课同你%s的%s课相互调换。 \n %s ", StringGrid1->Cells[lo2][ro2].SubString(ld2+1,8).c_str(),StringGrid1->Cells[lo1][ro1].SubString(ld1+1,8).c_str(), ComboBox5->Text.c_str(),ComboBox1->Text.c_str(),AnsiString("星期"+AnsiString(lo1)+"第"+AnsiString(ro1)+"节").c_str(),StringGrid1->Cells[lo1][ro1].SubString(1,ld1).c_str(),AnsiString("星期"+AnsiString(lo2)+"第"+AnsiString(ro2)+"节").c_str(),StringGrid1->Cells[lo2][ro2].SubString(1,ld2).c_str(),DateToStr(Date()));
switch(MessageBox(Handle,ssd,"调课通知单",MB_YESNOCANCEL | MB_ICONQUESTION))
{
case mrNo:
break;
case mrYes:
Table2->Active = true;
Table2->AppendRecord(ARRAYOFCONST((DateToStr(Date()),AnsiString("星期"+AnsiString(lo1)+"第"+AnsiString(ro1)+"节"),AnsiString("星期"+AnsiString(lo2)+"第"+AnsiString(ro2)+"节"),StringGrid1->Cells[lo1][ro1].SubString(ld1+1,8),ComboBox1->Text,ComboBox5->Text))); //代,原。时间,课程,原因,班,节次
}
delete ssd;
}
else
ShowMessage("由于两位教师任课有冲突,这两节课不能相互调换");
delete ow1,ow2,nv1,nv2;
lo1=0;
ro1=0;
Label3->Caption="";
}
}
//---------------------------------------------------------------------------
void __fastcall TForm6::StringGrid1DblClick(TObject *Sender)
{
if(ComboBox1->Visible==true&&msq==0){
lo1=StringGrid1->Col;
ro1=StringGrid1->Row;
Label3->Caption="选择了星期"+AnsiString(lo1)+"第"+AnsiString(ro1)+"节";
}
}
//---------------------------------------------------------------------------
void __fastcall TForm6::N2Click(TObject *Sender)
{
// char *ow1,*nv1,*ow2,*nv2;
if(ComboBox2->Visible==true&&msq==1){
RadioGroup1->Visible=false;
ComboBox4->Visible=true;
Label5->Visible=true;
ComboBox5->Visible=true;
Label6->Visible=true;
char *ow2,*nv2;
char mb[4];
int kf;
//ow1=new char[256];
// nv1=new char[256];
ow2=new char[256];
nv2=new char[256];
lo3=StringGrid1->Col;
ro3=StringGrid1->Row;
kf=(lo3-1)*7+ro3;
itoa(kf, mb, 10);
strcpy(nv2,"KCMC");
strcat(nv2,mb);
// int ld2;
ld3=Form2->Table3->FieldByName(nv2)->AsString.Length();
strcpy(ow2,"TXM");
strcat(ow2,mb);
ComboBox4->Items->Clear();
Form3->Table1->Active = true;
Form3->Table1->First();
while(!Form3->Table1->Eof&&ComboBox2->Text!=""){
ComboBox4->Text=Form3->Table1->FieldByName("TXM")->AsString;
if(ComboBox4->Text!=ComboBox2->Text){
Form2->Table3->Active = false;
Form2->Table3->IndexName="BJMC";
Form2->Table3->Active = true;
Form2->Table3->First();
bool ad1=true;
while(!Form2->Table3->Eof&&ad1){
if(Form2->Table3->FieldByName(ow2)->AsString==ComboBox4->Text)
ad1=false;
Form2->Table3->Next();
}
if(ad1)
ComboBox4->Items->Add(ComboBox4->Text);
}
Form3->Table1->Next();
}
ComboBox4->ItemIndex=0;
delete ow2,nv2;
}
else
ShowMessage("在按教师查询时才可以进行代课设置。");
}
//---------------------------------------------------------------------------
void __fastcall TForm6::N3Click(TObject *Sender)
{
pd=1;
N1Click(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm6::Button3Click(TObject *Sender)
{
Table3->Active = false; // 复制结果空表
Table3->TableName= "jg.dbf";
Table3->IndexName="";
Table3->Active = true;
Table3->Active = false; //
Table3->TableType = ttFoxPro;
if(ComboBox1->Visible==true&&msq==0)
Table3->TableName= ComboBox1->Text+".dbf";
else if(ComboBox2->Visible==true&&msq==1)
Table3->TableName= ComboBox2->Text+".dbf";
else if(ComboBox3->Visible==true&&msq==2)
Table3->TableName= ComboBox3->Text+".dbf";
else
Table3->TableName="";
if(Table3->TableName!=""){
Table3->CreateTable();
Table3->Active = true;
for(int i=1;i<8;i++)
Table3->AppendRecord(ARRAYOFCONST((i)));
Table3->First();
for(int i=1;i<7;i++){
for(int j=1;j<=7;j++){
Table3->Edit();
Table3->Fields->Fields[i]->AsString = StringGrid1->Cells[i][j];
Table3->Next();
}
Table3->First();
}
ShowMessage("已经成功的将本次查询结果输出到文件了。");
}
else
ShowMessage("由于对话框于功课表条目不一致,未能将本次查询结果输出到文件。");
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -