private void button1_Click(object sender, System.EventArgs e)
        {
            if (comboBox_Office.SelectedItem == null)
            {
                MessageBox.Show("请选择该居委会所在办事处!", "提醒!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }

            if (conn.KickOut(textBox_Committee_Name.Text) == "")
            {
                MessageBox.Show("必须输入居委会名称!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (textBox_Committee_Name.Text.Length > 15)
            {
                MessageBox.Show("请不要超长输入居委会名称!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            //去除'"?%=空格,修改办事处表
            string str_Sql, errorstring = "";

            str_Sql = "UPDATE Committee SET Committee_Name='" + conn.KickOut(textBox_Committee_Name.Text)
                      + "',Office_ID=" + comboBox_Office.SelectedValue.ToString()
                      + " WHERE Committee_ID=" + textBox_Committee_ID.Text;

            errorstring = conn.ExeSql(str_Sql);
            if (errorstring != "OK")
            {
                MessageBox.Show("修改不成功!请检查数据库!" + errorstring, "提醒!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                button1.Enabled = false;
                return;
            }
            MessageBox.Show("成功修改!", "提醒!",
                            MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

            //刷新DataGrid显示,选中最后一行反色显示
            str_Sql = "SELECT Committee_ID AS 居委会代码,Committee_Name AS 居委会名称,Office_Name AS 办事处名称,QuXian_Name AS 区县名称 FROM View_Committee";
            conn.Fill(str_Sql);
            DataGrid1.SetDataBinding(conn.ds, "TableIn");

            textBox_Committee_Name.Text = "";
        }
        private void button1_Click(object sender, System.EventArgs e)
        {
            if (conn.KickOut(textBox_Office_Name.Text) == "")
            {
                MessageBox.Show("必须输入办事处名称!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (textBox_Office_Name.Text.Length > 15)
            {
                MessageBox.Show("请不要超长输入办事处名称!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }

            //去除'"?%=空格,修改办事处表
            string str_Sql, errorstring = "";

            str_Sql = "UPDATE Office SET Office_Name='" + conn.KickOut(textBox_Office_Name.Text)
                      + "',QuXian_ID_OfficeIn=" + comboBox1_QuXian.SelectedValue
                      + " WHERE Office_ID=" + textBox_Office_ID.Text;

            errorstring = conn.ExeSql(str_Sql);
            if (errorstring != "OK")
            {
                MessageBox.Show("修改不成功!请检查数据库!" + errorstring, "提醒!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                button1.Enabled = false;
                return;
            }
            MessageBox.Show("成功修改!", "提醒!",
                            MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

            //刷新DataGrid显示,置空各信息项,等待选中新的有效项
            str_Sql = "SELECT Office.Office_ID AS 办事处代码,Office.Office_Name AS 办事处名称,QuXian.QuXian_Name AS 所在区县 FROM Office  inner join QuXian  on Office.QuXian_ID_OfficeIn=QuXian.QuXian_ID ";
            conn.Fill(str_Sql);
            DataGrid1.SetDataBinding(conn.ds, "TableIn");

            textBox_Office_ID.Text   = "";
            textBox_Office_Name.Text = "";

            button1.Enabled = false;
        }
        private void button1_Click(object sender, System.EventArgs e)
        {
            if (conn.KickOut(textBox_School_Type_Name.Text) == "")
            {
                MessageBox.Show("必须输入学校类型名称!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (textBox_School_Type_Name.Text.Length > 15)
            {
                MessageBox.Show("请不要超长输入学校类型名称!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }

            //去除'"?%=空格,修改学校类型表
            string str_Sql, errorstring = "";

            str_Sql = "UPDATE School_Type SET School_Type_Name='" + conn.KickOut(textBox_School_Type_Name.Text)
                      + "',School_Type_Year=" + numericUpDown1.Value.ToString()
                      + " WHERE School_Type_ID=" + textBox_School_Type_ID.Text;
            errorstring = conn.ExeSql(str_Sql);
            if (errorstring != "OK")
            {
                MessageBox.Show("修改不成功!请检查数据库!" + errorstring, "提醒!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                button1.Enabled = false;
                return;
            }
            MessageBox.Show("成功修改!", "提醒!",
                            MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

            //刷新DataGrid显示,置空各信息项,等待选中新的有效项
            str_Sql = "SELECT School_Type_ID As 学校类别代码,School_Type_Name As 学校类别名,School_Type_Year As 学校类别学制 FROM School_Type";
            conn.Fill(str_Sql);
            DataGrid1.SetDataBinding(conn.ds, "TableIn");

            textBox_School_Type_ID.Text   = "";
            textBox_School_Type_Name.Text = "";

            button1.Enabled = false;
        }
        private void button1_Click(object sender, System.EventArgs e)
        {
            if (conn.KickOut(textBox_Class_Type_Name.Text) == "")
            {
                MessageBox.Show("必须输入班级类型名称!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (textBox_Class_Type_Name.Text.Length > 15)
            {
                MessageBox.Show("请不要超长输入班级类型名称!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }

            //去除'"?%=空格,修改班级类型表
            string str_Sql, errorstring = "";

            str_Sql = "UPDATE Class_Type SET Class_Type_Name='" + conn.KickOut(textBox_Class_Type_Name.Text)
                      + "' WHERE Class_Type_ID=" + textBox_Class_Type_ID.Text;
            errorstring = conn.ExeSql(str_Sql);
            if (errorstring != "OK")
            {
                MessageBox.Show("修改不成功!请检查数据库!" + errorstring, "提醒!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                button1.Enabled = false;
                return;
            }
            MessageBox.Show("成功修改!", "提醒!",
                            MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

            //刷新DataGrid显示,置空各信息项,等待选中新的有效项
            str_Sql = "SELECT Class_Type.Class_Type_ID AS 班级类别代码,Class_Type.Class_Type_Name AS 班级类别名,School_Type.School_Type_Name AS 学校类别名 FROM Class_Type inner join School_Type on Class_Type.School_Type_ID_Class_Belong=School_Type.School_Type_ID";
            conn.Fill(str_Sql);
            DataGrid1.SetDataBinding(conn.ds, "TableIn");

            textBox_Class_Type_ID.Text   = "";
            textBox_Class_Type_Name.Text = "";
            textBox_School_Type.Text     = "";

            button1.Enabled = false;
        }
        private void button1_Click(object sender, System.EventArgs e)
        {
            if (conn.KickOut(textBox_Class_Type_Name.Text) == "")
            {
                MessageBox.Show("必须输入班级类型名称!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (textBox_Class_Type_Name.Text.Length > 15)
            {
                MessageBox.Show("请不要超长输入班级类型名称!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }

            //去除'"?%=空格,插入班级类型表
            string str_Sql, errorstring = "";

            str_Sql = "INSERT INTO Class_Type values(" + textBox_Class_Type_ID.Text.Trim() + ",'"
                      + conn.KickOut(textBox_Class_Type_Name.Text.Trim()) + "',"
                      + comboBox1_School_Type.SelectedValue.ToString() + ")";

            errorstring = conn.ExeSql(str_Sql);
            if (errorstring != "OK")
            {
                MessageBox.Show("未成功添加!请检查数据库!" + errorstring, "提醒!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                button1.Enabled = false;
                return;
            }
            MessageBox.Show("成功添加!", "提醒!",
                            MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

            //刷新DataGrid显示,选中最后一行反色显示
            str_Sql = "SELECT Class_Type.Class_Type_ID AS 班级类别代码,Class_Type.Class_Type_Name AS 班级类别名,School_Type.School_Type_Name AS 学校类别名 FROM Class_Type inner join School_Type on Class_Type.School_Type_ID=School_Type.School_Type_ID";
            conn.Fill(str_Sql);
            DataGrid1.SetDataBinding(conn.ds, "TableIn");
            DataGrid1.Select(conn.ds.Tables["TableIn"].Rows.Count - 1);

            textBox_Class_Type_ID.Text = conn.GetMaxId("Class_Type_ID", "Class_Type");
        }
        private void button1_Click(object sender, System.EventArgs e)
        {
            if (conn.KickOut(textBox_QuXian_Name.Text) == "")
            {
                MessageBox.Show("必须输入区县名称!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (textBox_QuXian_Name.Text.Length > 15)
            {
                MessageBox.Show("请不要超长输入区县名称!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }

            //去除'"?%=空格,修改学校类型表
            string str_Sql, errorstring = "";

            str_Sql = "UPDATE QuXian SET QuXian_Name='" + conn.KickOut(textBox_QuXian_Name.Text)
                      + "' WHERE QuXian_ID=" + textBox_QuXian_ID.Text;
            errorstring = conn.ExeSql(str_Sql);
            if (errorstring != "OK")
            {
                MessageBox.Show("修改不成功!请检查数据库!" + errorstring, "提醒!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                button1.Enabled = false;
                return;
            }
            MessageBox.Show("成功修改!", "提醒!",
                            MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

            //刷新DataGrid显示,置空各信息项,等待选中新的有效项
            str_Sql = "SELECT QuXian.QuXian_ID AS 区县代码,QuXian.QuXian_Name AS 区县名称 FROM QuXian";
            conn.Fill(str_Sql);
            DataGrid1.SetDataBinding(conn.ds, "TableIn");

            textBox_QuXian_ID.Text   = "";
            textBox_QuXian_Name.Text = "";

            button1.Enabled = false;
        }
Beispiel #7
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            if (conn.KickOut(textBox_Office_Name.Text) == "")
            {
                MessageBox.Show("必须输入办事处名称!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (textBox_Office_Name.Text.Length > 15)
            {
                MessageBox.Show("请不要超长输入办事处名称!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }

            //去除'"?%=空格,插入办事处表
            string str_Sql, errorstring = "";

            str_Sql = "INSERT INTO Office values(" + conn.KickOut(textBox_Office_ID.Text.Trim()) + ",'"
                      + conn.KickOut(textBox_Office_Name.Text.Trim()) + "'," + conn.KickOut(comboBox1_QuXian_ID.SelectedValue.ToString()) + ")";
            errorstring = conn.ExeSql(str_Sql);
            if (errorstring != "OK")
            {
                MessageBox.Show("未成功添加!请检查数据库!" + errorstring, "提醒!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                button1.Enabled = false;
                return;
            }
            MessageBox.Show("成功添加!", "提醒!",
                            MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

            //刷新DataGrid显示,选中最后一行反色显示
            str_Sql = "SELECT Office.Office_ID AS 办事处代码,Office.Office_Name AS 办事处名称,QuXian.QuXian_Name AS 区县名称 FROM QuXian inner join Office on QuXian.QuXian_ID=Office.QuXian_ID_OfficeIn";
            conn.Fill(str_Sql);
            DataGrid1.SetDataBinding(conn.ds, "TableIn");
            DataGrid1.Select(conn.ds.Tables["TableIn"].Rows.Count - 1);

            textBox_Office_Name.Text = "";
            textBox_Office_ID.Text   = conn.GetMaxId("Office_ID", "Office");
        }
        private void button1_Click(object sender, System.EventArgs e)
        {
            if (conn.KickOut(textBox_School_Type_Name.Text) == "")
            {
                MessageBox.Show("必须输入学校类型名称!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (textBox_School_Type_Name.Text.Length > 15)
            {
                MessageBox.Show("请不要超长输入学校类型名称!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }

            string str_Sql, errorstring = "";

            str_Sql = "INSERT INTO School_Type values(" + textBox_School_Type_ID.Text.Trim() + ",'"
                      + conn.KickOut(textBox_School_Type_Name.Text.Trim()) + "',"
                      + numericUpDown1.Value.ToString() + ")";
            errorstring = conn.ExeSql(str_Sql);
            if (errorstring != "OK")
            {
                MessageBox.Show("未成功添加!请检查数据库!" + errorstring, "提醒!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                button1.Enabled = false;
                return;
            }
            MessageBox.Show("成功添加!", "提醒!",
                            MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

            str_Sql = "SELECT School_Type_ID As 学校类别代码,School_Type_Name As 学校类别名,School_Type_Year As 学校类别学制 FROM School_Type";
            conn.Fill(str_Sql);
            DataGrid1.SetDataBinding(conn.ds, "TableIn");
            DataGrid1.Select(conn.ds.Tables["TableIn"].Rows.Count - 1);

            textBox_School_Type_ID.Text = conn.GetMaxId("School_Type_ID", "School_Type");
        }
        private void button1_Click(object sender, System.EventArgs e)
        {
            if (textBox_School_ID.Text == "" || textBox2_School_Name.Text == "")
            {
                MessageBox.Show("必须输入学校名称和学校代码!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (textBox_School_ID.Text.Length != 12 || textBox2_School_Name.Text.Length > 50 || textBox_Schoolmaster.Text.Length > 50 || textBox_School_Tel.Text.Length > 20 || textBox_School_Zip.Text.Length > 6 || textBox_School_Address.Text.Length > 100)
            {
                MessageBox.Show("请不要超长输入!\r\n学校代码只能为12位!\r\n邮编只能为六位数!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }

            //去除'"?%=空格,修改学校信息表
            string errorstring = "";
            string str_Sql     = "UPDATE School SET School_Name='" + conn.KickOut(textBox2_School_Name.Text)
                                 + "',School_Type_ID=" + comboBox1_School_Type.SelectedValue.ToString()
                                 + ",Schoolmaster='" + conn.KickOut(textBox_Schoolmaster.Text)
                                 + "',School_Tel='" + conn.KickOut(textBox_School_Tel.Text)
                                 + "',School_Zip='" + conn.KickOut(textBox_School_Zip.Text)
                                 + "',School_Address='" + conn.KickOut(textBox_School_Address.Text)
                                 + "' WHERE School_ID='" + conn.KickOut(textBox_School_ID.Text) + "'";

            errorstring = conn.ExeSql(str_Sql);
            if (errorstring != "OK")
            {
                MessageBox.Show("未成功修改!请检查数据库!" + errorstring, "提醒!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                button1.Enabled = false;
                return;
            }
            MessageBox.Show("成功修改!", "提醒!",
                            MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

            //刷新DataGrid显示,置空各信息项,等待选中新的有效项
            str_Sql = "SELECT School_ID AS 学校代码,School_Name AS 学校名称,School_Type_Name AS 学校类别,Schoolmaster AS 校长,School_Tel AS 电话,School_Zip AS 邮政编码,School_Address AS 学校地址,School_Type_Year AS 学校学制年限 FROM View_School";
            conn.Fill(str_Sql);
            DataGrid1.SetDataBinding(conn.ds, "TableIn");

            textBox_School_ID.Text      = "";
            textBox2_School_Name.Text   = "";
            textBox_Schoolmaster.Text   = "";
            textBox_School_Tel.Text     = "";
            textBox_School_Zip.Text     = "";
            textBox_School_Address.Text = "";

            button1.Enabled = false;;
        }
        private void button1_Click(object sender, System.EventArgs e)
        {
            if (conn.KickOut(textBox_UserName.Text) == "")
            {
                MessageBox.Show("必须输入用户名!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (textBox_UserName.Text.Length > 20)
            {
                MessageBox.Show("请不要超长输入用户名!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }

            bool bool_UserName_Had = true;

            try
            {
                bool_UserName_Had = conn.UserName_Had(textBox_UserName.Text);
            }
            catch
            {
                MessageBox.Show("数据库错误!!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            if (bool_UserName_Had == true)
            {
                MessageBox.Show("请不要输入重复的用户名!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (textBox_PassWord.Text == "")
            {
                MessageBox.Show("必须输入密码!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (textBox_PassWord.Text.Length > 20)
            {
                MessageBox.Show("请不要超长输入密码!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (conn.Sniffer_In(textBox_PassWord.Text) || conn.Sniffer_In(textBox_UserName.Text))
            {
                MessageBox.Show("用户名或密码不得用空格或者'\"?%=空格!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }

            //去除'"?%=空格,插入办事处表
            string errorstring = "", str_ReadOnly, str_Sql;

            if (checkBox_ReadOnly.Checked == true)
            {
                str_ReadOnly = "1";
            }
            else
            {
                str_ReadOnly = "0";
            }
            str_Sql = "insert into Users (UserName,PassWord,ReadOnly) values ('"
                      + conn.KickOut(textBox_UserName.Text) + "','" + conn.KickOut(textBox_PassWord.Text) + "'," + str_ReadOnly + ")";

            errorstring = conn.ExeSql(str_Sql);
            if (errorstring != "OK")
            {
                MessageBox.Show("未成功添加!请检查数据库!" + errorstring, "提醒!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                button1.Enabled = false;
                return;
            }
            MessageBox.Show("成功添加!", "提醒!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

            //刷新DataGrid显示
            str_Sql = "SELECT UserName AS 用户名,PassWord AS 密码,ReadOnly AS 仅为只读用户 FROM Users";
            try
            {
                errorstring = conn.Fill(str_Sql);
            }
            catch
            {
                MessageBox.Show(errorstring, "提醒!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                conn.Close();
            }
            DataGrid1.SetDataBinding(conn.ds, "TableIn");

            textBox_UserName.Text     = "";
            textBox_PassWord.Text     = "";
            checkBox_ReadOnly.Checked = true;
        }
        private void button1_Click(object sender, System.EventArgs e)
        {
            string str_Sql, errorstring = "";

            if (conn.KickOut(textBox_School_ID.Text) == "")
            {
                MessageBox.Show("必须输入学校代码!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (conn.KickOut(textBox2_School_Name.Text) == "")
            {
                MessageBox.Show("必须输入学校名称!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (textBox_School_ID.Text.Length != 12)
            {
                MessageBox.Show("学校代码只能为12位!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }

            if (textBox2_School_Name.Text.Length > 50)
            {
                MessageBox.Show("请不要超长输入学校名称!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (textBox_Schoolmaster.Text.Length > 50)
            {
                MessageBox.Show("请不要超长输入校长名!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (textBox_School_Tel.Text.Length > 20)
            {
                MessageBox.Show("请不要超长输入电话号码!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (textBox_School_Zip.Text.Length != 6)
            {
                MessageBox.Show("邮编只能为六位数!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (textBox_School_Address.Text.Length > 100)
            {
                MessageBox.Show("请不要超长输入地址!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (conn.School_ID_Had(textBox_School_ID.Text))
            {
                MessageBox.Show("请不要输入重复的学校代码!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }

            //去除'"?%=空格,插入办事处表
            str_Sql = "insert into School (School_ID,School_Name,School_Type_ID,Schoolmaster,School_Tel,School_Zip,School_Address) values ('"
                      + conn.KickOut(textBox_School_ID.Text) + "','" + conn.KickOut(textBox2_School_Name.Text) + "',"
                      + comboBox1_School_Type.SelectedValue.ToString() + ",'"
                      + conn.KickOut(textBox_Schoolmaster.Text) + "','"
                      + conn.KickOut(textBox_School_Tel.Text) + "','"
                      + conn.KickOut(textBox_School_Zip.Text) + "','"
                      + conn.KickOut(textBox_School_Address.Text) + "')";

            errorstring = conn.ExeSql(str_Sql);
            if (errorstring != "OK")
            {
                MessageBox.Show("未成功添加!请检查数据库!" + errorstring, "提醒!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                button1.Enabled = false;
                return;
            }
            MessageBox.Show("成功添加!" + errorstring, "提醒!",
                            MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

            //刷新DataGrid显示
            str_Sql     = "SELECT School_ID AS 学校代码,School_Name AS 学校名称,School_Type_Name AS 学校类别,Schoolmaster AS 校长,School_Tel AS 电话,School_Zip AS 邮政编码,School_Address AS 学校地址,School_Type_Year AS 学校学制年限 FROM View_School";
            errorstring = conn.Fill(str_Sql);
            if (errorstring != "OK")
            {
                MessageBox.Show("请检查数据库!" + errorstring, "提醒!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                button1.Enabled = false;
                return;
            }
            DataGrid1.SetDataBinding(conn.ds, "TableIn");
        }
Beispiel #12
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            if (conn.KickOut(textBox_New_School_ID.Text) == "")
            {
                MessageBox.Show("必须输入学校代码!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }

            if (textBox_New_School_ID.Text.Length != 12)
            {
                MessageBox.Show("学校代码只能为12位!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }

            if (conn.School_ID_Had(textBox_New_School_ID.Text))
            {
                MessageBox.Show("请不要输入重复的学校代码!", "警告!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }

            //转存学校信息,需要删除
            string str_Sql     = "Select * from School Where School_ID='" + textBox_Old_School_ID.Text + "'";
            string errorstring = conn.Fill(str_Sql);

            conn.dr = conn.ds.Tables[0].Rows[0];
            str_Sql = "insert into School (School_ID,School_Name,School_Type_ID,Schoolmaster,School_Tel,School_Zip,School_Address) values ('"
                      + conn.KickOut(textBox_New_School_ID.Text) + "','"
                      + conn.dr["School_Name"].ToString() + "',"
                      + conn.dr["School_Type_ID"].ToString() + ",'"
                      + conn.dr["Schoolmaster"].ToString() + "','"
                      + conn.dr["School_Tel"].ToString() + "','"
                      + conn.dr["School_Zip"].ToString() + "','"
                      + conn.dr["School_Address"].ToString() + "')";
            errorstring = conn.ExeSql(str_Sql);

            //更新教师信息,不用删除
            str_Sql = "Update Teacher Set School_ID='" + textBox_New_School_ID.Text
                      + "' Where School_ID='" + textBox_Old_School_ID.Text + "'";
            errorstring = conn.ExeSql(str_Sql);

            //转存班级信息,需要删除
            conn.ds.Reset();
            str_Sql     = "Select * from Class Where School_ID='" + textBox_Old_School_ID.Text + "'";
            errorstring = conn.Fill(str_Sql);

            for (int i = 0; i < conn.ds.Tables[0].Rows.Count; i++)
            {
                conn.dr = conn.ds.Tables[0].Rows[i];
                str_Sql = "INSERT INTO Class  (Class_ID,School_ID,Class_Type_ID,Class_Name,TeacherInCharge) values("
                          + conn.dr["Class_ID"].ToString() + ",'"
                          + textBox_New_School_ID.Text + "',"
                          + conn.dr["Class_Type_ID"].ToString() + ",'"
                          + conn.dr["Class_Name"].ToString() + "','"
                          + conn.dr["TeacherInCharge"].ToString() + "')";
                errorstring = conn.ExeSql(str_Sql);
            }

            //转存学生信息,不需要删除
            str_Sql = "Update Student Set School_ID='" + textBox_New_School_ID.Text
                      + "' Where School_ID='" + textBox_Old_School_ID.Text + "'";
            errorstring = conn.ExeSql(str_Sql);

            //删除该学校代码对应的所有信息,先删除学生,再删除班级,最后删除学校,以防外键冲突
            str_Sql = "DELETE from Class WHERE School_ID='" + textBox_Old_School_ID.Text + "'";
            conn.ExeSql(str_Sql);

            str_Sql = "DELETE from School WHERE School_ID='" + textBox_Old_School_ID.Text + "'";
            conn.ExeSql(str_Sql);

            MessageBox.Show("成功修改!", "提醒!",
                            MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

            button1.Enabled = false;
        }
        private void button1_Click(object sender, System.EventArgs e)
        {
            string str_Sql, errorstring;
            bool   HadSome = false;

            str_Sql = "SELECT School_Name AS 学校名称,Class_Type_Name AS 年级,Class_Name AS 班级,Student_ID As 身份证号码,Name As 姓名,Sex AS 性别,convert(char(10),Birthday,120) As 出生日期,Father AS 父亲,Mother AS 母亲,Keeper AS 监护人,StudentTel AS 联系电话,Student_Address AS 家庭住址,Father_Job AS 父亲职业,Father_XueLi AS 父亲学历,Mother_Job AS 母亲职业,Mother_XueLi AS 母亲学历 FROM View_StudentClass_Detail_City";

            //条件有输入的内容则参与查找,查找到的内容和DataGrid绑定
            if (checkBox_InQuXian.Checked == true)
            {
                str_Sql = str_Sql + " Where School_ID Like '____" + comboBox_QuXian.SelectedValue + "%'";
                HadSome = true;
            }
            if (checkBox_Student_QuXian.Checked == true)
            {
                str_Sql = str_Sql + " Where QuXian_ID =" + comboBox_Student_QuXian.SelectedValue;
                HadSome = true;
            }
            if (textBox_Student_ID.Text != "")
            {
                if (HadSome == false)
                {
                    str_Sql = str_Sql + " Where Student_ID LIKE '%" + textBox_Student_ID.Text + "%'";
                }
                else
                {
                    str_Sql = str_Sql + " AND Student_ID LIKE '%" + conn.KickOut(textBox_Student_ID.Text) + "%'";
                }
                HadSome = true;
            }
            if (textBox_Name.Text != "")
            {
                if (HadSome == false)
                {
                    str_Sql = str_Sql + " Where Name LIKE '%" + conn.KickOut(textBox_Name.Text) + "%'";
                }
                else
                {
                    str_Sql = str_Sql + " AND Name LIKE '%" + textBox_Name.Text + "%'";
                }
                HadSome = true;
            }
            if (textBox_Father.Text != "")
            {
                if (HadSome == false)
                {
                    str_Sql = str_Sql + " Where Father LIKE '%" + conn.KickOut(textBox_Father.Text) + "%'";
                }
                else
                {
                    str_Sql = str_Sql + " AND Father LIKE '%" + textBox_Father.Text + "%'";
                }
                HadSome = true;
            }
            if (textBox_Mother.Text != "")
            {
                if (HadSome == false)
                {
                    str_Sql = str_Sql + " Where Mother LIKE '%" + conn.KickOut(textBox_Mother.Text) + "%'";
                }
                else
                {
                    str_Sql = str_Sql + " AND Mother LIKE '%" + textBox_Mother.Text + "%'";
                }
                HadSome = true;
            }
            if (comboBox_Sex.Text != "")
            {
                if (HadSome == false)
                {
                    str_Sql = str_Sql + " Where Sex= '" + comboBox_Sex.SelectedItem + "'";
                }
                else
                {
                    str_Sql = str_Sql + " AND Sex= '" + comboBox_Sex.SelectedItem + "'";
                }
                HadSome = true;
            }

            errorstring = conn.Fill(str_Sql);
            if (errorstring != "OK")
            {
                MessageBox.Show("查找失败!请检查数据库!" + errorstring, "提醒!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                button1.Enabled = false;
                return;
            }
            DataGrid1.SetDataBinding(conn.ds, "TableIn");
        }