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

📄 usermanage.cs

📁 c#编写的汽车销售公司erp进销存系统
💻 CS
📖 第 1 页 / 共 3 页
字号:
			ts.GridLineColor=Color.FromArgb(ShareClass.Rcolor,ShareClass.Gcolor,ShareClass.Bcolor);
			ts.HeaderBackColor=Color.FromArgb(ShareClass.Rcolor,ShareClass.Gcolor,ShareClass.Bcolor);

			DataGridColumnStyle gs0 = new DataGridTextBoxColumn();
			gs0.MappingName = "id";
			gs0.HeaderText = "编号";
			gs0.ReadOnly=true;
			gs0.Width=40;
			ts.GridColumnStyles.Add(gs0);

			DataGridColumnStyle gs1 = new DataGridTextBoxColumn();
			gs1.MappingName = "mname";
			gs1.HeaderText = "菜单名称";
			gs1.ReadOnly=true;
			gs1.Width=90;
			ts.GridColumnStyles.Add(gs1);


			this.dgMenu.TableStyles.Add(ts);
		}

		private void btSave_Click(object sender, System.EventArgs e)
		{
			try
			{
				this.Cursor = Cursors.WaitCursor;
				this.btSave.Enabled = false;
				modifyData();
				this.btSave.Enabled = true;
				this.Cursor = Cursors.Arrow;
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}
		private void ClearData()
		{
			this.txtname.Text="";
			this.txtLogin.Text="";
			this.txtPwd.Text="";
			this.txtPwdC.Text="";
			this.txtDescript.Text="";
			this.cobLevel.SelectedIndex=0;
			this.txtMenu.Text="";
			this.txtId.Text="";
			this.txtTelnumber.Text="";
			getEnabled(false);
		}
		private SysoperatorInfo setData()
		{
			SysoperatorInfo sysinfo=new SysoperatorInfo();
			sysinfo.opassword=this.txtPwd.Text;
			sysinfo.lname=this.txtLogin.Text.Trim();
			sysinfo.oname=this.txtname.Text.Trim();
			sysinfo.odescription=this.txtDescript.Text.Trim();
			sysinfo.olevel=this.cobLevel.SelectedItem.ToString();
			sysinfo.omenuid=this.txtMenu.Text;
			sysinfo.oid = Convert.ToInt32(this.txtId.Text.Trim());
			sysinfo.otelnumnber= this.txtTelnumber.Text.Trim();
			return sysinfo;
		}

		private bool validate(){
			if(this.txtname.Text.Trim()=="")
			{
				MessageBox.Show(this,"用户名不能为空,请重新输入!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
				this.txtname.Focus();
				return false;
			}
			if(this.txtname.Text.Trim().Length>30)
			{
				MessageBox.Show(this,"用户名不能多于30个字符,请重新输入!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
				this.txtname.Focus();
				return false;
			}
			if(this.txtLogin.Text.Trim()=="")
			{
				MessageBox.Show(this,"登陆名不能为空,请重新输入!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
				this.txtLogin.Focus();
				return false;
			}
			if(this.txtLogin.Text.Trim().Length>30)
			{
				MessageBox.Show(this,"登陆名不能多于30个字符,请重新输入!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
				this.txtLogin.Focus();
				return false;
			}
			if(this.txtId.Text.Trim()=="")
			{
				MessageBox.Show(this,"坐席ID不能为空,请重新输入!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
				this.txtId.Focus();
				return false;
			}
			if(ShareClass.isNubmic(this.txtId.Text,"坐席ID") == 1)
			{
				return false;
			}
			if(this.cobLevel.Text.Trim()=="")
			{
				MessageBox.Show(this,"请选择用户级别!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
				this.cobLevel.Focus();
				return false;
			}
			if(this.txtPwd.Text.Trim().Length>10)
			{
				MessageBox.Show(this,"用户密码不能多于10个字符,请重新输入!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
				this.txtLogin.Focus();
				return false;
			}
			if(this.txtPwd.Text!=this.txtPwdC.Text)
			{
				MessageBox.Show("用户密码不一致,请重新输入!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
				this.txtPwd.Focus();
				return false;
			}

			if(this.txtTelnumber.Text.Trim()=="")
			{
				MessageBox.Show(this,"坐席电话不能为空,请重新输入!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
				this.txtTelnumber.Focus();
				return false;
			}
			if(this.txtTelnumber.Text.Trim().Length>20)
			{
				MessageBox.Show(this,"坐席电话不能多于20个字符,请重新输入!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
				this.txtTelnumber.Focus();
				return false;
			}

			if(this.txtDescript.Text.Trim()=="")
			{
				MessageBox.Show(this,"服务描述不能为空,请重新输入!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
				this.txtDescript.Focus();
				return false;
			}
			if(this.txtDescript.Text.Trim().Length>100)
			{
				MessageBox.Show(this,"服务描述不能多于100个字符,请重新输入!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
				this.txtDescript.Focus();
				return false;
			}
			return true;
		}
		private void modifyData()
		{
			if(!this.validate()){
				return;
			}
			SysoperatorInfo sysinfo=new SysoperatorInfo();
			sysinfo=setData();
			SysoperatorBLL sysbll=new SysoperatorBLL();
			int flag = sysbll.updateSysoperator(sysinfo);
			if(-2==flag)
			{
				MessageBox.Show(this,"坐席ID已存在,请重新输入!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
				this.txtId.Focus();
			}
			else if(flag>0)
			{
				MessageBox.Show(this,"修改成功!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
				getDataBind();
				ClearData();
			}
			else
			{
				MessageBox.Show(this,"修改失败!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
			}
		}
		private void insertData()
		{
			if(!this.validate())
			{
				return;
			}
			SysoperatorInfo sysinfo=new SysoperatorInfo();
			sysinfo=setData();
			SysoperatorBLL sysbll=new SysoperatorBLL();
			int flag = sysbll.addSysoperator(sysinfo);
			if(flag > 0)
			{
				MessageBox.Show(this,"添加成功","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
				getDataBind();
				ClearData();
			}
			else if(-1==flag)
			{
				MessageBox.Show(this,"登陆名已存在,请重新输入","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
				this.txtLogin.Focus();
			}
			else if(-2==flag)
			{
				MessageBox.Show(this,"坐席ID已存在,请重新输入","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
				this.txtId.Focus();
			}
			else
			{
				MessageBox.Show(this,"添加失败!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
			}
			
		}
		private void deleteXmlSkin(string loginname)
		{
			XmlDocument xmlDoc=new XmlDocument();
			xmlDoc.Load("system.xml");

			XmlNodeList xnl=xmlDoc.SelectSingleNode("system").ChildNodes;
 
			foreach(XmlNode xn in xnl)
			{
				XmlElement xe=(XmlElement)xn;
				if(xe.GetAttribute("name")==loginname)
				{
					xe.RemoveAll();//删除该节点的全部内容
				}
			}
			xmlDoc.Save("system.xml");

		}
		private void btDelete_Click(object sender, System.EventArgs e)
		{
			try
			{
				if(MessageBox.Show("确定要删除此条记录吗?","提示",MessageBoxButtons.YesNo,MessageBoxIcon.Warning)==DialogResult.Yes)
				{
					this.Cursor = Cursors.WaitCursor;
					deleteXmlSkin(Convert.ToString(this.dgUser[this.dgUser.CurrentCell.RowNumber,1]));
					SysoperatorBLL sysbll=new SysoperatorBLL();
					sysbll.delSysoperator(Convert.ToString(this.dgUser[this.dgUser.CurrentCell.RowNumber,1]));
					
					this.Cursor = Cursors.Arrow;
					getDataBind();
					ClearData();					
					MessageBox.Show(this,"删除成功!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
				}
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}

		private void getEnabled(bool enabled)
		{
			if(enabled==true)
			{
				this.btSave.Enabled=true;
				this.btDelete.Enabled=true;
				this.btReset.Enabled=true;
			}
			else
			{
				this.btSave.Enabled=false;
				this.btDelete.Enabled=false;
				this.btReset.Enabled=false;
			}
		}

		private void dgUser_DoubleClick(object sender, System.EventArgs e)
		{
//			this.dgUser.GetCellBounds
		}


		private void dgUser_CurrentCellChanged(object sender, System.EventArgs e)
		{
//			this.dgUser.Select(this.dgUser.CurrentCell.RowNumber);
			this.dgUser.ReadOnly=true;
			this.txtname.Text=Convert.ToString(this.dgUser[this.dgUser.CurrentCell.RowNumber,0]);
			this.txtLogin.Text=Convert.ToString(this.dgUser[this.dgUser.CurrentCell.RowNumber,1]);
			this.txtDescript.Text=Convert.ToString(this.dgUser[this.dgUser.CurrentCell.RowNumber,4]);
			this.cobLevel.Text=Convert.ToString(this.dgUser[this.dgUser.CurrentCell.RowNumber,2]);
			this.txtMenu.Text=Convert.ToString(this.dgUser[this.dgUser.CurrentCell.RowNumber,3]);
			this.txtId.Text=Convert.ToString(this.dgUser[this.dgUser.CurrentCell.RowNumber,5]);
			this.txtTelnumber.Text=Convert.ToString(this.dgUser[this.dgUser.CurrentCell.RowNumber,6]);
			this.txtPwd.Text=Convert.ToString(this.dgUser[this.dgUser.CurrentCell.RowNumber,7]);
			this.txtPwdC.Text=Convert.ToString(this.dgUser[this.dgUser.CurrentCell.RowNumber,7]);
			getEnabled(true);

		}

		private void btReset_Click(object sender, System.EventArgs e)
		{
			ClearData();
		}

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

		private void dgMenu_CurrentCellChanged(object sender, System.EventArgs e)
		{
			string strMenu;
			string strDgM="";
			this.dgMenu.Select(this.dgMenu.CurrentCell.RowNumber);
			this.dgMenu.ReadOnly=true;
			strMenu=this.txtMenu.Text.Trim();
			strDgM=this.dgMenu[this.dgMenu.CurrentCell.RowNumber,0].ToString()+",";
			if (strMenu.IndexOf(strDgM)==-1)
			{
				this.txtMenu.Text+=strDgM;
			}
			else
			{
				strMenu=strMenu.Replace(strDgM,"");
				this.txtMenu.Text=strMenu;
			}
			
		}

		private void txtMenu_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			this.button1.Visible=true;
			this.dgMenu.Visible=true;
			
		}

		private void txtMenu_MouseLeave(object sender, System.EventArgs e)
		{
//			MessageBox.Show(sender.GetType().ToString());
			if(sender.GetType().ToString()=="System.Windows.Forms.TextBox" || sender.GetType().ToString()=="System.Windows.Forms.DataGrid")
			{
				this.dgMenu.Visible=true;
				this.button1.Visible=true;
			}
			else
			{
				this.dgMenu.Visible=false;
				this.button1.Visible=false;
			}
		}

	

		private void button1_Click(object sender, System.EventArgs e)
		{
			this.dgMenu.Visible=false;
			this.button1.Visible=false;
		}

		private void btAdd_Click(object sender, System.EventArgs e)
		{
			insertData();
		}


	}

	}

⌨️ 快捷键说明

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