Example #1
0
 public bool ContainUser(dtUser tempOpe, List <dtUser> List)
 {
     foreach (dtUser temp in List)
     {
         if (temp.userId > 0)
         {
             if (temp.userId == tempOpe.userId)
             {
                 return(true);
             }
         }
         else
         {
             return(false);
         }
     }
     return(false);
 }
Example #2
0
        private void btn_save_Click(object sender, RoutedEventArgs e)
        {
            if (!Global_Object.ServerAlive())
            {
                return;
            }
            try
            {
                if (String.IsNullOrEmpty(passwordNewtb.Password) || String.IsNullOrEmpty(passwordNewConfirmtb.Password))
                {
                    System.Windows.Forms.MessageBox.Show("Password không được để trống!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    if (String.IsNullOrEmpty(passwordNewtb.Password))
                    {
                        passwordNewtb.Focus();
                    }
                    else
                    {
                        passwordNewConfirmtb.Focus();
                    }
                    return;
                }

                if (passwordNewtb.Password != passwordNewConfirmtb.Password)
                {
                    System.Windows.Forms.MessageBox.Show("New Password don't match the Confirm New Password!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    passwordNewtb.SelectAll();
                    passwordNewtb.Focus();
                    return;
                }

                dtUser user = new dtUser();
                user.userId          = Global_Object.userLogin;
                user.userName        = this.userNametb.Text;
                user.userAuthor      = Global_Object.userAuthor;
                user.userPasswordOld = this.passwordCurrenttb.Password;
                user.userPassword    = this.passwordNewtb.Password;

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"http://" + Properties.Settings.Default.serverIp + ":" + Properties.Settings.Default.serverPort + @"/robot/rest/" + "user/changPasswordUser");
                request.Method      = "POST";
                request.ContentType = @"application/json";
                string jsonData = JsonConvert.SerializeObject(user);
                System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
                Byte[] byteArray = encoding.GetBytes(jsonData);
                request.ContentLength = byteArray.Length;
                using (Stream dataStream = request.GetRequestStream())
                {
                    dataStream.Write(byteArray, 0, byteArray.Length);
                    dataStream.Flush();
                }
                HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                using (Stream responseStream = response.GetResponseStream())
                {
                    StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                    int          result = int.Parse(reader.ReadToEnd());

                    if (result == 1)
                    {
                        System.Windows.Forms.MessageBox.Show(String.Format(Global_Object.messageSaveSucced), Global_Object.messageTitileInformation, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Close();
                    }
                    else if (result == -2)
                    {
                        System.Windows.Forms.MessageBox.Show("Password is correct!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        passwordCurrenttb.SelectAll();
                        passwordCurrenttb.Focus();
                        return;
                    }
                    else
                    {
                        System.Windows.Forms.MessageBox.Show("Change Password fail!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                logFile.Error(ex.Message);
            }
        }
        private void Btn_Delete_Click(object sender, RoutedEventArgs e)
        {
            if (!Global_Object.ServerAlive())
            {
                return;
            }
            try
            {
                if (UsersListDg.SelectedItem == null || !UsersListDg.HasItems)
                {
                    System.Windows.Forms.MessageBox.Show(String.Format(Global_Object.messageNothingSelected), Global_Object.messageTitileWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (System.Windows.Forms.MessageBox.Show(String.Format(Global_Object.messageDeleteConfirm, "User"), Global_Object.messageTitileWarning, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                {
                    List <dtUser> listDelete = new List <dtUser>();
                    dtUser        user       = UsersListDg.SelectedItem as dtUser;
                    listDelete.Add(user);

                    string jsonData = JsonConvert.SerializeObject(listDelete);

                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"http://" + Properties.Settings.Default.serverIp + ":" + Properties.Settings.Default.serverPort + @"/robot/rest/" + "user/deleteListUser");
                    request.Method      = "DELETE";
                    request.ContentType = "application/json";

                    System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
                    Byte[] byteArray = encoding.GetBytes(jsonData);
                    request.ContentLength = byteArray.Length;
                    using (Stream dataStream = request.GetRequestStream())
                    {
                        dataStream.Write(byteArray, 0, byteArray.Length);
                        dataStream.Flush();
                    }

                    HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                    using (Stream responseStream = response.GetResponseStream())
                    {
                        StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                        int          result = 0;
                        int.TryParse(reader.ReadToEnd(), out result);
                        if (result == 1)
                        {
                            System.Windows.Forms.MessageBox.Show(String.Format(Global_Object.messageDeleteSucced), Global_Object.messageTitileInformation, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            userModel.ReloadListUsers();
                        }
                        else if (result == 2)
                        {
                            System.Windows.Forms.MessageBox.Show(String.Format(Global_Object.messageDeleteUse, "User", "Other Screen"), Global_Object.messageTitileWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                        else
                        {
                            System.Windows.Forms.MessageBox.Show(String.Format(Global_Object.messageDeleteFail), Global_Object.messageTitileError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logFile.Error(ex.Message);
            }
        }
Example #4
0
        private void btn_login_Click(object sender, RoutedEventArgs e)
        {
            if (!CheckAlive())
            {
                PingTestlb.Content = FindResource("LoginForm_LoginError");
                return;
            }
            PingTestlb.Content = "";
            try
            {
                if (string.IsNullOrEmpty(this.userNametb.Text) || this.userNametb.Text.Trim() == "")
                {
                    System.Windows.Forms.MessageBox.Show(String.Format(Global_Object.messageValidate, "User Name", "User Name"), Global_Object.messageTitileWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    this.userNametb.Focus();
                    return;
                }

                if (string.IsNullOrEmpty(this.passwordtb.Password) || this.passwordtb.Password.Trim() == "")
                {
                    System.Windows.Forms.MessageBox.Show(String.Format(Global_Object.messageValidate, "Password", "Password"), Global_Object.messageTitileWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    this.passwordtb.Focus();
                    return;
                }

                dtUser user = new dtUser();
                user.userName     = this.userNametb.Text;
                user.userPassword = this.passwordtb.Password;

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"http://" + Properties.Settings.Default.serverIp + ":" + Properties.Settings.Default.serverPort + @"/robot/rest/" + "user/getUserInfo");
                request.Method      = "POST";
                request.ContentType = @"application/json";
                string jsonData = JsonConvert.SerializeObject(user);
                System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
                Byte[] byteArray = encoding.GetBytes(jsonData);
                request.ContentLength = byteArray.Length;
                using (Stream dataStream = request.GetRequestStream())
                {
                    dataStream.Write(byteArray, 0, byteArray.Length);
                    dataStream.Flush();
                }
                HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                using (Stream responseStream = response.GetResponseStream())
                {
                    StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                    string       result = reader.ReadToEnd();
                    user = JsonConvert.DeserializeObject <dtUser>(result);

                    if (user.userAuthor == 0 || user.userAuthor == 1 || user.userAuthor == 2)
                    {
                        Global_Object.userAuthor = user.userAuthor;
                        Global_Object.userLogin  = user.userId;
                        Global_Object.userName   = user.userName;
                        this.Close();
                    }
                    else
                    {
                        System.Windows.Forms.MessageBox.Show("Login Fail!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
            catch (Exception ex)
            {
                logFile.Error(ex.Message);
            }
        }
Example #5
0
        public void ReloadListUsers()
        {
            if (!Global_Object.ServerAlive())
            {
                return;
            }
            try
            {
                usersList.Clear();
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"http://" + Properties.Settings.Default.serverIp + ":" + Properties.Settings.Default.serverPort + @"/robot/rest/" + "user/getListUser");
                request.Method      = "POST";
                request.ContentType = @"application/json";
                dtUser userSend = new dtUser();
                userSend.userAuthor = Global_Object.userAuthor;
                string jsonData = JsonConvert.SerializeObject(userSend);
                System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
                Byte[] byteArray = encoding.GetBytes(jsonData);
                request.ContentLength = byteArray.Length;
                using (Stream dataStream = request.GetRequestStream())
                {
                    dataStream.Write(byteArray, 0, byteArray.Length);
                    dataStream.Flush();
                }
                HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                using (Stream responseStream = response.GetResponseStream())
                {
                    StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                    string       result = reader.ReadToEnd();

                    DataTable users = JsonConvert.DeserializeObject <DataTable>(result);
                    foreach (DataRow dr in users.Rows)
                    {
                        dtUser user = new dtUser
                        {
                            creUsrId = int.Parse(dr["creUsrId"].ToString()),
                            creDt    = dr["creDt"].ToString(),
                            updUsrId = int.Parse(dr["updUsrId"].ToString()),
                            updDt    = dr["updDt"].ToString(),

                            userId       = int.Parse(dr["userId"].ToString()),
                            userName     = dr["userName"].ToString(),
                            userPassword = dr["userPassword"].ToString(),
                            userAuthor   = int.Parse(dr["userAuthor"].ToString()),
                            //userDevices
                            flagModify      = int.Parse(dr["flagModify"].ToString()),
                            userDeviceId    = int.Parse(dr["userDeviceId"].ToString()),
                            deviceId        = int.Parse(dr["deviceId"].ToString()),
                            deviceName      = dr["deviceName"].ToString(),
                            userPasswordOld = dr["userPasswordOld"].ToString(),
                        };
                        if (!ContainUser(user, usersList))
                        {
                            usersList.Add(user);
                        }
                    }
                }
                if (GroupedUsers.IsEditingItem)
                {
                    GroupedUsers.CommitEdit();
                }

                if (GroupedUsers.IsAddingNew)
                {
                    GroupedUsers.CommitNew();
                }

                GroupedUsers.Refresh();
                if (userManagement.UsersListDg.HasItems)
                {
                    userManagement.UsersListDg.SelectedItem = userManagement.UsersListDg.Items[0];
                }
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }
        }