📄 clientdatamanage.h
字号:
#pragma once
#include "LinkDataBase.h"
#include "DataGridComboBoxColumn.h"
#include "DataGridNoActiveCellColumn.h"
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
namespace My
{
/// <summary>
/// ClientDataManage 摘要
///
/// 警告: 如果您更改该类的名称,则将需要更改
/// 与该类所依赖的所有 .resx 文件关联的托管资源编译器工具的
/// “资源文件名”属性。 否则,
/// 设计器将不能与此窗体关联的
/// 本地化资源正确交互。
/// </summary>
public __gc class ClientDataManage : public System::Windows::Forms::Form
{
//--------------------成员声明------------------------
public:
String* SendClientID;
String* SendClientName;
private:
LinkDataBase* MyDataBase; //数据库连接类
DataSet* ds;
bool blSellTableShow;
String* strTableName;
private: System::Windows::Forms::GroupBox * groupBox1;
private: System::Windows::Forms::Label * label1;
private: System::Windows::Forms::Button * btnSearch;
private: System::Windows::Forms::TextBox * tboxClientWord;
String* strSQL;
//-------------------成员声明结束-----------------------
public:
ClientDataManage(void)
{
InitializeComponent();
}
protected:
void Dispose(Boolean disposing)
{
if (disposing && components)
{
components->Dispose();
}
__super::Dispose(disposing);
}
private: System::Windows::Forms::ToolBarButton * tbarDelete;
private: System::Windows::Forms::ImageList * imageList1;
private: System::Windows::Forms::ToolBar * toolBar1;
private: System::Windows::Forms::ToolBarButton * tbarSave;
private: System::Windows::Forms::DataGrid * dgrdClientData;
private: System::ComponentModel::IContainer * components;
private:
/// <summary>
/// 必需的设计器变量。
/// </summary>
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
void InitializeComponent(void)
{
this->components = new System::ComponentModel::Container();
System::Resources::ResourceManager * resources = new System::Resources::ResourceManager(__typeof(My::ClientDataManage));
this->tbarDelete = new System::Windows::Forms::ToolBarButton();
this->imageList1 = new System::Windows::Forms::ImageList(this->components);
this->toolBar1 = new System::Windows::Forms::ToolBar();
this->tbarSave = new System::Windows::Forms::ToolBarButton();
this->dgrdClientData = new System::Windows::Forms::DataGrid();
this->groupBox1 = new System::Windows::Forms::GroupBox();
this->label1 = new System::Windows::Forms::Label();
this->btnSearch = new System::Windows::Forms::Button();
this->tboxClientWord = new System::Windows::Forms::TextBox();
(__try_cast<System::ComponentModel::ISupportInitialize * >(this->dgrdClientData))->BeginInit();
this->groupBox1->SuspendLayout();
this->SuspendLayout();
//
// tbarDelete
//
this->tbarDelete->ImageIndex = 1;
this->tbarDelete->Text = S"删除";
this->tbarDelete->ToolTipText = S"删除数据";
//
// imageList1
//
this->imageList1->ImageSize = System::Drawing::Size(16, 16);
this->imageList1->ImageStream = (__try_cast<System::Windows::Forms::ImageListStreamer * >(resources->GetObject(S"imageList1.ImageStream")));
this->imageList1->TransparentColor = System::Drawing::Color::Transparent;
//
// toolBar1
//
System::Windows::Forms::ToolBarButton* __mcTemp__1[] = new System::Windows::Forms::ToolBarButton*[2];
__mcTemp__1[0] = this->tbarSave;
__mcTemp__1[1] = this->tbarDelete;
this->toolBar1->Buttons->AddRange(__mcTemp__1);
this->toolBar1->DropDownArrows = true;
this->toolBar1->ImageList = this->imageList1;
this->toolBar1->Location = System::Drawing::Point(0, 0);
this->toolBar1->Name = S"toolBar1";
this->toolBar1->ShowToolTips = true;
this->toolBar1->Size = System::Drawing::Size(744, 41);
this->toolBar1->TabIndex = 6;
this->toolBar1->ButtonClick += new System::Windows::Forms::ToolBarButtonClickEventHandler(this, toolBar1_ButtonClick);
//
// tbarSave
//
this->tbarSave->ImageIndex = 0;
this->tbarSave->Text = S"保存";
this->tbarSave->ToolTipText = S"保存修改";
//
// dgrdClientData
//
this->dgrdClientData->DataMember = S"";
this->dgrdClientData->Dock = System::Windows::Forms::DockStyle::Fill;
this->dgrdClientData->HeaderForeColor = System::Drawing::SystemColors::ControlText;
this->dgrdClientData->Location = System::Drawing::Point(0, 112);
this->dgrdClientData->Name = S"dgrdClientData";
this->dgrdClientData->Size = System::Drawing::Size(744, 293);
this->dgrdClientData->TabIndex = 5;
this->dgrdClientData->DoubleClick += new System::EventHandler(this, dgrdClientData_DoubleClick);
//
// groupBox1
//
this->groupBox1->Controls->Add(this->label1);
this->groupBox1->Controls->Add(this->btnSearch);
this->groupBox1->Controls->Add(this->tboxClientWord);
this->groupBox1->Dock = System::Windows::Forms::DockStyle::Top;
this->groupBox1->Location = System::Drawing::Point(0, 41);
this->groupBox1->Name = S"groupBox1";
this->groupBox1->Size = System::Drawing::Size(744, 71);
this->groupBox1->TabIndex = 10;
this->groupBox1->TabStop = false;
//
// label1
//
this->label1->Location = System::Drawing::Point(152, 28);
this->label1->Name = S"label1";
this->label1->Size = System::Drawing::Size(96, 16);
this->label1->TabIndex = 11;
this->label1->Text = S"客户名称拼音";
//
// btnSearch
//
this->btnSearch->Location = System::Drawing::Point(504, 23);
this->btnSearch->Name = S"btnSearch";
this->btnSearch->Size = System::Drawing::Size(88, 24);
this->btnSearch->TabIndex = 10;
this->btnSearch->Text = S"查询";
this->btnSearch->Click += new System::EventHandler(this, btnSearch_Click);
//
// tboxClientWord
//
this->tboxClientWord->Location = System::Drawing::Point(264, 23);
this->tboxClientWord->Name = S"tboxClientWord";
this->tboxClientWord->Size = System::Drawing::Size(216, 21);
this->tboxClientWord->TabIndex = 12;
this->tboxClientWord->Text = S"";
//
// ClientDataManage
//
this->AutoScaleBaseSize = System::Drawing::Size(6, 14);
this->ClientSize = System::Drawing::Size(744, 405);
this->Controls->Add(this->dgrdClientData);
this->Controls->Add(this->groupBox1);
this->Controls->Add(this->toolBar1);
this->Name = S"ClientDataManage";
this->Text = S"ClientDataManage";
(__try_cast<System::ComponentModel::ISupportInitialize * >(this->dgrdClientData))->EndInit();
this->groupBox1->ResumeLayout(false);
this->ResumeLayout(false);
}
//--------------------成员方法------------------------
public:
ClientDataManage(bool blShowToolBar)
{
InitializeComponent();
this->MyDataBase = new LinkDataBase();
this->strTableName = new String("客户清单");
this->strSQL = new String("Select * from 客户清单;");
this->ds = this->MyDataBase->SelectDataBase(this->strSQL,this->strTableName);
//如果ToolBar可见,则只显示商品资料维护表,DataGrid可编辑;如果不可见,则同时显示销售表,DataGrid不可编辑
this->DataGridStateControl(!blShowToolBar);
this->dgrdClientData->DataSource = ds->Tables->Item[S"客户清单"];
this->toolBar1->Enabled = blShowToolBar;
this->toolBar1->Visible = blShowToolBar;
}
void DataGridStateControl(bool blReadOnly)
{
DataGridTableStyle* ts = new DataGridTableStyle();
ts->AlternatingBackColor = Color::LightGray;
ts->MappingName = this->ds->Tables->Item[S"客户清单"]->TableName;
ts->AllowSorting = false;
int numCols = this->ds->Tables->Item[S"客户清单"]->Columns->Count;
for(int i = 0;i < numCols;i++)
{
if(!blReadOnly)
{
//如果DataGrid可以编辑,则可以选中任意单元
DataGridTextBoxColumn* aTextColumn = new DataGridTextBoxColumn();
aTextColumn->MappingName = this->ds->Tables->Item[S"客户清单"]->Columns->Item[i]->ColumnName;
aTextColumn->HeaderText = this->ds->Tables->Item[S"客户清单"]->Columns->Item[i]->ColumnName;
aTextColumn->NullText = String::Empty;
ts->GridColumnStyles->Add(aTextColumn);
}
else
{
//如果DataGrid不可编辑,则单击选中整行
DataGridNoActiveCellColumn* aNoActiveCellColumn = new DataGridNoActiveCellColumn();
aNoActiveCellColumn->get_TextBox()->Enabled = false;
aNoActiveCellColumn->MappingName = this->ds->Tables->Item[0]->Columns->Item[i]->ColumnName;
aNoActiveCellColumn->HeaderText = this->ds->Tables->Item[0]->Columns->Item[i]->ColumnName;
aNoActiveCellColumn->NullText = String::Empty;
aNoActiveCellColumn->Format = S"F";
ts->GridColumnStyles->Add(aNoActiveCellColumn);
}
}
this->dgrdClientData->TableStyles->Add(ts);
}
//-----------------------------设置表格为只读--------------------------------------
void SetDataGridReadOnly(bool blInSell)
{
this->dgrdClientData->ReadOnly = true;
if(blInSell == true)
blSellTableShow = true;
else
blSellTableShow = false;
}
//------------------------根据商品拼音编码查询商品---------------------------------
private: System::Void btnSearch_Click(System::Object * sender, System::EventArgs * e)
{
String* strSpellWord = this->tboxClientWord->Text;
String* tempSQL = String::Format("Select * from 客户清单 where 拼音编码 like '%{0}%';",strSpellWord);
this->ds->Clear();
this->MyDataBase->SelectDataBase(this->ds,tempSQL,strTableName);
}
//------------------------对数据的修改,增加和删除---------------------------------
private: System::Void toolBar1_ButtonClick(System::Object * sender, System::Windows::Forms::ToolBarButtonClickEventArgs * e)
{
if(String::Compare(e->Button->ToolTipText,S"保存修改") == 0)
{
try
{
//改变当前单元的编辑状态
int row = this->dgrdClientData->CurrentCell.RowNumber;
int col = this->dgrdClientData->CurrentCell.ColumnNumber;
this->dgrdClientData->CurrentCell = DataGridCell(row + 1,col);
if(this->ds->HasChanges())
{
this->MyDataBase->UpdateDataBase(this->ds,strTableName);
//更新ds中的数据
this->ds->AcceptChanges();
}
else
{
MessageBox::Show(S"没有要修改的数据!",S"错误");
return;
}
}
catch(Exception* e)
{
String* temp = String::Format("{0}: {1}",e->get_Source(),e->Message);
MessageBox::Show(temp,S"错误");
return;
}
MessageBox::Show(S"数据修改成功!",S"提示");
}
else if(String::Compare(e->Button->ToolTipText,S"删除数据") == 0)
{
if(MessageBox::Show(S"确实要删除这条记录吗?",S"询问",MessageBoxButtons::YesNo) == DialogResult::Yes)
{
int intRowNumber = this->dgrdClientData->CurrentCell.RowNumber;
try
{
this->ds->Tables->Item[0]->Rows->Item[intRowNumber]->Delete();
this->MyDataBase->UpdateDataBase(this->ds->GetChanges(),strTableName);
//更新ds中的数据
this->ds->AcceptChanges();
}
catch(Exception* e)
{
String* temp = String::Format("{0}: {1}",e->get_Source(),e->Message);
MessageBox::Show(temp,S"错误");
return;
}
MessageBox::Show(S"删除数据成功!",S"提示");
}
}
}
//-------------------其他窗体调用商品信息窗体时,双击选择商品信息----------------------
private: System::Void dgrdClientData_DoubleClick(System::Object * sender, System::EventArgs * e)
{
if(this->dgrdClientData->ReadOnly == true)
{
int intCurrentRowNumber = this->dgrdClientData->CurrentCell.RowNumber;
SendClientID = this->dgrdClientData->get_Item(intCurrentRowNumber,0)->ToString();
SendClientName = this->dgrdClientData->get_Item(intCurrentRowNumber,3)->ToString();
this->DialogResult = DialogResult::OK;
}
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -