//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "CalFee.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfmCalFee *fmCalFee;
//---------------------------------------------------------------------------
__fastcall TfmCalFee::TfmCalFee(TComponent* Owner)
: TForm(Owner)
{
StringGrid1->ColWidths[0] = 80;
StringGrid1->ColWidths[1] = 150;
StringGrid1->Cells[0][0] = "编号(拼音回车)";
StringGrid1->Cells[1][0] = "名称";
StringGrid1->Cells[2][0] = "规格";
StringGrid1->Cells[3][0] = "单位";
StringGrid1->Cells[4][0] = "单价";
StringGrid1->Cells[5][0] = "数量";
StringGrid1->Cells[6][0] = "金额";
// 设置combobox列表值
pQuery->DatabaseName = "db";
pQuery->SQL->Clear();
pQuery->SQL->Add("select 名称 from 科室资料");
pQuery->Open();
while(!pQuery->Eof)
{
ComboBox2->Items->Add(pQuery->FieldByName("名称")->AsString);
pQuery->Next();
}
// 设置医生combobox
pQuery->SQL->Clear();
pQuery->SQL->Add("select 姓名 from 医生资料");
pQuery->Open();
while(!pQuery->Eof)
{
ComboBox3->Items->Add(pQuery->FieldByName("姓名")->AsString);
pQuery->Next();
}
Edit1->Text = "";
Edit2->Text = "";
Edit3->Text = "0";
ComboBox1->Text = "";
ComboBox2->Text = "";
ComboBox3->Text = "";
StringGrid1->Col = 0;
StringGrid1->Row = 1;
m_nCurRow = 1;
m_nCurCol = 0;
}
//---------------------------------------------------------------------------
void __fastcall TfmCalFee::FormClose(TObject *Sender, TCloseAction &Action)
{
// 删除窗体并回收空间
Action = caFree;
}
//---------------------------------------------------------------------------
void __fastcall TfmCalFee::ComboBox1DropDown(TObject *Sender)
{
DBGrid1->Visible = true;
DBGrid1->SetFocus();
}
//---------------------------------------------------------------------------
void __fastcall TfmCalFee::DBGrid1KeyUp(TObject *Sender, WORD &Key,
TShiftState Shift)
{
// 设置门诊号及相应信息
if(Key == 13)
{
DBGrid1DblClick(NULL);
}
}
//---------------------------------------------------------------------------
void __fastcall TfmCalFee::DBGrid1DblClick(TObject *Sender)
{
// 设置门诊号及相应信息
ComboBox1->Text = Table1->FieldByName("编号")->AsString;
Edit1->Text = Table1->FieldByName("姓名")->AsString;
Edit2->Text = Table1->FieldByName("性别")->AsString;
ComboBox2->Text = Table1->FieldByName("挂号科室")->AsString;
ComboBox3->Text = Table1->FieldByName("医生")->AsString;
DBGrid1->Visible = false;
}
//---------------------------------------------------------------------------
void __fastcall TfmCalFee::StringGrid1SelectCell(TObject *Sender, int ACol,
int ARow, bool &CanSelect)
{
// 名称/规格/单位/单价列不可以输入
if(ACol == 1 || ACol == 2 || ACol == 3 || ACol == 4 || ACol == 6 )
CanSelect = false;
// 计算金额合计
if(m_nCurCol == 5 &&
StringGrid1->Cells[5][m_nCurRow].Length()>0 &&
StringGrid1->Cells[4][m_nCurRow].Length()>0 )
{
try
{
double dNum = 0;
double dPrice = 0;
dNum = StrToFloat(StringGrid1->Cells[5][m_nCurRow]);
dPrice = StrToFloat(StringGrid1->Cells[4][m_nCurRow]);
StringGrid1->Cells[6][m_nCurRow] =
FloatToStr(dNum * dPrice);
}
catch(...)
{
}
// 合计总金额
double dTotal = 0;
for(int i=1; i<50; i++)
{
if(StringGrid1->Cells[6][i].Trim().Length()>0)
dTotal += StrToFloat(StringGrid1->Cells[6][i]);
}
Edit3->Text = FloatToStr(dTotal);
}
m_nCurCol = ACol;
m_nCurRow = ARow;
}
//---------------------------------------------------------------------------
void __fastcall TfmCalFee::StringGrid1KeyPress(TObject *Sender, char &Key)
{
// 根据拼音选择收费项目
if(Key == 13 && m_nCurCol == 0)
{
Table2->Filtered = "";
Table2->Filtered = false;
Table2->Filter = "拼音码 = '" + StringGrid1->Cells[0][m_nCurRow] + "*'";
Table2->Filtered = true;
DBGrid2->Visible = true;
DBGrid2->SetFocus();
}
else if(Key == 13 && m_nCurCol == 5)
// 跳到下一行输入
{
StringGrid1->Row = StringGrid1->Row + 1;
StringGrid1->Col = 0;
}
}
//---------------------------------------------------------------------------
void __fastcall TfmCalFee::DBGrid2DblClick(TObject *Sender)
{
// 设置选择项目相应信息
StringGrid1->Cells[0][m_nCurRow] =
Table2->FieldByName("编号")->AsString;
StringGrid1->Cells[1][m_nCurRow] =
Table2->FieldByName("名称")->AsString;
StringGrid1->Cells[2][m_nCurRow] =
Table2->FieldByName("规格")->AsString;
StringGrid1->Cells[3][m_nCurRow] =
Table2->FieldByName("单位")->AsString;
StringGrid1->Cells[4][m_nCurRow] =
Table2->FieldByName("单价")->AsString;
DBGrid2->Visible = false;
// 跳转到数量输入
StringGrid1->Cells[5][m_nCurRow] = 1;
StringGrid1->Col = 5;
StringGrid1->SetFocus();
//StringGrid1->Options << goEditing;
}
//---------------------------------------------------------------------------
void __fastcall TfmCalFee::DBGrid2KeyUp(TObject *Sender, WORD &Key,
TShiftState Shift)
{
// 设置选择项目相应信息
if(Key == 13)
{
DBGrid2DblClick(NULL);
}
}
//---------------------------------------------------------------------------
void __fastcall TfmCalFee::BitBtn1Click(TObject *Sender)
{
// 保存数据
// 先检查合法性
if(ComboBox1->Text.IsEmpty() || ComboBox2->Text.IsEmpty() ||
ComboBox3->Text.IsEmpty())
{
Application->MessageBox("门诊号,科室,医生 为必填字段","请检查",MB_OK);
return;
}
if(StrToFloat(Edit3->Text)==0)
{
Application->MessageBox("没有划价明细","请检查",MB_OK);
return;
}
// 写入主表
//获得最大编号
pQuery->DatabaseName = "db";
TDateTime dt;
dt = dt.CurrentDateTime();
unsigned short nyear, nmonth, nday;
int nID = 1;
AnsiString szID;
dt.DecodeDate(&nyear, &nmonth, &nday);
// 编号带年份
AnsiString sql;
sql = "select max(编号) as 编号 from 门诊划价 where 编号 like '";
sql += IntToStr(nyear) + "%'";
pQuery->SQL->Clear();
pQuery->SQL->Add(sql);
pQuery->Open();
if(pQuery->RecordCount > 0 &&
!pQuery->FieldByName("编号")->AsString.IsEmpty())
{
szID = pQuery->FieldByName("编号")->AsString;
nID = StrToInt(szID.SubString(5,7));
nID ++;
}
szID = IntToStr(nID);
// 编号补足7位
while(szID.Length()<7)
szID = "0" + szID;
szID = IntToStr(nyear) + szID;
// 写入主表 门诊划价
pQuery->SQL->Clear();
sql = "Insert into 门诊划价(编号, 科室, 挂号编号, 医生, 划价时间, ";
sql += "划价员, 是否收费,划价金额, 是否发药) values ('";
sql += szID + "','";
sql += ComboBox2->Text + "','";
sql += ComboBox1->Text + "','";
sql += ComboBox3->Text + "','";
sql += dt.DateTimeString() + "','";
sql += "张三','否',";
sql += Edit3->Text + ",'否')";
pQuery->SQL->Add(sql);
pQuery->ExecSQL();
// 写入从表,明细表
for(int i=1; i<50; i++)
{
if(StringGrid1->Cells[6][i].Trim().Length()== 0 ||
StringGrid1->Cells[1][i].Trim().Length()== 0 ||
StringGrid1->Cells[5][i].Trim().Length()== 0 )
continue;
pQuery->SQL->Clear();
sql = "Insert into 门诊划价明细(划价编号, 药品编号, 单价, 数量, 金额)";
sql += " values ('";