- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
BitBtn1->Enabled=false;
String KolDaysInMonth=MonthDays[IsLeapYear(Edit1->Text.ToInt())][ComboBox1->ItemIndex];//кол-во дней в месяце выбранного года
String TimeOT="cast('"+String(ComboBox1->ItemIndex+1)+".01."+Edit1->Text+" 00:00:00' as datetime)";
String TimeDO="cast('"+String(ComboBox1->ItemIndex+1)+"."+KolDaysInMonth+"."+Edit1->Text+" 23:59:59' as datetime)";
String BTWOTDO="BETWEEN "+TimeOT+" and "+TimeDO;
AnsiString NomZav="";
AnsiString NomPar="";
//заявки
ADOQuery1->Close(); //and nomzav NOT IN (select distinct nomzav from ochzav.dbf where deleted=0 and nomopr IN (select distinct nomoprl from kompar.dbf where deleted=0 and nompar IN (select distinct nompar from kompar.dbf where deleted=0 and datzaob NOT "+BTWOTDO+")))
ADOQuery1->SQL->Clear(); //and nomzav NOT IN (select distinct nomzav from ochzav.dbf where deleted=0 and dakote NOT "+BTWOTDO+")
ADOQuery1->SQL->Add("select distinct nomzav from ochzav.dbf where deleted=0 and dakote "+BTWOTDO+" and nomzav NOT IN (select distinct nomzav from ochzav.dbf where deleted=0 and dakote>"+TimeDO+") and nomzav NOT IN (select distinct nomzav from ochzav.dbf where deleted=0 and nomopr IN (select distinct nomoprl from kompar.dbf where deleted=0 and datzaob IS NULL)) and nomzav NOT IN (select distinct nomzav from ochzav.dbf where deleted=0 and nomopr IN (select distinct nomoprl from kompar.dbf where deleted=0 and nompar IN (select distinct nompar from kompar.dbf where deleted=0 and nomoprl IN (select distinct nomopr from ochzav.dbf where deleted=0 and dakote IS NULL))))");
ADOQuery1->Open();
if (!ADOQuery1->Eof) {//если что то нашлось
while (!ADOQuery1->Eof) {
NomZav=NomZav+"'"+ADOQuery1->FieldByName("nomzav")->AsString.Trim()+"',";
ADOQuery1->Next();
}
NomZav=NomZav.Delete(NomZav.Length(),1);//обрезаем запятую на конце
//партии
ADOQuery1->Close();
ADOQuery1->SQL->Clear(); //and nompar NOT IN (select distinct nompar from kompar.dbf where deleted=0 and datzaob NOT "+BTWOTDO+")
ADOQuery1->SQL->Add("select distinct nompar from kompar.dbf where deleted=0 and nompar IN (select distinct nompar from kompar.dbf where deleted=0 and nomoprl IN (select distinct nomopr from ochzav.dbf where deleted=0 and nomzav IN ("+NomZav+")))");
ADOQuery1->Open();
if (!ADOQuery1->Eof) {//если что то нашлось
while (!ADOQuery1->Eof) {
NomPar=NomPar+"'"+ADOQuery1->FieldByName("nompar")->AsString.Trim()+"',";
ADOQuery1->Next();
}
NomPar=NomPar.Delete(NomPar.Length(),1);//обрезаем запятую на конце
}
}
if (NomZav.Trim().Length()==0||NomPar.Trim().Length()==0) {
ShowMessage("Не найденно завершённых заявок и партий за "+ComboBox1->Text+" "+Edit1->Text+" года");
BitBtn1->Enabled=true;
Abort();
}
if (Application->MessageBoxA(AnsiString("Вы действительно хотите удалить все завершённые заявки и партии за "+ComboBox1->Text+" "+Edit1->Text+" года?\n\n"
"Завершённые заявки: "+NomZav+"\nЗавершённые партии: "+NomPar).c_str(),"Удаление завершённых заявок и партий",MB_YESNO)==IDYES) {
//удаление партий из ochpar.dbf
ADOQuery1->Close();
ADOQuery1->SQL->Clear();
ADOQuery1->SQL->Add("update ochpar.dbf set deleted=1 where deleted=0 and nompar IN ("+NomPar+")");
ADOQuery1->ExecSQL();
//удаление партий из kompar.dbf
ADOQuery1->Close();
ADOQuery1->SQL->Clear();
ADOQuery1->SQL->Add("update kompar.dbf set deleted=1 where deleted=0 and nompar IN ("+NomPar+")");
ADOQuery1->ExecSQL();
//удаление заявок из ochzav.dbf
ADOQuery1->Close();
ADOQuery1->SQL->Clear();
ADOQuery1->SQL->Add("update ochzav.dbf set deleted=1 where deleted=0 and nomzav IN ("+NomZav+")");
ADOQuery1->ExecSQL();
ShowMessage("Удаление партий и заявок за "+ComboBox1->Text+" "+Edit1->Text+" года завершено успешно");
}
BitBtn1->Enabled=true;
}
Комментарии (0) RSS
Добавить комментарий