Exemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (Validate())
            {
                int i = 0;
                try
                {
                    WSScalper.UserRow u = new WSScalper.UserRow();
                    u.LoginId  = txtLoginID.Text.Trim();
                    u.EmailId  = txtEmailID.Text.Trim();
                    u.Active   = cmbActive.SelectedIndex == 0 ? true : false;
                    u.LoggedIn = false;
                    u.PhoneNo  = txtContactNo.Text.Trim();
                    u.Username = txtLoginName.Text.Trim();

                    WSScalper.WebServicesScalper ws = new WSScalper.WebServicesScalper();

                    if (!edit)
                    {
                        u.Password = "******";//deafault password for the new user
                        i          = ws.CreateUser(u);
                        frmAdmin.GetSingletonAdminform().RefreshDataset(true);
                    }
                    else
                    {
                        u.Id = ua.id;
                        i    = ws.EditUsers(u);
                        frmAdmin.GetSingletonAdminform().RefreshDataset(true);
                    }
                }
                catch (Exception ex)
                {
                    //if(ex.Message = "Unable to connect the remote server")
                    MessageBox.Show(ex.Message, "TC Admin");
                    //Application.Exit();
                    return;
                }

                if (i >= 1)
                {
                    if (ua == null)
                    {
                        ua = new UserAttribute();
                    }

                    ua.emailid  = txtEmailID.Text.Trim();
                    ua.active   = cmbActive.SelectedIndex == 0 ? true : false;
                    ua.loginID  = txtLoginID.Text.Trim();
                    ua.phoneno  = txtContactNo.Text.Trim();
                    ua.username = txtLoginName.Text.Trim();


                    btnCancel.Enabled = false;
                    btnEdit.Enabled   = true;
                    btnNew.Enabled    = true;
                    btnSave.Enabled   = false;
                    btnDelete.Enabled = true;
                    if (edit)
                    {
                        MessageBox.Show("Modified Successfully", "TC Admin");
                        DisplayRecords(ua);
                    }
                    else
                    {
                        ua.id = i;
                        MessageBox.Show("Created Successfully", "TC Admin");
                    }

                    //frmAdmin.GetSingletonAdminform().RefreshGrid();
                    //RefreshDataset();

                    //refreah the dataset
                    //dsUsers = frmAdmin.GetSingletonAdminform().dsUsers;

                    frmAdmin.GetSingletonAdminform().DG_Enabled = true;

                    //frmAdmin.GetSingletonAdminform().DG_SelectRow(ua.id);



                    DisableForm();
                    edit = false;
                }
                else if (i == -3)
                {
                    MessageBox.Show("Login ID or Email ID already exist", "TC Admin");
                }
                else if (i == -4)
                {
                    MessageBox.Show("Login Creation Failed", "TC Admin");
                }
            }
        }