Beispiel #1
0
 private void frmGUserDetail_Load(object sender, EventArgs e)
 {
     try
     {
         if (mode == "A") //Add new group
         {
             this.Text        = "Add new user group";
             txtID.ReadOnly   = false;
             btnApply.Enabled = false;
             txtID.Text       = GroupUser.GenGroupId();
         }
         else
         if (mode == "E")     //Edit group
         {
             this.Text        = title;
             txtID.ReadOnly   = true;
             btnApply.Enabled = true;
             txtName.Focus();
             GetGroupUser();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Beispiel #2
0
        /// <summary>
        /// Save data to DB
        /// </summary>
        private void btnApply_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtID.Text.Count() <= 0)
                {
                    MessageBox.Show("Group ID can't be empty");
                    txtID.Focus();
                    return;
                }

                if (mode == "A")
                {
                    //Add new group user
                    GroupUser g      = new GroupUser(txtID.Text, txtName.Text);
                    string    result = g.Add(userId);
                    if (result == "OK")
                    {
                        DialogResult dr = MessageBox.Show("Add group " + txtName.Text + " success!", "Sucess", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        if (dr == DialogResult.OK)
                        {
                            txtID.Text = GroupUser.GenGroupId();
                            txtName.Focus();
                            txtName.Text     = "";
                            btnApply.Enabled = true;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Error: " + result);
                    }
                }
                else
                if (mode == "E")
                {
                    //Update group user
                    GroupUser g      = new GroupUser(txtID.Text, txtName.Text);
                    string    result = g.Update(userId);
                    if (result == "OK")
                    {
                        DialogResult dr = MessageBox.Show("Update group " + txtName.Text + " success!", "Sucess", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        if (dr == DialogResult.OK)
                        {
                            this.Hide();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Error: " + result);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }