Example #1
0
		private void simpleButton_ModifyButton_Click(object sender, System.EventArgs e)
		{
			tID = textEdit_tID.EditValue.ToString();
			TeacherBase tcBase = new TeacherBase();
			TeacherBaseSystem tcBaseSystem = new TeacherBaseSystem();
			DialogResult messageResult = MessageBox.Show("是否确认保存修改内容?","消息提示框!",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
			if ( messageResult == DialogResult.Yes )
			{
				try
				{
					bool doDataInsertLoopOnce = true;
					TeacherCheckInfo teacherCheckInfo = new TeacherCheckInfo();
					while(doDataInsertLoopOnce)
					{
						tcBase.TCareer = tRecord.SelectedItem.ToString().Replace(" ","");
						tcBase.TMerrige = tMarrige.SelectedItem.ToString().Replace(" ","");
						tcBase.TAddr = tAddr.Text.Replace(" ","");
						tcBase.TDepart = tDept.SelectedItem.ToString().Replace(" ","");
						tcBase.TLevel = tLevel.SelectedItem.ToString().Replace(" ","");
						tcBase.TDuty = tDuty.SelectedItem.ToString().Replace(" ","");
						tcBase.TTechnicalPost = tTechnicalPost.SelectedItem.ToString().Replace(" ","");
						tcBase.TID = tID;

						if(!teacherCheckInfo.isValidTcName(tName.Text.Replace(" ","")))
						{
							MessageBox.Show("教师姓名请正确填写!");
							break;
						}
						else
							tcBase.TName = tName.Text.Replace(" ","");

						if ( gridView1.RowCount > 0 )
						{
							if ( teacherCheckInfo.hasCard(tID,tNumber.Text))
							{
								MessageBox.Show("该教师已经发过卡,修改工号会存在潜在风险,修改失败!");
								break;
							}
							else
							{
								//获取顺序工号
								if ( tNumber.Text.Equals("") )
									tcBase.TNumber = teacherCheckInfo.getSerialTcNumber();
								else
								{
							
									if ( !teacherCheckInfo.isValidTcNumber(tNumber.Text.Replace(" ","")))
									{
										MessageBox.Show("请确保输入的工号是有效工号!");
										break;
									}
									else
									{
										if ( !teacherCheckInfo.hasSameNumber( tNumber.Text.Replace(" ",""),
											tcBase.TID ) )
										{
											MessageBox.Show("您所选择的教师工号已经存在,请更换!");
											break;
										}
									}
									tcBase.TNumber = tNumber.Text.Replace(" ","");
								}
							}
						}
						else
							MessageBox.Show("教师记录不存在还无法进行修改!");

						if(!teacherCheckInfo.isValidTcHomePhone(tHomePhone.Text.Replace(" ","")))
						{
							MessageBox.Show("教师家庭电话填写不正确!");
							break;
						}
						else
							tcBase.THomeTel = tHomePhone.Text.Replace(" ","");
						
						if(!teacherCheckInfo.isValidTcTime(tEnterTime.DateTime.Date,tJoinDate.DateTime.Date))
						{
							MessageBox.Show("时间填写不当,请重新输入!");
							break;
						}
						else
						{
							tcBase.TEnterTime = Convert.ToDateTime(tEnterTime.Text.Replace(" ",""));
							tcBase.TWorkTime  = Convert.ToDateTime(tJoinDate.Text.Replace(" ",""));}
						if(!teacherCheckInfo.isValidTcSex(tSex.Text.Replace(" ","")))
						{
							MessageBox.Show("教师性别不正确!");
							break;
						}
						else
							tcBase.TSex = tSex.Text.Replace(" ","");

						if(!teacherCheckInfo.isValidTcWorkPhone(tWorkPhone.Text.Replace(" ","")))
						{
							MessageBox.Show("教师办公电话填写不正确,请正确填写!");
							break;
						}
						else
							tcBase.TWorkTel = tWorkPhone.Text.Replace(" ","");

						if(!teacherCheckInfo.isValidTcPhone(tPhone.Text.Replace(" ","")))
						{
							MessageBox.Show("教师手机号码不正确!");
							break;
						}
						else
							tcBase.TPhone = tPhone.Text.Replace(" ","");
						
						if ( pictureEdit_LoadImageData.Image == null )
							imageDataBuffer = null;
						else
						{
							imageMSReader = new MemoryStream();
							pictureEdit_LoadImageData.Image.Save(imageMSReader,ImageFormat.Jpeg);
							imageDataBuffer = imageMSReader.ToArray();
						}
						tcBase.ImageData = imageDataBuffer;

						tcBaseSystem.UpdateTcBaseInfo(tcBase);
			

						if(!gridView1.GetDataRow(gridView1.GetSelectedRows()[0])["T_Number"].ToString().Equals(tcBase.TNumber))
						{
							new UserSystem().DeleteUserAccount(gridView1.GetDataRow(gridView1.GetSelectedRows()[0])
								["T_Number"].ToString());

							new UserSystem().CreateUserAccount(tcBase.TNumber,textEdit_UserPwd.Text);
						}

						int rtnValue = new UserSystem().UpdateUserRole(tcBase.TNumber,comboBoxEdit_Privilege.SelectedItem.ToString());

						if (rtnValue == -1) MessageBox.Show("如果您执行此修改,系统将不存在最高权限,这是不允许的,修改失败!");
						else if (rtnValue == 0)
						{
							new UserSystem().DeleteUserAccount(tcBase.TNumber);
							new UserSystem().CreateUserAccount(tcBase.TNumber,textEdit_UserPwd.Text);
							new UserSystem().AddUserRole(tcBase.TNumber,comboBoxEdit_Privilege.SelectedItem.ToString());
							MessageBox.Show("修改完毕!");
						}
						else MessageBox.Show("修改完毕!");

						doDataInsertLoopOnce = false;

						//刷新绑定信息
						TextDataUnBindings();
						TextDataClear();
//						loadPage(new TeacherBaseSystem().SearchTcBaseInfoByCondition("","","",""));
						loadPage(new TeacherBaseSystem().SearchTcBaseInfoByCondition(comboBoxEdit_Grade.SelectedItem.ToString().Replace(" ",""),
							comboBoxEdit_Class.SelectedItem.ToString().Replace(" ",""),textEdit_Name.Text.Replace(" ",""),textEdit_Number.Text.Replace(" ","")));

					}
				}
				catch(Exception ex)
				{
					MessageBox.Show(ex.Message);
				}
			}
		}
Example #2
0
		private void simpleButton_SaveButton_Click(object sender, System.EventArgs e)
		{		
			tID = textEdit_tID.EditValue.ToString();
			TeacherBase tcBase = new TeacherBase();
			TeacherBaseSystem tcBaseSystem = new TeacherBaseSystem();
			DialogResult messageResult = MessageBox.Show("是否确认保存这些数据?","消息提示框!",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
			if ( messageResult == DialogResult.Yes )
			{
				try
				{
					bool doDataInsertLoopOnce = true;
					TeacherCheckInfo teacherCheckInfo = new TeacherCheckInfo();
					while(doDataInsertLoopOnce)
					{
						tcBase.TCareer = tRecord.SelectedItem.ToString().Replace(" ","");
						tcBase.TMerrige = tMarrige.SelectedItem.ToString().Replace(" ","");						
						tcBase.TDepart = tDept.SelectedItem.ToString().Replace(" ","");
						tcBase.TLevel = tLevel.SelectedItem.ToString().Replace(" ","");
						tcBase.TDuty = tDuty.SelectedItem.ToString().Replace(" ","");
						tcBase.TTechnicalPost = tTechnicalPost.SelectedItem.ToString().Replace(" ","");
						if ( !tID.Equals("") )
							tcBase.TID = tID;
						else
							tcBase.TID = Guid.NewGuid().ToString();

						if(!teacherCheckInfo.isValidTcName(tName.Text.Replace(" ","")))
						{
							MessageBox.Show("教师姓名请正确填写!");
							break;
						}
						else{tcBase.TName = tName.Text.Replace(" ","");}

                        //获取顺序工号
						if ( tNumber.Text.Equals("") )
						{
							tcBase.TNumber = teacherCheckInfo.getSerialTcNumber();

							if ( tcBase.TNumber.Equals("-1") )
							{
								MessageBox.Show("已超出系统所允许的最大教师数量!");
								break;
							}

						}
						else
						{
							if ( !teacherCheckInfo.isValidTcNumber(tNumber.Text.Replace(" ","")))
							{
								MessageBox.Show("请确保输入的工号是有效工号!");
								break;
							}
							else
							{
								if ( !teacherCheckInfo.hasSameNumber( tNumber.Text.Replace(" ",""),
									tcBase.TID ) )
								{
									MessageBox.Show("您所选择的教师工号已经存在,请更换!");
									break;
								}
							}
							tcBase.TNumber = tNumber.Text.Replace(" ","");
						}

						if(!teacherCheckInfo.isValidTcHomePhone(tHomePhone.Text.Replace(" ","")))
						{
							tcBase.THomeTel = "未填写";
							MessageBox.Show("教师家庭电话填写不正确!");
							break;
						}
						else
							tcBase.THomeTel = tHomePhone.Text.Replace(" ","");
						
						if(!teacherCheckInfo.isValidTcTime(Convert.ToDateTime(tEnterTime.Text.Replace(" ","")),Convert.ToDateTime(tJoinDate.Text.Replace(" ",""))))
						{
							MessageBox.Show("时间填写不当,请重新输入!");
							break;
						}
						else
						{
							tcBase.TWorkTime = Convert.ToDateTime(tEnterTime.Text.Replace(" ",""));
							tcBase.TEnterTime = Convert.ToDateTime(tJoinDate.Text.Replace(" ",""));
						}
						if(!teacherCheckInfo.isValidTcSex(tSex.Text.Replace(" ","")))
						{
							MessageBox.Show("教师性别不正确!");
							break;
						}
						else
							tcBase.TSex = tSex.Text.Replace(" ","");
						if(!teacherCheckInfo.isValidTcWorkPhone(tWorkPhone.Text.Replace(" ","")))
						{
							tcBase.TWorkTel = "未填写";
							MessageBox.Show("教师办公电话填写不正确,请正确填写!");
							break;
						}
						else
							tcBase.TWorkTel = tWorkPhone.Text.Replace(" ","");

						if(!teacherCheckInfo.isValidTcPhone(tPhone.Text.Replace(" ","")))
						{
							tcBase.TPhone = "未填写";
							MessageBox.Show("教师手机号码不正确!");
							break;
							
						}
						else
							tcBase.TPhone = tPhone.Text.Replace(" ","");


						tcBase.TAddr = tAddr.Text.Replace(" ","");

						if ( pictureEdit_LoadImageData.Image == null )
							imageDataBuffer = null;
						else
						{
							imageMSReader = new MemoryStream();
							pictureEdit_LoadImageData.Image.Save(imageMSReader,ImageFormat.Jpeg);
							imageDataBuffer = imageMSReader.ToArray();
						}
						tcBase.ImageData = imageDataBuffer;
						
						tcBaseSystem.InsertTcBaseInfo(tcBase);

						new UserSystem().CreateUserAccount(tcBase.TNumber,
							textEdit_UserPwd.Text);

						new UserSystem().AddUserRole(tcBase.TNumber,
							comboBoxEdit_Privilege.SelectedItem.ToString());

						MessageBox.Show("保存完毕!");
						doDataInsertLoopOnce = false;

                        dataNavigator1.Buttons.DoClick(dataNavigator1.Buttons.CancelEdit);
						//dataNavigator1.Buttons.CancelEdit.DoClick();
						//刷新绑定信息
						TextDataUnBindings();
						loadPage(new TeacherBaseSystem().SearchTcBaseInfoByCondition("","","",""));

						simpleButton_SaveButton.Enabled = false;
						simpleButton_ModifyButton.Enabled = true;
					}
				}
				catch(Exception ex)
				{
					MessageBox.Show(ex.Message);
				}
			}
		}