📄 bomform.h
字号:
//新建一个数据视图
DataView* ViewMaterial = new DataView(tempTable);
if(parentRow == NULL)
{
//输入的是根节点
ViewMaterial->RowFilter = S"低层码 = 0";
}
else
{
ViewMaterial->RowFilter = String::Format(S"父项编号 = '{0}'",parentRow->Item[S"物料编号"]->ToString()->Trim());
}
//添加所有子节点
int RowLength = ViewMaterial->Count;
//如果该节点没有子节点则返回
if(RowLength <= 0)
return;
for(int i = 0;i < RowLength; i++)
{
strMaterialName = ViewMaterial->Item[i]->Item[S"物料名称"]->ToString()->Trim();
strMaterialName = String::Format(S"{0}({1})",strMaterialName,ViewMaterial->Item[i]->Item[S"物料编号"]->ToString()->Trim());
TreeNode* node = new TreeNode(strMaterialName);
if(parentNode == NULL)
{
//添加的是根节点
this->tvMaterialTree->Nodes->Add(node);
}
else
{
parentNode->Nodes->Add(node);
}
//添加子节点的下一级节点
PopulateTreeView(strMaterialName,node,ViewMaterial->Item[i]);
}
}
//显示所有节点
private: System::Void BomForm_Load(System::Object * sender, System::EventArgs * e)
{
this->PopulateTreeView(NULL,NULL,NULL);
this->SetModify(false);
this->DataBidings();
}
//显示所选节点的详细信息
private: System::Void tvMaterialTree_AfterSelect(System::Object * sender, System::Windows::Forms::TreeViewEventArgs * e)
{
int subIndex = e->Node->Text->LastIndexOf(S"(") + 1;
String* strMaterialID = e->Node->Text->Substring(subIndex,e->Node->Text->Length - subIndex - 1);
String* strUpMaterialID = S"0";
if(e->Node->Parent == NULL)
{
strUpMaterialID = S"0";
}
else
{
subIndex = e->Node->Parent->Text->LastIndexOf(S"(") + 1;
strUpMaterialID = e->Node->Parent->Text->Substring(subIndex,e->Node->Parent->Text->Length - subIndex - 1);
}
//将物料清单另存为tempTable
DataTable* tempTable = this->ds->Tables->Item[S"物料清单"];
for(int i = 0;i < tempTable->Rows->Count;i++)
{
String* tempString = tempTable->Rows->Item[i]->Item[S"物料编号"]->ToString()->Trim();
if(String::Compare(tempString,strMaterialID) == 0)
{
tempString = tempTable->Rows->Item[i]->Item[S"父项编号"]->ToString()->Trim();
if(String::Compare(tempString,strUpMaterialID) == 0)
{
this->cmBom->Position = i;
}
}
}
String* Filter = String::Format(S"物料编号 = '{0}'",tempTable->Rows->Item[this->cmBom->Position]->Item[S"父项编号"]->ToString()->Trim());
DataRow* row[] = tempTable->Select(Filter);
//如果没有这种物料则返回
int RowLength = row->Length;
if(RowLength <= 0)
return;
this->tBoxTopperName->Text = row[0]->Item[S"物料名称"]->ToString()->Trim();
/*//新建一个数据视图
DataView* ViewMaterial = new DataView(tempTable);
ViewMaterial->RowFilter = String::Format(S"物料编号 = '{0}'",strMaterialID);
//如果没有这种物料则返回
int RowLength = ViewMaterial->Count;
if(RowLength <= 0)
return;
//显示物料信息
this->tBoxMaterialID->Text = strMaterialID;
this->tBoxMaterialName->Text = ViewMaterial->Item[0]->Item[S"物料名称"]->ToString()->Trim();
this->tBoxDemandingQuantity->Text = ViewMaterial->Item[0]->Item[S"需要数量"]->ToString()->Trim();
this->tBoxInnerCode->Text = ViewMaterial->Item[0]->Item[S"低层码"]->ToString()->Trim();
this->tBoxAuditingDate->Text = ViewMaterial->Item[0]->Item[S"审核日期"]->ToString()->Trim();
this->tBoxDrawingWorkshop->Text = ViewMaterial->Item[0]->Item[S"领料车间"]->ToString()->Trim();
this->tBoxDrawedDepot->Text = ViewMaterial->Item[0]->Item[S"领料库房"]->ToString()->Trim();
this->tBoxOthers->Text = ViewMaterial->Item[0]->Item[S"其它事项"]->ToString()->Trim();
ViewMaterial->RowFilter = String::Format(S"物料编号 = '{0}'",ViewMaterial->Item[0]->Item[S"父项编号"]->ToString()->Trim());
//如果没有这种物料则返回
RowLength = ViewMaterial->Count;
if(RowLength <= 0)
return;
this->tBoxTopperID->Text = ViewMaterial->Item[0]->Item[S"物料编号"]->ToString()->Trim();
this->tBoxTopperName->Text = ViewMaterial->Item[0]->Item[S"物料名称"]->ToString()->Trim();
*/
this->SetModify(false);
}
//-----------------设置控件属性-----------------------
void SetModify(bool isModifiable)
{
this->tBoxAuditingDate->ReadOnly = !isModifiable;
this->tBoxDemandingQuantity->ReadOnly = !isModifiable;
this->tBoxDrawedDepot->ReadOnly = !isModifiable;
this->tBoxDrawingWorkshop->ReadOnly = !isModifiable;
this->tBoxInnerCode->ReadOnly = !isModifiable;
this->tBoxMaterialID->ReadOnly = !isModifiable;
this->tBoxMaterialName->ReadOnly = !isModifiable;
this->tBoxOthers->ReadOnly = !isModifiable;
this->tBoxTopperID->ReadOnly = !isModifiable;
this->tBoxTopperName->ReadOnly = !isModifiable;
this->btnLookup->Enabled = isModifiable;
}
//-----------------设置数据邦定-----------------------
void DataBidings()
{
this->tBoxAuditingDate->DataBindings->Add("Text",this->ds->Tables->Item[S"物料清单"],"审核日期");
this->tBoxDemandingQuantity->DataBindings->Add("Text",this->ds->Tables->Item[S"物料清单"],"需要数量");
this->tBoxDrawedDepot->DataBindings->Add("Text",this->ds->Tables->Item[S"物料清单"],"领料车间");
this->tBoxDrawingWorkshop->DataBindings->Add("Text",this->ds->Tables->Item[S"物料清单"],"领料库房");
this->tBoxInnerCode->DataBindings->Add("Text",this->ds->Tables->Item[S"物料清单"],"低层码");
this->tBoxMaterialID->DataBindings->Add("Text",this->ds->Tables->Item[S"物料清单"],"物料编号");
this->tBoxMaterialName->DataBindings->Add("Text",this->ds->Tables->Item[S"物料清单"],"物料名称");
this->tBoxOthers->DataBindings->Add("Text",this->ds->Tables->Item[S"物料清单"],"其它事项");
this->tBoxTopperID->DataBindings->Add("Text",this->ds->Tables->Item[S"物料清单"],"父项编号");
}
private: System::Void btnLookup_Click(System::Object * sender, System::EventArgs * e)
{
SelectMaterials* newFrm = new SelectMaterials();
if(newFrm->ShowDialog(this) == DialogResult::OK)
{
this->tBoxMaterialID->Text = newFrm->SeletedMaterialID;
this->tBoxMaterialName->Text = newFrm->SeletedMaterialName;
}
}
private: System::Void toolBar1_ButtonClick(System::Object * sender, System::Windows::Forms::ToolBarButtonClickEventArgs * e)
{
if(String::Compare(e->Button->ToolTipText->Trim(),S"新增") == 0)
{
//显示物料选择窗口
SelectMaterials* newFrm = new SelectMaterials();
if(newFrm->ShowDialog(this) == DialogResult::OK)
{
//如果选择了物料则添加新记录
//默认添加为当前物料的下属物料
String* TopperID = this->tBoxMaterialID->Text;
String* TopperName = this->tBoxMaterialName->Text;
int InnerCode = System::Convert::ToInt32(this->tBoxInnerCode->Text) + 1;
this->cmBom->AddNew();
this->tBoxMaterialID->Text = newFrm->SeletedMaterialID;
this->tBoxMaterialName->Text = newFrm->SeletedMaterialName;
this->tBoxTopperID->Text = TopperID;
this->tBoxTopperName->Text = TopperName;
this->tBoxInnerCode->Text = InnerCode.ToString()->Trim();
TreeNode* node = this->tvMaterialTree->SelectedNode;
String* tempString = String::Format(S"{0}({1})",this->tBoxMaterialName->Text,this->tBoxMaterialID->Text);
TreeNode* Newnode = new TreeNode(tempString);
node->Nodes->Add(Newnode);
this->tvMaterialTree->SelectedNode = Newnode;
this->cmBom->EndCurrentEdit();
//重新显示
//this->tvMaterialTree->Nodes->Clear();
//this->PopulateTreeView(NULL,NULL,NULL);
this->SetModify(true);
}
else
{
//如果没有选择物料则返回
return;
}
}
else if(String::Compare(e->Button->ToolTipText->Trim(),S"修改") == 0)
{
this->SetModify(true);
}
else if(String::Compare(e->Button->ToolTipText->Trim(),S"删除") == 0)
{
if(MessageBox::Show(S"删除物料及下属物料?",S"删除物料",MessageBoxButtons::OKCancel) == DialogResult::OK)
{
if(this->cmBom->Count > 0)
{
int InnerCode = System::Convert::ToInt32(this->tBoxInnerCode->Text) + 1;
//删除下属物料
String* Filter = String::Format(S"父项编号 = '{0}' And 低层码 = {1}",this->tBoxMaterialID->Text,InnerCode.ToString()->Trim());
DataRow* rows[] = this->ds->Tables->Item[S"物料清单"]->Select(Filter);
for(int i = 0;i < rows->Length;i++)
{
rows[i]->Delete();
}
//删除所选物料
InnerCode--;
Filter = String::Format(S"物料编号 = '{0}' And 低层码 = {1}",this->tBoxMaterialID->Text,InnerCode.ToString()->Trim());
rows = this->ds->Tables->Item[S"物料清单"]->Select(Filter);
for(int i = 0;i < rows->Length;i++)
{
rows[i]->Delete();
}
this->cmBom->EndCurrentEdit();
//重新显示
this->tvMaterialTree->Nodes->Clear();
this->PopulateTreeView(NULL,NULL,NULL);
this->SetModify(false);
}
}
else
{
MessageBox::Show(S"表中无可删除数据",S"提示");
}
}
else if(String::Compare(e->Button->ToolTipText->Trim(),S"保存") == 0)
{
this->btnLookup->Focus();
this->cmBom->EndCurrentEdit();
this->MyDataBase->UpdateDataBase(this->BomAdapter,this->ds,S"物料清单");
this->SetModify(false);
}
else if(String::Compare(e->Button->ToolTipText->Trim(),S"取消") == 0)
{
this->cmBom->CancelCurrentEdit();
this->SetModify(false);
}
else if(String::Compare(e->Button->ToolTipText->Trim(),S"退出") == 0)
{
this->Close();
}
}
private: System::Void BomAdapter_RowUpdating(System::Object * sender, System::Data::SqlClient::SqlRowUpdatingEventArgs * e)
{
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -