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

📄 addvaluation.cs

📁 本系统为资产管理系统
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace AssetManagement
{
	/// <summary>
	/// addValuation 的摘要说明。
	/// </summary>
	public class addValuation : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox textBox2;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.TextBox textBox4;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.DateTimePicker dateTimePicker1;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private string employeeNo;
		private System.Windows.Forms.Label label4;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public addValuation()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}
		public addValuation(string str)
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();
            employeeNo = str;
			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.textBox2 = new System.Windows.Forms.TextBox();
			this.label5 = new System.Windows.Forms.Label();
			this.textBox4 = new System.Windows.Forms.TextBox();
			this.label6 = new System.Windows.Forms.Label();
			this.label7 = new System.Windows.Forms.Label();
			this.label8 = new System.Windows.Forms.Label();
			this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.label4 = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Dock = System.Windows.Forms.DockStyle.Top;
			this.label1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label1.Location = new System.Drawing.Point(0, 0);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(408, 32);
			this.label1.TabIndex = 0;
			this.label1.Text = "资产估价";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 72);
			this.label2.Name = "label2";
			this.label2.TabIndex = 1;
			this.label2.Text = "估价编号";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(144, 72);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(120, 21);
			this.textBox1.TabIndex = 2;
			this.textBox1.Text = "textBox1";
			this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(16, 128);
			this.label3.Name = "label3";
			this.label3.TabIndex = 3;
			this.label3.Text = "资产编号";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// textBox2
			// 
			this.textBox2.Location = new System.Drawing.Point(144, 128);
			this.textBox2.Name = "textBox2";
			this.textBox2.Size = new System.Drawing.Size(120, 21);
			this.textBox2.TabIndex = 4;
			this.textBox2.Text = "textBox2";
			this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(16, 192);
			this.label5.Name = "label5";
			this.label5.TabIndex = 7;
			this.label5.Text = "估价日期";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// textBox4
			// 
			this.textBox4.Location = new System.Drawing.Point(144, 256);
			this.textBox4.Name = "textBox4";
			this.textBox4.Size = new System.Drawing.Size(128, 21);
			this.textBox4.TabIndex = 8;
			this.textBox4.Text = "textBox4";
			this.textBox4.TextChanged += new System.EventHandler(this.textBox4_TextChanged);
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(16, 256);
			this.label6.Name = "label6";
			this.label6.TabIndex = 9;
			this.label6.Text = "当前价值";
			this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(280, 72);
			this.label7.Name = "label7";
			this.label7.TabIndex = 11;
			this.label7.Text = "*";
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(280, 128);
			this.label8.Name = "label8";
			this.label8.TabIndex = 12;
			this.label8.Text = "*";
			// 
			// dateTimePicker1
			// 
			this.dateTimePicker1.Location = new System.Drawing.Point(144, 192);
			this.dateTimePicker1.Name = "dateTimePicker1";
			this.dateTimePicker1.Size = new System.Drawing.Size(136, 21);
			this.dateTimePicker1.TabIndex = 14;
			this.dateTimePicker1.TabStop = false;
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(192, 368);
			this.button1.Name = "button1";
			this.button1.TabIndex = 15;
			this.button1.Text = "添加";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(312, 368);
			this.button2.Name = "button2";
			this.button2.TabIndex = 16;
			this.button2.Text = "退出";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(280, 256);
			this.label4.Name = "label4";
			this.label4.TabIndex = 17;
			this.label4.Text = "*";
			// 
			// addValuation
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(408, 422);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.dateTimePicker1);
			this.Controls.Add(this.label8);
			this.Controls.Add(this.label7);
			this.Controls.Add(this.label6);
			this.Controls.Add(this.textBox4);
			this.Controls.Add(this.label5);
			this.Controls.Add(this.textBox2);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.textBox1);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Name = "addValuation";
			this.Text = "addValuation";
			this.Load += new System.EventHandler(this.addValuation_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private void button1_Click(object sender, System.EventArgs e)
		{
			if (this.textBox1.Text.Trim() == "")
			{
				MessageBox.Show("估价编号不能为空!");
				this.textBox1.Focus();
			}
			else
			{
				if (this.textBox2.Text.Trim() == "")
				{
					MessageBox.Show("资产编号不能为空!");
					this.textBox2.Focus();
				}
				else
				{
					if (this.textBox4.Text.Trim() == "")
					{
						MessageBox.Show("当前价值不能为空!");
						this.textBox4.Focus();
					}
					else
					{
						bool check = true;
						Connection s = new Connection(); 
						SqlConnection conn = new SqlConnection(s.getConnectionString);
						conn.Open();
						string strr1 = "select * from valuation";
						SqlCommand cmd1 = new SqlCommand(strr1,conn);
						SqlDataReader dr = cmd1.ExecuteReader();
						while (dr.Read())
						{
							if (this.textBox1.Text.Trim() == Convert.ToString(dr["valuationNo"]))
							{
								check = false;
								MessageBox.Show("估价编号已存在!");
								this.textBox1.Text = "";
								this.textBox1.Focus();
								break;
							}
						}
						dr.Close();
						if (check)
						{
							check = false;
							string strr2 = "select * from asset";
							SqlCommand cmd2 = new SqlCommand(strr2,conn);
							SqlDataReader dr1 = cmd1.ExecuteReader();
							while (dr1.Read())
							{
								if (this.textBox2.Text.Trim() == Convert.ToString(dr1["assetNo"]))
								{
									check = true;
									//MessageBox.Show("估价编号已存在!");
									//this.textBox1.Text = "";
									//this.textBox1.Focus();
									break;
								}
							}
							dr1.Close();

							if (check)
							{
								SqlCommand cmd = new SqlCommand("addValuation1",conn);
								cmd.CommandType = CommandType.StoredProcedure;
								SqlParameter ValuationNo = new SqlParameter("@valuationNo",System.Data.SqlDbType.VarChar,10);
								ValuationNo.Value = this.textBox1.Text.Trim();
								cmd.Parameters.Add(ValuationNo);
								SqlParameter AssetNo = new SqlParameter("@assetNo",SqlDbType.VarChar,10);
								AssetNo.Value  = this.textBox2.Text.Trim();
								cmd.Parameters.Add(AssetNo);
								SqlParameter EmployeeNo = new SqlParameter("@employeeNo",SqlDbType.VarChar,10);
								EmployeeNo.Value = this.employeeNo;
								cmd.Parameters.Add(EmployeeNo);
								MessageBox.Show(this.employeeNo);
								SqlParameter ValuationDate = new SqlParameter("@valuationDate",SqlDbType.VarChar,20);
								ValuationDate.Value = this.dateTimePicker1.Value.ToShortDateString();
								cmd.Parameters.Add(ValuationDate);
								//SqlParameter ValuationPrice = new SqlParameter("@valuationPrice",SqlDbType.Float,8);
								try
								{
									SqlParameter ValuationPrice = new SqlParameter("@valuationPrice",SqlDbType.Float,8);
									ValuationPrice.Value = float.Parse(this.textBox4.Text.Trim());
									cmd.Parameters.Add(ValuationPrice);
									check = true;
								}
								catch
								{
									MessageBox.Show("当前价值应为数字!");
									this.textBox4.Text = "";
									this.textBox4.Focus();
									check = false;
								}
								if (check)
								{
									try
									{
										cmd.ExecuteNonQuery();
										MessageBox.Show("添加成功!");
									}
									catch
									{
										MessageBox.Show("添加失败!");
									}
								}
							}
							else
							{
								MessageBox.Show("资产号不存在!");
								this.textBox2.Text = "";
								this.textBox2.Focus();
							}
						
						}
						conn.Close();
					}
				}
			}
		}

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

		private void addValuation_Load(object sender, System.EventArgs e)
		{
			this.textBox1.Text = "";
			this.textBox2.Text = "";
			this.textBox4.Text = "";
		}

		private void textBox1_TextChanged(object sender, System.EventArgs e)
		{
			if (this.textBox1.Text.Trim().Length > 10)
			{
				MessageBox.Show("输入无效,请重输!");
				this.textBox1.Text = "";
				this.textBox1.Focus();
			}
		}

		private void textBox2_TextChanged(object sender, System.EventArgs e)
		{
			if (this.textBox2.Text.Trim().Length > 10)
			{
				MessageBox.Show("输入无效,请重输!");
				this.textBox2.Text = "";
				this.textBox2.Focus();
			}
		}

		private void textBox4_TextChanged(object sender, System.EventArgs e)
		{
			string s = "";
			if (this.textBox4.Text.Trim().Length > 8)
			{
				MessageBox.Show("输入数据无效!");
				this.textBox4.Text = "";
				this.textBox4.Focus();
			}
			else
			{
				if (this.textBox4.Text.Trim() != "")
				{
					s = this.textBox4.Text.Trim();
					for (int i = 0;i < s.Length;i++)
					{
						if (s[i] >= '0'&&s[i] <= '9')
						{
							continue;
						}
						else
						{
							MessageBox.Show(" 当前价值应为数字!");
							this.textBox4.Text = "";
							this.textBox4.Focus();
						}
					}
					if ((s.Length >= 2) && (s[0] == '0'))
					{
						MessageBox.Show("无效数据,请重输!");
						this.textBox4.Text = "";
						this.textBox4.Focus();
					}
				}
			}
		}
	}
}

⌨️ 快捷键说明

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