⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 factoryschedule.h

📁 Visual C++.net数据库开发经典案例
💻 H
📖 第 1 页 / 共 3 页
字号:
			this->sqlUpdateCommand1->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->sqlUpdateCommand1->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@Original_记帐人", System::Data::SqlDbType::VarChar, 10, System::Data::ParameterDirection::Input, false, (System::Byte)0, (System::Byte)0, S"记帐人", System::Data::DataRowVersion::Original, 0));
			this->sqlUpdateCommand1->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@Original_需求数量", System::Data::SqlDbType::Decimal, 9, System::Data::ParameterDirection::Input, false, (System::Byte)15, (System::Byte)2, S"需求数量", System::Data::DataRowVersion::Original, 0));
			// 
			// sqlDeleteCommand1
			// 
			this->sqlDeleteCommand1->CommandText = S"DELETE FROM 主需求计划 WHERE (年份 = @Original_年份) AND (物料编号 = @Original_物料编号) AND (计划期 " 
				S"= @Original_计划期) AND (修改日期 = @Original_修改日期 OR @Original_修改日期 IS NULL AND 修改日期 I" 
				S"S NULL) AND (备注 = @Original_备注 OR @Original_备注 IS NULL AND 备注 IS NULL) AND (开始日期" 
				S" = @Original_开始日期 OR @Original_开始日期 IS NULL AND 开始日期 IS NULL) AND (状态 = @Origina" 
				S"l_状态) AND (结束日期 = @Original_结束日期 OR @Original_结束日期 IS NULL AND 结束日期 IS NULL) AND" 
				S" (编号 = @Original_编号 OR @Original_编号 IS NULL AND 编号 IS NULL) AND (记帐人 = @Original" 
				S"_记帐人 OR @Original_记帐人 IS NULL AND 记帐人 IS NULL) AND (需求数量 = @Original_需求数量)";
			this->sqlDeleteCommand1->Connection = this->sqlConnection1;
			this->sqlDeleteCommand1->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->sqlDeleteCommand1->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->sqlDeleteCommand1->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->sqlDeleteCommand1->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->sqlDeleteCommand1->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@Original_备注", System::Data::SqlDbType::VarChar, 40, System::Data::ParameterDirection::Input, false, (System::Byte)0, (System::Byte)0, S"备注", System::Data::DataRowVersion::Original, 0));
			this->sqlDeleteCommand1->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->sqlDeleteCommand1->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@Original_状态", System::Data::SqlDbType::VarChar, 10, System::Data::ParameterDirection::Input, false, (System::Byte)0, (System::Byte)0, S"状态", System::Data::DataRowVersion::Original, 0));
			this->sqlDeleteCommand1->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->sqlDeleteCommand1->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->sqlDeleteCommand1->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@Original_记帐人", System::Data::SqlDbType::VarChar, 10, System::Data::ParameterDirection::Input, false, (System::Byte)0, (System::Byte)0, S"记帐人", System::Data::DataRowVersion::Original, 0));
			this->sqlDeleteCommand1->Parameters->Add(new System::Data::SqlClient::SqlParameter(S"@Original_需求数量", System::Data::SqlDbType::Decimal, 9, System::Data::ParameterDirection::Input, false, (System::Byte)15, (System::Byte)2, S"需求数量", System::Data::DataRowVersion::Original, 0));
			// 
			// FactorySchedule
			// 
			this->AutoScaleBaseSize = System::Drawing::Size(6, 14);
			this->ClientSize = System::Drawing::Size(768, 485);
			this->Controls->Add(this->dgrdFactorySchedule);
			this->Controls->Add(this->groupBox2);
			this->Controls->Add(this->groupBox1);
			this->Controls->Add(this->toolBar1);
			this->Name = S"FactorySchedule";
			this->Text = S"工厂日历";
			this->groupBox1->ResumeLayout(false);
			this->groupBox2->ResumeLayout(false);
			(__try_cast<System::ComponentModel::ISupportInitialize *  >(this->dgrdFactorySchedule))->EndInit();
			this->ResumeLayout(false);

		}		

		//----------------设置控件ReadOnly属性------------------------
		void SetModify(bool isModifiable)
		{
			this->tBoxYearDisplay->ReadOnly = !isModifiable;
			this->tBoxPlanDateDisplay->ReadOnly = !isModifiable;
			this->tBoxBeginDate->ReadOnly = !isModifiable;
			this->tBoxEndedDate->ReadOnly = !isModifiable;
			this->tBoxMemo->ReadOnly = !isModifiable;			

			this->btnSearch->Enabled = !isModifiable;

			this->dgrdFactorySchedule->ReadOnly = !isModifiable;
		}
		//---------------------设置控件的数据邦定--------------------------
		void SetDataBindings()
		{
			this->tBoxYearDisplay->DataBindings->Add(S"Text",this->ds->Tables->Item[S"工厂日历"],S"年份");
			this->tBoxPlanDateDisplay->DataBindings->Add(S"Text",this->ds->Tables->Item[S"工厂日历"],S"计划期");
			this->tBoxBeginDate->DataBindings->Add(S"Text",this->ds->Tables->Item[S"工厂日历"],S"开始日期");
			this->tBoxEndedDate->DataBindings->Add(S"Text",this->ds->Tables->Item[S"工厂日历"],S"结束日期");
			this->tBoxMemo->DataBindings->Add(S"Text",this->ds->Tables->Item[S"工厂日历"],S"备注");
			
		}
		//-----------------------设置表格各列的属性-----------------------
		void DataGridStateControl()
		{

			DataGridTableStyle* ts = new DataGridTableStyle();			
			ts->MappingName = this->ds->Tables->Item[S"工厂日历"]->TableName;
			
			DataGridTextBoxColumn* aTextColumn;
			ts->AllowSorting = false;
			ts->AlternatingBackColor = Color::LightGray;
			int numCols = this->ds->Tables->Item[0]->Columns->Count;
			for(int i = 0;i < numCols;i++)
			{				
				aTextColumn = new DataGridNoActiveCellColumn();				
				aTextColumn->ReadOnly = true;
				aTextColumn->get_TextBox()->Enabled = false;
				aTextColumn->MappingName = this->ds->Tables->Item[0]->Columns->Item[i]->ColumnName;
				aTextColumn->HeaderText =  this->ds->Tables->Item[0]->Columns->Item[i]->ColumnName;
				aTextColumn->NullText = String::Empty;									
				ts->GridColumnStyles->Add(aTextColumn);				
			}
			this->dgrdFactorySchedule->TableStyles->Add(ts);
  		 }

private: System::Void toolBar1_ButtonClick(System::Object *  sender, System::Windows::Forms::ToolBarButtonClickEventArgs *  e)
		 {
			 //设置控件属性
			 this->SetModify(false);

			 if(String::Compare(e->Button->ToolTipText,S"首记录") == 0)
			 {
				 this->dgrdFactorySchedule->UnSelect(this->cmOrders->Position);
				 this->cmOrders->Position = 0;
				 this->dgrdFactorySchedule->Select(this->cmOrders->Position);
				 this->dgrdFactorySchedule->CurrentRowIndex = this->cmOrders->Position;
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"上一记录") == 0)
			 {
				 if(this->cmOrders->Position > 0)
				 {
					 this->dgrdFactorySchedule->UnSelect(this->cmOrders->Position);
					 this->cmOrders->Position--;
					 this->dgrdFactorySchedule->Select(this->cmOrders->Position);
					 this->dgrdFactorySchedule->CurrentRowIndex = this->cmOrders->Position;
				 }
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"下一记录") == 0)
			 {
				 if(this->cmOrders->Position < this->cmOrders->Count)
				 {
					 this->dgrdFactorySchedule->UnSelect(this->cmOrders->Position);
					 this->cmOrders->Position++;
					 this->dgrdFactorySchedule->Select(this->cmOrders->Position);
					 this->dgrdFactorySchedule->CurrentRowIndex = this->cmOrders->Position;
				 }
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"尾记录") == 0)
			 {
				 this->dgrdFactorySchedule->UnSelect(this->cmOrders->Position);
				 this->cmOrders->Position = this->cmOrders->Count;
				 this->dgrdFactorySchedule->Select(this->cmOrders->Position);
				 this->dgrdFactorySchedule->CurrentRowIndex = this->cmOrders->Position;
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"新增") == 0)
			 {
				 this->cmOrders->AddNew();
				 //设置默认值
				 this->SetModify(true);

				 this->dgrdFactorySchedule->UnSelect(this->cmOrders->Position);
				 this->cmOrders->Position = this->cmOrders->Count;
				 this->dgrdFactorySchedule->Select(this->cmOrders->Position);
				 this->dgrdFactorySchedule->CurrentRowIndex = this->cmOrders->Position;
                 
				 DataRow* row = this->copyTable->Rows->Item[this->copyTable->Rows->Count - 1];				 
				 this->tBoxYearDisplay->Text = row->Item[S"年份"]->ToString()->Trim();
				 //计划期自动加一
				 int plandate = System::Convert::ToInt32(row->Item[S"计划期"]->ToString()->Trim()) + 1;
				 this->tBoxPlanDateDisplay->Text = System::Convert::ToString(plandate);				 
				 //开始日期是上一次结束日期的后两天
				 int begindate = System::Convert::ToInt32(row->Item[S"结束日期"]->ToString()->Trim()) + 2;
				 this->tBoxBeginDate->Text = System::Convert::ToString(begindate);		
				 //结束日期与开始日期为同一天				 
				 this->tBoxEndedDate->Text =  System::Convert::ToString(begindate);	
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"修改") == 0)
			 {
				 this->SetModify(true);
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"删除") == 0)
			 {
				 System::Windows::Forms::DialogResult r = MessageBox::Show(S"确定删除?",S"删除数据",MessageBoxButtons::OKCancel);
				 if(r == DialogResult::OK)
				 {
					 if(this->cmOrders->Count > 0)
						 this->cmOrders->RemoveAt(this->cmOrders->Position);
					 else
						 MessageBox::Show(S"表格已空,无可删除数据",S"提示");
				 }
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"提交") == 0)
			 {
				 this->cmOrders->EndCurrentEdit();
				 this->MyDataBase->UpdateDataBase(this->ds,S"工厂日历");
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"取消") == 0)
			 {
				 try
				 {
					 this->cmOrders->CancelCurrentEdit();
				 }
				 catch(Exception* e)
				 {
					 MessageBox::Show(e->Message,S"提示");
				 }
			 }
			 else if(String::Compare(e->Button->ToolTipText,S"退出") == 0)
			 {
				 this->Close();
			 }
		 }
		 //设置工具栏
		 void SetToolBar(bool Enable)
		 {
			 this->toolBar1->Enabled = Enable;
			 this->toolBar1->Visible = Enable;
		 }

