Example #1
0
        private void LLblLogin_MouseClick(object sender, MouseEventArgs e)
        {
            try
            {
                if (LTextBoxEmail.Text.Trim() != "" && LTextBoxPassword.Text.Trim() != "")
                {
                    if (objUserService.GetAunthenticatedUsers(LTextBoxEmail.Text, LTextBoxPassword.Text).Count > 0)
                    {
                        List <Login_Tbl> loginDetail = new List <Login_Tbl>();
                        loginDetail = record();
                        if (loginDetail.Count > 0)
                        {
                            if (loginDetail[0].Last_Login_Date < DateTime.Now && DateTime.Now < loginDetail[0].Expiration_Date && loginDetail[0].IsAuthenticated == 1)
                            {
                                using (RMSDBEntities db = new RMSDBEntities())
                                {
                                    Login_Tbl RowinDb = db.Login_Tbl.SingleOrDefault();
                                    RowinDb.Last_Login_Date = DateTime.Now;
                                    db.SaveChanges();
                                }

                                int asdf = Convert.ToInt32((loginDetail[0].Expiration_Date - DateTime.Now).TotalDays);
                                if (asdf < 11)
                                {
                                    MessageBox.Show("You Subcription will expire within " + asdf + " Days.Please Contact Softangle for uninterrupted use of software");
                                }


                                List <UserTable> singleuserInList = new List <UserTable>();
                                singleuserInList = objUserService.GetSpecificUsers(LTextBoxEmail.Text);
                                if (singleuserInList[0].IsAdmin == 1)
                                {
                                    LTextBoxEmail.Text    = "";
                                    LTextBoxPassword.Text = "";
                                    Admin objadmin = new Admin(this);
                                    LTextBoxEmail.Focus();
                                    objadmin.Show();
                                }
                                else
                                {
                                    LTextBoxEmail.Text    = "";
                                    LTextBoxPassword.Text = "";
                                    CashierId             = singleuserInList[0].UserId;
                                    Cashier objCashier = new Cashier(this);
                                    LTextBoxEmail.Focus();
                                    objCashier.Show();
                                }
                            }
                            else
                            {
                                using (RMSDBEntities db = new RMSDBEntities())
                                {
                                    Login_Tbl RowinDb = db.Login_Tbl.SingleOrDefault();
                                    RowinDb.IsAuthenticated = 0;
                                    db.SaveChanges();
                                }
                                MessageBox.Show("Subcription Expired.");
                                SubcriptionForm obk = new SubcriptionForm();
                                obk.Show();
                            }
                        }
                        else
                        {
                            MessageBox.Show("Subcription Expired.");
                            SubcriptionForm obk = new SubcriptionForm();
                            obk.Show();
                        }
                    }
                    else if (LTextBoxEmail.Text == Variable.Class1.u && LTextBoxPassword.Text == Variable.Class1.p)
                    {
                        try
                        {
                            LTextBoxEmail.Clear();
                            LTextBoxPassword.Clear();
                            DevelopersControl obj = new DevelopersControl(this);
                            obj.Show();
                        }
                        catch (Exception exp)
                        {
                            MessageBox.Show(exp.Message, "Error!");
                        }
                    }
                    else
                    {
                        MessageBox.Show("UserName or Password Incorrect!");
                        LTextBoxEmail.Focus();
                        LTextBoxEmail.Text    = "";
                        LTextBoxPassword.Text = "";
                    }
                }
                else
                {
                    MessageBox.Show("Please Fill both Feilds to Login");
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message, "Exception Error In Loging");
            }
        }
        private void buttonActivate_MouseClick(object sender, MouseEventArgs e)
        {
            try
            {
                int match = 0;
                if (textBox1.Text != "")
                {
                    List <Subcription_Tbl> sk = new List <Subcription_Tbl>();
                    sk = Key();
                    for (int i = 0; i < sk.Count; i++)
                    {
                        Encryption.Class1 obj = new Encryption.Class1();


                        if (textBox1.Text.Equals(Encryption.Class1.Decrypt(sk[i].SubcriptionKey, "Softangle@2999")))
                        {
                            if (Encryption.Class1.Decrypt(sk[i].UserTyoe, "Softangle@2999").Equals("keynotused"))
                            {
                                using (RMSDBEntities db = new RMSDBEntities())
                                {
                                    Login_Tbl obj1 = new Login_Tbl();
                                    obj1.First_Login_Date = DateTime.Now;
                                    obj1.Expiration_Date  = DateTime.Now.AddMonths(Convert.ToInt32(Encryption.Class1.Decrypt(sk[i].ForeignId, "Softangle@2999")));
                                    obj1.Last_Login_Date  = DateTime.Now;
                                    obj1.IsAuthenticated  = 1;

                                    List <Login_Tbl> lt = new List <Login_Tbl>();
                                    lt = record();
                                    if (lt.Count == 0)
                                    {
                                        db.Login_Tbl.Add(obj1);
                                        db.SaveChanges();
                                    }
                                    else
                                    {
                                        Login_Tbl RowinDb1 = db.Login_Tbl.SingleOrDefault();
                                        RowinDb1.First_Login_Date = obj1.First_Login_Date;
                                        RowinDb1.Expiration_Date  = obj1.Expiration_Date;
                                        RowinDb1.Last_Login_Date  = obj1.Last_Login_Date;
                                        RowinDb1.IsAuthenticated  = 1;
                                        db.SaveChanges();
                                    }

                                    // updating key used to change value
                                    Subcription_Tbl ok = new Subcription_Tbl();
                                    ok.SubcriptionKey = Encryption.Class1.Encrypt(textBox1.Text, "Softangle@2999");


                                    Subcription_Tbl RowinDb = db.Subcription_Tbl.Where(d => d.SubcriptionKey == ok.SubcriptionKey).SingleOrDefault();
                                    RowinDb.UserTyoe = Encryption.Class1.Encrypt("keyalreadyused", "Softangle@2999");

                                    db.SaveChanges();
                                    MessageBox.Show("Software Registered Successfully");
                                    match = 1;
                                    textBox1.Clear();
                                }
                            }
                            else
                            {
                                MessageBox.Show("Subcription Key Already Used.");
                                textBox1.Clear();
                            }
                        }
                        else
                        {
                            if (i == sk.Count - 1 && match == 0)
                            {
                                MessageBox.Show("Invalid Subcription Key.");
                                textBox1.Clear();
                            }
                        }
                    } // foreloop end
                }
                else
                {
                    MessageBox.Show("Enter Subcription Key.");
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message, "Error Message");
            }
        }