Exemplo n.º 1
0
        private void Initialize()
        {
            this.webcamImage = webcam;
            if (Properties.Settings.Default.WebcamEnabled)
            {
                this.camera = new Webcam(this);
            }
            this.restApi      = new RESTAPI();
            this.database     = new DBConnect();
            this.parkingIn    = new ParkingIn();
            autoComplete      = new AutoCompleteStringCollection();
            nonCash.Checked   = true;
            ip_address_server = Properties.Settings.Default.IPAddressServer;

            StartLiveCamera();

            this.bni = new BNI();

            this.mifareCard = new MifareCard(this);
            this.mifareCard.RunMain();

            // initialize vehicle type options
            try
            {
                comboBox1.Items.Add("- Pilih Tipe Kendaraan -");
                string masterDataFile = TKHelper.GetApplicationExecutableDirectoryName() + Constant.PATH_FILE_MASTER_DATA_PARKING_OUT;
                using (StreamReader reader = new StreamReader(masterDataFile))
                {
                    string  json         = reader.ReadToEnd();
                    dynamic vehicleTypes = JsonConvert.DeserializeObject(json);
                    foreach (var types in vehicleTypes["VehicleTypes"])
                    {
                        comboBox1.Items.Add(types);
                    }
                    comboBox1.SelectedIndex = 0;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                notifyIcon.ShowBalloonTip(Constant.NOTIFICATION_TRAY_TIMEOUT, "Error", Constant.ERROR_MESSAGE_FAIL_TO_FETCH_VEHICLE_TYPE_DATA, ToolTipIcon.Error);
            }
        }
Exemplo n.º 2
0
        private void InitData()
        {
            nonCash.Checked = true;
            datetimeIn.Text = TKHelper.GetCurrentDatetime();
            try
            {
                string masterDataFile = TKHelper.GetApplicationExecutableDirectoryName() + Constant.PATH_FILE_MASTER_DATA_PARKING_IN;
                using (StreamReader reader = new StreamReader(masterDataFile))
                {
                    string  json           = reader.ReadToEnd();
                    dynamic pedestrianData = JsonConvert.DeserializeObject(json);
                    foreach (var data in pedestrianData["pedestrian"])
                    {
                        string pedestrianName = data["name"];
                        int    pedestrianFare = data["fare"];
                        PedestrianTypes.Add(pedestrianName, pedestrianFare);
                    }

                    foreach (string data in pedestrianData["notes"])
                    {
                        FreePassTypes.Add(data);
                    }
                    string defaultText = "- Pilih Tipe Muatan -";
                    tarifMuatan.Items.Add(defaultText);
                    tarifMuatan.Items.Add("Tidak Ada Muatan");
                    tarifMuatan.SelectedIndex = 0;
                    foreach (var data in pedestrianData["cargo"])
                    {
                        string cargoName         = data["name"];
                        int    cargoFare         = data["fare"];
                        string CargoNameWithFare = String.Format("{0} - {1}", cargoName, TKHelper.IDRWithCurrency(cargoFare.ToString()));
                        Cargos.Add(CargoNameWithFare, cargoFare);
                        CargoTypes.Add(CargoNameWithFare, cargoName);
                        tarifMuatan.Items.Add(CargoNameWithFare);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                notifyIcon.ShowBalloonTip(Constant.NOTIFICATION_TRAY_TIMEOUT, "Error", Constant.ERROR_MESSAGE_FAIL_TO_FETCH_PEDESTRIAN_DATA, ToolTipIcon.Error);
            }
        }
Exemplo n.º 3
0
 private void InitVehicleType()
 {
     try
     {
         tipe_kendaraan.Items.Add("- Pilih Tipe Kendaraan -");
         string masterDataFile = TKHelper.GetApplicationExecutableDirectoryName() + Constant.PATH_FILE_MASTER_DATA_PARKING_OUT;
         using (StreamReader reader = new StreamReader(masterDataFile))
         {
             string  json         = reader.ReadToEnd();
             dynamic vehicleTypes = JsonConvert.DeserializeObject(json);
             foreach (var types in vehicleTypes["VehicleTypes"])
             {
                 tipe_kendaraan.Items.Add(types);
             }
             tipe_kendaraan.SelectedIndex = 0;
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         notifyIcon.ShowBalloonTip(Constant.NOTIFICATION_TRAY_TIMEOUT, "Error", Constant.ERROR_MESSAGE_FAIL_TO_FETCH_VEHICLE_TYPE_DATA, ToolTipIcon.Error);
     }
 }
Exemplo n.º 4
0
        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);
                }
            }
        }