コード例 #1
0
 private void applyButton_Click(object sender, RoutedEventArgs e)
 {
     if (oldUsername.Text.Trim() == "" || oldPassword.Password.Trim() == "" || newUsername.Text.Trim() == "" || newPassword.Password.Trim() == "" || newPassword2.Password.Trim() == "")
     {
         MessageBox.Show("لطفا همه ی قسمت ها را پر بفرمایید", "خطا", MessageBoxButton.OK, MessageBoxImage.Error);
         return;
     }
     if (newPassword.Password != newPassword2.Password)
     {
         MessageBox.Show("رمز جدید در دو محل یکسان وارد نشده است لطفا در وارد کردن صحیح و یکسان آن در دو فیلد مربوطه دقت فرمایید", "خطا", MessageBoxButton.OK, MessageBoxImage.Error);
         newPassword.Clear();
         newPassword2.Clear();
         return;
     }
     try
     {
         SqlConnection con = new SqlConnection(DB.getConnectionString());
         con.Open();
         SqlCommand cmd = con.CreateCommand();
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.CommandText = "LoginIsValid";
         SqlParameter param1 = new SqlParameter("@u", SqlDbType.NVarChar, 50);
         param1.Value = MyCrypt.encryptWithDefaultValues(oldUsername.Text);
         cmd.Parameters.Add(param1);
         SqlParameter param2 = new SqlParameter("@p", SqlDbType.NVarChar, 50);
         param2.Value = MyCrypt.encryptWithDefaultValues(oldPassword.Password);
         cmd.Parameters.Add(param2);
         Int32 b = (Int32)cmd.ExecuteScalar();
         cmd.Dispose();
         if (b == 1)
         {
             SqlCommand setCmd = con.CreateCommand();
             setCmd.CommandText = "SetLoginInfo";
             setCmd.CommandType = CommandType.StoredProcedure;
             SqlParameter para1 = new SqlParameter("@u", SqlDbType.NVarChar, 50);
             para1.Value = MyCrypt.encryptWithDefaultValues(newUsername.Text);
             setCmd.Parameters.Add(para1);
             SqlParameter para2 = new SqlParameter("@p", SqlDbType.NVarChar, 50);
             para2.Value = MyCrypt.encryptWithDefaultValues(newPassword.Password);
             setCmd.Parameters.Add(para2);
             setCmd.ExecuteNonQuery();
             con.Close();
             setCmd.Dispose();
             MessageBox.Show("اطلاعات وارد شدن به نرم افزار با موفقیت اعمال گردید", "تغییر شناسه یا رمز ورود به برنامه", MessageBoxButton.OK, MessageBoxImage.Information);
             Close();
         }
         else
         {
             con.Close();
             MessageBox.Show("شناسه ی ورود فعلی یا رمز ورود فعلی اشتباه وارد گردیده است لطفا با دقت دوباره امتحان شودید", "خطا", MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
     catch (Exception)
     {
         MessageBox.Show("خطا در اتصال و یا اجرای درخواست از پایگاه داده ها", "خطا", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
コード例 #2
0
 private void loginButton_Click(object sender, RoutedEventArgs e)
 {
     msgShown = false;
     if (username.Text.Trim() == "" || password.Password.Trim() == "")
     {
         msgShown = true;
         MessageBox.Show("لطفا هر دو قسمت را پر بفرمایید", "خطا", MessageBoxButton.OK, MessageBoxImage.Error);
         return;
     }
     try
     {
         SqlConnection con = new SqlConnection(DB.getConnectionString());
         con.Open();
         SqlCommand cmd = con.CreateCommand();
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.CommandText = "LoginIsValid";
         SqlParameter param1 = new SqlParameter("@u", SqlDbType.NVarChar, 50);
         param1.Value = MyCrypt.encryptWithDefaultValues(username.Text);
         cmd.Parameters.Add(param1);
         SqlParameter param2 = new SqlParameter("@p", SqlDbType.NVarChar, 50);
         param2.Value = MyCrypt.encryptWithDefaultValues(password.Password);
         cmd.Parameters.Add(param2);
         Int32 b = (Int32)cmd.ExecuteScalar();
         if (b == 1)
         {
             //msgShown = true;
             //MessageBox.Show("اطلاعات صحیح می باشد پس به برنامه وارد می گردید", "ورود موفقیت آمیز", MessageBoxButton.OK, MessageBoxImage.Information);
             Window w = new Window1();
             this.Close();
             w.Show();
         }
         else
         {
             msgShown = true;
             MessageBox.Show("شناسه ی ورود یا رمز ورود اشتباه وارد گردیده است لطفا با دقت دوباره امتحان شودید", "خطا", MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
     catch (Exception)
     {
         msgShown = true;
         MessageBox.Show("خطا در اتصال و یا اجرای درخواست از پایگاه داده ها", "خطا", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
コード例 #3
0
 private void loginButton_Click(object sender, RoutedEventArgs e)
 {
     msgShown = false;
     if (username.Text.Trim() == "" || password.Password.Trim() == "")
     {
         msgShown = true;
         MessageBox.Show("لطفا هر دو قسمت را پر بفرمایید", "خطا", MessageBoxButton.OK, MessageBoxImage.Error);
         return;
     }
     try
     {
         SqlConnection con = new SqlConnection(DB.getConnectionString());
         con.Open();
         SqlCommand cmd = con.CreateCommand();
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.CommandText = "LoginIsValid";
         SqlParameter param1 = new SqlParameter("@u", SqlDbType.NVarChar, 50);
         param1.Value = MyCrypt.encryptWithDefaultValues(username.Text);
         cmd.Parameters.Add(param1);
         SqlParameter param2 = new SqlParameter("@p", SqlDbType.NVarChar, 50);
         param2.Value = MyCrypt.encryptWithDefaultValues(password.Password);
         cmd.Parameters.Add(param2);
         Int32 b = (Int32)cmd.ExecuteScalar();
         if (b == 1)
         {
             // Admin Login
             //msgShown = true;
             //MessageBox.Show("اطلاعات صحیح می باشد پس به برنامه وارد می گردید", "ورود موفقیت آمیز", MessageBoxButton.OK, MessageBoxImage.Information);
             Window1 w   = new Window1();
             Session ses = new Session("admin");
             w.session = ses;
             this.Close();
             w.Show();
         }
         else
         {
             SqlCommand command = con.CreateCommand();
             command.CommandType = CommandType.StoredProcedure;
             command.CommandText = "UserLoginIsValid";
             SqlParameter para1 = new SqlParameter("@u", SqlDbType.NVarChar, 50);
             para1.Value = username.Text;
             command.Parameters.Add(para1);
             SqlParameter para2 = new SqlParameter("@p", SqlDbType.NVarChar, 50);
             para2.Value = password.Password;
             command.Parameters.Add(para2);
             Int32 res = (Int32)command.ExecuteScalar();
             if (res == 1)
             {
                 // User Login
                 String    q   = "EXEC GetPermissionsOfUser N'" + username.Text + "',N'" + password.Password + "'";
                 DataTable dt  = DB.execSqlReturnDataTable(q, 0);
                 Object[]  ob  = dt.Rows[0].ItemArray;
                 Window1   w   = new Window1();
                 Session   ses = new Session("user", (Boolean)ob[0], (Boolean)ob[1], (Boolean)ob[2], (Boolean)ob[3]);
                 w.session = ses;
                 this.Close();
                 w.Show();
             }
             else
             {
                 msgShown = true;
                 MessageBox.Show("شناسه ی ورود یا رمز ورود اشتباه وارد گردیده است لطفا با دقت دوباره امتحان کنید", "خطا", MessageBoxButton.OK, MessageBoxImage.Error);
             }
             con.Close();
             command.Dispose();
             cmd.Dispose();
         }
     }
     catch (Exception)
     {
         msgShown = true;
         MessageBox.Show("خطا در اتصال و یا اجرای درخواست از پایگاه داده ها", "خطا", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
コード例 #4
0
        void openingDB_DoWork(object sender, DoWorkEventArgs e)
        {
            if (openingDB.CancellationPending)
            {
                e.Cancel = true;
                return;
            }
            try
            {
                Object obj = DB.execSqlReturnScalar("EXEC GetExpInfo");
                if (obj == null)
                {
                    MessageBox.Show("اطلاعات مربوط به تاریخ مصرف برنامه صحیح نمی باشد لطفا با پشتیبانی برنامه تماس حاصل بفرمایید", "خطای چک کردن مهلت استفاده", MessageBoxButton.OK, MessageBoxImage.Error);
                    Environment.Exit(1);
                }
                else
                {
                    try
                    {
                        String s = (String)obj;

                        byte[] b = new byte[s.Length];
                        for (int i = 0; i < s.Length; i++)
                        {
                            b[i] = (byte)s[i];
                        }
                        FileStream fs = new FileStream("config.conf", FileMode.Create, FileAccess.Write);
                        fs.Write(b, 0, b.Length);
                        fs.Flush();
                        fs.Close();
                        fs.Dispose();

                        String exp = MyCrypt.decryptWithDefaultValues(s);
                        if (exp == "0000")   // first time use
                        {
                            // enabled - begin - last - duration
                            String arg = "1-" + DateTime.Today.ToShortDateString() + "-" + DateTime.Today.ToShortDateString() + "-" + Codes.ExpireDurationInDays.ToString();
                            arg = MyCrypt.encryptWithDefaultValues(arg);
                            DB.execSql("EXEC SetExpInfo N'" + arg + "'", 0);
                            expireLblString = Codes.ExpireDurationInDays.ToString();

                            // generating serial number for this product now
                            String serial     = "";
                            int    serialLeng = 10;
                            Random rand       = new Random();
                            for (int i = 0; i < serialLeng; i++)
                            {
                                serial += rand.Next(0, 9);
                            }
                            DB.execSql("EXEC SetSerialNumber N'" + serial + "'", 0);
                        }
                        else if (exp == "111111")    // registered
                        {
                            registered = true;
                        }
                        else    // in trail period
                        {
                            String[] str = exp.Split('-');
                            String   c   = str[0];
                            if (c == "0")     // expired
                            {
                                expired = true;
                            }
                            else
                            {
                                DateTime begin    = DateTime.Parse(str[1]);
                                DateTime last     = DateTime.Parse(str[2]);
                                int      diffInDB = Int32.Parse(str[3]);
                                if (DateTime.Today < last)   // expire it now because user change the time more than 1 day
                                {
                                    String arg = "0-" + begin.ToShortDateString() + "-" + DateTime.Today.ToShortDateString() + "-0";
                                    arg = MyCrypt.encryptWithDefaultValues(arg);
                                    DB.execSql("EXEC SetExpInfo N'" + arg + "'", 0);
                                    expireLblString = "0";
                                    expired         = true;
                                }
                                TimeSpan duration = DateTime.Today.Subtract(begin);
                                int      diff     = Codes.ExpireDurationInDays - duration.Days;
                                if (diff <= 0 || diffInDB < diff)   // expire it now
                                {
                                    String arg = "0-" + begin.ToShortDateString() + "-" + DateTime.Today.ToShortDateString() + "-0";
                                    arg = MyCrypt.encryptWithDefaultValues(arg);
                                    DB.execSql("EXEC SetExpInfo N'" + arg + "'", 0);
                                    expireLblString = "0";
                                    expired         = true;
                                }
                                else
                                {
                                    String arg = "1-" + begin.ToShortDateString() + "-" + DateTime.Today.ToShortDateString() + "-" + diff.ToString();
                                    arg = MyCrypt.encryptWithDefaultValues(arg);
                                    DB.execSql("EXEC SetExpInfo N'" + arg + "'", 0);
                                    expireLblString = diff.ToString();
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("اطلاعات مربوط به تاریخ مصرف برنامه صحیح نمی باشد لطفا با پشتیبانی برنامه تماس حاصل بفرمایید", "خطای چک کردن مهلت استفاده", MessageBoxButton.OK, MessageBoxImage.Error);
                        MessageBox.Show("لطفا متن زیر را به پشتیبانی برنامه اعلام بفرمایید \n\n" + ex.Message, "متن تکنیکی خطا", MessageBoxButton.OK, MessageBoxImage.Error);
                        Environment.Exit(1);
                    }
                    try
                    {
                        Codes.setMainDirectory();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("مکان برنامه به درستی یافت نگردید", "خطای بدست آوردن محل اجرای برنامه", MessageBoxButton.OK, MessageBoxImage.Error);
                        MessageBox.Show("لطفا متن زیر را به پشتیبانی برنامه اعلام بفرمایید \n\n" + ex.Message, "متن تکنیکی خطا", MessageBoxButton.OK, MessageBoxImage.Error);
                        Environment.Exit(1);
                    }
                }

                DB.execSql("SELECT * FROM ApartemanMaskooniEstijari", 0);
                //DB.execSqlInArchive("SELECT * FROM ApartemanMaskooniEstijari");
            }
            catch (Exception ex)
            {
                MessageBox.Show("خطا در اتصال به پایگاه داده ها \n لطفا سرور و فایل های مربوط به پایگاه داده ها را چک بفرمایید", "خطا", MessageBoxButton.OK, MessageBoxImage.Error);
                MessageBox.Show("لطفا متن زیر را به پشتیبانی برنامه اعلام بفرمایید \n\n" + ex.Message, "متن تکنیکی خطا", MessageBoxButton.OK, MessageBoxImage.Error);
                Environment.Exit(1);
            }
            //openingDB.CancelAsync();
        }
コード例 #5
0
        void openingDB_DoWork(object sender, DoWorkEventArgs e)
        {
            if (openingDB.CancellationPending)
            {
                e.Cancel = true;
                return;
            }
            try
            {
                Object obj = DB.execSqlReturnScalar("EXEC GetExpInfo");
                if (obj == null)
                {
                    MessageBox.Show("اطلاعات مربوط به تاریخ مصرف برنامه صحیح نمی باشد لطفا با پشتیبانی برنامه تماس حاصل بفرمایید", "خطای چک کردن مهلت استفاده", MessageBoxButton.OK, MessageBoxImage.Error);
                    Environment.Exit(1);
                }
                else
                {
                    try
                    {
                        String s = (String)obj;

                        byte[] b = new byte[s.Length];
                        for (int i = 0; i < s.Length; i++)
                        {
                            b[i] = (byte)s[i];
                        }
                        FileStream fs = new FileStream("config.conf", FileMode.Create, FileAccess.Write);
                        fs.Write(b, 0, b.Length);
                        fs.Flush();
                        fs.Close();
                        fs.Dispose();

                        String exp = MyCrypt.decryptWithDefaultValues(s);
                        if (exp == "0000")   // first time use
                        {
                            // enabled - begin - last - duration
                            String arg = "1-" + DateTime.Today.ToShortDateString() + "-" + DateTime.Today.ToShortDateString() + "-" + Codes.ExpireDurationInDays.ToString();
                            arg = MyCrypt.encryptWithDefaultValues(arg);
                            DB.execSql("EXEC SetExpInfo N'" + arg + "'");
                            expireLblString = Codes.ExpireDurationInDays.ToString();
                        }
                        else if (exp == "111111")    // registered
                        {
                            expireLbl.Visibility = Visibility.Hidden;
                            expireStr.Content    = "نسخه ی کامل برنامه ی نگین در اختیار شما است .";
                        }
                        else    // in trail period
                        {
                            String[] str = exp.Split('-');
                            String   c   = str[0];
                            if (c == "0")     // expired
                            {
                                expired = true;
                            }
                            else
                            {
                                DateTime begin    = DateTime.Parse(str[1]);
                                DateTime last     = DateTime.Parse(str[2]);
                                int      diffInDB = Int32.Parse(str[3]);
                                if (DateTime.Today < last)   // expire it now because user change the time more than 1 day
                                {
                                    String arg = "0-" + begin.ToShortDateString() + "-" + DateTime.Today.ToShortDateString() + "-0";
                                    arg = MyCrypt.encryptWithDefaultValues(arg);
                                    DB.execSql("EXEC SetExpInfo N'" + arg + "'");
                                    expireLblString = "0";
                                    expired         = true;
                                }
                                TimeSpan duration = DateTime.Today.Subtract(begin);
                                int      diff     = Codes.ExpireDurationInDays - duration.Days;
                                if (diff <= 0 || diffInDB < diff)   // expire it now
                                {
                                    String arg = "0-" + begin.ToShortDateString() + "-" + DateTime.Today.ToShortDateString() + "-0";
                                    arg = MyCrypt.encryptWithDefaultValues(arg);
                                    DB.execSql("EXEC SetExpInfo N'" + arg + "'");
                                    expireLblString = "0";
                                    expired         = true;
                                }
                                else
                                {
                                    String arg = "1-" + begin.ToShortDateString() + "-" + DateTime.Today.ToShortDateString() + "-" + diff.ToString();
                                    arg = MyCrypt.encryptWithDefaultValues(arg);
                                    DB.execSql("EXEC SetExpInfo N'" + arg + "'");
                                    expireLblString = diff.ToString();
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("اطلاعات مربوط به تاریخ مصرف برنامه صحیح نمی باشد لطفا با پشتیبانی برنامه تماس حاصل بفرمایید", "خطای چک کردن مهلت استفاده", MessageBoxButton.OK, MessageBoxImage.Error);
                        Environment.Exit(1);
                    }
                }

                DB.execSql("SELECT * FROM ApartemanMaskooniEstijari");
                DB.execSqlInArchive("SELECT * FROM ApartemanMaskooniEstijari");
            }
            catch (Exception)
            {
                MessageBox.Show("خطا در اتصال به پایگاه داده ها \n لطفا سرور و فایل های مربوط به پایگاه داده ها را چک بفرمایید", "خطا", MessageBoxButton.OK, MessageBoxImage.Error);
                Environment.Exit(1);
            }
            openingDB.CancelAsync();
        }