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

📄 usercontrol1.cs

📁 图书管理系统,.net2003+sql2000,分为三个模块,用户端,操作员端,系统管理员端.基本上是用自定义控件dll来完成,内含完整sql语句,包括存储过程.
💻 CS
📖 第 1 页 / 共 3 页
字号:

		}
		#endregion

		private void UserControl1_Load(object sender, System.EventArgs e)
		{	
			if(this.UserType=="reader"||this.UserType=="operator")
			{
				////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
				公共数据dll.Store.sqlStr="select * from readerinfo where 证件号='"+公共数据dll.Store.str_temp+"'";
				MessageBox.Show(公共数据dll.Store.sqlStr);
				公共数据dll.Store.myDataAdapter=new System.Data.SqlClient.SqlDataAdapter(公共数据dll.Store.sqlStr,公共数据dll.Store.cn);
				公共数据dll.Store.cb =new System.Data.SqlClient.SqlCommandBuilder(公共数据dll.Store.myDataAdapter);
				公共数据dll.Store.myDataAdapter.Fill(公共数据dll.Store.ds,"readerinfo");
				//			try
				//			{
				//				公共数据dll.Store.ds.Tables["readerinfo"].Rows[0][0]="000";
				//				公共数据dll.Store.myDataAdapter.Update(公共数据dll.Store.ds,"readerinfo");
				//			}
				//			catch
				//			{
				//				MessageBox.Show("更新出错!");
				//			}
				公共数据dll.Store.sqlStr="select record.条码号,题名,馆藏地,借阅日期,应归还日期,操作='续借该书' from record,bookinfoview where record.条码号=bookinfoview.条码号 and 证件号='"+公共数据dll.Store.str_temp+"' and record.状态='未还' or record.状态='超期'";
				公共数据dll.Store.myDataAdapter=new System.Data.SqlClient.SqlDataAdapter(公共数据dll.Store.sqlStr,公共数据dll.Store.cn);
				公共数据dll.Store.cb =new System.Data.SqlClient.SqlCommandBuilder(公共数据dll.Store.myDataAdapter);
				公共数据dll.Store.myDataAdapter.Fill(公共数据dll.Store.ds,"currentrecord");
				this.dataGrid1.SetDataBinding(公共数据dll.Store.ds,"currentrecord");

				foreach(DataRow dr in 公共数据dll.Store.ds.Tables["readerinfo"].Rows)
				{
					textBox4.Text=dr["姓名"].ToString();
					textBox2.Text=dr["密码"].ToString();//////////////////
					textBox1.Text=dr["证件号"].ToString();
					comboBox1.Text=dr["文化程度"].ToString();
					dateTimePicker1.Text=dr["出生日期"].ToString();
					decimal year=(decimal)int.Parse(dr["年龄"].ToString());
					numericUpDown1.Value=year;
					comboBox6.Text=dr["工作单位"].ToString();
					comboBox3.Text=dr["性别"].ToString();
					comboBox4.Text=dr["职业"].ToString();
					comboBox5.Text=dr["最大借书量"].ToString();
					textBox3.Text=dr["电话"].ToString();////////////////////////////
					textBox5.Text=dr["E-MAIL"].ToString();/////////////////////////

				}
				公共数据dll.Store.cn.Close();/////////关闭连接
			}
			else if(this.UserType=="systemmanager")
			{
				this.dataGrid1.Visible=false;
			}
			//设置访问权限
			if(this.UserType=="reader"|| this.UserType=="operator")
			{
				textBox4.Enabled=false;
				textBox1.Enabled=false;
				comboBox1.Enabled=false;
				dateTimePicker1.Enabled=false;
				numericUpDown1.Enabled=false;
				comboBox6.Enabled=false;
				comboBox3.Enabled=false;
				comboBox4.Enabled=false;
				comboBox5.Enabled=false;
				this.button2.Enabled=false;
				if(this.UserType=="operator")
				{
					textBox2.Enabled=false;
					textBox3.Enabled=false;
					textBox5.Enabled=false;
					this.button1.Enabled=false;
					this.button2.Enabled=false;
				}
			}
		}

		private void button1_Click(object sender, System.EventArgs e)//修改读者信息
		{
			公共数据dll.Store.cn.Open();
            公共数据dll.Store.sqlStr="update readerinfo set 密码='"+textBox2.Text+"', 电话='"+textBox3.Text+"', [E-MAIL]='"+textBox5.Text+"' where 证件号='"+公共数据dll.Store.str_temp+"'";
			MessageBox.Show(公共数据dll.Store.sqlStr);
			公共数据dll.Store.cmd=new System.Data.SqlClient.SqlCommand(公共数据dll.Store.sqlStr,公共数据dll.Store.cn);
			if(公共数据dll.Store.cmd.ExecuteNonQuery()==1)
				MessageBox.Show("修改成功!","success",MessageBoxButtons.OK,MessageBoxIcon.Information);
			else
				MessageBox.Show("修改出错!");
			公共数据dll.Store.cn.Close();
		}

		private void button2_Click(object sender, System.EventArgs e)/////删除读者记录///////系统管理员权限
		{
			公共数据dll.Store.cn.Open();
            公共数据dll.Store.sqlStr="delete from readerinfo  where 证件号='"+公共数据dll.Store.str_temp+"'";
			MessageBox.Show(公共数据dll.Store.sqlStr);
			DialogResult re=MessageBox.Show("警告:你将会彻底读者:"+公共数据dll.Store.str_temp+"的所有信息!","警告",MessageBoxButtons.OKCancel,MessageBoxIcon.Warning);
			if(re==DialogResult.OK)
			{
				公共数据dll.Store.cmd=new System.Data.SqlClient.SqlCommand(公共数据dll.Store.sqlStr,公共数据dll.Store.cn);
				if(公共数据dll.Store.cmd.ExecuteNonQuery()==1)
					MessageBox.Show("删除成功!","success",MessageBoxButtons.OK,MessageBoxIcon.Information);
				else
					MessageBox.Show("删除出错!");
			}
			
			公共数据dll.Store.cn.Close();
		}

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

		private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)//设置续借功能
		{
			if(this.linkLabel1.Enabled==false)return;
			//条码号,题名,借阅日期,应归还日期
			if(dataGrid1.CurrentCell.ColumnNumber==5)
			{
				//条码号
				string id=dataGrid1[dataGrid1.CurrentCell.RowNumber,0].ToString();
				MessageBox.Show(id);
//				int a=int.Parse(dataGrid1[dataGrid1.CurrentCell.RowNumber,3])-int.Parse(dataGrid1[dataGrid1.CurrentCell.RowNumber,2]);
				DateTime dt1 = DateTime.Parse(dataGrid1[dataGrid1.CurrentCell.RowNumber,3].ToString());
				DateTime dt2 = DateTime.Parse(dataGrid1[dataGrid1.CurrentCell.RowNumber,4].ToString());
				TimeSpan ts = dt2.Subtract(dt1);
				MessageBox.Show(ts.TotalDays.ToString());
				//根据馆藏地不同的续借时间
				string address=dataGrid1[dataGrid1.CurrentCell.RowNumber,2].ToString();
				MessageBox.Show(address);
//-------------------------------------借书时限,每本书只能续借一次
//新书阅览室                       7天,续借一次7天
//文理书库                         90天,续借一次30天
//工程技术图书阅览室               3天,续借一次3天
//................
				int historyMax=0;
				int days=0;
				switch(address)
				{
					case "新书阅览室":
					{
						days=7;historyMax=7;
					}						break;

					case "文理书库": 
					{
						days=30;historyMax=90;
					}						break;

					case "工程技术图书阅览室":
					{
						days=3;historyMax=3;
					}						break;

				}//判断一个时间间隔到现在的时间是否超过续借所能到达的天数
				TimeSpan nowlength=dt2.Subtract(DateTime.Today);
				MessageBox.Show("距还书日期还有:"+nowlength.TotalDays.ToString());	
				if(ts.TotalDays>historyMax)MessageBox.Show("对不起,你已续借了一次,操作失败!","Msg",MessageBoxButtons.OK,MessageBoxIcon.Information);
					else if(nowlength.TotalDays>=days)MessageBox.Show("对不起,该书还未到续借日期!","Msg",MessageBoxButtons.OK,MessageBoxIcon.Information);
				else//续借书目
				{
					公共数据dll.Store.cn.Open();
//					DateTime.Today.AddDays(days);
//					MessageBox.Show(DateTime.Today.AddDays(days).ToString());
//					公共数据dll.Store.ds.Tables["currentrecord"].Rows[dataGrid1.CurrentCell.RowNumber][4]=DateTime.Today.AddDays(days).ToString();
//					try
//					{
//						公共数据dll.Store.myDataAdapter.Update(公共数据dll.Store.ds,"currentrecord");
//						公共数据dll.Store.cn.Close();
//					}
//					catch(Exception ex)
//					{
//						MessageBox.Show(ex.ToString());
//					}
					公共数据dll.Store.sqlStr="update record set 应归还日期='"+DateTime.Today.AddDays(days).ToString()+"' where 条码号='"+id+"' and 状态='未还'";
					MessageBox.Show(公共数据dll.Store.sqlStr);
					公共数据dll.Store.cmd=new System.Data.SqlClient.SqlCommand(公共数据dll.Store.sqlStr,公共数据dll.Store.cn);
					if(公共数据dll.Store.cmd.ExecuteNonQuery()==1)
						MessageBox.Show("修改成功!","success",MessageBoxButtons.OK,MessageBoxIcon.Information);
					else
						MessageBox.Show("修改出错!");
					公共数据dll.Store.ds.Tables["currentrecord"].Clear();	
					公共数据dll.Store.sqlStr="select record.条码号,题名,馆藏地,借阅日期,应归还日期,操作='续借该书' from record,bookinfoview where record.条码号=bookinfoview.条码号 and 证件号='"+公共数据dll.Store.str_temp+"' and record.状态='未还' or record.状态='超期'";
					公共数据dll.Store.myDataAdapter=new System.Data.SqlClient.SqlDataAdapter(公共数据dll.Store.sqlStr,公共数据dll.Store.cn);
					公共数据dll.Store.cb =new System.Data.SqlClient.SqlCommandBuilder(公共数据dll.Store.myDataAdapter);
					公共数据dll.Store.myDataAdapter.Fill(公共数据dll.Store.ds,"currentrecord");
					this.dataGrid1.SetDataBinding(公共数据dll.Store.ds,"currentrecord");

					公共数据dll.Store.cn.Close();

				}
			
			}
		}

		private void dataGrid1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)//设置在列"续借该书"时鼠标的外观
		{
			if(this.linkLabel1.Enabled==false)return;
		    DataGrid.HitTestInfo hti=this.dataGrid1.HitTest(e.X,e.Y);
			if(hti.Type==DataGrid.HitTestType.Cell)
			{
				if(hti.Column==5)
				this.Cursor=System.Windows.Forms.Cursors.Hand;
			}
			else
			{
				this.Cursor=System.Windows.Forms.Cursors.Default;
			}

		}
		static int first=1;
		private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)//查看历史记录
		{
			this.Cursor=System.Windows.Forms.Cursors.Default;
			this.linkLabel2.Visible=true;//显示返回linklable
			label15.Visible=false;//显示文本隐藏文本
			linkLabel1.Visible=false;//隐藏自身,进入历史记录只可读
			//清空上次数据集中的表"historyrecord",除了第一次外,以后每次都要清空
			if(first==2)公共数据dll.Store.ds.Tables["historyrecord"].Clear();
			first=2;
			this.dataGrid1.Location=new Point(32, 56);
			this.dataGrid1.Size=new Size(672, 488);
			公共数据dll.Store.cn.Open();
			公共数据dll.Store.sqlStr="select record.条码号,题名,馆藏地,借阅日期,还书日期 from record,bookinfoview where record.条码号=bookinfoview.条码号 and 证件号='"+公共数据dll.Store.str_temp+"'";
			公共数据dll.Store.myDataAdapter=new SqlDataAdapter(公共数据dll.Store.sqlStr,公共数据dll.Store.cn);

			公共数据dll.Store.myDataAdapter.Fill(公共数据dll.Store.ds,"historyrecord");
			this.dataGrid1.SetDataBinding(公共数据dll.Store.ds,"historyrecord");
			公共数据dll.Store.cn.Close();
				
		}

		private void linkLabel2_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)//返回到主窗口外观
		{
			this.dataGrid1.Location=new Point(32, 288);
			this.dataGrid1.Size=new Size(672, 256);
			label15.Visible=true;//显示文本
			linkLabel1.Visible=true;//显示linklable1
			this.linkLabel2.Visible=false;
			公共数据dll.Store.cn.Open();
			this.dataGrid1.SetDataBinding(公共数据dll.Store.ds,"currentrecord");
			公共数据dll.Store.cn.Close();

		}


	}
}

⌨️ 快捷键说明

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