Ejemplo n.º 1
0
        private void btnLogOut_Click(object sender, RoutedEventArgs e)
        {
            Settings.Default.DR_Username    = "";
            Settings.Default.DR_Password    = "";
            Settings.Default.DR_Remember_Me = false;

            LogInSection.Visibility         = Visibility.Visible;
            LandingSection.Visibility       = Visibility.Collapsed;
            DirectResponseBorder.Visibility = Visibility.Collapsed;

            Color color      = Color.FromRgb(0, 0, 0);
            Brush background = new SolidColorBrush(color);

            windowBorderDrag.Background = background;

            Model.User user = this.documentManagerVM.CurrentUserVM.Model;
            string     path = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\Assets\\" + user.UserName + user.Id + "_msg.dr";

            if (!File.Exists(path))
            {
                XmlWriterSettings xmlSettings = new XmlWriterSettings();
                xmlSettings.Indent = true;
                using (XmlWriter writer = XmlWriter.Create(path, xmlSettings))
                {
                    DataContractSerializer serializer = new DataContractSerializer(typeof(Model.User));
                    serializer.WriteObject(writer, user);
                }
            }
            else
            {
                XmlWriterSettings xmlSettings = new XmlWriterSettings();
                xmlSettings.Indent = true;
                using (XmlWriter writer = XmlWriter.Create(path, xmlSettings))
                {
                    DataContractSerializer serializer = new DataContractSerializer(typeof(Model.User));
                    serializer.WriteObject(writer, user);
                }
            }

            Server.Logout();
        }
