public void addUser() { if (tb_new_user.Text.Trim() != "" && tb_new_password.Text.Trim() != "" && tb_company.Text.Trim() != "") { hailyEntities db = new hailyEntities(); user _user_add = new user(); _user_add.username = tb_new_user.Text; _user_add.password = EncodeMD5.getMD5(tb_new_password.Text.Trim());//tb_new_password.Text; _user_add.permission = cb_new_permission.SelectedIndex; _user_add.company = tb_company.Text; db.user.Add(_user_add); db.SaveChanges(); MessageBox.Show("用户创建成功!"); FormMain formMain = new FormMain("userControlPage"); formMain.Show(); this.Close(); } else if (tb_new_user.Text.Trim() == "") { MessageBox.Show("请输入用户名!", "缺少参数", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (tb_new_password.Text.Trim() == "" && tb_new_user.Text.Trim() != "") { MessageBox.Show("请输入密码!", "缺少参数", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (tb_new_user.Text.Trim() != "" && tb_new_password.Text.Trim() != "" && tb_company.Text.Trim() == "") { MessageBox.Show("请输入公司名!", "缺少参数", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public void addSoftware() { if (tb_new_soft.Text.Trim() != "" && tb_new_model.Text.Trim() != "" && tb_new_version.Text.Trim() != "") { hailyEntities db = new hailyEntities(); software _software_add = new software(); _software_add.name = tb_new_soft.Text; _software_add.model = tb_new_model.Text; //默认授予新用户的软件模块使用 _software_add.version = tb_new_version.Text; db.software.Add(_software_add); db.SaveChanges(); MessageBox.Show("软件添加成功!"); FormMain formMain = new FormMain("softwareControlPage"); formMain.Show(); this.Close(); } else if (tb_new_soft.Text.Trim() == "") { MessageBox.Show("请输入软件名!", "缺少参数", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (tb_new_model.Text.Trim() == "" && tb_new_soft.Text.Trim() != "") { MessageBox.Show("请输入模块名!", "缺少参数", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (tb_new_soft.Text.Trim() != "" && tb_new_model.Text.Trim() != "" && tb_new_version.Text.Trim() == "") { MessageBox.Show("请输入版本号!", "缺少参数", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public void updateUserInfo(String userName) { if (tb_username.Text != null && tb_up_password.Text != null && tb_company.Text != null) { hailyEntities db = new hailyEntities(); //查询要获取的对象 var userInfo = from u in db.user where u.username == userName select u; //获得具体对象 var userInfoObject = userInfo.FirstOrDefault(); //修改密码 userInfoObject.password = EncodeMD5.getMD5(tb_up_password.Text.Trim()); ////如果用户名与原始用户名不同,则修改用户名 //if (userName != tb_username.Text) //{ // //用户信息表中的用户名 // userInfoObject.username = tb_username.Text; // //软件授权记录表中的用户名,也应修改 // var permissionInfo = from u in db.permission // where u.username == userName // select u; // var softwareInfoObject = permissionInfo.FirstOrDefault(); // softwareInfoObject.username = tb_username.Text; // db.Entry<permission>(softwareInfoObject).State = System.Data.Entity.EntityState.Modified; //} userInfoObject.company = tb_company.Text; userInfoObject.permission = cb_new_permission.SelectedIndex; //指定状态。 db.Entry <user>(userInfoObject).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); MessageBox.Show("用户信息已更新!"); FormMain formMain = new FormMain("userControlPage"); formMain.Show(); this.Hide(); } else if (tb_username.Text == null) { MessageBox.Show("请输入用户名!", "缺少参数", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (tb_up_password == null && tb_username != null) { MessageBox.Show("请输入密码!", "缺少参数", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MessageBox.Show("请重新输入用户信息!", "缺少参数", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void signIn_Click(object sender, EventArgs e) { hailyEntities db = new hailyEntities(); try { userName_main = tb_username.Text.ToString(); if (userName_main == ConfigurationManager.AppSettings["name"] && ConfigurationManager.AppSettings["password"].Length == 32) { passWord = ConfigurationManager.AppSettings["password"]; } else { passWord = EncodeMD5.getMD5(tb_password.Text.Trim());//tb_password.Text.ToString(); } //1.判断用户名是否存在 List <user> list = db.user.Where(u => u.username == userName_main).ToList(); if (list.Count >= 1) { //用户存在 //2.判断密码是否正确 List <user> list2 = db.user.Where(u => u.username == userName_main && u.password == passWord).ToList(); if (list2.Count >= 1) { //用户存在且密码正确 saveAutoSignIn(); FormMain formMain = new FormMain(); formMain.Show(); this.Hide(); } else { MessageBox.Show("用户存在但密码不正确!", "温馨提示"); } } else { MessageBox.Show("用户不存在!", "温馨提示"); } } catch { } }
public void updateSoftwareInfo() { if (tb_up_software.Text != null && tb_up_model.Text != null && tb_up_version.Text != null) { hailyEntities db = new hailyEntities(); //查询要获取的对象 var softwareInfo = from u in db.software where (u.name == soft_main.name && u.model == soft_main.model && u.version == soft_main.version) select u; //获得具体对象 var softwareInfoObject = softwareInfo.FirstOrDefault(); //修改软件名 softwareInfoObject.name = tb_up_software.Text.Trim(); softwareInfoObject.model = tb_up_model.Text.Trim(); softwareInfoObject.version = tb_up_version.Text.Trim(); //指定状态。 db.Entry <software>(softwareInfoObject).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); MessageBox.Show("软件信息已更新!"); this.Close(); } else if (tb_up_software.Text == null) { MessageBox.Show("请输入软件名!", "缺少参数", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (tb_up_model == null && tb_up_software != null) { MessageBox.Show("请输入模块名!", "缺少参数", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (tb_up_software.Text != null && tb_up_model.Text != null && tb_up_version.Text == null) { MessageBox.Show("请输入软件版本号!", "缺少参数", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }