uMain.cpp
上传用户:liuxiao
上传日期:2022-07-06
资源大小:1115k
文件大小:19k
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "uMain.h"
- #include "uCommon.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma link "frxClass"
- #pragma link "frxPreview"
- #pragma link "WinSkinData"
- #pragma link "frxDBSet"
- #pragma link "frxDesgn"
- #pragma resource "*.dfm"
- TfrmMain *frmMain;
- //---------------------------------------------------------------------------
- __fastcall TfrmMain::TfrmMain(TComponent* Owner)
- : TForm(Owner)
- {
- //
- Caption = g_strAppTitle;
- Application->Title = g_strAppTitle;
- // 使用皮肤
- sknMain->Active = true;
- // 连接数据库
- con->Connected = false;
- con->ConnectionString = String("Provider=Microsoft.Jet.OLEDB.4.0;")
- + "Data Source=" + ExtractFilePath(ParamStr(0)) + "data.mdb;"
- + "Persist Security Info=False";
- con->Connected = true;
- //
- tblTemp->Open();
- // 默认为欢迎页面
- pgcMain->ActivePageIndex = 0;
- //
- lblAppTitle->Caption = g_strAppTitle;
- lblAppTitle->Left = (Width - lblAppTitle->Width) / 2;
- lblAppVer->Caption = g_strAppVer;
- lblAppVer->Left = lblAppTitle->Left + (lblAppTitle->Width - lblAppVer->Width);
- //
- dtpGenBillDate->Date = Now();
- dtpQueryStart->Date = Now();
- dtpQueryEnd->Date = Now();
- //
- // frReport->AddFunction("function NumToRMBStr(fValue: DOUBLE): String;", "Myfunction", "小写金额转大写的函数");
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::btnCloseOrderClick(TObject *Sender)
- {
- pgcMain->ActivePageIndex = 0;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::miExitAppClick(TObject *Sender)
- {
- Close();
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::miShowOrderClick(TObject *Sender)
- {
- pgcMain->ActivePageIndex = 1;
- if(!tblTemp->Active)
- tblTemp->Active = true;
- if(tblTemp->RecordCount)
- {
- tblTemp->First();
- while(!tblTemp->Eof)
- tblTemp->Delete();
- }
- CrnClearOrderForm();
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::miShowQueryClick(TObject *Sender)
- {
- pgcMain->ActivePageIndex = 2;
- btnQueryAllClick(Sender);
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::miPrintBillClick(TObject *Sender)
- {
- if(qryOrder->Active && qryOrder->RecordCount)
- {
- if(MessageBox(Handle,
- String().sprintf("确定要打印单据号为 %s 的这条记录吗? ",
- qryOrder->FieldByName("fBillNumber")->AsString).c_str(),
- g_strAppName.c_str(),
- MB_YESNO | MB_ICONQUESTION) == IDYES)
- {
- frReport->LoadFromFile(ExtractFilePath(ParamStr(0)) + "Report.fr3");
- ((TfrxMemoView *)frReport->FindObject("mmoTitle"))->Memo->Text =
- qryOrder->FieldByName("fTitle")->AsString; // + " ";;
- ((TfrxMemoView *)frReport->FindObject("mmoBillNumber"))->Memo->Text =
- qryOrder->FieldByName("fBillNumber")->AsString; // + " ";;
- ((TfrxMemoView *)frReport->FindObject("mmoClient"))->Memo->Text =
- qryOrder->FieldByName("fClient")->AsString; // + " ";;
- ((TfrxMemoView *)frReport->FindObject("mmoGenBillDate"))->Memo->Text =
- FormatDateTime("yyyy-mm-dd",
- qryOrder->FieldByName("fGenBillDate")->AsDateTime);
- ((TfrxMemoView *)frReport->FindObject("mmoOpera"))->Memo->Text =
- qryOrder->FieldByName("fOpera")->AsString; // + " ";
- ((TfrxMemoView *)frReport->FindObject("mmoBillAuthor"))->Memo->Text =
- qryOrder->FieldByName("fBillAuthor")->AsString; // + " ";
- ((TfrxMemoView *)frReport->FindObject("mmoDiscount"))->Memo->Text =
- String("让利 ¥") + FormatFloat("#0.00#",
- qryOrder->FieldByName("fDiscount")->AsFloat);
- ((TfrxMemoView *)frReport->FindObject("Memo30"))->Memo->Text =
- qryOrder->FieldByName("fAddress")->AsString;
- ((TfrxMemoView *)frReport->FindObject("Memo32"))->Memo->Text =
- qryOrder->FieldByName("fTel")->AsString;
- ((TfrxMemoView *)frReport->FindObject("Memo34"))->Memo->Text =
- qryOrder->FieldByName("fGath")->AsString;
- ((TfrxMemoView *)frReport->FindObject("Memo36"))->Memo->Text =
- qryOrder->FieldByName("fIssue")->AsString;
- ((TfrxMemoView *)frReport->FindObject("Memo38"))->Memo->Text =
- qryOrder->FieldByName("fCheck")->AsString;
- ((TfrxMemoView *)frReport->FindObject("Memo40"))->Memo->Text =
- qryOrder->FieldByName("fHotLine")->AsString;
- float fSumValue = 0.0;
- qryDetail->First();
- for(int i=0; i<qryDetail->RecordCount; i++)
- {
- fSumValue += qryDetail->FieldByName("fSum")->AsFloat;
- qryDetail->Next();
- }
- ((TfrxMemoView *)frReport->FindObject("mmoSumValue"))->Memo->Text =
- FormatFloat("#0.00#", fSumValue);
- ((TfrxMemoView *)frReport->FindObject("mmoRMBStr"))->Memo->Text =
- NumToRMBStr(fSumValue);
-
- qryDetail->First();
- frReport->ShowReport();
- }
- }
- else
- {
- MessageBox(Handle, "请先选择一条订单再选择打印",
- g_strAppName.c_str(), MB_OK | MB_ICONINFORMATION);
- pgcMain->ActivePageIndex = 2;
- btnQueryAllClick(Sender);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::miShowAboutClick(TObject *Sender)
- {
- MessageBox(Handle,
- (g_strAppTitle + g_strAppVer + "rn"
- + "-------------------------rn"
- + "by CrazyCamel(CrazyCamel@126.com)rn"
- + "2006.12 - -#").c_str(),
- g_strAppName.c_str(),
- MB_OK | MB_ICONINFORMATION);
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::FormKeyPress(TObject *Sender, char &Key)
- {
- if(Key == VK_RETURN)
- {
- Key = 0;
- SelectNext(ActiveControl, true, true);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::tmrClockTimer(TObject *Sender)
- {
- stbMain->Panels->Items[1]->Text = FormatDateTime(" yyyy-mm-dd hh:nn:ss", Now());
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::CrnClearOrderForm()
- {
- for(int i=0; i<ComponentCount; i++)
- {
- if(Components[i]->ClassNameIs("TLabeledEdit"))
- if(((TLabeledEdit *)Components[i])->Parent == tsOrder)
- ((TLabeledEdit *)Components[i])->Text = "";
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::btnContinueDetailClick(TObject *Sender)
- {
- if(edtTitle->Text.Trim().Length() < 1)
- {
- MessageBox(Handle, "单据标题必须填写!",
- g_strAppName.c_str(),
- MB_OK | MB_ICONWARNING);
- pgcMain->ActivePageIndex = 1;
- return;
- }
- pgcMain->ActivePageIndex = 2;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::btnOrderInfoClick(TObject *Sender)
- {
- pgcMain->ActivePageIndex = 1;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::btnSaveAndPrintClick(TObject *Sender)
- {
- qryOrder->Close();
- qryOrder->SQL->Text = String().sprintf(
- "select top 1 * from tblOrder where fBillNumber='%s'",
- edtBillNumber->Text);
- qryOrder->Open();
- if(qryOrder->RecordCount)
- {
- MessageBox(Handle, "已经存在相同单据号的订单记录!",
- g_strAppName.c_str(), MB_OK | MB_ICONWARNING);
- edtBillNumber->SetFocus();
- return;
- }
- if(tblTemp->RecordCount < 1)
- {
- MessageBox(Handle, "至少要输入一条药品明细记录!",
- g_strAppName.c_str(), MB_OK | MB_ICONWARNING);
- dbgrdTemp->SetFocus();
- return;
- }
- qryOrder->Append();
- qryOrder->FieldByName("fBillNumber")->AsString = edtBillNumber->Text;
- qryOrder->FieldByName("fGenBillDate")->AsDateTime = dtpGenBillDate->Date;
- qryOrder->FieldByName("fClient")->AsString = edtClient->Text;
- qryOrder->FieldByName("fOpera")->AsString = edtOpera->Text;
- qryOrder->FieldByName("fBillAuthor")->AsString = edtBillAuthor->Text;
- qryOrder->FieldByName("fAddress")->AsString = edtAddress->Text;
- qryOrder->FieldByName("fTel")->AsString = edtTel->Text;
- qryOrder->FieldByName("fGath")->AsString = edtGath->Text;
- qryOrder->FieldByName("fIssue")->AsString = edtIssue->Text;
- qryOrder->FieldByName("fCheck")->AsString = edtCheck->Text;
- qryOrder->FieldByName("fHotLine")->AsString = edtHotLine->Text;
- qryOrder->FieldByName("fTitle")->AsString = edtTitle->Text;
- qryOrder->Post();
- qryDetail->Close();
- qryDetail->SQL->Text = "select top 1 * from tblDetail";
- qryDetail->Open();
- int nCount = tblTemp->RecordCount;
- tblTemp->First();
-
- for(int i=0; i<nCount; i++)
- {
- qryDetail->Append();
- qryDetail->FieldByName("fBillNumber")->AsString = edtBillNumber->Text;
- qryDetail->FieldByName("fBatchNumber")->AsString = tblTemp->FieldByName("fBatchNumber")->AsString;
- qryDetail->FieldByName("fLeechdom")->AsString = tblTemp->FieldByName("fLeechdom")->AsString;
- qryDetail->FieldByName("fSpec")->AsString = tblTemp->FieldByName("fSpec")->AsString;
- qryDetail->FieldByName("fProFact")->AsString = tblTemp->FieldByName("fProFact")->AsString;
- qryDetail->FieldByName("fUnit")->AsString = tblTemp->FieldByName("fUnit")->AsString;
- qryDetail->FieldByName("fAmount")->AsInteger = tblTemp->FieldByName("fAmount")->AsInteger;
- qryDetail->FieldByName("fUnitPrice")->AsCurrency = tblTemp->FieldByName("fUnitPrice")->AsCurrency;
- qryDetail->FieldByName("fSum")->AsCurrency = tblTemp->FieldByName("fSum")->AsCurrency;
- qryDetail->FieldByName("fRefer")->AsCurrency = tblTemp->FieldByName("fRefer")->AsCurrency;
- qryDetail->FieldByName("fCasing")->AsString = tblTemp->FieldByName("fCasing")->AsString;
- qryDetail->FieldByName("fBale")->AsString = tblTemp->FieldByName("fBale")->AsString;
- qryDetail->Post();
- tblTemp->Next();
- }
- if(nCount)
- {
- tblTemp->First();
- while(!tblTemp->Eof)
- tblTemp->Delete();
- }
- MessageBox(Handle,
- String().sprintf("订单添加成功. 共有 %d 条药品明细.", nCount).c_str(),
- g_strAppName.c_str(),
- MB_OK | MB_ICONINFORMATION);
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::btnQueryAllClick(TObject *Sender)
- {
- qryOrder->Close();
- qryOrder->SQL->Text = "select * from tblOrder";
- qryOrder->Open();
- dbgrdOrderCellClick(NULL);
- stbMain->Panels->Items[0]->Text = String().sprintf("共有 %d 条订单记录.", qryOrder->RecordCount);
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::btnQueryClick(TObject *Sender)
- {
- String strSQL("");
- if(edtQueryByBillNumber->Text.Trim().Length() > 0)
- strSQL += String().sprintf(" and fBillNumber='%s'", edtQueryByBillNumber->Text);
- if(edtQueryByClient->Text.Trim().Length() > 0)
- strSQL += String().sprintf(" and fClient like '%%%s%%'", edtQueryByClient->Text);
- if(edtQueryByBillAuthor->Text.Trim().Length() > 0)
- strSQL = String().sprintf(" and fBillAuthor='%s'", edtQueryByBillAuthor->Text);
- if(edtQueryByOpera->Text.Trim().Length() > 0)
- strSQL = String().sprintf(" and fOpera='%s'", edtQueryByOpera->Text);
- if(chkQueryByDate->Checked)
- strSQL = String().sprintf(" and fGenBillDate between #%s# and #%s#",
- FormatDateTime("yyy-mm-dd", dtpQueryStart->Date),
- FormatDateTime("yyy-mm-dd", dtpQueryEnd->Date + 1));
- qryOrder->Close();
- qryOrder->SQL->Text = "select * from tblOrder where 1=1" + strSQL;
- qryOrder->Open();
- if(qryOrder->RecordCount)
- {
- qryDetail->Close();
- qryDetail->SQL->Text = String().sprintf(
- "select * from tblDetail where fBillNumber='%s'",
- qryOrder->FieldByName("fBillNumber")->AsString);
- qryDetail->Open();
- }
- stbMain->Panels->Items[0]->Text = String().sprintf("共有 %d 条订单记录.", qryOrder->RecordCount);
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::btnDeleteOrderClick(TObject *Sender)
- {
- if(qryOrder->Active && qryOrder->RecordCount)
- {
- if(MessageBox(Handle,
- String().sprintf("确定要删除单据号为 %s 的这条记录吗? "
- "相关的药品明细记录也将删除.",
- qryOrder->FieldByName("fBillNumber")->AsString).c_str(),
- g_strAppName.c_str(),
- MB_YESNO | MB_ICONQUESTION) == IDYES)
- {
- //
- qryDetail->Close();
- qryDetail->SQL->Text = String().sprintf(
- "delete from tblDetail where fBillNumber='%s'",
- qryOrder->FieldByName("fBillNumber")->AsString);
- qryDetail->ExecSQL();
- //
- qryOrder->Delete();
- }
- btnQueryAllClick(Sender);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::btnDeleteDetailClick(TObject *Sender)
- {
- if(qryDetail->Active && qryDetail->RecordCount)
- {
- if(MessageBox(Handle,
- String().sprintf("确定要删除批号为 %s 的这条记录吗?",
- qryDetail->FieldByName("fBatchNumber")->AsString).c_str(),
- g_strAppName.c_str(),
- MB_YESNO | MB_ICONQUESTION) == IDYES)
- {
- qryDetail->Delete();
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::btnClearDetailClick(TObject *Sender)
- {
- CrnClearOrderForm();
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::dbgrdOrderCellClick(TColumn *Column)
- {
- if(qryOrder->RecordCount)
- {
- qryDetail->Close();
- qryDetail->SQL->Text = String().sprintf(
- "select * "
- "from tblDetail "
- "where fBillNumber='%s'",
- qryOrder->FieldByName("fBillNumber")->AsString);
- qryDetail->Open();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::btnSaveDetailClick(TObject *Sender)
- {
- if(qryDetail->State == dsEdit || qryDetail->State == dsInsert)
- qryDetail->Post();
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::btnSaveOrderClick(TObject *Sender)
- {
- if(qryOrder->State == dsEdit || qryOrder->State == dsInsert)
- qryOrder->Post();
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::btnDeleteTempClick(TObject *Sender)
- {
- if(tblTemp->Active && tblTemp->RecordCount)
- {
- if(MessageBox(Handle,
- String().sprintf("确定要删除批号为 %s 的这条记录吗?",
- tblTemp->FieldByName("fBatchNumber")->AsString).c_str(),
- g_strAppName.c_str(),
- MB_YESNO | MB_ICONQUESTION) == IDYES)
- {
- tblTemp->Delete();
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::btnSaveTempClick(TObject *Sender)
- {
- if(tblTemp->State == dsEdit || tblTemp->State == dsInsert)
- tblTemp->Post();
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::qryDetailBeforePost(TDataSet *DataSet)
- {
- if(DataSet->FieldByName("fBillNumber")->AsString.Trim().Length() < 1)
- {
- if(qryOrder->Active && qryOrder->RecordCount)
- DataSet->FieldByName("fBillNumber")->AsString =
- qryOrder->FieldByName("fBillNumber")->AsString;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::miDesignReportClick(TObject *Sender)
- {
- frReport->LoadFromFile(ExtractFilePath(ParamStr(0)) + "Report.fr3");
- frReport->DesignReport();
- }
- //---------------------------------------------------------------------------
- Variant __fastcall TfrmMain::frReportUserFunction(
- const AnsiString MethodName, Variant &Params)
- {
- // if(UpperCase(MethodName) == UpperCase("NumToRMBStr"))
- // return NumToRMBStr(Params.GetElement(0));
- return 0;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::qryDetailAfterInsert(TDataSet *DataSet)
- {
- DataSet->FieldByName("fAmount")->AsInteger = 0;
- DataSet->FieldByName("fUnitPrice")->AsFloat = 0.0;
- DataSet->FieldByName("fSum")->AsFloat = 0.0;
- DataSet->FieldByName("fRefer")->AsFloat = 0.0;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::tblTempAfterInsert(TDataSet *DataSet)
- {
- DataSet->FieldByName("fAmount")->AsInteger = 0;
- DataSet->FieldByName("fUnitPrice")->AsFloat = 0.0;
- DataSet->FieldByName("fSum")->AsFloat = 0.0;
- DataSet->FieldByName("fRefer")->AsFloat = 0.0;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::tblTempfUnitPriceChange(TField *Sender)
- {
- Sender->DataSet->FieldByName("FSum")->AsCurrency = Sender->AsCurrency
- * Sender->DataSet->FieldByName("fAmount")->AsCurrency;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::tblTempfAmountChange(TField *Sender)
- {
- Sender->DataSet->FieldByName("FSum")->AsCurrency = Sender->AsCurrency
- * Sender->DataSet->FieldByName("fUnitPrice")->AsCurrency;
- }
- //---------------------------------------------------------------------------