예제 #1
0
        private void bgwLoad_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            //Cek koneksi
            HttpClient client = new HttpClient();

            _errorMessage = string.Empty;

            client.BaseAddress = new Uri(_strUri + "/testConnection");
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            HttpResponseMessage response = new HttpResponseMessage();

            try
            {
                response = client.GetAsync(_strUri + "/testConnection").Result;
                if (!response.IsSuccessStatusCode)
                {
                    _errorMessage = "Koneksi Gagal : " + response.StatusCode;
                    return;
                }
            }
            catch (Exception)
            {
                _errorMessage = "Koneksi Gagal : 99";
                return;
            }

            //POST User From API and Get Column Data
            string cpuInfo = string.Empty;

            cpuInfo = SerialKey.RetrieveIDMachine();

            USERAPP usr = new USERAPP();

            usr.userName  = _username;
            usr.guid      = _guid;
            usr.idMachine = cpuInfo;

            var            jsonBody       = JsonConvert.SerializeObject(usr);
            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(_strUri + "/dev/postSettingClientWithParam");

            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "POST";
            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                streamWriter.Write(jsonBody);
                streamWriter.Flush();
                streamWriter.Close();
            }

            var    httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            string jsonParse    = string.Empty;

            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
                jsonParse = result;
            }
            List <UserSettingColumn> usrSett = new List <UserSettingColumn>();

            if (httpResponse.StatusCode == HttpStatusCode.OK)
            {
                JObject jObj     = JObject.Parse(jsonParse);
                JToken  jUser    = jObj["body"];
                JToken  jCode    = jObj["code"];
                JToken  jMessage = jObj["message"];

                if (string.Compare(jCode.ToString(), "200") == 0)
                {
                    usrSett = JsonConvert.DeserializeObject <List <UserSettingColumn> >(jUser.ToString());
                }
                else
                {
                    _errorMessage = jMessage.ToString();
                }
            }

            //Create XML upload excel
            List <Setting> lstSetting = new List <Setting>();
            List <NOP>     lstNop     = new List <NOP>();
            List <USERAPP> lstUser    = new List <USERAPP>();
            string         urlApi     = _strUri;
            string         errMessage = string.Empty;

            lstUser.Add(usr);
            NOP           itemNop = new NOP();
            List <string> arrNop  = new List <string>();

            arrNop = usrSett.Select(x => x.Nop).Distinct().ToList();
            foreach (var item in arrNop)
            {
                itemNop.nop = item;
                switch (item.Substring(10, 3))
                {
                case "901":
                    itemNop.jenisPajak = "HOTEL";
                    break;

                case "902":
                    itemNop.jenisPajak = "RESTORAN";
                    break;

                case "903":
                    itemNop.jenisPajak = "HIBURAN";
                    break;

                case "907":
                    itemNop.jenisPajak = "PARKIR";
                    break;

                default:
                    break;
                }

                lstNop.Add(itemNop);
            }

            foreach (var item in usrSett)
            {
                Setting sett = new Setting();
                sett.nop         = item.Nop;
                sett.column_name = item.Column_Name;
                sett.column_text = item.Column_Text;
                lstSetting.Add(sett);
            }

            ClassHelper.WriteXmlFile(lstSetting, lstNop, urlApi, lstUser, out errMessage);
        }
예제 #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;
            }
        }
예제 #3
0
        private void bgwTesKoneksi_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            HttpClient client = new HttpClient();

            _pesan = string.Empty;
            try
            {
                client.BaseAddress = new Uri(tbAPI.Text + "/testConnection");
            }
            catch (Exception ex)
            {
                if (ex.Message.ToUpper().Contains("THE HOSTNAME COULD NOT BE PARSED"))
                {
                    _pesan = "Mohon periksa kembali URL tersebut tidak ditemukan.";
                }
                else
                {
                    _pesan = "Mohon periksa kembali URL : " + ex.Message;
                }

                return;
            }

            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            try
            {
                var    request   = (HttpWebRequest)WebRequest.Create(_urlApi + "/testConnection");
                var    response  = (HttpWebResponse)request.GetResponse();
                string valStatus = string.Empty;

                using (var streamReader = new StreamReader(response.GetResponseStream()))
                {
                    var     result = streamReader.ReadToEnd();
                    JObject jObj   = Newtonsoft.Json.Linq.JObject.Parse(result);
                    JToken  jVal   = jObj["value"];
                    JToken  jBody  = jObj["body"];

                    if (jVal.ToString().Contains("OK"))
                    {
                        _lstPort = JsonConvert.DeserializeObject <List <ExceptionPort> >(jBody.ToString());
                        ClassHelper.ListNotAllowedPort(ref _lstPort);

                        _pesan        = "Koneksi Berhasil.";
                        _isApiConnect = true;
                    }
                    else
                    {
                        _pesan        = jVal.ToString();
                        _isApiConnect = false;
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.ToString().ToUpper().Contains("UNABLE TO CONNECT TO THE REMOTE SERVER"))
                {
                    _pesan = "Koneksi Gagal : API Tidak terhubung ke server";
                }
                _isApiConnect = false;
            }
        }
예제 #4
0
        private void btnReAktivasi_Click(object sender, EventArgs e)
        {
            var           httpWebRequest = (HttpWebRequest)WebRequest.Create(ClassHelper.urlAPI + "/setting/SerialKeyExist");
            StringBuilder sb             = new StringBuilder();

            sb.Append("{\"serialKey\":\"" + tbKodeLama.Text + "\",\"username\":\"" + ClassHelper.userName + "\",\"cpuId\":\"" + ClassHelper.idMachine + "\"}");
            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "POST";
            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                streamWriter.Write(sb.ToString());
                streamWriter.Flush();
                streamWriter.Close();
            }

            try
            {
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                _isSukses                 = true;
                ClassHelper.SerialNo      = tbKodeLama.Text;
                tbKeteranganAktivasi.Text = "Aplikasi berhasil terdaftar. Terima kasih";

                //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);
            }
            catch (Exception)
            {
                StringBuilder sbMessage = new StringBuilder();
                sbMessage.AppendLine("Kode Registrasi Tidak Valid");
                sbMessage.AppendLine("Mohon hubungi Badan Pengelolaan Keuangan dan Pajak Daerah Kota Surabaya untuk kode aktivasi aplikasi Pajak Online");

                _isSukses = false;
                tbKeteranganAktivasi.Text = sbMessage.ToString();
            }
            //var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            //if (httpResponse.StatusCode == HttpStatusCode.OK)
            //{
            //    _isSukses = true;
            //    ClassHelper.SerialNo = tbKodeLama.Text;
            //    tbKeteranganAktivasi.Text = "Aplikasi berhasil terdaftar. Terima kasih";

            //    //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);
            //}
            //else
            //{
            //    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");

            //    _isSukses = false;
            //    tbKeteranganAktivasi.Text = sb.ToString();
            //}
        }