Exemple #1
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            button1.Enabled = false;
            string str_Sql, errorstring = "OK", str_School_ID_In;

            //导入学校信息
            conn.ds.Reset();
            try
            {
                conn.ds.ReadXmlSchema(textBox_LocationDBOut.Text + "\\School.xsd");
                conn.ds.ReadXml(textBox_LocationDBOut.Text + "\\School.xml");
            }
            catch
            {            //对话框
                MessageBox.Show("School文件打开失败!" + errorstring, "提醒!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            conn.dr          = conn.ds.Tables[0].Rows[0];
            str_School_ID_In = conn.dr["School_ID"].ToString();

            DialogResult result;

            if (conn.School_ID_Had(str_School_ID_In))
            {
                result = MessageBox.Show(this, "真的要导入学校代码为 " + str_School_ID_In + " 的学校吗?"
                                         + "其学校名称为" + conn.School_IDtoWhat(str_School_ID_In, "School_Name")
                                         + "操作会替换该学校原有的所有信息", "提醒!",
                                         MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            }
            else
            {
                result = MessageBox.Show(this, "真的要导入吗?", "提醒!",
                                         MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            }


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

                str_Sql = "DELETE from Class WHERE School_ID='" + str_School_ID_In + "'";
                conn.ExeSql(str_Sql);

                str_Sql = "DELETE from Teacher WHERE School_ID='" + str_School_ID_In + "'";
                conn.ExeSql(str_Sql);

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

                conn.ds.Reset();
                conn.ds.ReadXmlSchema(textBox_LocationDBOut.Text + "\\School.xsd");
                conn.ds.ReadXml(textBox_LocationDBOut.Text + "\\School.xml");

                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,QuXian_Code) values ('"
                          + str_School_ID_In + "','"
                          + 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() + "','"
                          + conn.dr["QuXian_Code"].ToString() + "')";
                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);

                //导入教师信息
                conn.ds.Reset();
                try
                {
                    conn.ds.ReadXmlSchema(textBox_LocationDBOut.Text + "\\Teacher.xsd");
                    conn.ds.ReadXml(textBox_LocationDBOut.Text + "\\Teacher.xml");
                }
                catch
                {                        //对话框
                    MessageBox.Show("Teacher文件打开失败!" + errorstring, "提醒!",
                                    MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }
                for (int i = 0; i < conn.ds.Tables[0].Rows.Count; i++)
                {
                    string str_InWorkSheet, str_IsFullTime;
                    conn.dr = conn.ds.Tables[0].Rows[i];

                    if (conn.dr["InWorkSheet"].ToString() == "True")
                    {
                        str_InWorkSheet = "1";
                    }
                    else
                    {
                        str_InWorkSheet = "0";
                    }
                    if (conn.dr["IsFullTime"].ToString() == "True")
                    {
                        str_IsFullTime = "1";
                    }
                    else
                    {
                        str_IsFullTime = "0";
                    }

                    str_Sql = "INSERT INTO Teacher (School_ID,Teacher_ID,Name,Sex,Birthday,WorkTime,SchoolType,PostCan,PostIn,SchoolGrad,GradTime,SpecialIn,LessonTeach,InWorkSheet,IsFullTime) values('"
                              + conn.dr["School_ID"].ToString()
                              + "','" + conn.dr["Teacher_ID"].ToString()
                              + "','" + conn.dr["Name"].ToString()
                              + "','" + conn.dr["Sex"].ToString()
                              + "','" + conn.dr["Birthday"].ToString()
                              + "','" + conn.dr["WorkTime"].ToString()
                              + "','" + conn.dr["SchoolType"].ToString()
                              + "','" + conn.dr["PostCan"].ToString()
                              + "','" + conn.dr["PostIn"].ToString()
                              + "','" + conn.dr["SchoolGrad"].ToString()
                              + "','" + conn.dr["GradTime"].ToString()
                              + "','" + conn.dr["SpecialIn"].ToString()
                              + "','" + conn.dr["LessonTeach"].ToString()
                              + "'," + str_InWorkSheet
                              + "," + str_IsFullTime + ")";
                    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); conn.ds.Reset();

                //导入班级信息
                conn.ds.Reset();
                try
                {
                    conn.ds.ReadXmlSchema(textBox_LocationDBOut.Text + "\\Class.xsd");
                    conn.ds.ReadXml(textBox_LocationDBOut.Text + "\\Class.xml");
                }
                catch
                {                        //对话框
                    MessageBox.Show("Class文件打开失败!" + errorstring, "提醒!",
                                    MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }
                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() + ",'"
                              + conn.dr["School_ID"].ToString() + "',"
                              + conn.dr["Class_Type_ID"].ToString() + ",'"
                              + conn.dr["Class_Name"].ToString() + "','"
                              + conn.dr["TeacherInCharge"].ToString() + "')";
                    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); conn.ds.Reset();

                //导入学生信息
                conn.ds.Reset();
                try
                {
                    conn.ds.ReadXmlSchema(textBox_LocationDBOut.Text + "\\Student.xsd");
                    conn.ds.ReadXml(textBox_LocationDBOut.Text + "\\Student.xml");
                }
                catch
                {                        //对话框
                    MessageBox.Show("Student文件打开失败!" + errorstring, "提醒!",
                                    MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }
                for (int i = 0; i < conn.ds.Tables[0].Rows.Count; i++)
                {
                    conn.dr = conn.ds.Tables[0].Rows[i];
                    str_Sql = "insert into Student (School_ID,Student_ID,Class_ID,Name,Birthday,Sex,Father,Mother,Keeper,StudentTel,QuXian_ID,Office_ID,Committee_ID,Student_Address,Father_Job,Father_XueLi,Mother_Job,Mother_XueLi) values ('"
                              + conn.dr["School_ID"].ToString() + "','"
                              + conn.dr["Student_ID"].ToString() + "',"
                              + conn.dr["Class_ID"].ToString() + ",'"
                              + conn.dr["Name"].ToString() + "','"
                              + conn.dr["Birthday"].ToString() + "','"
                              + conn.dr["Sex"].ToString() + "','"
                              + conn.dr["Father"].ToString() + "','"
                              + conn.dr["Mother"].ToString() + "','"
                              + conn.dr["Keeper"].ToString() + "','"
                              + conn.dr["StudentTel"].ToString() + "',"
                              + conn.dr["QuXian_ID"].ToString() + ","
                              + conn.dr["Office_ID"].ToString() + ",'"
                              + conn.dr["Committee_ID"].ToString() + "','"
                              + conn.dr["Student_Address"].ToString() + "','"
                              + conn.dr["Father_Job"].ToString() + "','"
                              + conn.dr["Father_XueLi"].ToString() + "','"
                              + conn.dr["Mother_Job"].ToString() + "','"
                              + conn.dr["Mother_XueLi"].ToString() + "')";
                    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);

                conn.Close();
                this.Dispose();
            }
            else
            {
                return;
            }
        }        /**//**/
        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");
        }
Exemple #3
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;
        }