Ejemplo n.º 1
0
        private void btnValidate_Click(object sender, EventArgs e)
        {
            var result = SerialKey.ValidateKey(tbValUsername.Text, tbValKey.Text, tbValSerialKey.Text);

            lblValResult.Text = $"Result = {result}";
        }
Ejemplo n.º 2
0
        private void btnApply_Click(object sender, EventArgs e)
        {
            _isSukses = false;
            if (string.IsNullOrEmpty(tbSerialNo.Text))
            {
                MessageBox.Show("Serial Key tidak boleh kosong.", "Peringatan");
                _isSukses = false;
                return;
            }

            StringBuilder sbMessage = new StringBuilder();

            sbMessage.AppendLine("Kode Registrasi Tidak Valid");
            sbMessage.AppendLine("Mohon hubungi Badan Pengelolaan Keuangan Pemerintah Daerah Kota Surabaya untuk kode aktivasi aplikasi Pajak Online");

            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(ClassHelper.urlAPI + "/setting/online_register_serialKey");

            httpWebRequest.Accept = "application/json";
            httpWebRequest.Method = "POST";
            serialRequest req = new serialRequest();

            req.serial   = tbSerialNo.Text;
            req.username = tbUsername.Text;
            req.HWId     = tbIDMachine.Text;

            var body = Newtonsoft.Json.JsonConvert.SerializeObject(req);

            try
            {
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    streamWriter.Write(body);
                    streamWriter.Flush();
                    streamWriter.Close();
                }

                string message      = string.Empty;
                var    httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var result = streamReader.ReadToEnd();
                    if (!string.IsNullOrEmpty(result))
                    {
                        Newtonsoft.Json.Linq.JObject jObj     = Newtonsoft.Json.Linq.JObject.Parse(result);
                        Newtonsoft.Json.Linq.JToken  jCode    = jObj["code"];
                        Newtonsoft.Json.Linq.JToken  jMessage = jObj["message"];

                        message = jMessage.ToString();
                    }
                }

                if (string.Compare(message, "Valid") == 0)
                {
                    _isSukses = true;
                }
                else
                {
                    //Validate user key
                    if (!SerialKey.ValidateKey(tbUsername.Text, tbIDMachine.Text, tbSerialNo.Text))
                    {
                        tbKeterangan.Text = sbMessage.ToString();

                        _isSukses = false;
                        return;
                    }
                    else
                    {
                        _isSukses = true;
                    }
                }
            }
            catch (Exception)
            {
                tbKeterangan.Text = sbMessage.ToString();
                _isSukses         = false;
                return;
            }

            if (_isSukses)
            {
                //delete existing serial key file (TRIAL MODE)
                FileInfo info = new FileInfo(ClassHelper.SerialFile);
                if (info.Exists)
                {
                    info.Delete();
                }

                //register serial key(REGISTERED MODE)
                ClassHelper.GenerateSerialFile("REGISTERED", tbSerialNo.Text);

                tbKeterangan.Text    = "Aplikasi berhasil terdaftar. Terima kasih";
                ClassHelper.SerialNo = tbSerialNo.Text;
                _isSukses            = true;
            }
        }