📄 requireplan.h
字号:
//
// DemandUpdateSqlCmd
//
this->DemandUpdateSqlCmd->CommandText = S"UPDATE 主需求计划 SET 编号 = @编号, 物料编号 = @物料编号, 年份 = @年份, 计划期 = @计划期, 开始日期 = @开始日期, 结束日期"
S" = @结束日期, 需求数量 = @需求数量, 记帐人 = @记帐人, 修改日期 = @修改日期, 状态 = @状态, 备注 = @备注 WHERE (年份 ="
S" @Original_年份) AND (物料编号 = @Original_物料编号) AND (计划期 = @Original_计划期) AND (编号 = @"
S"Original_编号)";
this->DemandUpdateSqlCmd->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@编号", System::Data::SqlDbType::VarChar, 14, S"编号"));
this->DemandUpdateSqlCmd->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@物料编号", System::Data::SqlDbType::VarChar, 14, S"物料编号"));
this->DemandUpdateSqlCmd->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@年份", System::Data::SqlDbType::Int, 4, S"年份"));
this->DemandUpdateSqlCmd->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@计划期", System::Data::SqlDbType::Int, 4, S"计划期"));
this->DemandUpdateSqlCmd->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@开始日期", System::Data::SqlDbType::Int, 4, S"开始日期"));
this->DemandUpdateSqlCmd->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@结束日期", System::Data::SqlDbType::Int, 4, S"结束日期"));
this->DemandUpdateSqlCmd->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@需求数量", System::Data::SqlDbType::Decimal, 9, System::Data::ParameterDirection::Input, false, (System::Byte)15, (System::Byte)2, S"需求数量", System::Data::DataRowVersion::Current, 0));
this->DemandUpdateSqlCmd->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@记帐人", System::Data::SqlDbType::VarChar, 10, S"记帐人"));
this->DemandUpdateSqlCmd->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@修改日期", System::Data::SqlDbType::Int, 4, S"修改日期"));
this->DemandUpdateSqlCmd->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@状态", System::Data::SqlDbType::VarChar, 10, S"状态"));
this->DemandUpdateSqlCmd->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@备注", System::Data::SqlDbType::VarChar, 40, S"备注"));
this->DemandUpdateSqlCmd->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@Original_年份", System::Data::SqlDbType::Int, 4, System::Data::ParameterDirection::Input, false, (System::Byte)0, (System::Byte)0, S"年份", System::Data::DataRowVersion::Original, 0));
this->DemandUpdateSqlCmd->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@Original_物料编号", System::Data::SqlDbType::VarChar, 14, System::Data::ParameterDirection::Input, false, (System::Byte)0, (System::Byte)0, S"物料编号", System::Data::DataRowVersion::Original, 0));
this->DemandUpdateSqlCmd->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@Original_计划期", System::Data::SqlDbType::Int, 4, System::Data::ParameterDirection::Input, false, (System::Byte)0, (System::Byte)0, S"计划期", System::Data::DataRowVersion::Original, 0));
this->DemandUpdateSqlCmd->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@Original_编号", System::Data::SqlDbType::VarChar, 14, System::Data::ParameterDirection::Input, false, (System::Byte)0, (System::Byte)0, S"编号", System::Data::DataRowVersion::Original, 0));
//
// RequirePlan
//
this->AutoScaleBaseSize = System::Drawing::Size(6, 14);
this->ClientSize = System::Drawing::Size(768, 629);
this->Controls->Add(this->dgrdRequirePlan);
this->Controls->Add(this->groupBox2);
this->Controls->Add(this->groupBox1);
this->Controls->Add(this->toolBar1);
this->Name = S"RequirePlan";
this->Text = S"主需求计划";
this->groupBox2->ResumeLayout(false);
this->groupBox1->ResumeLayout(false);
(__try_cast<System::ComponentModel::ISupportInitialize * >(this->dgrdRequirePlan))->EndInit();
this->ResumeLayout(false);
}
//------------------设置主需求计划表格样式----------------------
void DataGridStateControl()
{
DataGridTableStyle* ts = new DataGridTableStyle();
DataGridNoActiveCellColumn* aTextColumn;
ts->AlternatingBackColor = Color::LightGray;
ts->MappingName = this->ds->Tables->Item[S"主需求计划表"]->TableName;
int numCols = this->ds->Tables->Item[S"主需求计划表"]->Columns->Count;
for(int i = 0;i < numCols;i++)
{
aTextColumn = new DataGridNoActiveCellColumn();
aTextColumn->get_TextBox()->Enabled = false;
aTextColumn->MappingName = this->ds->Tables->Item[S"主需求计划表"]->Columns->Item[i]->ColumnName;
aTextColumn->HeaderText = this->ds->Tables->Item[S"主需求计划表"]->Columns->Item[i]->ColumnName;
aTextColumn->NullText = S"";
ts->GridColumnStyles->Add(aTextColumn);
}
this->dgrdRequirePlan->TableStyles->Add(ts);
}
//------------------设置数据绑定----------------------
void DataBidings()
{
this->tBoxMaterialIDShow->DataBindings->Add("Text",this->ds->Tables->Item[S"主需求计划表"],"物料编号");
this->tBoxMaterialName->DataBindings->Add("Text",this->ds->Tables->Item[S"主需求计划表"],"物料名称");
this->tBoxYearDisplay->DataBindings->Add("Text",this->ds->Tables->Item[S"主需求计划表"],"年份");
this->tBoxPlanDateDisplay->DataBindings->Add("Text",this->ds->Tables->Item[S"主需求计划表"],S"计划期");
this->tBoxBeginDate->DataBindings->Add("Text",this->ds->Tables->Item[S"主需求计划表"],"开始日期");
this->tBoxEndedDate->DataBindings->Add("Text",this->ds->Tables->Item[S"主需求计划表"],"结束日期");
this->tBoxDemand->DataBindings->Add("Text",this->ds->Tables->Item[S"主需求计划表"],"需求数量");
this->cmbStatus->DataBindings->Add("Text",this->ds->Tables->Item[S"主需求计划表"],"状态");
this->tBoxMemo->DataBindings->Add("Text",this->ds->Tables->Item[S"主需求计划表"],"备注");
}
//-----------------设置控件属性-----------------------
void SetModify(bool isModifiable)
{
this->tBoxMaterialIDShow->ReadOnly = !isModifiable;
this->tBoxMaterialName->ReadOnly = !isModifiable;
this->tBoxYearDisplay->ReadOnly = !isModifiable;
this->tBoxPlanDateDisplay->ReadOnly = !isModifiable;
this->tBoxBeginDate->ReadOnly = !isModifiable;
this->tBoxEndedDate->ReadOnly = !isModifiable;
this->tBoxDemand->ReadOnly = !isModifiable;
this->tBoxMemo->ReadOnly = !isModifiable;
this->cmbStatus->Enabled = isModifiable;
//编辑时允许选择物料和工厂日历
this->btnSelectMaterial->Enabled = isModifiable;
this->btnSelectSchedule->Enabled = isModifiable;
//编辑时不允许搜索
this->btnSearch->Enabled = !isModifiable;
}
//选择物料
private: System::Void btnSelectMaterial_Click(System::Object * sender, System::EventArgs * e)
{
SelectMaterials* newFrm = new SelectMaterials();
if(newFrm->ShowDialog(this) == DialogResult::OK)
{
this->tBoxMaterialIDShow->Text = newFrm->SeletedMaterialID;
this->tBoxMaterialName->Text = newFrm->SeletedMaterialName;
}
}
//选择工厂日历
private: System::Void btnSelectSchedule_Click(System::Object * sender, System::EventArgs * e)
{
FactorySchedule* newFrm = new FactorySchedule(true);
if(newFrm->ShowDialog(this) == DialogResult::OK)
{
this->tBoxYearDisplay->Text = newFrm->Year;
this->tBoxBeginDate->Text = newFrm->BeginDate;
this->tBoxEndedDate->Text = newFrm->EndDate;
this->tBoxPlanDateDisplay->Text = newFrm->PlanDate;
}
}
//搜索主需求计划表
private: System::Void btnSearch_Click(System::Object * sender, System::EventArgs * e)
{
String* strMaterialID = this->tBoxMaterialID->Text->Trim();
String* strYear = this->tBoxYear->Text->Trim();
String* strPlanDate = this->tBoxPlanDate->Text->Trim();
String* Filter = S"";
if(String::Compare(strMaterialID,String::Empty) != 0)
{
Filter = String::Format(S"{0} AND (主需求计划.物料编号 LIKE '%{1}%')",Filter,strMaterialID);
}
if(String::Compare(strYear,String::Empty) != 0)
{
Filter = String::Format(S"{0} AND (主需求计划.年份 = {1})",Filter,strYear);
}
if(String::Compare(strPlanDate,String::Empty) != 0)
{
Filter = String::Format(S"{0} AND (主需求计划.计划期 = {1})",Filter,strPlanDate);
}
if(String::Compare(Filter,String::Empty) != 0)
{
Filter = Filter->Substring(5,Filter->Length - 5);
this->DemandAdapter->SelectCommand->CommandText = String::Format(S"SELECT 编号, 主需求计划.物料编号, 物料主文件.物料名称, 年份, 计划期, 开始日期, 结束日期, 需求数量, 记帐人, 修改日期, 状态, 备注 FROM 主需求计划 INNER JOIN 物料主文件 ON 主需求计划.物料编号 = 物料主文件.物料编号 WHERE {0}",Filter);
this->ds->Tables->Item[S"主需求计划表"]->Clear();
this->DemandAdapter->Fill(this->ds,S"主需求计划表");
this->SetModify(false);
}
}
private: System::Void toolBar1_ButtonClick(System::Object * sender, System::Windows::Forms::ToolBarButtonClickEventArgs * e)
{
if(String::Compare(e->Button->ToolTipText->Trim(),S"首记录") == 0)
{
this->dgrdRequirePlan->UnSelect(this->cmRequire->Position);
this->cmRequire->Position = 0;
this->dgrdRequirePlan->Select(this->cmRequire->Position);
this->dgrdRequirePlan->CurrentRowIndex = this->cmRequire->Position;
}
else if(String::Compare(e->Button->ToolTipText->Trim(),S"上一记录") == 0)
{
if(this->cmRequire->Position > 0)
{
this->dgrdRequirePlan->UnSelect(this->cmRequire->Position);
this->cmRequire->Position--;
this->dgrdRequirePlan->Select(this->cmRequire->Position);
this->dgrdRequirePlan->CurrentRowIndex = this->cmRequire->Position;
}
}
else if(String::Compare(e->Button->ToolTipText->Trim(),S"下一记录") == 0)
{
if(this->cmRequire->Position < this->cmRequire->Count - 1)
{
this->dgrdRequirePlan->UnSelect(this->cmRequire->Position);
this->cmRequire->Position++;
this->dgrdRequirePlan->Select(this->cmRequire->Position);
this->dgrdRequirePlan->CurrentRowIndex = this->cmRequire->Position;
}
}
else if(String::Compare(e->Button->ToolTipText->Trim(),S"尾记录") == 0)
{
this->dgrdRequirePlan->UnSelect(this->cmRequire->Position);
this->cmRequire->Position = this->cmRequire->Count - 1;
this->dgrdRequirePlan->Select(this->cmRequire->Position);
this->dgrdRequirePlan->CurrentRowIndex = this->cmRequire->Position;
}
else if(String::Compare(e->Button->ToolTipText->Trim(),S"新增") == 0)
{
//显示物料选择窗口
SelectMaterials* newFrm = new SelectMaterials();
if(newFrm->ShowDialog(this) == DialogResult::OK)
{
//如果选择了物料则添加新记录
this->cmRequire->AddNew();
this->tBoxMaterialIDShow->Text = newFrm->SeletedMaterialID;
this->tBoxMaterialName->Text = newFrm->SeletedMaterialName;
//默认状态为正常
this->cmbStatus->Text = S"正常";
this->tBoxDemand->Text = S"0";
this->tBoxYearDisplay->Text = S"2005";
this->tBoxPlanDateDisplay->Text = S"2005";
this->cmRequire->EndCurrentEdit();
//设置编号
String* tempSQL = S"Select max(编号) 最大编号 from 主需求计划";
SqlCommand* sqlCmd = new SqlCommand(tempSQL,this->MyDataBase->myConnection);
int MaxID = 1;
Object* r = sqlCmd->ExecuteScalar();
if(r != System::DBNull::Value)
MaxID = System::Convert::ToInt32(r) + 1;
int row = this->cmRequire->Position;
this->ds->Tables->Item[S"主需求计划表"]->Rows->Item[row]->Item[S"编号"] = MaxID.ToString();
this->SetModify(true);
System::Windows::Forms::SendKeys::Send("{Tab}");
this->cmRequire->EndCurrentEdit();
}
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->cmRequire->Count > 0)
{
int row = this->cmRequire->Position;
String* DemandID = this->ds->Tables->Item[S"主需求计划表"]->Rows->Item[row]->Item[S"编号"]->ToString();
String* tempSQL = String::Format(S"Delete from 主需求计划 where 编号 = '{0}'",DemandID);
this->MyDataBase->SQLOperate(tempSQL);
this->cmRequire->RemoveAt(this->cmRequire->Position);
this->cmRequire->EndCurrentEdit();
this->SetModify(false);
}
}
else
{
MessageBox::Show(S"表中无可删除数据",S"提示");
}
}
else if(String::Compare(e->Button->ToolTipText->Trim(),S"保存") == 0)
{
this->btnSearch->Focus();
if(String::Compare(this->tBoxMaterialIDShow->Text,String::Empty) == 0)
{
MessageBox::Show(S"物料编号不能为空");
return;
}
if(String::Compare(this->tBoxDemand->Text,String::Empty) == 0)
{
MessageBox::Show(S"需求数量不能为空");
return;
}
if(String::Compare(this->tBoxPlanDateDisplay->Text,String::Empty) == 0)
{
MessageBox::Show(S"计划期不能为空");
return;
}
this->cmRequire->EndCurrentEdit();
this->MyDataBase->UpdateDataBase(this->DemandAdapter,this->ds,S"主需求计划表");
this->SetModify(false);
}
else if(String::Compare(e->Button->ToolTipText->Trim(),S"取消") == 0)
{
this->cmRequire->CancelCurrentEdit();
this->SetModify(false);
}
else if(String::Compare(e->Button->ToolTipText->Trim(),S"退出") == 0)
{
this->Close();
}
}
private: System::Void dgrdRequirePlan_Click(System::Object * sender, System::EventArgs * e)
{
//点击其它记录则不可编辑
this->SetModify(false);
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -