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

📄 analyse.cs

📁 企业管理系统
💻 CS
📖 第 1 页 / 共 2 页
字号:
			this.btnCancel.TabIndex = 59;
			this.btnCancel.Text = "取消";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.btnSelectAll);
			this.groupBox1.Controls.Add(this.checkedListBox1);
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.Controls.Add(this.label3);
			this.groupBox1.Controls.Add(this.dateTimePicker1);
			this.groupBox1.Controls.Add(this.dateTimePicker2);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Controls.Add(this.btnCancel);
			this.groupBox1.Controls.Add(this.btnApply);
			this.groupBox1.Location = new System.Drawing.Point(40, 24);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(408, 128);
			this.groupBox1.TabIndex = 65;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "选择分析";
			// 
			// btnSelectAll
			// 
			this.btnSelectAll.Image = ((System.Drawing.Image)(resources.GetObject("btnSelectAll.Image")));
			this.btnSelectAll.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.btnSelectAll.Location = new System.Drawing.Point(224, 88);
			this.btnSelectAll.Name = "btnSelectAll";
			this.btnSelectAll.Size = new System.Drawing.Size(64, 24);
			this.btnSelectAll.TabIndex = 61;
			this.btnSelectAll.Text = "全选";
			this.btnSelectAll.Click += new System.EventHandler(this.btnSelectAll_Click);
			// 
			// checkedListBox1
			// 
			this.checkedListBox1.Location = new System.Drawing.Point(88, 56);
			this.checkedListBox1.Name = "checkedListBox1";
			this.checkedListBox1.Size = new System.Drawing.Size(120, 52);
			this.checkedListBox1.TabIndex = 6;
			this.checkedListBox1.SelectedIndexChanged += new System.EventHandler(this.checkedListBox1_SelectedIndexChanged);
			// 
			// sqlConnection1
			// 
			this.sqlConnection1.ConnectionString = "packet size=4096;integrated security=SSPI;data source=localhost;persist security " +
				"info=False;initial catalog=Sell";
			// 
			// sqlDataAdapter1
			// 
			this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
			this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
			this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
			this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
																									  new System.Data.Common.DataTableMapping("Table", "ProSell", new System.Data.Common.DataColumnMapping[] {
																																																				 new System.Data.Common.DataColumnMapping("ProductID", "ProductID"),
																																																				 new System.Data.Common.DataColumnMapping("ProSellID", "ProSellID"),
																																																				 new System.Data.Common.DataColumnMapping("ProductName", "ProductName"),
																																																				 new System.Data.Common.DataColumnMapping("ProSellNumber", "ProSellNumber"),
																																																				 new System.Data.Common.DataColumnMapping("ProSellPrice", "ProSellPrice"),
																																																				 new System.Data.Common.DataColumnMapping("ProSellDate", "ProSellDate")})});
			this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
			// 
			// sqlDeleteCommand1
			// 
			this.sqlDeleteCommand1.CommandText = @"DELETE FROM ProSell WHERE (ProSellID = @Original_ProSellID) AND (ProSellDate = @Original_ProSellDate OR @Original_ProSellDate IS NULL AND ProSellDate IS NULL) AND (ProSellNumber = @Original_ProSellNumber OR @Original_ProSellNumber IS NULL AND ProSellNumber IS NULL) AND (ProSellPrice = @Original_ProSellPrice OR @Original_ProSellPrice IS NULL AND ProSellPrice IS NULL) AND (ProductID = @Original_ProductID OR @Original_ProductID IS NULL AND ProductID IS NULL) AND (ProductName = @Original_ProductName OR @Original_ProductName IS NULL AND ProductName IS NULL)";
			this.sqlDeleteCommand1.Connection = this.sqlConnection1;
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ProSellID", System.Data.SqlDbType.VarChar, 5, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ProSellID", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ProSellDate", System.Data.SqlDbType.DateTime, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ProSellDate", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ProSellNumber", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ProSellNumber", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ProSellPrice", System.Data.SqlDbType.Float, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ProSellPrice", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ProductID", System.Data.SqlDbType.VarChar, 5, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ProductID", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ProductName", System.Data.SqlDbType.VarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ProductName", System.Data.DataRowVersion.Original, null));
			// 
			// sqlInsertCommand1
			// 
			this.sqlInsertCommand1.CommandText = @"INSERT INTO ProSell(ProductID, ProSellID, ProductName, ProSellNumber, ProSellPrice, ProSellDate) VALUES (@ProductID, @ProSellID, @ProductName, @ProSellNumber, @ProSellPrice, @ProSellDate); SELECT ProductID, ProSellID, ProductName, ProSellNumber, ProSellPrice, ProSellDate FROM ProSell WHERE (ProSellID = @ProSellID)";
			this.sqlInsertCommand1.Connection = this.sqlConnection1;
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProductID", System.Data.SqlDbType.VarChar, 5, "ProductID"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProSellID", System.Data.SqlDbType.VarChar, 5, "ProSellID"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProductName", System.Data.SqlDbType.VarChar, 20, "ProductName"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProSellNumber", System.Data.SqlDbType.Int, 4, "ProSellNumber"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProSellPrice", System.Data.SqlDbType.Float, 8, "ProSellPrice"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProSellDate", System.Data.SqlDbType.DateTime, 8, "ProSellDate"));
			// 
			// sqlSelectCommand1
			// 
			this.sqlSelectCommand1.CommandText = "SELECT ProductID, ProSellID, ProductName, ProSellNumber, ProSellPrice, ProSellDat" +
				"e FROM ProSell";
			this.sqlSelectCommand1.Connection = this.sqlConnection1;
			// 
			// sqlUpdateCommand1
			// 
			this.sqlUpdateCommand1.CommandText = @"UPDATE ProSell SET ProductID = @ProductID, ProSellID = @ProSellID, ProductName = @ProductName, ProSellNumber = @ProSellNumber, ProSellPrice = @ProSellPrice, ProSellDate = @ProSellDate WHERE (ProSellID = @Original_ProSellID) AND (ProSellDate = @Original_ProSellDate OR @Original_ProSellDate IS NULL AND ProSellDate IS NULL) AND (ProSellNumber = @Original_ProSellNumber OR @Original_ProSellNumber IS NULL AND ProSellNumber IS NULL) AND (ProSellPrice = @Original_ProSellPrice OR @Original_ProSellPrice IS NULL AND ProSellPrice IS NULL) AND (ProductID = @Original_ProductID OR @Original_ProductID IS NULL AND ProductID IS NULL) AND (ProductName = @Original_ProductName OR @Original_ProductName IS NULL AND ProductName IS NULL); SELECT ProductID, ProSellID, ProductName, ProSellNumber, ProSellPrice, ProSellDate FROM ProSell WHERE (ProSellID = @ProSellID)";
			this.sqlUpdateCommand1.Connection = this.sqlConnection1;
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProductID", System.Data.SqlDbType.VarChar, 5, "ProductID"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProSellID", System.Data.SqlDbType.VarChar, 5, "ProSellID"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProductName", System.Data.SqlDbType.VarChar, 20, "ProductName"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProSellNumber", System.Data.SqlDbType.Int, 4, "ProSellNumber"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProSellPrice", System.Data.SqlDbType.Float, 8, "ProSellPrice"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProSellDate", System.Data.SqlDbType.DateTime, 8, "ProSellDate"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ProSellID", System.Data.SqlDbType.VarChar, 5, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ProSellID", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ProSellDate", System.Data.SqlDbType.DateTime, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ProSellDate", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ProSellNumber", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ProSellNumber", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ProSellPrice", System.Data.SqlDbType.Float, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ProSellPrice", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ProductID", System.Data.SqlDbType.VarChar, 5, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ProductID", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ProductName", System.Data.SqlDbType.VarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ProductName", System.Data.DataRowVersion.Original, null));
			// 
			// ProfitAnalyse
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(492, 393);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.dataGrid1);
			this.Controls.Add(this.btnExit);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "ProfitAnalyse";
			this.Text = "利润分析";
			this.Load += new System.EventHandler(this.ProfitAnalyse_Load);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.dataSetAnalyse1)).EndInit();
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion
		
		public void ErrorHandle(System.Exception E)
		{
			MessageBox.Show(E.ToString());
		}

		private void ProfitAnalyse_Load(object sender, System.EventArgs e)
		{			
			string mySelectQuery="select * from Product";			
			SqlCommand myCommand=new SqlCommand(mySelectQuery,this.sqlConnection1);
			//创建SqlCommand对象来从Product表中取数据
			if(this.sqlConnection1.State==ConnectionState.Closed)
			{
				this.sqlConnection1.Open();//打开数据库连接		
			}
			SqlDataReader myReader=myCommand.ExecuteReader();
			//执行SqlCommad对象的ExecuteReader方法来顺序读取数据记录
			while(myReader.Read())
			{
				this.checkedListBox1.Items.Add(myReader[0]);
				//向CheckedListBox控件中添加商品号
			}
			myReader.Close();
			this.sqlConnection1.Close();
		}

		private void checkedListBox1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
		
		}

		private void btnExit_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			for(int i=0;i<this.checkedListBox1.Items.Count;i++)
			{
				this.checkedListBox1.SetItemChecked(i,false);
				//取消CheckListBox中所有项的选中状态
			}
			
		}
		
		private void btnSelectAll_Click(object sender, System.EventArgs e)
		{
			for(int i=0;i<this.checkedListBox1.Items.Count;i++)
			{
				this.checkedListBox1.SetItemChecked(i,true);
				//选中CheckListBox中所有项
			}
		}

		private void btnApply_Click(object sender, System.EventArgs e)
		{			
			
			Sale.BussinessRule.CreateTableProfitAnalyse ProfitAnalyseclass=new CreateTableProfitAnalyse();
			analyseTable=ProfitAnalyseclass.ProfitAnalyse;//创建DataTable实例analyseTable
			SqlCommand ProfitAnalyse=new SqlCommand();
			ProfitAnalyse.Connection=this.sqlConnection1;
			ProfitAnalyse.CommandType=CommandType.StoredProcedure;
			ProfitAnalyse.CommandText="dbo.StoredProcedureProfitAnalyse";
			//调用存储过程StoredProcedureProfitAnalyse
			SqlParameter parinputProID=ProfitAnalyse.Parameters.Add("@ProID",SqlDbType.Char);
			parinputProID.Direction=ParameterDirection.Input;
			//定义商品号码@ProID为输入参数
			SqlParameter parinputStartTime=ProfitAnalyse.Parameters.Add("@StartTime",SqlDbType.DateTime);
			parinputStartTime.Direction=ParameterDirection.Input;
			parinputStartTime.Value=this.dateTimePicker1.Value;
			//定义起始日期@SartTime为输入参数
			SqlParameter parinputEndTime=ProfitAnalyse.Parameters.Add("@EndTime",SqlDbType.DateTime);
			parinputEndTime.Direction=ParameterDirection.Input;
			parinputEndTime.Value=this.dateTimePicker2.Value;
			//定义截至日期@EndTime为输入参数
			SqlParameter paroutputTotalNumber=ProfitAnalyse.Parameters.Add("@TotalNumber",SqlDbType.Int);
			paroutputTotalNumber.Direction=ParameterDirection.Output;
			//定义商品销售总量@TotalNumber为输出参数
			SqlParameter paroutputTotalProfit=ProfitAnalyse.Parameters.Add("@TotalProfit",
				SqlDbType.Float);
			paroutputTotalProfit.Direction=ParameterDirection.Output;
			//定义商品销售总额@TotalProfit为输出参数
			
			try
			{
				foreach(int indexChecked in checkedListBox1.CheckedIndices)
			{//在所有CheckListBox选中项中循环
					DataRow newAnalyse=analyseTable.NewRow();
					//为analyseTable创建新行
					parinputProID.Value=this.checkedListBox1.Items[indexChecked].ToString().Trim();
					//输入参数@ProID的值
					if(this.sqlConnection1.State==ConnectionState.Closed)
					{
						this.sqlConnection1.Open();	
					}
					ProfitAnalyse.ExecuteNonQuery();
					//执行存储过程
					newAnalyse["ProID"]=this.checkedListBox1.Items[indexChecked].ToString().Trim();
					newAnalyse["TotalNumber"]=paroutputTotalNumber.Value;
					newAnalyse["TotalProfit"]=paroutputTotalProfit.Value;
					//为数据行newAnalyse的各个字段赋值
					analyseTable.Rows.Add(newAnalyse);
					//把数据行newAnalyse添加到数据表analyseTable
					this.sqlConnection1.Close();					                    					
			}
				this.dataGrid1.DataSource=analyseTable;
				this.dataGrid1.DataMember="";
				this.dataGrid1.Refresh(); 
				//把数据表analyseTable绑定到DataGrid控件中并显示
			}
			catch(System.Exception E)
			{	
			    this.ErrorHandle(E);				
				this.sqlConnection1.Close();				
			}		


		}	


	}
}

⌨️ 快捷键说明

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