コード例 #1
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("");
        }