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

📄 frmpredict.cs

📁 车载GPS?今天这个就是最好的工具
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace GEROSYS
{
	/// <summary>
	/// frmPredict 的摘要说明。
	/// </summary>
	public class frmPredict : System.Windows.Forms.Form
	{
		private System.Windows.Forms.DataGrid grdPredict;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.Button cmdOK;
		private System.Windows.Forms.Button cmdExit;
		private GEROMain frm;
		private DataRow myDataRow;
		private DataTable dtEmp = new DataTable();
//		protected const string SQL_CONNECTION_STRING  = @"Data Source=diaodushi;DataBase=gero;user id=sa;password=sasa";
//		protected const string SQL_CONNECTION_STRING  = @"Server=(local)\PCMS;DataBase=gero;user id=sa;password=pcms;Integrated Security=SSPI";
		private string strConn= new AccessData().ConnectionString ;

		public frmPredict(GEROMain frm)
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();
			this.frm =frm;

			//
			// 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.grdPredict = new System.Windows.Forms.DataGrid();
			this.cmdOK = new System.Windows.Forms.Button();
			this.cmdExit = new System.Windows.Forms.Button();
			((System.ComponentModel.ISupportInitialize)(this.grdPredict)).BeginInit();
			this.SuspendLayout();
			// 
			// grdPredict
			// 
			this.grdPredict.DataMember = "";
			this.grdPredict.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.grdPredict.Location = new System.Drawing.Point(0, 0);
			this.grdPredict.Name = "grdPredict";
			this.grdPredict.Size = new System.Drawing.Size(624, 328);
			this.grdPredict.TabIndex = 0;
			// 
			// cmdOK
			// 
			this.cmdOK.Location = new System.Drawing.Point(448, 336);
			this.cmdOK.Name = "cmdOK";
			this.cmdOK.Size = new System.Drawing.Size(88, 40);
			this.cmdOK.TabIndex = 1;
			this.cmdOK.Text = "确定(&O)";
			this.cmdOK.Click += new System.EventHandler(this.cmdOK_Click);
			// 
			// cmdExit
			// 
			this.cmdExit.Location = new System.Drawing.Point(536, 336);
			this.cmdExit.Name = "cmdExit";
			this.cmdExit.Size = new System.Drawing.Size(88, 40);
			this.cmdExit.TabIndex = 2;
			this.cmdExit.Text = "退出(&E)";
			this.cmdExit.Click += new System.EventHandler(this.cmdExit_Click);
			// 
			// frmPredict
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(632, 381);
			this.Controls.Add(this.cmdExit);
			this.Controls.Add(this.cmdOK);
			this.Controls.Add(this.grdPredict);
			this.Name = "frmPredict";
			this.Text = "抢修预案成员表";
			this.Load += new System.EventHandler(this.frmPredict_Load);
			((System.ComponentModel.ISupportInitialize)(this.grdPredict)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void frmPredict_Load(object sender, System.EventArgs e)
		{
			InitPredictGrid();
			InitFlag();
		}

		#region grdPredict 抢修预案人员表初始化处理
		private void InitPredictGrid() //初始化网格
		{
			string mstr;	
			grdPredict.BackColor = Color.GhostWhite;
			grdPredict.BackgroundColor = Color.Lavender;
			grdPredict.BorderStyle = BorderStyle.None;
			grdPredict.CaptionBackColor = Color.RoyalBlue;
			grdPredict.CaptionFont = new Font("Tahoma", 10.0F, FontStyle.Bold);
			grdPredict.CaptionForeColor = Color.Bisque;
			grdPredict.CaptionText = "抢修预案人员表";
			grdPredict.Font = new Font("Tahoma", 8.0F);
			grdPredict.ParentRowsBackColor = Color.Lavender;
			grdPredict.ParentRowsForeColor = Color.MidnightBlue;
			
			mstr="Select PredictID,Duty,EmpName,Phone,MobilPhone,Flag,Currently,Instancy,Special From Predict";	

			SqlConnection scnn = new SqlConnection(strConn);
			scnn.Open();
			SqlCommand scmd = new SqlCommand(mstr,scnn);
			SqlDataAdapter sda = new SqlDataAdapter(scmd);
			DataSet dsProducts = new DataSet(); 
			try 
			{
				sda.Fill(dsProducts);
				grdPredict.DataSource = dsProducts.Tables[0];
			} 
			catch(SqlException expSql)
			{
				MessageBox.Show(expSql.ToString(), this.Text);
				return;
			}
			scnn.Close();
			scnn.Dispose();
			DataGridTableStyle grdTableStyle1 = new DataGridTableStyle();
			grdTableStyle1.AlternatingBackColor = Color.GhostWhite;
			grdTableStyle1.BackColor = Color.GhostWhite;
			grdTableStyle1.ForeColor = Color.MidnightBlue;
			grdTableStyle1.GridLineColor = Color.RoyalBlue;
			grdTableStyle1.HeaderBackColor = Color.MidnightBlue;
			grdTableStyle1.HeaderFont = new Font("Tahoma", 8.0F, FontStyle.Bold);
			grdTableStyle1.HeaderForeColor = Color.Lavender;
			grdTableStyle1.SelectionBackColor = Color.Teal;
			grdTableStyle1.SelectionForeColor = Color.PaleGreen;
			grdTableStyle1.MappingName = dsProducts.Tables[0].TableName;
			grdTableStyle1.RowHeaderWidth =5;

			DataGridTextBoxColumn grdColStyle1 = new DataGridTextBoxColumn();
			grdColStyle1.HeaderText = "预案编码";
			grdColStyle1.MappingName = "PredictID";
			grdColStyle1.Alignment =  HorizontalAlignment.Center;
			grdColStyle1.ReadOnly = true;

			DataGridTextBoxColumn grdColStyle2 = new DataGridTextBoxColumn();
			grdColStyle2.HeaderText = "职务";
			grdColStyle2.MappingName = "Duty";
			grdColStyle2.Alignment =  HorizontalAlignment.Left;
			grdColStyle2.ReadOnly = true;
       
			DataGridTextBoxColumn grdColStyle3 = new DataGridTextBoxColumn();
			grdColStyle3.HeaderText = "姓名";
			grdColStyle3.MappingName = "EmpName";
			grdColStyle3.Alignment =  HorizontalAlignment.Center;
			grdColStyle3.ReadOnly = true;
			
			DataGridTextBoxColumn grdColStyle4 = new DataGridTextBoxColumn();
			grdColStyle4.HeaderText = "电话";
			grdColStyle4.MappingName = "Phone";
			grdColStyle4.Alignment =  HorizontalAlignment.Center;
			grdColStyle4.ReadOnly = true;

			DataGridTextBoxColumn grdColStyle5 = new DataGridTextBoxColumn();
			grdColStyle5.HeaderText = "移动电话";
			grdColStyle5.MappingName = "MobilPhone";
			grdColStyle5.Alignment =  HorizontalAlignment.Center;
			grdColStyle5.ReadOnly = true;

			DataGridBoolColumn  grdColStyle6 = new DataGridBoolColumn();
			grdColStyle6.HeaderText = "是否参与";
			grdColStyle6.MappingName = "Flag";
			grdColStyle6.Alignment =  HorizontalAlignment.Center;
			grdColStyle6.ReadOnly = false;

			DataGridBoolColumn  grdColStyle7 = new DataGridBoolColumn();
			grdColStyle7.HeaderText = "一般";
			grdColStyle7.MappingName = "Currently";

			DataGridBoolColumn  grdColStyle8 = new DataGridBoolColumn();
			grdColStyle8.HeaderText = "紧急";
			grdColStyle8.MappingName = "Instancy";

			DataGridBoolColumn  grdColStyle9 = new DataGridBoolColumn();
			grdColStyle9.HeaderText = "灾害";
			grdColStyle9.MappingName = "Special";


			grdColStyle1.Width = 0;
			grdColStyle2.Width = 150;
			grdColStyle3.Width = 100;
			grdColStyle4.Width = 120;
			grdColStyle5.Width = 110;
			grdColStyle6.Width = 100;
			grdColStyle7.Width = 0;
			grdColStyle8.Width = 0;
			grdColStyle9.Width = 0;
			grdTableStyle1.GridColumnStyles.AddRange(new DataGridColumnStyle[] 
						{grdColStyle1, grdColStyle2, grdColStyle3,grdColStyle4,grdColStyle5,grdColStyle6,grdColStyle7,grdColStyle8,grdColStyle9});

			grdPredict.TableStyles.Clear();
			grdPredict.TableStyles.Add(grdTableStyle1);

		}
		#endregion

		#region grdPredict 抢修预案表字段是否参与初始化处理
		private void InitFlag()
		{
			
			dtEmp=(DataTable)grdPredict.DataSource;
			if (dtEmp.Rows.Count < 1)
			{
				return;
			} 
			
			for(int i = 0;i < dtEmp.Rows.Count; i ++ )
			{
				myDataRow=dtEmp.Rows[i];

				if (frm.strPredict.ToString() =="一般行动")
				{
					myDataRow["Flag"]=myDataRow["Currently"].ToString();
				}	
				else if (frm.strPredict.ToString() =="紧急行动")
				{
					myDataRow["Flag"]=myDataRow["instancy"].ToString();
				}
//				else if (frm.strPredict.ToString() =="特别行动")
//				{
//					myDataRow["Flag"]=myDataRow["especial"].ToString();
//				}	
				else if (frm.strPredict.ToString() =="灾害行动")
				{
					myDataRow["Flag"]=myDataRow["special"].ToString();
				}	
				else
				{
					myDataRow["Flag"]=0;
				}
			}
		}
		#endregion

		private void cmdExit_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
		
		#region 抢修预案成员表确认按钮
		private void cmdOK_Click(object sender, System.EventArgs e)
		{
			string mstrName;
			if (dtEmp.Rows.Count < 1)
			{
				return;
			} 
			for(int i = 0;i < dtEmp.Rows.Count; i ++ )
			{
				myDataRow=dtEmp.Rows[i];
				if (myDataRow["Flag"].ToString() == "True")
				{
					mstrName ="Update Predict Set Flag = 1 Where PredictID ='" +
						       myDataRow["PredictID"].ToString() +"'" ;

					try 
					{
						SqlConnection scnn = new SqlConnection(strConn);
						scnn.Open();
						SqlCommand scmd = new SqlCommand(mstrName,scnn);
						scmd.ExecuteNonQuery();
						scnn.Close();
						scmd.Dispose();
						scnn.Dispose();
					} 
					catch(SqlException expSql)
					{
						MessageBox.Show(expSql.ToString(), this.Text);
						return;
					}
				}
			}
			
			this.Close();
		}
		#endregion

	}
}

⌨️ 快捷键说明

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