public static int Insert(tblUserInGroup userGroup)
 {
   var db = new dbEcustomEntities(Common.Decrypt(ConfigurationManager.ConnectionStrings["dbEcustomEntities"].ConnectionString, true));
   db.AddTotblUserInGroups(userGroup);
   int re= db.SaveChanges();
   db.Connection.Close();
   return re;
 }
Пример #2
0
    private void btnUpdateListGroup_Click(object sender, EventArgs e)
    {
      //check is user exist
      tblUser user = UserFactory.GetByID(_userID);
      if (user == null)
      {
        MessageBox.Show("Người dùng này không còn tại tại trong hệ thống nữa, xin kiểm tra lại");
        return;
      }

      //delete all current Group of this User before add new ones
      UserInGroupFactory.DeleteUserInGroupByUserID(_userID);
      //add selected group into userInGroup
      try
      {
        foreach (DataGridViewRow dr in grvGroup.Rows)
        {
          if (dr.Cells[0].Value + "" == "True")
          {
            int groupID = new Int32();
            groupID = (Int32)dr.Cells[1].Value;
            tblUserInGroup userInGroup = new tblUserInGroup();
            userInGroup.GroupID = groupID;
            userInGroup.UserID = _userID;
            UserInGroupFactory.Insert(userInGroup);
          }
        }
      }
      catch (Exception)
      {
        MessageBox.Show(ConstantInfo.MESSAGE_ADD_USER_IN_GROUP_FAIL);
        return;
      }
      MessageBox.Show(ConstantInfo.MESSAGE_ADD_USER_IN_GROUP_SUCESSFULLY);
    }
    private void btnSave_Click(object sender, EventArgs e)
    {

      //delete all current user of this Group before add new ones
      UserInGroupFactory.DeleteUserInGroupByGroupID(_groupID);
      //add selected user into groups
      try
      {
        foreach (DataGridViewRow dr in grvUser.Rows)
        {
          if (dr.Cells[0].Value + "" == "True")
          {
            int userID = new Int32();
            userID = (Int32)dr.Cells[1].Value;
            tblUserInGroup userInGroup = new tblUserInGroup();
            userInGroup.GroupID = _groupID;
            userInGroup.UserID = userID;
            UserInGroupFactory.Insert(userInGroup);
          }
        }
      }
      catch (Exception)
      {
        MessageBox.Show(ConstantInfo.MESSAGE_ADD_USER_IN_GROUP_FAIL);
        return;
      }

      MessageBox.Show(ConstantInfo.MESSAGE_ADD_USER_IN_GROUP_SUCESSFULLY);
      // Bind the lastest to the parrent
      Form[] listForm = this.Owner.OwnedForms;
      foreach (Form form in listForm)
      {
        if (form.Name == "frmAddGroup")
        {
          ((frmAddGroup)form).BindData();
        }
      }
      this.Close();
    }