Ejemplo n.º 1
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            config connFirst = new config();
            //测试数据库连接
            string str_Sql     = "SELECT School_Type_ID As 学校类别代码,School_Type_Name As 学校类别名,School_Type_Year As 学校类别学制 FROM School_Type";
            string errorstring = connFirst.Fill(str_Sql);

            if (errorstring != "OK")
            {
                MessageBox.Show("请检查数据库!" + errorstring, "提醒!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                connFirst.Close();
                return;
            }

            //特殊字符不能用
            if (connFirst.Sniffer_In(textBox_User.Text) || connFirst.Sniffer_In(textBox_PassWord.Text))
            {
                MessageBox.Show("用户名或密码不得用空格或者'\"?%=等特殊字符!" + errorstring, "提醒!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                connFirst.Close();
                return;
            }

            //判断用户合法
            str_Sql = "Select * FROM Users WHERE UserName= '******' AND PassWord='******'";
            if (connFirst.GetRowCount(str_Sql) != 1)
            {
                MessageBox.Show("错误的用户名或密码!" + errorstring, "提醒!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                connFirst.Close();

                button1.Enabled = true;
                return;
            }
            else
            {
                str_User_login = textBox_User.Text;
                this.Close();
            }
        }
        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;
        }
Ejemplo n.º 3
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            if (checkBox_First.Checked == true)
            {
                try
                {
                    string      path = "SchoolManage.exe.config";
                    XmlDocument xd   = new XmlDocument();
                    xd.Load(path);
                    //判断节点是否存在,如果存在则修改当前节点
                    foreach (XmlNode xn1 in xd.SelectNodes("/configuration/appSettings/add"))
                    {
                        if (xn1.Attributes["key"].Value == "Database")
                        {
                            xn1.Attributes["value"].Value = textBox_Database.Text;
                            //break;
                        }
                        if (xn1.Attributes["key"].Value == "DatabaseServer")
                        {
                            xn1.Attributes["value"].Value = textBox_DBServer.Text;
                            //break;
                        }
                        if (xn1.Attributes["key"].Value == "DatabaseUser")
                        {
                            xn1.Attributes["value"].Value = textBox_DbUser.Text;
                            break;
                        }

                        /*if(xn1.Attributes["key"].Value=="DatabasePassword")
                         * {
                         *      xn1.Attributes["value"].Value=textBox_DbPassWord.Text;
                         *      break;
                         * }*/
                    }
                    //保存web.config
                    xd.Save(path);
                    //return true;
                    MessageBox.Show("成功修改!", "提醒!",
                                    MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                catch
                {
                    //return false;
                    throw new Exception("Config设置文件读取失败!");
                }
            }

            //测试数据库连接
            string str_Sql, errorstring;

            str_Sql     = "SELECT School_Type_ID As 学校类别代码,School_Type_Name As 学校类别名,School_Type_Year As 学校类别学制 FROM School_Type";
            errorstring = conn.Fill(str_Sql);
            if (errorstring != "OK")
            {
                MessageBox.Show("请检查数据库!" + errorstring, "提醒!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                conn.Close();
                return;
            }

            //特殊字符不能用
            if (conn.Sniffer_In(textBox_User.Text) || conn.Sniffer_In(textBox_PassWord.Text))
            {
                MessageBox.Show("用户名或密码不得用空格或者'\"?%=等特殊字符!" + errorstring, "提醒!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                conn.Close();
                return;
            }

            //判断用户合法
            str_Sql = "Select * FROM Users WHERE UserName= '******' AND PassWord='******'";
            if (conn.GetRowCount(str_Sql) != 1)
            {
                MessageBox.Show("错误的用户名或密码!" + errorstring, "提醒!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                conn.Close();

                button1.Enabled = true;
                return;
            }
            else
            {
                str_User_login = textBox_User.Text;

                this.Close();
            }
        }
Ejemplo n.º 4
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;
            }
        }        /**//**/
Ejemplo n.º 5
0
        private void button3_Click(object sender, System.EventArgs e)
        {
            string str_LocationDBBackup = "";
            string errorstring = "", str_Sql = "";
            //DELETE from School WHERE School_ID='"+textBox_School_ID.Text+"'";

            DialogResult result = MessageBox.Show(this, "真的要删除所有学校的信息吗?不可恢复!", "提醒!", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (result == DialogResult.OK)
            {
                try
                {
                    string      path = "SchoolManage.exe.config";
                    XmlDocument xd   = new XmlDocument();
                    xd.Load(path);
                    foreach (XmlNode xn1 in xd.SelectNodes("/configuration/appSettings/add"))
                    {
                        if (xn1.Attributes["key"].Value == "DatabaseBackup")
                        {
                            str_LocationDBBackup = xn1.Attributes["value"].Value;
                            break;
                        }
                    }
                }
                catch
                {
                    //return false;
                    throw new Exception("Config设置文件读取失败!");
                }
                str_Sql = "backup database " + ConfigurationSettings.AppSettings["Database"]
                          + " TO disk='" + str_LocationDBBackup + "\\在" + System.DateTime.Now.ToString().Replace(":", "-") + "对郑州市教育统计监控系统的数据备份.bak'";

                try
                {
                    errorstring = conn.ExeSql(str_Sql);
                }
                catch
                {
                    MessageBox.Show("备份失败!", "提醒!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    conn.Close();
                }

                str_Sql     = "DELETE from Student";
                errorstring = conn.ExeSql(str_Sql);

                str_Sql     = "DELETE from Class";
                errorstring = conn.ExeSql(str_Sql);

                str_Sql     = "DELETE from Teacher";
                errorstring = conn.ExeSql(str_Sql);

                str_Sql     = "DELETE from School";
                errorstring = conn.ExeSql(str_Sql);
                if (errorstring != "OK")
                {
                    MessageBox.Show("未成功删除!请检查本地数据库!" + errorstring, "提醒!",
                                    MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    button3.Enabled = false;
                    return;
                }
                MessageBox.Show("成功删除!备份于文件夹" + str_LocationDBBackup, "提醒!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else
            {
                return;
            }
            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");

            button3.Enabled = false;
        }