private void frmRegister_Load(object sender, EventArgs e) { string cpuInfo = string.Empty; cpuInfo = SerialKey.RetrieveIDMachine(); tbIDMachine.Text = cpuInfo; tbUsername.Text = ClassHelper.userName; ClassHelper.idMachine = cpuInfo; }
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); }