📄 frmsbubjectinfo.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using property.model.GetConnection;
using property.model.SubjectInfo;
using property.control.Subject;
using System.Data.SqlClient;
namespace property.view.SubjectInfo
{
public partial class frmSbubjectInfo : Form
{
public frmSbubjectInfo()
{
InitializeComponent();
}
public int G_int_select;//全局变量
public int G_int_Delet;//全局变量
public string G_str_Update;//全局变量
//判段输入的是否为数字
private void txtSubjectId_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar))
{
e.Handled = true;
MessageBox.Show("编号只能输入数字", "有情提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}//end if
}// end block if
//自动生成编号
private void rdbZudong_CheckedChanged(object sender, EventArgs e)
{
if (this.rdbZudong.Checked == true)
{
GetSubject subj = new GetSubject();
this.txtSubjectId.Text = Convert.ToString(subj.getSubId());//获得自动编号
this.txtSubjectId.Enabled = false;
txtPing.Text = "";
txtSubjectName.Text = "";
txtSubjectPage.Text = "";
}// end block if
}
//添加科目
private void bntSure_Click(object sender, EventArgs e)
{
if (txtSubjectId.Text == "")
{
MessageBox.Show("科目编号不能为空", "友情提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtSubjectId.Focus();
}//end block menthod if
else if (txtSubjectName.Text == "")
{
MessageBox.Show("科目名称不能为空", "友情提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtSubjectName.Focus();
}//end block menthod elseif
else if (txtPing.Text == "")
{
MessageBox.Show("拼音简码不能为空", "友情提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtPing.Focus();
}//end block menthod elseif
else
{
GetSubject sub = new GetSubject();
SubInfo info = new SubInfo();
info.setsubId(Convert.ToInt32(txtSubjectId.Text.Trim()));
info.setsubGkb(txtPing.Text.Trim());
info.setsubName(txtSubjectName.Text.Trim());
info.setsubMoney("0");
info.setsubPage(txtSubjectPage.Text.Trim());
string P_str_Insert = sub.subjectInsert(info);
if (P_str_Insert == "OK")
{
MessageBox.Show("科目编号已在\n请重新输入", "友情提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.txtSubjectId.Text = "";
this.txtSubjectId.Focus();
}// end block if
if (P_str_Insert == "insetOk")
{
MessageBox.Show("添加成功", "友情提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.txtPing.Text = "";
this.txtSubjectId.Text = "";
this.txtSubjectId.Enabled = true;
this.txtSubjectName.Text = "";
txtSubjectPage.Text = "";
sub.fillId(this.cmbSubjectID);//返回所有ID
sub.fillId(this.cmbId);
this.rdbShoudong.Checked = true;
//this.rdbZudong.Checked = false;
}// end block if
if (P_str_Insert == "insetNo")
{
MessageBox.Show("添加失败", "友情提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}// end block if
if (P_str_Insert == "addError")
{
MessageBox.Show("系统错误", "友情提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}// end block i
}//end block menthod else
}
//取消退出
private void bntEsceADD_Click(object sender, EventArgs e)
{
DialogResult a = MessageBox.Show("是否要退出?", "退出", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (Convert.ToString(a) == "Yes")
{
this.Close();
}// end block
}
//private void tpSubjectUpdate_Click(object sender, EventArgs e)
//{
// Subject sub = new Subject();
// sub.fillId(this.cmbSubjectID);//返回所有ID
// this.cmbSubjectID.DataSource = sub.SubDataSetSubId();//返回所有ID
// this.cmbSubjectID.DisplayMember = "subId";
//}
private void bntEsceUpdae_Click(object sender, EventArgs e)
{
DialogResult a = MessageBox.Show("是否要退出?", "退出", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (Convert.ToString(a) == "Yes")
{
this.Close();
}// end block
}
private void bntEsceDelete_Click(object sender, EventArgs e)
{
DialogResult a = MessageBox.Show("是否要退出?", "退出", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (Convert.ToString(a) == "Yes")
{
this.Close();
}// end block
}
private void frmSbubjectInfo_Load(object sender, EventArgs e)
{
GetSubject sub = new GetSubject();
sub.fillId(this.cmbSubjectID);//返回所有ID
//this.cmbSubjectID.DataSource = sub.SubDataSetSubId();//返回所有ID
//this.cmbSubjectID.DisplayMember = "subId";
//this.cmbSubjectID.ValueMember = "subId";
//this.cmbSubjectID.SelectedIndex = 0;
sub.fillId(this.cmbId);
}
//修改信息
private void btnSureUpdate_Click(object sender, EventArgs e)
{
if (cmbSubjectID.Text == "")
{ MessageBox.Show("科目编号不能为空", "修改提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
cmbSubjectID.Focus();
}// end block if
else if (txtJian.Text == "")
{
MessageBox.Show("简拼不能为空", "修改提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtJian.FindForm();
}// end if
else if (txtUpdatNmae.Text == "")
{
MessageBox.Show("科目名称为空", "修改提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtUpdatNmae.Focus();
}// end block else if
else
{
SubInfo info = new SubInfo();
GetSubject sub = new GetSubject();
info.setsubId(Convert.ToInt32(this.cmbSubjectID.Text.Trim()));
info.setsubGkb(txtJian.Text);
info.setsubName(txtUpdatNmae.Text);
info.setsubPage(txtUpdatepage.Text);
string P_str_result = sub.SubjectUpdate(info);//调用修改函数
if (P_str_result == "updateOk")
{
MessageBox.Show("修改成功", "修改提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
cmbSubjectID.Text = "";
txtUpdatNmae.Text = "";
txtUpdatepage.Text = "";
txtJian.Text = "";
}// end block if
if (P_str_result == "updateNO")
{
MessageBox.Show("修改失败", "修改提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
cmbSubjectID.Text = "";
cmbSubjectID.Focus();
txtUpdatNmae.Text = "";
txtUpdatepage.Text = "";
txtJian.Text = "";
}// end block if
if (P_str_result == "updateError")
{
MessageBox.Show("出现错误,请确认操作", "修改提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
cmbSubjectID.Text = "";
cmbSubjectID.Focus();
txtUpdatNmae.Text = "";
txtUpdatepage.Text = "";
txtJian.Text = "";
}// end block if
}// end block else //修改
}
private void txtUpdatepage_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar != 8 && !char.IsDigit(e.KeyChar))
{
MessageBox.Show("页码只能输入数字", "有情提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
e.Handled = true;
}
}
//查找信息
private void bntFind_Click(object sender, EventArgs e)
{
if (cmbSubjectID.Text == "")
{
MessageBox.Show("科目编号不能为空\n请选择编号进行查询", "有情提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
cmbSubjectID.Focus();
}// end block
else
{
GetSubject sub = new GetSubject();
SubInfo info = new SubInfo();
int P_int_update = Convert.ToInt32(G_str_Update);
info.setsubId(P_int_update);
SqlDataReader dr = sub.getSelectDr(info);
while (dr.Read())
{
this.txtJian.Text = dr[1].ToString();
this.txtUpdatNmae.Text = dr[2].ToString();
this.txtUpdatepage.Text = dr[4].ToString();
}// ennd block if
dr.Close();
}// end block menthod
}
private void cmbSubjectID_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.cmbSubjectID.Text!= null)
{
G_str_Update = this.cmbSubjectID.Text;//把值传给全局变量
}// end block if
}
private void bntclear_Click(object sender, EventArgs e)
{
this.cmbSubjectID.Text = "";
txtJian.Text = "";
txtUpdatepage.Text = "";
txtUpdatNmae.Text = "";
}
private void cmbId_SelectedIndexChanged(object sender, EventArgs e)
{
if (cmbId.Text != "")
{
SubInfo info= new SubInfo();
GetSubject ject = new GetSubject();
info.setsubId(Convert.ToInt32(cmbId.Text.Trim()));
ject.GedListView(this.listView1,info);//调用方法帮定ListView控件
G_int_Delet = Convert.ToInt32(cmbId.Text);
}// end block menthod
}
//删除
private void bntSureDelete_Click(object sender, EventArgs e)
{
if (this.G_int_Delet==0)
{
MessageBox.Show("请选择删除条件", "有情提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
cmbId.Focus();
}// end block if
if (this.G_int_Delet!=0)
{
DialogResult diResult = MessageBox.Show("你确定要删除此记录吗?","友情提示",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
if (Convert.ToString(diResult) == "Yes")
{
GetSubject subje = new GetSubject();
SubInfo info = new SubInfo();
info.setsubId(this.G_int_Delet);
string P_str_delte = subje.SubjectDelet(info);
if (P_str_delte == "deleteOk")// 册子成功
{
MessageBox.Show("册除成功","册除提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
subje.fillId(cmbId);
subje.GedListView(this.listView1, info);//调用方法帮定ListView控件
cmbId.Text = "";
cmbId.Focus();
GetSubject sub = new GetSubject();
sub.fillId(this.cmbSubjectID);
}// end block if
if (P_str_delte == "deleteNO")
{
MessageBox.Show("册除失败\n请选择正确的条件", "册除提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
cmbId.Text = "";
cmbId.Focus();
}// end block if
if (P_str_delte == "deleteError")
{
MessageBox.Show("系统错误", "册除提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
cmbId.Text = "";
cmbId.Focus();
}// end block if
}// end block if
}// end block
}
private void txtSubjectPage_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar))
{
e.Handled = true;
MessageBox.Show("账本页码只能输入数字", "有情提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}//end if
}
private void rdbShoudong_CheckedChanged(object sender, EventArgs e)
{
if (this.rdbShoudong.Checked == true)
{
this.txtPing.Text = "";
this.txtSubjectId.Text = "";
this.txtSubjectId.Enabled = true;
this.txtSubjectName.Text = "";
txtSubjectPage.Text = "";
}
// end block if 控制手写和自动编号
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void txtUpdatepage_TextChanged(object sender, EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -