Example #1
0
        private void btnNewApp_Click(object sender, RoutedEventArgs e)
        {
            string sql;
            string name = txtAppName.Text;

            if (name.Length < 2)
            {
                txtInfo.Text = "应用程序名称长度不小于2";
                return;
            }
            //不允许应用重名
            sql = string.Format("select applicationname from applications where applicationname='{0}'", name);
            DataTable dt = DBOperate.getDataTable(sql);

            if (dt.Rows.Count > 0)
            {
                txtInfo.Text = "同名应用程序已存在,请更改应用名称!";
                return;
            }

            sql = string.Format("insert applications (applicationname) values ('{0}')", name);
            if (DBOperate.executeCommand(sql))
            {
                vm.refreshApplication();
                txtInfo.Text    = string.Format("应用程序{0}已添加。", name);
                txtAppName.Text = "";
            }
        }
Example #2
0
        private void btnNewDBS_Click(object sender, RoutedEventArgs e)
        {
            string sql;
            string group = txtDBSName.Text;
            string name  = txtConnName.Text;

            if (group.Length < 2 || name.Length < 2 || string.IsNullOrWhiteSpace(vm.applicationid))
            {
                txtInfo.Text = "数据源名称和连接名称长度不小于2";
                return;
            }
            //同一程序中,不允许连接重名
            sql = string.Format("select connname from connections where applicationid='{0}' and connname='{1}'", vm.applicationid, name);
            DataTable dt = DBOperate.getDataTable(sql);

            if (dt.Rows.Count > 0)
            {
                txtInfo.Text = "应用程序中已存在同名连接,请更改!";
                return;
            }

            sql = string.Format("insert connections (applicationid,connname,datasourcename) values ('{0}','{1}','{2}')", vm.applicationid, name, group);
            if (DBOperate.executeCommand(sql))
            {
                vm.refreshConn();
                txtInfo.Text    = string.Format("数据源{0}={1}已添加。", group, name);
                txtDBSName.Text = txtConnName.Text = "";
            }
        }
Example #3
0
        private void UserControl_Initialized(object sender, EventArgs e)
        {
            vm.dtApplication = DBOperate.getDataTable("select * from applications");


            grdMain.DataContext = vm;
        }
Example #4
0
        private void btnNewModel_Click(object sender, RoutedEventArgs e)
        {
            string sql;
            string name = txtModelName.Text;

            if (name.Length < 2 || string.IsNullOrWhiteSpace(vm.applicationid))
            {
                txtInfo.Text = "模块名称长度不小于2";
                return;
            }
            //应用程序范围内,不允许模块名重复
            sql = string.Format("select modelname from models where modelname='{0}' and applicationid='{1}'", name, vm.applicationid);
            DataTable dt = DBOperate.getDataTable(sql);

            if (dt.Rows.Count > 0)
            {
                txtInfo.Text = "应用程序内已存在同名模块!";
                return;
            }
            sql = string.Format("insert models (applicationid,modelname) values ('{0}','{1}')", vm.applicationid, name);
            if (DBOperate.executeCommand(sql))
            {
                vm.refreshModel();
                txtInfo.Text      = string.Format("模块{0}已添加。", name);
                txtModelName.Text = "";
            }
        }
Example #5
0
        private void btnNewUser_Click(object sender, RoutedEventArgs e)
        {
            string sql;
            string username = txtUserName.Text;
            string password = txtPassword.Text;

            if (username.Length < 5 || password.Length < 6 || string.IsNullOrWhiteSpace(vm.applicationid))
            {
                txtInfo.Text = "用户名长度不小于5,口令长度不小于6";
                return;
            }
            password = DES.EncryptString(password, DES.theKey);
            //全范围不允许用户重名,这是为了防止不同应用程序之间的用户冒名替代
            sql = string.Format("select username from users where username='******'", username);
            DataTable dt = DBOperate.getDataTable(sql);

            if (dt.Rows.Count > 0)
            {
                txtInfo.Text = "用户名已存在,请更改用户名";
                return;
            }
            sql = string.Format("insert users (applicationid,username,password) values ('{0}','{1}','{2}')", vm.applicationid, username, password);
            if (DBOperate.executeCommand(sql))
            {
                vm.refreshUser();
                txtInfo.Text     = string.Format("用户{0}已添加。", username);
                txtUserName.Text = txtPassword.Text = "";
            }
        }
Example #6
0
        private void btnNewRole_Click(object sender, RoutedEventArgs e)
        {
            string sql;
            string name = txtRoleName.Text;

            if (name.Length < 2 || string.IsNullOrWhiteSpace(vm.applicationid))
            {
                txtInfo.Text = "角色名称长度不小于2";
                return;
            }
            //同一程序中,不允许角色重名
            sql = string.Format("select rolename from roles where applicationid='{0}' and rolename='{1}'", vm.applicationid, name);
            DataTable dt = DBOperate.getDataTable(sql);

            if (dt.Rows.Count > 0)
            {
                txtInfo.Text = "角色名已存在,请更改!";
                return;
            }

            sql = string.Format("insert roles (applicationid,rolename) values ('{0}','{1}')", vm.applicationid, name);
            if (DBOperate.executeCommand(sql))
            {
                vm.refreshRole();
                txtInfo.Text     = string.Format("角色{0}已添加。", name);
                txtRoleName.Text = "";
            }
        }
Example #7
0
 internal void refreshModelConn()
 {
     dtModelConn = DBOperate.getDataTable(string.Format("select t1.*, case when t1.isreadonly=0 then '读写' else '只读' end as flag ,t2.ConnName,t2.DatasourceName,t3.ModelName from ConnectionsInModels t1, Connections t2, Models t3 where t1.ConnID=t2.ConnID and t1.ModelID=t3.ModelID and t2.ApplicationID='{0}' order by t3.ModelName", applicationid));
     RaisePropertyChanged(() => dtModelConn);
 }
Example #8
0
 internal void refreshRoleModel()
 {
     dtRoleModel = DBOperate.getDataTable(string.Format("select t1.*,t2.RoleName,t3.ModelName from ModelsInRoles t1, Roles t2, Models t3 where t1.RoleID=t2.RoleID and t1.ModelID=t3.ModelID and t2.ApplicationID='{0}' order by t2.rolename", applicationid));
     RaisePropertyChanged(() => dtRoleModel);
 }
Example #9
0
 internal void refreshRoleUser()
 {
     dtRoleUser = DBOperate.getDataTable(string.Format("select t1.*,t2.RoleName,t3.UserName from UsersInRoles t1, Roles t2, Users t3 where t1.RoleID=t2.RoleID and t1.UserID=t3.UserID and t2.ApplicationID='{0}' order by t3.username", applicationid));
     RaisePropertyChanged(() => dtRoleUser);
 }
Example #10
0
 internal void refreshConn()
 {
     dtConn = DBOperate.getDataTable(string.Format("select * from connections where applicationid='{0}' order by connname", applicationid));
     RaisePropertyChanged(() => dtConn);
 }
Example #11
0
 internal void refreshModel()
 {
     dtModel = DBOperate.getDataTable(string.Format("select * from models where applicationid='{0}' order by modelname", applicationid));
     RaisePropertyChanged(() => dtModel);
 }
Example #12
0
 internal void refreshUser()
 {
     dtUser = DBOperate.getDataTable(string.Format("select * from users where applicationid='{0}' order by username", applicationid));
     RaisePropertyChanged(() => dtUser);
 }
Example #13
0
 internal void refreshRole()
 {
     dtRole = DBOperate.getDataTable(string.Format("select * from roles where applicationid='{0}' order by rolename", applicationid));
     RaisePropertyChanged(() => dtRole);
 }
Example #14
0
 internal void refreshApplication()
 {
     dtApplication = DBOperate.getDataTable(string.Format("select * from applications"));
     RaisePropertyChanged(() => dtApplication);
 }