private: System::Void btnSearch_Click(System::Object *  sender, System::EventArgs *  e)
		 {
			 String* strYear = this->tBoxYear->Text->Trim();
			 String* strPlanDate = this->tBoxPlanDate->Text->Trim();			
			 String* Filter = S"";
			 if(String::Compare(strYear,String::Empty) != 0)
			 {
				 Filter = String::Format(S"{0} AND (年份 LIKE '%{1}%')",Filter,strYear);
			 }
			 if(String::Compare(strPlanDate,String::Empty) != 0)
			 {
				 Filter = String::Format(S"{0} AND (计划期 LIKE '%{1}%')",Filter,strPlanDate);
			 }			 

			 this->ds->Tables->Item[S"工厂日历"]->Clear();

			 if(String::Compare(Filter,String::Empty) != 0)
			 {
				 Filter = Filter->Substring(5,Filter->Length - 5);
				 //查询工厂日历				 
				 this->strSQL = String::Format(S"Select * from 工厂日历 where {0}",Filter);
				 this->strTableName = S"工厂日历";
				 this->MyDataBase->SelectDataBase(this->ds,this->strSQL,this->strTableName);           
			 }
			 else
			 {
				 //查询工厂日历
				 this->strSQL = S"Select * from 工厂日历";
				 this->strTableName = S"工厂日历";
				 this->MyDataBase->SelectDataBase(this->ds,this->strSQL,this->strTableName);            
			 }
		 }

private: System::Void tBoxYearDisplay_Leave(System::Object *  sender, System::EventArgs *  e)
		 {
			 if(String::Compare(this->tBoxYearDisplay->Text,String::Empty) == 0)
			 {
				 MessageBox::Show(S"年份不能为空",S"提示");
				 this->tBoxYearDisplay->Undo();
			 }
		 }

private: System::Void tBoxPlanDateDisplay_Leave(System::Object *  sender, System::EventArgs *  e)
		 {
			 if(String::Compare(this->tBoxPlanDateDisplay->Text,String::Empty) == 0)
			 {
				 MessageBox::Show(S"计划期不能为空",S"提示");
				 this->tBoxPlanDateDisplay->Undo();
			 }
		 }

private: System::Void dgrdFactorySchedule_DoubleClick(System::Object *  sender, System::EventArgs *  e)
		 {
			 if(!this->CallByOthers)
				 return;
			 int row = this->dgrdFactorySchedule->CurrentRowIndex;
			 this->Year = this->ds->Tables->Item[S"工厂日历"]->Rows->Item[row]->Item[S"年份"]->ToString()->Trim();
			 this->PlanDate = this->ds->Tables->Item[S"工厂日历"]->Rows->Item[row]->Item[S"计划期"]->ToString()->Trim();
			 this->BeginDate = this->ds->Tables->Item[S"工厂日历"]->Rows->Item[row]->Item[S"开始日期"]->ToString()->Trim();
			 this->EndDate = this->ds->Tables->Item[S"工厂日历"]->Rows->Item[row]->Item[S"结束日期"]->ToString()->Trim();

			 this->DialogResult = DialogResult::OK;
		 }

};
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -