Ejemplo n.º 1
0
        private void ApiSignIn(string username, string password)
        {
            var           APIUrl        = Properties.Resources.LoginAPIURL;
            SignInRequest signInRequest = new SignInRequest(username, password);
            string        sent_param    = JsonConvert.SerializeObject(signInRequest);

            DataResponseArray response = (DataResponseArray)restApi.post(this.ip_address_server, APIUrl, false, sent_param);

            if (response != null)
            {
                switch (response.Status)
                {
                case 201:
                    try
                    {
                        switch (Properties.Settings.Default.GateType.ToLower())
                        {
                        case "in":
                            this.passKadeIn = new PassKadeIn(this);
                            this.passKadeIn.Show();
                            break;

                        case "out":
                            this.cashier = new Cashier(this);
                            this.cashier.Show();
                            break;

                        default:
                            this.pedestrian = new Pedestrian(this);
                            this.pedestrian.Show();
                            break;
                        }
                        Hide();
                    }
                    catch (Exception)
                    {
                        notifyIcon.ShowBalloonTip(Constant.NOTIFICATION_TRAY_TIMEOUT, "Error", Constant.ERROR_MESSAGE_FAIL_TO_CONNECT_WEBCAM, ToolTipIcon.Error);
                        return;
                    }
                    break;

                default:
                    notifyIcon.ShowBalloonTip(Constant.NOTIFICATION_TRAY_TIMEOUT, "Error", response.Message, ToolTipIcon.Error);
                    break;
                }
            }
            else
            {
                notifyIcon.ShowBalloonTip(Constant.NOTIFICATION_TRAY_TIMEOUT, "Error", Constant.ERROR_MESSAGE_FAIL_TO_CONNECT_SERVER, ToolTipIcon.Error);
            }
        }
Ejemplo n.º 2
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);
                }
            }
        }