Example #1
0
        private void SelectContentForm_Load(object sender, EventArgs e)
        {
            this.Text = courseName;
            CourseActive course = new CourseActive();

            path = Manager.path + @"Files\" + courseKey;

            try
            {
                string prdKeymd5 = null;
                string value     = null;

                using (MD5 md5Hash = MD5.Create())
                {
                    prdKeymd5 = VDCSDK.App.GetMd5Hash(md5Hash, "PEVCSALL");
                }

                value = VDCSDK.App.GetValueOfKey(prdKeymd5);
                if (value != null)
                {
                    try
                    {
                        string encryted1 = VDCSDK.App.DecryptKey(value, true);
                        string encryted2 = VDCSDK.App.DecryptKey(encryted1.Substring(0, encryted1.Length - 14), true);

                        Common.CheckAppKey("PEVCSALL", encryted2);
                        string timeActive = encryted1.Substring(encryted1.Length - 14);
                        var    activeDate = DateTime.ParseExact(timeActive, "yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture);
                        int    result     = DateTime.Compare(activeDate, DateTime.Now);
                        if (result < 0)
                        {
                            course.typeKey = "Expired";
                        }
                        else
                        {
                            course.typeKey = "Actived";
                        }

                        ActiveContent("PEVCSALL", course, 0);
                        return;
                    }
                    catch
                    {
                        // do not nothing
                    }
                }

                using (MD5 md5Hash = MD5.Create())
                {
                    prdKeymd5 = VDCSDK.App.GetMd5Hash(md5Hash, "PEVCS" + courseKey);
                }

                value = VDCSDK.App.GetValueOfKey(prdKeymd5);
                if (value != null)
                {
                    try
                    {
                        string encryted1 = VDCSDK.App.DecryptKey(value, true);
                        string encryted2 = VDCSDK.App.DecryptKey(encryted1.Substring(0, encryted1.Length - 14), true);

                        int time = Common.CheckAppKey("PEVCS" + courseKey, encryted2);

                        if (time != 0)
                        {
                            string timeActive = encryted1.Substring(encryted1.Length - 14);
                            var    activeDate = DateTime.ParseExact(timeActive, "yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture);
                            int    result     = DateTime.Compare(activeDate, DateTime.Now);
                            if (result > 0)
                            {
                                trialFlg = true;
                            }
                        }
                        else
                        {
                            course.typeKey = "Actived";
                            ActiveContent("PEVCS" + courseKey, course, 0);
                            return;
                        }
                    }
                    catch
                    {
                        // do not nothing
                    }
                }

                int count = 0;
                int index = 0;
                foreach (string folderName in Directory.GetDirectories(path))
                {
                    string contentKey = folderName.Remove(0, folderName.LastIndexOf('\\') + 1);
                    if (contentKey.Substring(0, 3) == courseKey)
                    {
                        course         = new CourseActive();
                        course.typeKey = "UnActive";

                        using (MD5 md5Hash = MD5.Create())
                        {
                            prdKeymd5 = VDCSDK.App.GetMd5Hash(md5Hash, contentKey);
                        }

                        value = VDCSDK.App.GetValueOfKey(prdKeymd5);
                        if (value != null)
                        {
                            string encryted1 = VDCSDK.App.DecryptKey(value, true);
                            string encryted2 = VDCSDK.App.DecryptKey(encryted1.Substring(0, encryted1.Length - 14), true);

                            int time = Common.CheckAppKey(contentKey, encryted2);

                            if (time != 0)
                            {
                                string timeActive = encryted1.Substring(encryted1.Length - 14);
                                var    activeDate = DateTime.ParseExact(timeActive, "yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture);
                                int    result     = DateTime.Compare(activeDate, DateTime.Now);
                                if (result < 0)
                                {
                                    course.typeKey = "Expired";
                                }
                                else
                                {
                                    course.typeKey = "Upgrade";
                                }
                            }
                            else
                            {
                                course.typeKey = "Actived";
                            }
                        }

                        if (typeKey == "Upgrade" && count < 2 && trialFlg)
                        {
                            course.typeKey = "Upgrade";
                        }

                        ActiveContent(contentKey, course, index);
                        index++;
                        count++;
                    }
                }
            }
            catch (Exception ex)
            {
                this.log.Error(ex.Message);
            }
            finally
            {
                course = null;
            }
        }
Example #2
0
        private void ActiveCourse(string courseKeySub, CourseActive course)
        {
            if (courseKeySub == "PEVCSALL")
            {
                btnActiveAll.Visible = false;
            }

            foreach (Control control in this.Controls)
            {
                if (courseKeySub == "PEVCSALL")
                {
                    if (control.GetType() == typeof(Button))
                    {
                        Button btn = (Button)control;
                        btn.Enabled = course.btnVisiable;

                        string courseKey = (string)btn.Tag;
                        //if (String.IsNullOrEmpty(courseKey)) continue;

                        if (File.Exists(String.Format(@"{0}\Images\Courses\{1}\{1}.JPG", Directory.GetCurrentDirectory(), courseKey)))
                        {
                            btn.Image = Image.FromFile(String.Format(@"{0}\Images\Courses\{1}\{1}.JPG", Directory.GetCurrentDirectory(), courseKey));
                        }
                        else
                        {
                            btn.Image = Image.FromFile(Directory.GetCurrentDirectory() + @"\Images\Courses\noImage.JPG");
                        }
                    }
                    if (control.GetType() == typeof(LinkLabel))
                    {
                        control.Visible = course.linkVisiable;
                    }
                }
                else
                {
                    if (control.GetType() == typeof(Button))
                    {
                        Button btn       = (Button)control;
                        string courseKey = (string)btn.Tag;

                        if (String.Equals(courseKey, courseKeySub))
                        {
                            btn.Enabled = course.btnVisiable;

                            if (String.IsNullOrEmpty(courseKey))
                            {
                                continue;
                            }

                            if (File.Exists(String.Format(@"{0}\Images\Courses\{1}\{1}.JPG", Directory.GetCurrentDirectory(), courseKey)))
                            {
                                btn.Image = Image.FromFile(String.Format(@"{0}\Images\Courses\{1}\{1}.JPG", Directory.GetCurrentDirectory(), courseKey));
                            }
                            else
                            {
                                btn.Image = Image.FromFile(Directory.GetCurrentDirectory() + @"\Images\Courses\noImage.JPG");
                            }

                            if (course.typeKey == "Upgrade")
                            {
                                btn.AccessibleName = "Upgrade";
                            }
                        }
                    }
                    if (control.GetType() == typeof(LinkLabel))
                    {
                        if (String.Equals(control.Tag, courseKeySub) && control.Name.Contains("Active"))
                        {
                            control.Visible = course.linkVisiable;
                            if (control.Visible)
                            {
                                control.Text = course.linkText;
                                if (course.typeKey == "Upgrade")
                                {
                                    control.AccessibleName = "Upgrade";
                                    control.Text           = course.linkText;
                                }
                            }
                        }

                        if (String.Equals(control.Tag, courseKeySub) && control.Name.Contains("View"))
                        {
                            control.Visible = course.linkVisiable;
                            if (course.typeKey == "Upgrade")
                            {
                                control.AccessibleName = "Upgrade";
                            }
                        }
                    }
                }

                if (control.GetType() == typeof(Button))
                {
                    Button btn = (Button)control;
                    if (btn.Name != "btnActiveAll" && btn.Image == null)
                    {
                        btn.Image = Image.FromFile(Directory.GetCurrentDirectory() + @"\Images\Courses\noImage.JPG");
                    }
                }
            }
        }
Example #3
0
        private void ActiveContent(string prdKeySub, CourseActive course, int index)
        {
            if (prdKeySub == "PEVCSALL" || (prdKeySub == "PEVCS" + courseKey && course.typeKey != "Upgrade"))
            {
                index = 0;
                foreach (string folderName in Directory.GetDirectories(path))
                {
                    string contentKey = folderName.Remove(0, folderName.LastIndexOf('\\') + 1);
                    if (contentKey.Substring(0, 3) == courseKey)
                    {
                        foreach (Control control in this.Controls)
                        {
                            if (control.GetType() == typeof(Button))
                            {
                                Button btn = (Button)control;
                                if (btn.TabIndex == index)
                                {
                                    btn.Visible = true;

                                    if (File.Exists(String.Format(@"{0}\Images\Courses\{1}\{2}.JPG", Directory.GetCurrentDirectory(), courseKey, contentKey)))
                                    {
                                        btn.Image = Image.FromFile(String.Format(@"{0}\Images\Courses\{1}\{2}.JPG", Directory.GetCurrentDirectory(), courseKey, contentKey));
                                    }
                                    else
                                    {
                                        btn.Image = Image.FromFile(Directory.GetCurrentDirectory() + @"\Images\Courses\noImage.JPG");
                                    }

                                    btn.Tag            = contentKey;
                                    btn.AccessibleName = course.typeKey;
                                }
                            }
                        }

                        index++;
                    }
                }
            }
            else
            {
                foreach (Control control in this.Controls)
                {
                    if (control.GetType() == typeof(Button))
                    {
                        Button btn = (Button)control;
                        if (btn.TabIndex == index)
                        {
                            btn.Visible = true;

                            if (File.Exists(String.Format(@"{0}\Images\Courses\{1}\{2}.JPG", Directory.GetCurrentDirectory(), courseKey, prdKeySub)))
                            {
                                btn.Image = Image.FromFile(String.Format(@"{0}\Images\Courses\{1}\{2}.JPG", Directory.GetCurrentDirectory(), courseKey, prdKeySub));
                            }
                            else
                            {
                                btn.Image = Image.FromFile(Directory.GetCurrentDirectory() + @"\Images\Courses\noImage.JPG");
                            }

                            btn.Tag            = prdKeySub;
                            btn.AccessibleName = course.typeKey;
                        }
                    }
                }
            }
        }
Example #4
0
        private void btnActive_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtKey.Text == "")
                {
                    MessageBox.Show("Vui lòng điền mã key trước khi kích hoạt.", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                string keyDecrypt = VDCSDK.App.DecryptKey(txtKey.Text, true);

                string sub = null;
                if (Key.Length == 3)
                {
                    sub = "PEVCS" + Key;
                }
                else
                {
                    sub = Key;
                }

                int time = Common.CheckAppKey(sub, keyDecrypt);

                string prdKeymd5 = null;

                using (MD5 md5Hash = MD5.Create())
                {
                    prdKeymd5 = VDCSDK.App.GetMd5Hash(md5Hash, sub);
                }

                if (Type == "Upgrade" || Type == "Expired")
                {
                    string value = VDCSDK.App.GetValueOfKey(prdKeymd5);
                    if (value != null)
                    {
                        string encryted1  = VDCSDK.App.DecryptKey(value, true);
                        string activedKey = encryted1.Substring(0, encryted1.Length - 14);
                        if (String.Equals(activedKey, txtKey.Text))
                        {
                            throw new Exception();
                        }
                    }
                }

                DateTime endDate = DateTime.Now;

                if (time != 0)
                {
                    endDate = DateTime.Now.AddDays(time);
                }
                else
                {
                    endDate = DateTime.Now.AddYears(5);
                }

                string end       = endDate.ToString("yyyyMMddHHmmss");
                string keyEncryt = VDCSDK.App.EncryptKey(txtKey.Text + end, true);

                VDCSDK.App.RegisterKey(prdKeymd5, keyEncryt);
                course = new CourseActive();

                if (time != 0)
                {
                    course.typeKey      = "Upgrade";
                    course.linkText     = "Upgrade";
                    course.linkVisiable = true;
                }
                else
                {
                    course.typeKey      = "Actived";
                    course.linkVisiable = false;
                }

                if (frmName == "SelectCourseForm")
                {
                    course.btnVisiable = true;
                    ActiveCourseEvent(this, EventArgs.Empty);
                }
                else
                {
                    ActiveContentEvent(this, EventArgs.Empty);
                }

                this.Dispose();
            }
            catch (Exception ex)
            {
                this.log.Error(ex.Message);
                DialogResult result = MessageBox.Show("Mã kích hoạt không đúng.\r\nVui lòng kiểm tra lại.", "Lỗi", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning);
                if (result == DialogResult.Cancel)
                {
                    this.Dispose();
                }
            }
        }