Ejemplo n.º 2
0
        public MainWindow()
        {
            InitializeComponent();
            _channelFactory = new DuplexChannelFactory <IDirectResponseWebService>(new ClientCallback(), "DirectResponseServiceEndPoint");
            Server          = _channelFactory.CreateChannel();
            ((INotifyCollectionChanged)MessageList.Items).CollectionChanged += ListView_CollectionChanged;
            this.DataContext          = documentManagerVM;
            soundPlayer.SoundLocation = @Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\Assets\\intuition.wav";

            if (Settings.Default.DR_Username == "username" && Settings.Default.DR_Password == "password")
            {
                LogInSection.Visibility         = Visibility.Visible;
                LandingSection.Visibility       = Visibility.Collapsed;
                DirectResponseBorder.Visibility = Visibility.Collapsed;
            }
            else
            {
                LogInSection.Visibility         = Visibility.Collapsed;
                LandingSection.Visibility       = Visibility.Visible;
                DirectResponseBorder.Visibility = Visibility.Visible;

                Color color      = Color.FromRgb(38, 50, 56);
                Brush background = new SolidColorBrush(color);
                windowBorderDrag.Background = background;

                string username = Settings.Default.DR_Username;
                string password = Settings.Default.DR_Password;

                OpUserSelect ous = new OpUserSelect();
                ous.Criteria = new CriteriaUser {
                    Username = username, Password = password
                };
                OperationResult obj = OperationManager.Singleton.executeOperation(ous);

                if ((obj == null) || (!obj.Status))
                {
                    MessageBox.Show("Error while connectiong to the database.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else
                {
                    if (obj.DbItems.Count() == 1)
                    {
                        DbItem[] items = obj.DbItems;
                        UserDb[] users = items.Cast <UserDb>().ToArray();

                        int returnValue = Server.Login(users[0].Username, users[0].Full_Name, users[0].User_Id);
                        if (returnValue == 1)
                        {
                            MessageBox.Show("You are already loged in!");
                            Settings.Default.DR_Username    = "";
                            Settings.Default.DR_Password    = "";
                            Settings.Default.DR_Remember_Me = false;

                            LogInSection.Visibility         = Visibility.Visible;
                            LandingSection.Visibility       = Visibility.Collapsed;
                            DirectResponseBorder.Visibility = Visibility.Collapsed;

                            Color color2      = Color.FromRgb(0, 0, 0);
                            Brush background2 = new SolidColorBrush(color2);
                            windowBorderDrag.Background = background2;

                            Server.Logout();
                        }
                        string path = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\Assets\\" + users[0].Username + users[0].User_Id + "_msg.dr";
                        if (File.Exists(path))
                        {
                            using (XmlReader reader = XmlReader.Create(path))
                            {
                                DataContractSerializer serializer = new DataContractSerializer(typeof(Model.User));
                                Model.User             user       = serializer.ReadObject(reader) as Model.User;
                                this.documentManagerVM.CurrentUserVM = new UserVM(user);
                            }
                        }
                        else
                        {
                            this.documentManagerVM.CurrentUserVM = new UserVM(new Model.User()
                            {
                                FullName = users[0].Full_Name,
                                UserName = users[0].Username,
                                Email    = users[0].Email,
                                Password = users[0].Password,
                                Image    = users[0].Image,
                                Id       = users[0].User_Id
                            });
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            username = tbUserName.Text;
            password = tbPassword.Password.ToString();
            remember = chbRememberMe.IsChecked ?? false;
            OpUserSelect ous = new OpUserSelect();

            ous.Criteria = new CriteriaUser {
                Username = username
            };
            OperationResult obj = OperationManager.Singleton.executeOperation(ous);

            if ((obj == null) || (!obj.Status))
            {
                MessageBox.Show("Error while connectiong to the database.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                if (obj.DbItems.Count() == 1)
                {
                    ous.Criteria = new CriteriaUser {
                        Password = password
                    };
                    OperationResult obj1 = OperationManager.Singleton.executeOperation(ous);

                    if (obj1.DbItems.Count() == 1)
                    {
                        #region Setting Property's and Login Section
                        Settings.Default.DR_Username    = username;
                        Settings.Default.DR_Password    = password;
                        Settings.Default.DR_Remember_Me = remember;

                        LogInSection.Visibility         = Visibility.Collapsed;
                        LandingSection.Visibility       = Visibility.Visible;
                        DirectResponseBorder.Visibility = Visibility.Visible;

                        Color color      = Color.FromRgb(38, 50, 56);
                        Brush background = new SolidColorBrush(color);
                        windowBorderDrag.Background = background;
                        #endregion

                        DbItem[] items = obj.DbItems;
                        UserDb[] users = items.Cast <UserDb>().ToArray();

                        int returnValue = Server.Login(users[0].Username, users[0].Full_Name, users[0].User_Id);
                        if (returnValue == 1)
                        {
                            MessageBox.Show("You are already loged in!");
                            Settings.Default.DR_Username    = "";
                            Settings.Default.DR_Password    = "";
                            Settings.Default.DR_Remember_Me = false;

                            LogInSection.Visibility         = Visibility.Visible;
                            LandingSection.Visibility       = Visibility.Collapsed;
                            DirectResponseBorder.Visibility = Visibility.Collapsed;

                            Color color2      = Color.FromRgb(0, 0, 0);
                            Brush background2 = new SolidColorBrush(color2);
                            windowBorderDrag.Background = background2;

                            Server.Logout();
                        }
                        string path = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\Assets\\" + users[0].Username + users[0].User_Id + "_msg.dr";
                        if (File.Exists(path))
                        {
                            using (XmlReader reader = XmlReader.Create(path))
                            {
                                DataContractSerializer serializer = new DataContractSerializer(typeof(Model.User));
                                Model.User             user       = serializer.ReadObject(reader) as Model.User;
                                this.documentManagerVM.CurrentUserVM = new UserVM(user);
                            }
                        }
                        else
                        {
                            this.documentManagerVM.CurrentUserVM = new UserVM(new Model.User()
                            {
                                FullName = users[0].Full_Name,
                                UserName = users[0].Username,
                                Email    = users[0].Email,
                                Password = users[0].Password,
                                Image    = users[0].Image,
                                Id       = users[0].User_Id
                            });
                        }
                    }
                    else
                    {
                        Color color      = Color.FromRgb(219, 21, 21);
                        Brush background = new SolidColorBrush(color);
                        tbPassword.BorderBrush = background;
                        Color colorGray   = Color.FromRgb(55, 71, 79);
                        Brush borderbrush = new SolidColorBrush(colorGray);
                        tbUserName.BorderBrush        = borderbrush;
                        tbUserNameFailIcon.Visibility = Visibility.Collapsed;
                        tbPasswordFailIcon.Visibility = Visibility.Visible;
                    }
                }
                else
                {
                    Color color      = Color.FromRgb(219, 21, 21);
                    Brush background = new SolidColorBrush(color);
                    tbUserName.BorderBrush        = background;
                    tbPassword.BorderBrush        = background;
                    tbUserNameFailIcon.Visibility = Visibility.Visible;
                    tbPasswordFailIcon.Visibility = Visibility.Visible;
                }
            }
        }