- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "Main.h"
- #include "login.h"
- #include "GoodManage.h"
- #include "SupplyManage.h"
- #include "CustomManage.h"
- #include "PurchaseManage.h"
- #include "SaleManage.h"
- #include "StoreQuery.h"
- #include "Right.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TfmMain *fmMain;
- //---------------------------------------------------------------------------
- __fastcall TfmMain::TfmMain(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TfmMain::FormCreate(TObject *Sender)
- {
- TfmLogin *pForm = new TfmLogin(Application);
- pForm->ShowModal();
- if(pForm->m_szUserCode.IsEmpty())
- // 取消了,退出程序
- {
- Application->Terminate();
- }
- else
- {
- m_szUserCode = pForm->m_szUserCode;
- m_szUserName = pForm->m_szUserName;
- StatusBar1->Panels->Items[1]->Text = m_szUserName;
- }
- delete pForm;
- // 设置功能菜单的状态,屏蔽用户不可操作的功能
- // 如果是系统管理员登录,则不设置
- if(m_szUserCode == "1") return;
- TQuery* pQuery = new TQuery(NULL);
- pQuery->DatabaseName = "db";
- pQuery->SQL->Add("select 权限名称 from 权限清单 where 用户编号='" + m_szUserCode + "'");
- pQuery->Open();
- TStringList* plst = new TStringList();
- while(!pQuery->Eof)
- {
- plst->Add(pQuery->FieldByName("权限名称")->AsString);
- pQuery->Next();
- }
- // 判断是否可操作,不在plst列表中表示不可操作,菜单变灰色
- for(int j=0; j<MainMenu1->Items->Count; j++)
- {
- TMenuItem* pItem = MainMenu1->Items->Items[j];
- for(int i=0; i<pItem->Count; i++)
- {
- TMenuItem* pSubItem = pItem->Items[i];
- if(pSubItem->Count == 0 && plst->IndexOf(pSubItem->Caption)<=0)
- pSubItem->Enabled = false;
- }
- }
- delete pQuery;
- delete plst;
- }
- //---------------------------------------------------------------------------
- TForm* TfmMain::FormExist(AnsiString szCaption)
- {
- for(int i=0; i<this->MDIChildCount; i++)
- {
- TForm *pForm = this->MDIChildren[i];
- if(pForm->Caption == szCaption)
- return pForm; // 已存在窗体,返回该窗体
- }
- return NULL; // 不存在窗体,返回空值
- }
- //---------------------------------------------------------------------------
- void __fastcall TfmMain::mnuGoodManageClick(TObject *Sender)
- {
- // 显示商品信息维护窗体
- TForm *pForm = FormExist("商品信息维护");
- // 如果已存在则激活,否则新建一个窗体
- if(pForm)
- pForm->SetFocus();
- else
- pForm = new TfmGoodManage(Application);
- pForm->Show();
- }
- //---------------------------------------------------------------------------
- void __fastcall TfmMain::mnuSupplyManageClick(TObject *Sender)
- {
- // 显示供货商信息维护窗体
- TForm *pForm = FormExist("供货商信息维护");
- // 如果已存在则激活,否则新建一个窗体
- if(pForm)
- pForm->SetFocus();
- else
- pForm = new TfmSupplyManage(Application);
- pForm->Show();
- }
- //---------------------------------------------------------------------------
- void __fastcall TfmMain::mnuCustomManageClick(TObject *Sender)
- {
- // 显示客户信息维护窗体
- TForm *pForm = FormExist("客户信息维护");
- // 如果已存在则激活,否则新建一个窗体
- if(pForm)
- pForm->SetFocus();
- else
- pForm = new TfmCustomManage(Application);
- pForm->Show();
- }
- //---------------------------------------------------------------------------
- void __fastcall TfmMain::mnuPurchaseManageClick(TObject *Sender)
- {
- // 显示进货单窗体
- TForm *pForm = FormExist("进货单");
- // 如果已存在则激活,否则新建一个窗体
- if(pForm)
- pForm->SetFocus();
- else
- pForm = new TfmPurchaseManage(Application);
- pForm->Show();
- }
- //---------------------------------------------------------------------------
- void __fastcall TfmMain::mnuSaleManageClick(TObject *Sender)
- {
- // 显示销售单窗体
- TForm *pForm = FormExist("销售单");
- // 如果已存在则激活,否则新建一个窗体
- if(pForm)
- pForm->SetFocus();
- else
- pForm = new TfmSaleManage(Application);
- pForm->Show();
- }
- //---------------------------------------------------------------------------
- void __fastcall TfmMain::mnuStockQueryClick(TObject *Sender)
- {
- // 显示库存查询窗体
- TForm *pForm = FormExist("库存查询");
- // 如果已存在则激活,否则新建一个窗体
- if(pForm)
- pForm->SetFocus();
- else
- pForm = new TfmStoreQuery(Application);
- pForm->Show();
- }
- //---------------------------------------------------------------------------
- void __fastcall TfmMain::mnuRightManageClick(TObject *Sender)
- {
- // 显示权限管理窗体
- TForm *pForm = FormExist("权限管理");
- // 如果已存在则激活,否则新建一个窗体
- if(pForm)
- pForm->SetFocus();
- else
- pForm = new TfmRightManage(Application);
- pForm->Show();
- }
- //---------------------------------------------------------------------------