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

📄 form2.cs

📁 超市运行模拟软件源程序源代码,是一个用c#语言编写的C/S软件,开发环境是VS.NET 2003 登陆时可以看数据库中的姓名和密码,不然无法登陆,具体操作见里面的说明!
💻 CS
📖 第 1 页 / 共 2 页
字号:
			// 
			this.sqlDeleteCommand1.CommandText = @"DELETE FROM good WHERE (goodid = @Original_goodid) AND (goodnm = @Original_goodnm OR @Original_goodnm IS NULL AND goodnm IS NULL) AND (goodnum = @Original_goodnum OR @Original_goodnum IS NULL AND goodnum IS NULL) AND (goodprice = @Original_goodprice OR @Original_goodprice IS NULL AND goodprice IS NULL)";
			this.sqlDeleteCommand1.Connection = this.sqlConnection1;
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_goodid", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "goodid", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_goodnm", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "goodnm", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_goodnum", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "goodnum", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_goodprice", System.Data.SqlDbType.Money, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "goodprice", System.Data.DataRowVersion.Original, null));
			// 
			// sqlConnection1
			// 
			this.sqlConnection1.ConnectionString = "workstation id=HP110;packet size=4096;integrated security=SSPI;data source=\".\";pe" +
				"rsist security info=False;initial catalog=sqlgoods";
			// 
			// sqlInsertCommand1
			// 
			this.sqlInsertCommand1.CommandText = "INSERT INTO good(goodid, goodnm, goodprice, goodnum) VALUES (@goodid, @goodnm, @g" +
				"oodprice, @goodnum); SELECT goodid, goodnm, goodprice, goodnum FROM good WHERE (" +
				"goodid = @goodid)";
			this.sqlInsertCommand1.Connection = this.sqlConnection1;
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@goodid", System.Data.SqlDbType.Int, 4, "goodid"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@goodnm", System.Data.SqlDbType.VarChar, 50, "goodnm"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@goodprice", System.Data.SqlDbType.Money, 8, "goodprice"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@goodnum", System.Data.SqlDbType.Int, 4, "goodnum"));
			// 
			// sqlSelectCommand1
			// 
			this.sqlSelectCommand1.CommandText = "SELECT goodid, goodnm, goodprice, goodnum FROM good";
			this.sqlSelectCommand1.Connection = this.sqlConnection1;
			// 
			// sqlUpdateCommand1
			// 
			this.sqlUpdateCommand1.CommandText = @"UPDATE good SET goodid = @goodid, goodnm = @goodnm, goodprice = @goodprice, goodnum = @goodnum WHERE (goodid = @Original_goodid) AND (goodnm = @Original_goodnm OR @Original_goodnm IS NULL AND goodnm IS NULL) AND (goodnum = @Original_goodnum OR @Original_goodnum IS NULL AND goodnum IS NULL) AND (goodprice = @Original_goodprice OR @Original_goodprice IS NULL AND goodprice IS NULL); SELECT goodid, goodnm, goodprice, goodnum FROM good WHERE (goodid = @goodid)";
			this.sqlUpdateCommand1.Connection = this.sqlConnection1;
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@goodid", System.Data.SqlDbType.Int, 4, "goodid"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@goodnm", System.Data.SqlDbType.VarChar, 50, "goodnm"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@goodprice", System.Data.SqlDbType.Money, 8, "goodprice"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@goodnum", System.Data.SqlDbType.Int, 4, "goodnum"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_goodid", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "goodid", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_goodnm", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "goodnm", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_goodnum", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "goodnum", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_goodprice", System.Data.SqlDbType.Money, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "goodprice", System.Data.DataRowVersion.Original, null));
			// 
			// btnprev
			// 
			this.btnprev.Location = new System.Drawing.Point(360, 64);
			this.btnprev.Name = "btnprev";
			this.btnprev.TabIndex = 8;
			this.btnprev.Text = "向上";
			this.btnprev.Visible = false;
			this.btnprev.Click += new System.EventHandler(this.btnprev_Click);
			// 
			// btnnext
			// 
			this.btnnext.Location = new System.Drawing.Point(360, 104);
			this.btnnext.Name = "btnnext";
			this.btnnext.TabIndex = 9;
			this.btnnext.Text = "向下";
			this.btnnext.Visible = false;
			this.btnnext.Click += new System.EventHandler(this.btnnext_Click);
			// 
			// linkLabel1
			// 
			this.linkLabel1.ActiveLinkColor = System.Drawing.Color.Blue;
			this.linkLabel1.Cursor = System.Windows.Forms.Cursors.Hand;
			this.linkLabel1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.linkLabel1.ForeColor = System.Drawing.Color.Red;
			this.linkLabel1.LinkColor = System.Drawing.Color.Red;
			this.linkLabel1.Location = new System.Drawing.Point(680, 208);
			this.linkLabel1.Name = "linkLabel1";
			this.linkLabel1.Size = new System.Drawing.Size(96, 23);
			this.linkLabel1.TabIndex = 10;
			this.linkLabel1.TabStop = true;
			this.linkLabel1.Text = "查看销售总额";
			this.linkLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
			// 
			// Form2
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(784, 386);
			this.Controls.Add(this.linkLabel1);
			this.Controls.Add(this.btnnext);
			this.Controls.Add(this.btnprev);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.btnclose);
			this.Controls.Add(this.btnupdata);
			this.Controls.Add(this.dataGrid1);
			this.Name = "Form2";
			this.Text = "Form2";
			this.Load += new System.EventHandler(this.Form2_Load);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void Form2_Load(object sender, System.EventArgs e)
		{
			try
			{
				this.sqlDataAdapter1.Fill(dataSet11,"good");
				this.txtacount3.Enabled=false;
				this.txtallnum3.Enabled=false;
			}
			catch (Exception err)
			{
				MessageBox.Show(err.Message);
			}
		}

		private void btnupdata_Click(object sender, System.EventArgs e)
		{
			this.dataGrid1.UnSelect (this.dataGrid1.CurrentRowIndex);
			this.dataGrid1.Select(this.dataGrid1.CurrentRowIndex);
			this.sqlDataAdapter1.Update(dataSet11,"good");
			
		}

		

		

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

		private void btnout_Click(object sender, System.EventArgs e)
		{
			try
			{
				int i,count,flag = 0,flag2=1;		
				for (i=0; i < this.dataSet11.good.Rows.Count; i++)
				{
					if( this.txtid3.Text == this.dataSet11.good.Rows[i]["goodid"].ToString() ||txtnm3.Text==this.dataSet11.good.Rows[i]["goodnm"].ToString())
					{	
						count=Convert.ToInt32(this.txtnum3.Text);
						if( count>Convert.ToInt32(this.dataSet11.good.Rows[i]["goodnum"].ToString()))
						{
							MessageBox.Show("商品数量不够!");
							flag=1;
						}
						else
						{
							
							this.dataSet11.good.Rows[i]["goodnum"] = Convert.ToInt32(this.dataSet11.good.Rows[i]["goodnum"])-count;
							txtid3.Text=this.dataSet11.good.Rows[i]["goodid"].ToString();
							txtprice3.Text=Convert.ToString(Convert.ToDouble(this.dataSet11.good.Rows[i]["goodprice"])+1);
							txtnm3.Text=Convert.ToString(this.dataSet11.good.Rows[i]["goodnm"]);
							outallnum+=count;
							txtallnum3.Text=outallnum.ToString();
							outallmoney+=count*(Convert.ToDouble(this.dataSet11.good.Rows[i]["goodprice"])+1);
							txtacount3.Text=Convert.ToString(outallmoney);
							
							if(Convert.ToInt32(this.dataSet11.good.Rows[i]["goodnum"])<=0)
							{
								this.dataSet11.good.Rows[i].Delete();
								this.sqlDataAdapter1.Update(dataSet11,"good");
							}
							this.sqlDataAdapter1.Update(dataSet11,"good");
							flag = 1;
							flag2=0;
							
						}
						
					}
				}
										
				if(flag == 0)
					MessageBox.Show("商品未选中或没有该商品!");
				if(flag2==0)
				{
					
					btnout.Enabled=false;
					
				}
  					
				
				
			}
			
			catch (Exception err)
			{
				MessageBox.Show(err.Message);
			}
		}

		

		

		private void btnshou_Click_1(object sender, System.EventArgs e)
		{
			try
			{
				if(Convert.ToDouble(txtmoney.Text)-Convert.ToDouble(txtacount3.Text)<0)
				{
					MessageBox.Show(" 付款不足:"+"\n"+"应付:  "+Convert.ToString(txtacount3.Text)+ " 元 "+"\n"+"\n"+"只付:  "+Convert.ToString(txtmoney.Text)+" 元"+"\n"+"\n"+"不足:  "+Convert.ToString(-(Convert.ToDouble(txtmoney.Text)-Convert.ToDouble(txtacount3.Text)))+" 元");
				}
				else
				{
					MessageBox.Show("找零:  "+Convert.ToString(Convert.ToDouble(txtmoney.Text)-Convert.ToDouble(txtacount3.Text))+ " 元");
					outallmoney2+=Convert.ToDouble(txtacount3.Text);
					txtid3.Clear();
					txtnm3.Clear();
					txtprice3.Clear();
					txtnum3.Clear();
					this.txtallnum3.Text="";
					this.txtacount3.Text="";
					txtmoney.Clear();
					outallmoney=0;outallnum=0;
					btnout.Enabled=true;

				}
			}
			catch (Exception err)
			{
				MessageBox.Show(err.Message);
			}

		}

		private void btnprev_Click(object sender, System.EventArgs e)
		{
			try
			{
				this.dataGrid1.UnSelect(this.dataGrid1.CurrentRowIndex);
				if(this.dataGrid1.CurrentRowIndex >0)
					this.dataGrid1.CurrentRowIndex --;
				this.dataGrid1.Select(this.dataGrid1.CurrentRowIndex);
			}
			catch (Exception err)
			{
				MessageBox.Show(err.Message);
			}
		}

		private void btnnext_Click(object sender, System.EventArgs e)
		{
			try
			{

				this.dataGrid1.CurrentRowIndex = this.BindingContext[dataSet11.Tables["good"]].Position;
				this.dataGrid1.UnSelect(this.dataGrid1.CurrentRowIndex);
				this.BindingContext[dataSet11.Tables["good"]].Position++;
				this.dataGrid1.CurrentRowIndex = this.BindingContext[dataSet11.Tables["good"]].Position;
				this.dataGrid1.Select(this.dataGrid1.CurrentRowIndex);
				
			}
			catch (Exception err)
			{
				MessageBox.Show(err.Message);
			}
		}

		private void txtid3_TextChanged(object sender, System.EventArgs e)
		{
		try
		 { 
			int flag=0;
			this.sqlDataAdapter1.Update(dataSet11,"good");
			 for (int i=0; i < this.dataSet11.good.Rows.Count; i++)
			 {
				 if( this.txtid3.Text == this.dataSet11.good.Rows[i]["goodid"].ToString())
				 {
					 txtnm3.Text =this.dataSet11.good.Rows[i]["goodnm"].ToString();
					 txtprice3.Text=Convert.ToString(Convert.ToInt32(this.dataSet11.good.Rows[i]["goodprice"])+1);
					 btnout.Enabled=true;
					 i=0;flag=1;
					 break;
				 }
				 else if(this.txtid3.Text =="")
				 {
					 txtnm3.Clear();
					 txtprice3.Clear();
					 btnout.Enabled=true;
					 i=0;flag=1;
					 break;
				 }
			 }
			if(flag==0)
			{
				txtnm3.Clear();
				txtprice3.Clear();
				MessageBox.Show("该商品已售完");
				txtid3.Clear();

			}
		 }

		catch (Exception err)
		{
			MessageBox.Show(err.Message);
		}
		}

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

		private void txtnum3_TextChanged(object sender, System.EventArgs e)
		{
			try
			{
				if(Convert.ToInt32(txtnum3.Text)<=0)
				{
					MessageBox.Show("数量的输入有误");
				}
			}
			catch(Exception err)
			{
				
			}
		}

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

		private void button2_Click(object sender, System.EventArgs e)
		{
			MessageBox.Show("取消操作","取消购物?",MessageBoxButtons.YesNo,MessageBoxIcon.Asterisk);
		/*	if()
			{
			}===============*/
		}

		private void txtmoney_TextChanged(object sender, System.EventArgs e)
		{
			try
			{
			if(txtmoney.Text!="")
			 {
				 btnshou.Enabled=true;
			 }
			 else
				 btnshou.Enabled=false;
			}
			catch (Exception err)
			{
				MessageBox.Show(err.Message);
			}
			
		}

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

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

		private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
		{
			try
			{
			    MessageBox.Show(outallmoney2.ToString());
			}
			catch (Exception err)
			{
				MessageBox.Show(err.Message);
			}
		}

		


		
	}
}

⌨️ 快捷键说明

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