Ejemplo n.º 1
0
        private void BtnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtusername.Text == "")
                {
                    MessageBox.Show("Enter Username");
                }
                else if (txtpassword.Text == "")
                {
                    MessageBox.Show("Enter Password");
                }
                else
                {
                    string Username = txtusername.Text;
                    string Password = txtpassword.Text;

                    //Local Database check
                    var result = LoginBL.CheckUserExists(Username, EncryptandDecryptAES.Encrypt(Password));

                    if (string.IsNullOrEmpty(result) && NetConnectionChecker.Connection == false)
                    {
                        MessageBox.Show("Login Cannot be done need internet Connection");
                    }
                    else if (string.IsNullOrEmpty(result) && NetConnectionChecker.Connection == true)
                    {
                        //Method is use to Validate User Credentials from Web Server
                        ValidateUserandGetResponse(Username, Password);
                    }
                    else
                    {
                        ShareObject.CLientIDToken = result;
                        ShareObject.Username      = Username;
                        MessageBox.Show("Login Successfully");
                        this.Hide();
                        Login frm1 = new Login();
                        frm1.Close();
                        AddProduct addpro = new AddProduct();
                        addpro.Show();
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Callback Method Gets Called when WEB API is Giving Response
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Callback(object sender, UploadStringCompletedEventArgs e)
        {
            string ClientToken = ConfigurationManager.AppSettings["CLientIDToken"].ToString();
            string keyValue    = ConfigurationManager.AppSettings["keyValue"].ToString();
            string IVValue     = ConfigurationManager.AppSettings["IVValue"].ToString();

            if (e.Error != null)
            {
            }
            if (e.Result != null || !string.IsNullOrEmpty(e.Result))
            {
                string finalData = JToken.Parse(e.Result).ToString();

                string data = EncryptionDecryptorTripleDES.Decryption(finalData, keyValue, IVValue);

                UserLogin userlogin = JsonConvert.DeserializeObject <UserLogin>(data);

                if (userlogin != null)
                {
                    if (!string.IsNullOrEmpty(userlogin.RegistrationID))
                    {
                        var resultdata = LoginBL.CheckUserExists(userlogin.Username, userlogin.Password); //Local Database check

                        if (!string.IsNullOrEmpty(resultdata))
                        {
                            ShareObject.CLientIDToken = userlogin.RegistrationID;
                            MessageBox.Show("Login Successfully");
                            this.Hide();
                            Login frm1 = new Login();
                            frm1.Close();
                            AddProduct addpro = new AddProduct();
                            addpro.Show();
                        }
                        else
                        {
                            var result = LoginBL.InsertLoginData(userlogin);

                            if (result != 0)
                            {
                                ShareObject.CLientIDToken = userlogin.RegistrationID;
                                MessageBox.Show("Login Successfully");
                                this.Hide();
                                Login frm1 = new Login();
                                frm1.Close();
                                AddProduct addpro = new AddProduct();
                                addpro.Show();
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("InValid Credentials");
                    }
                }
                else
                {
                    MessageBox.Show("InValid Credentials");
                }
            }
            else
            {
                MessageBox.Show("InValid Credentials");
            }
        }