コード例 #1
0
        private String dayDifPutPresent()
        {
            // get present date from system
            DateTime    dt        = DateTime.Now;
            IsConstiant date_conv = new IsConstiant();

            string today = ConvertDateCalendar(dt, "en-US");
            //DateTime presentDate = Convert.ToDateTime(today);
            DateTime presentDate = DateTime.ParseExact(today, "M/d/yyyy", System.Globalization.CultureInfo.InvariantCulture);
            // get instalation date
            RegistryKey regkey = Registry.CurrentUser;

            regkey = regkey.CreateSubKey(globalPath); //path
            string   Br = (string)regkey.GetValue("Install");
            DateTime installationDate = DateTime.ParseExact(Br, "M/d/yyyy", System.Globalization.CultureInfo.InvariantCulture);

            TimeSpan diff      = presentDate.Subtract(installationDate); //first.Subtract(second);
            int      totaldays = (int)diff.TotalDays;

            // special check if user chenge date in system
            string   usd     = (string)regkey.GetValue("Use");
            DateTime lastUse = DateTime.ParseExact(usd, "M/d/yyyy", System.Globalization.CultureInfo.InvariantCulture);
            //Convert.ToDateTime(usd);
            TimeSpan diff1      = presentDate.Subtract(lastUse); //first.Subtract(second);
            int      useBetween = (int)diff1.TotalDays;


            if (useBetween >= 0)
            {
                if (totaldays < 0)
                {
                    return("Error"); // if user change date in system like date set before installation
                }
                else if (totaldays >= 0 && totaldays <= 100)
                {
                    regkey.SetValue("Use", today);
                    upd_use(today);
                    return(Convert.ToString(100 - totaldays));
                }//how many days remaining
                else
                {
                    regkey.SetValue("Use", today);
                    upd_use(today);
                    return("Expired"); //Expired
                }
            }
            else
            {
                return("Error"); // if user change date in system
            }
        }
コード例 #2
0
        private void firstTime()
        {
            RegistryKey regkey = Registry.CurrentUser;

            regkey = regkey.CreateSubKey(globalPath); //path

            IsConstiant date_conv = new IsConstiant();
            string      toDate    = date_conv.ConvertDateCalendar(DateTime.Now, "en-US");

            // DateTime dt = DateTime.Now;
            string onlyDate = date_conv.ConvertDateCalendar(DateTime.Now, "en-US"); // get only date not time

            regkey.SetValue("Install", onlyDate);                                   //Value Name,Value Data
            regkey.SetValue("Use", onlyDate);                                       //Value Name,Value Data
        }
コード例 #3
0
        public string instailserual()
        {
            // string con_ss = File.ReadAllText(Application.StartupPath + "\\conn.txt");
            string     sql;
            SqlCommand cm;

            sql = "select * from Serial_Table";
            SqlDataReader dr;

            try
            {
                Declaration dec;
                dec = new Declaration();

                //  = new Declaration();
                if (dec.Activity(getMACAdress()) == "No")
                {
                    DialogResult ds = MessageBox.Show("معذرة هذا الجهاز غير مصرح له بتشغيل النظام يرجى التواصل مع مدير النظام" + "/n" + EncryptionClass.Encrypt("nanoahmedmohammmadnaelzadf18", getMACAdress() + "t3xzq162") + "\n" + "هل تريد انشاء ملف طلب تصريح?", "الامان والحماية", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);

                    if (ds == DialogResult.Yes)
                    {
                        string filename = "Save Here";

                        SaveFileDialog sf = new SaveFileDialog();

                        sf.FileName = filename;

                        if (sf.ShowDialog() == DialogResult.OK)
                        {
                            string savePath = Path.GetDirectoryName(sf.FileName);



                            FileStream f = new FileStream(savePath + "\\Declaration.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
                            // StreamWriter stw = new StreamWriter(f);
                            byte[] da = new byte[255];
                            da = ASCIIEncoding.Unicode.GetBytes(EncryptionClass.Encrypt("nanoahmedmohammmadnaelzadf18", getMACAdress() + "t3xzq162") + ":" + getMACAdress());
                            f.Write(da, 0, da.Length);
                            f.Close();
                        }
                    }
                    return("");
                }
                day = int.Parse(dec.day);

                // con = new SqlConnection(" Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename =" + con_db + "; Integrated Security = True; Connect Timeout = 30;");
                DBConnection db = new DBConnection();
                conn = db.masterConn();
                cm   = new SqlCommand(sql, conn);
                /////////////////////////////////////////////
                // Connect = new SqlConnection(connStr);
                try
                {
                    if (conn.State == ConnectionState.Closed)
                    {
                        conn.Open();
                    }
                    dr = cm.ExecuteReader();
                    if (dr.Read())
                    {
                        key_serial = getMACAdress();
                        // instail = EncryptionClass.Decrypt (dr["Install"].ToString(), "t3xzq162");
                        instail = dec.dateinstail;

                        use = EncryptionClass.Decrypt(dr["use_date"].ToString(), "t3xzq162");
                        dr.Close();
                        conn.Close();
                        chek = true;
                        return(key_serial);
                    }
                    else
                    {//"8/3/2019"
                        key_serial = getMACAdress();
                        dr.Close();
                        IsConstiant date_conv = new IsConstiant();
                        // string onlyDate = date_conv.ConvertDateCalendar(DateTime.Now, "en-US");

                        string onlyDate = dec.dateinstail;//date_conv.ConvertDateCalendar(DateTime.Now, "en-US");
                        //MessageBox.Show(onlyDate);
                        cm = new SqlCommand("insert into Serial_Table values('" + key_serial + "','','" + EncryptionClass.Encrypt(onlyDate, "t3xzq162") + "','" + EncryptionClass.Encrypt(onlyDate, "t3xzq162") + "')", conn);
                        cm.ExecuteNonQuery();
                        conn.Close();
                        chek    = false;
                        instail = onlyDate;
                        use     = onlyDate;
                        //MessageBox.Show(onlyDate);
                        return(key_serial);
                    }
                }
                catch
                {
                    // FormConnet ff = new FormConnet("data");
                    //ff.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("معذرة هذا الجهاز غير مصرح له بتشغيل النظام يرجى التواصل مع مدير النظام" + "/n" + EncryptionClass.Encrypt("nanoahmedmohammmadnaelzadf18", getMACAdress() + "t3xzq162") + "/n" + ex.Message, "Product key", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //if (ds == DialogResult.Yes)
                //{
            }
            ///////////////////////////////////////

            conn.Close();

            return("");
        }