private void SendDataToServer(int totalFare, string base64Image, string paymentMethod, string bankCode = "") { JObject param = new JObject(); param["uid"] = textBox1.Text.ToString(); param["vehicle"] = comboBox1.Text.ToString(); param["waktu_keluar"] = this.helper.ConvertDatetimeToDefaultFormat(textBox4.Text.ToString()); param["username"] = Properties.Settings.Default.Username; param["plate_number"] = textBox2.Text.ToString(); param["total_fare"] = totalFare; param["ipv4"] = this.helper.GetLocalIPAddress(); param["payment_method"] = paymentMethod; param["bank_code"] = bankCode; param["image"] = base64Image; var sent_param = JsonConvert.SerializeObject(param); RESTAPI save = new RESTAPI(); string ip_address_server = "http://" + Properties.Settings.Default.IPAddressServer; DataResponse response = save.API_Post(ip_address_server, Properties.Resources.SaveDataParkingAPIURL, sent_param); if (response != null) { switch (response.Status) { case 206: MessageBox.Show("Transaksi Berhasil.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Clear(true); break; default: MessageBox.Show(response.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); break; } } else { MessageBox.Show("Error found when receiving server response.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e) { if (comboBox1.SelectedIndex != 0) { if (textBox1.Text != "" && textBox1.Text != "UID Card") { if (comboBox1.SelectedIndex != 0) { // send data API var APIUrl = Properties.Resources.RequestUIDFareAPIURL; JObject param = new JObject(); param["uid"] = textBox1.Text; param["vehicle"] = comboBox1.Text; var sent_param = JsonConvert.SerializeObject(param); RESTAPI api = new RESTAPI(); string ip_address_server = "http://" + Properties.Settings.Default.IPAddressServer; DataResponse response = api.API_Post(ip_address_server, APIUrl, sent_param); if (response != null) { switch (response.Status) { case 206: //MessageBox.Show(response.Message, "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); foreach (JObject data in response.Data) { // Duration Data Process string duration = data["lama_parkir"].ToString(); string[] temp = duration.Split(':'); txtHour.Text = temp[0]; txtMinute.Text = temp[1]; txtSecond.Text = temp[2]; // Total Fare Process txtGrandTotal.Text = data["tarif_parkir"].ToString(); // Datetime Parking In string datetime_in = data["waktu_masuk"].ToString(); string[] temp_dt_in = datetime_in.Split(' '); textBox3.Text = this.helper.ConvertDatetime(temp_dt_in[0], temp_dt_in[1]); // Datetime Out string datetime_out = data["waktu_keluar"].ToString(); string[] temp_dt_out = datetime_out.Split(' '); textBox4.Text = this.helper.ConvertDatetime(temp_dt_out[0], temp_dt_out[1]); // Load Picture of face and plate number string URL_pict_face = "http://" + Properties.Settings.Default.IPAddressServer + Properties.Resources.repo + "/" + data["gambar_face"].ToString(); PictFace.Load(URL_pict_face); PictFace.BackgroundImageLayout = ImageLayout.Stretch; PictFace.SizeMode = PictureBoxSizeMode.StretchImage; string URL_pict_vehicle = "http://" + Properties.Settings.Default.IPAddressServer + Properties.Resources.repo + "/" + data["gambar_plate"].ToString(); PictVehicle.Load(URL_pict_vehicle); PictVehicle.BackgroundImageLayout = ImageLayout.Stretch; PictVehicle.SizeMode = PictureBoxSizeMode.StretchImage; // Total Fare Process string total_fare = data["tarif_parkir"].ToString(); txtGrandTotal.Text = this.helper.IDR(total_fare); } break; default: MessageBox.Show(response.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Clear(); break; } } else { MessageBox.Show("Error : Can't establish connection to server.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("Silahkan Tap Kartunya Terlebih Dahulu.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.ResetComboBox(); return; } } }
private void btnLogin_Click(object sender, EventArgs e) { string username = textBox1.Text.ToString(); string password = textBox2.Text.ToString(); if (username == "" || username == "Username") { MessageBox.Show("Username Harus Diisi.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (password == "" || password == "Password") { MessageBox.Show("Password Harus Diisi.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (string.IsNullOrEmpty(this.setting.IPAddressServer)) { MessageBox.Show("Invalid IP Address Server.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (string.IsNullOrEmpty(this.setting.IPAddressLiveCamera)) { MessageBox.Show("Invalid IP Address Live Camera.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } // validate TID & Settlement MID for further transaction if (string.IsNullOrEmpty(this.tmid.TID)) { MessageBox.Show("Invalid 'TID' value.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (string.IsNullOrEmpty(this.tmid.MID)) { MessageBox.Show("Invalid 'Settlement MID' value.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } using (Loading loading = new Loading(SignIn)) { loading.ShowDialog(this); // check local database connection DBConnect database = new DBConnect(); if (!database.CheckMySQLConnection()) { MessageBox.Show("Error : Can't Establish Connection to Local Database.\nPlease setup properly.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // check reader connection BNI bni = new BNI(); if (!bni.CheckReaderConn()) { MessageBox.Show("Error : Contactless Reader not available.\nPlease plug it and then try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // remember me feature if (checkBox1.Checked) { Properties.Settings.Default.Username = username; Properties.Settings.Default.Password = password; Properties.Settings.Default.RememberMe = "yes"; } else { Properties.Settings.Default.Username = username; Properties.Settings.Default.Password = ""; Properties.Settings.Default.RememberMe = "no"; } Properties.Settings.Default.Save(); string ip_address_server = "http://" + this.setting.IPAddressServer; // pull some data from server e.g. Vehicle Types string APIPullData = Properties.Resources.RequestVehicleTypeAPIURL; RESTAPI pull = new RESTAPI(); DataResponse receivedData = pull.API_Get(ip_address_server, APIPullData); if (receivedData != null) { switch (receivedData.Status) { case 206: JArray receivedVehicleTypes = receivedData.Data; JObject vehicleTypes = new JObject(); vehicleTypes.Add(new JProperty("VehicleTypes", receivedVehicleTypes)); // write into a file called 'master-data.json' try { string savedDir = tk.GetApplicationExecutableDirectoryName() + "\\src\\master-data.json"; string json = JsonConvert.SerializeObject(vehicleTypes); System.IO.File.WriteAllText(@savedDir, json); //MessageBox.Show("Pull Master Data is Success.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { Console.WriteLine(ex.Message); MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } break; default: MessageBox.Show(receivedData.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); break; } } else { MessageBox.Show("Error : Can't establish connection to server.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } // send data API var APIUrl = Properties.Resources.LoginAPIURL; JObject param = new JObject(); param["username"] = username; param["password"] = password; var sent_param = JsonConvert.SerializeObject(param); RESTAPI api = new RESTAPI(); DataResponse response = api.API_Post(ip_address_server, APIUrl, sent_param); if (response != null) { switch (response.Status) { case 201: //MessageBox.Show(response.Message, "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); try { this.cashier = new Cashier(this); this.cashier.Show(); Hide(); } catch (Exception ex) { MessageBox.Show("Error : Can't Connect to Webcam.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } break; default: MessageBox.Show(response.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); break; } } else { MessageBox.Show("Error : Can't establish connection to server.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }