Esempio n. 1
0
        private void getOwnerInfo(int id)
        {
            try
            {
                //initialize Rest Client
                RestClient  client    = new RestClient("http://52.163.93.95:8080/FeatherAssets/");
                RestRequest ownerInfo = new RestRequest("/api/user/" + id, Method.GET);

                var authToken = tokenValue;

                //add needed headers
                ownerInfo.RequestFormat = DataFormat.Json;
                ownerInfo.AddHeader("Content-Type", "application/json; charset=utf-8");
                ownerInfo.AddHeader("X-Auth-Token", authToken);

                //execute request
                var response = client.Execute <GlobalClass.GetSetClass>(ownerInfo);
                //client.ExecuteAsync<GlobalClass.GetSetClass>(ownerInfo, response =>
                //{
                var content = response.Content;

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    //deserialize json response into object
                    JsonDeserializer        deserial = new JsonDeserializer();
                    GlobalClass.GetSetClass info     = deserial.Deserialize <GlobalClass.GetSetClass>(response);

                    name = info.firstName + " " + info.lastName;    //info.lastName + ", " + info.firstName;
                }
                else
                {
                    MessageBox.Show("Unable to reach server.. please try again later", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);

                    //Application.Restart();

                    /*this.Hide();
                     * LoginActivity loginActivity = new LoginActivity();
                     * loginActivity.Show();*/
                }

                //});
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 2
0
        private void SubmitImage()
        {
            Bitmap Image = (Bitmap)cameraBox.Image;

            Image.Save("img.jpg", ImageFormat.Jpeg);

            RestClient  client = new RestClient("http://52.163.93.95:8080/FeatherAssets/");
            RestRequest upload = new RestRequest("/api/upload/image", Method.POST);

            upload.AddHeader("X-Auth-Token", tokenvalue);
            upload.AddHeader("Content-Type", "multipart/form-data");
            upload.AlwaysMultipartFormData = true;
            upload.AddFile("file", "img.jpg", "image/jpg");
            upload.AddParameter("companyId", 1);
            upload.AddParameter("type", "asset");


            IRestResponse response = client.Execute(upload);

            /*if (language.ToUpper() == "JAPANESE")
             * {
             *  if (imgCapture2.Image == null) btnCapturePhoto.Text = "有効な証明ID写真を取り込みます";
             *  else btnCapturePhoto.Text = "取り込み官僚";
             * }
             * else
             * {
             *  if (imgCapture2.Image == null) btnCapturePhoto.Text = "Capture Valid ID Photo";
             *  else btnCapturePhoto.Text = "Capture Completed";
             * }*/
            getCaptureButtonText();

            var content = response.Content;

            if (response.StatusCode == HttpStatusCode.OK)//if (response.IsSuccessStatusCode)
            {
                JsonDeserializer        deserial    = new JsonDeserializer();
                GlobalClass.GetSetClass imageResult = deserial.Deserialize <GlobalClass.GetSetClass>(response);

                ImgFileName = imageResult.message;
            }
            else
            {
                MessageBox.Show("Error Code " +
                                response.StatusCode /*+ " : Message - " + response.ErrorMessage*/);
                return;
            }
        }
Esempio n. 3
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(cmbLocation.Text))
                {
                    lblLocation.Visible = true;
                    cmbLocation.Focus();
                    return;
                }
                else if (txtUserName.TextLength == 0 || txtPassword.TextLength == 0)
                {
                    lblUserPasswordRequired.Visible = true;
                    txtUserName.Focus();
                    return;
                }
                else
                {
                    lblUserPasswordRequired.Visible = false;

                    //picLoading.Visible = true;
                    lblLoggingIn.Visible = true;//btnLogin.Text = "Logging in...";
                    this.Refresh();

                    GlobalClass.GetSetClass loginInfo = new GlobalClass.GetSetClass();
                    //store information to object
                    loginInfo.email    = txtUserName.Text;
                    loginInfo.password = txtPassword.Text;

                    //initialize web service
                    //RestClient(request);
                    RestClient  client = new RestClient("http://52.163.93.95:8080/FeatherAssets/");//("http://127.0.0.1:8080/");
                    RestRequest login  = new RestRequest("/login", Method.POST);


                    //pass information to web service
                    login.AddHeader("Content-Type", "application/json; charset=utf-8");
                    login.RequestFormat = DataFormat.Json;
                    login.AddBody(loginInfo);

                    //retrieve response
                    IRestResponse response = client.Execute(login);
                    lblLoggingIn.Visible = false;

                    var content = response.Content;

                    //check for errors
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        //deserialize JSON -> Object
                        GlobalClass.GetSetClass loginResult = new GlobalClass.GetSetClass();

                        JsonDeserializer deserial = new JsonDeserializer();
                        loginResult = deserial.Deserialize <GlobalClass.GetSetClass>(response);
                        readerInfo  = cmbLocation.Text;

                        if (locationInfo == null)
                        {
                            locationInfo = cmbLocation.Text;
                        }
                        else
                        {
                            string[] loc = locationInfo.Split(',');
                            for (int i = 0; i < loc.Length; i++)
                            {
                                if (loc[i].ToLower() == cmbLocation.Text.ToLower())
                                {
                                    save = false;
                                    break;
                                }
                                else
                                {
                                    save = true;
                                }
                            }
                            if (save == true)
                            {
                                locationInfo = !string.IsNullOrEmpty(locationInfo) ? locationInfo + ',' + cmbLocation.Text : cmbLocation.Text;
                            }
                        }
                        companyid   = loginResult.companyId;
                        companyName = loginResult.companyName;
                        SaveAssetSystemInfo(loginResult.authenticationToken, loginResult.roles, loginResult.userId, loginResult.firstName + " " + loginResult.lastName /*txtUserName.Text.Trim()*/, readerInfo, companyName, locationInfo);


                        //check authorities
                        if (loginResult.roles == "ROLE_SUPERADMIN")
                        {
                            this.Hide();
                            MainMenu MenuForm = new MainMenu(loginResult.authenticationToken, /*cmbComPort.Text,*/ loginResult.roles);
                            MenuForm.ShowDialog();
                        }
                        else if (loginResult.roles == "ROLE_ADMIN")
                        {
                            this.Hide();
                            MainMenu MenuForm = new MainMenu(loginResult.authenticationToken, /*cmbComPort.Text,*/ loginResult.roles);
                            MenuForm.ShowDialog();
                        }
                        else if (loginResult.roles == "ROLE_GUARD")
                        {
                            //TODO RFID SCAN CODE MISSING
                            this.Hide();
                            Verification verification = new Verification();//loginResult.authenticationToken, loginResult.roles);
                            verification.Show();
                        }
                        else if (loginResult.roles == "ROLE_USER")
                        {
                            this.Hide();
                            Assets asset = new Assets(/*loginResult.authenticationToken, loginResult.roles*/);
                            asset.Show();
                        }
                    }
                    else if (response.StatusCode == HttpStatusCode.NotFound)
                    {
                        MessageBox.Show("Error connecting to server.. please try again later");
                    }
                    else
                    {
                        HttpStatusCode statusCode        = response.StatusCode;
                        int            numericStatusCode = (int)statusCode;

                        if (numericStatusCode == 401)
                        {
                            txtPassword.Text = string.Empty;
                            txtPassword.Focus();
                            MessageBox.Show("Incorrect Username or Password, Please try again.");
                        }
                        else if (numericStatusCode == 500)
                        {
                            MessageBox.Show("Error connecting to server... please try again later");
                        }
                        else
                        {
                            MessageBox.Show("Error connecting to server... Please try again later");
                        }
                    }

                    //picLoading.Visible = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void SaveTransaction(DateTime?startDate, DateTime?validUntil)
        {
            //Saving to transaction table
            try
            {
                //For Web Service
                GlobalClass.GetSetClass transactDet = new GlobalClass.GetSetClass();

                //transactDet.companyId = companyId;//1;
                //transactDet.readerInfo = readerInfo;
                //transactDet.type = "RENEW-ID";
                ////transactDet.readerId = 1;
                ////transactDet.notes = txtExplanationNotes.Text.Trim();
                ////transactDet.imageUrl = newImgFileNames;//txtCapturedImagePath.Text;//txtImagePath.Text;
                ////transactDet.assetId = Verification.AssetIdValue;
                ////if (AssetRegistration.assetId != 0)
                ////    transactDet.assetId = AssetRegistration.assetId;
                ////else
                //    transactDet.assetId = assetId;//Verification.AssetIdValue;

                transactDet.companyId      = companyId;//1;
                transactDet.validityPeriod = validUntil == null ? "Start " + startDate.Value.ToString("g") + " - No End Date" : "Start " + startDate.Value.ToString("g") + " Until " + validUntil.Value.ToString("g");
                transactDet.ownerName      = ownerName;
                //transactDet.position = position;
                //transactDet.email = email;
                //transactDet.userType = userType;
                transactDet.description = description;
                transactDet.takeOutNote = takeOutNote;
                //transactDet.ownerImageUrl = ownerImageUrl;
                //transactDet.assetImageUrl = newImgFileNames;
                transactDet.updatedBy  = userName;
                transactDet.readerInfo = readerInfo;
                //transactDet.notes = notes;
                transactDet.type      = "RENEW-ID";
                transactDet.assetId   = assetId;
                transactDet.location  = baseLocation;
                transactDet.classType = classification;

                RestClient  client   = new RestClient("http://52.163.93.95:8080/FeatherAssets/");//("http://feather-assets.herokuapp.com/");
                RestRequest transact = new RestRequest("/api/asset/transact", Method.POST);

                var authToken = tokenvalue;
                transact.AddHeader("X-Auth-Token", authToken);
                transact.AddHeader("Content-Type", "application/json; charset=utf-8");
                transact.RequestFormat = DataFormat.Json;
                transact.AddBody(transactDet);

                //lblSubmittingInformation.Visible = true;
                //this.Refresh();

                IRestResponse response = client.Execute(transact);
                lblSubmittingInformation.Visible = false;

                var content = response.Content;

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    JsonDeserializer        deserial   = new JsonDeserializer();
                    GlobalClass.GetSetClass restResult = deserial.Deserialize <GlobalClass.GetSetClass>(response);

                    if (restResult.result != "OK")
                    {
                        if (language.ToLower() == "japanese")
                        {
                            MessageBox.Show("取引が保存されました..." + "\n" + restResult.result + " " + restResult.message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("transaction saved..." + "\n" + restResult.result + " " + restResult.message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Saving transaction..." + "\n" + "Error Code " +
                                    response.StatusCode /*+ " : Message - " + response.ErrorMessage*/);
                    return;
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                //For Validity Expiration
                if (dtStartTimePicker.Checked)
                {
                    startDateValue = dtStartDate.Value.ToString("yyyy-MM-dd") + dtStartTimePicker.Value.ToString("THH:mm");
                }
                else
                {
                    startDateValue = dtStartDate.Value.ToString("yyyy-MM-dd");  //+ "17:00";
                }
                if (Convert.ToDateTime(startDateValue) < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd THH:mm")))
                {
                    MessageBox.Show("Start Date must not less than to current Date and Time.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (rbtnValidToday.Checked)
                {
                    startDateValue  = DateTime.UtcNow.ToString("yyyy-MM-dd"); //+ "00:01";
                    validUntilValue = DateTime.UtcNow.ToString("yyyy-MM-dd T") + "17:00";

                    if (Convert.ToDateTime(validUntilValue) < Convert.ToDateTime(DateTime.Now.ToString("g")))
                    {
                        MessageBox.Show("ID Validity Period is already expired.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else if (rbtnValidUntil.Checked)
                {
                    //startDateValue = dtStartDate.Value.ToString("yyyy-MM-dd"); //+ "00:01";

                    if (dtTimePicker.Checked)
                    {
                        validUntilValue = dtDatePicker.Value.ToString("yyyy-MM-dd") + dtTimePicker.Value.ToString("THH:mm");
                    }
                    else
                    {
                        validUntilValue = dtDatePicker.Value.ToString("yyyy-MM-dd T") + "17:00";
                    }

                    if (Convert.ToDateTime(startDateValue) > Convert.ToDateTime(validUntilValue))
                    {
                        MessageBox.Show("Start Date must not greater than Until Date.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else if (Convert.ToDateTime(validUntilValue) < Convert.ToDateTime(DateTime.Now.ToString("g")))
                    {
                        MessageBox.Show("Until Date must not less than to current Date and Time.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else
                {
                    //startDateValue = null;
                    validUntilValue = null;
                }

                //For Web Service
                GlobalClass.GetSetClass assetExtend = new GlobalClass.GetSetClass();

                DateTime?dt = null;
                assetExtend.startDate = startDateValue != null?Convert.ToDateTime(startDateValue) : dt;

                assetExtend.validUntil = validUntilValue != null?Convert.ToDateTime(validUntilValue) : dt;

                //if (AssetRegistration.assetId != 0)
                //    assetExtend.assetId = AssetRegistration.assetId;
                //else
                assetExtend.assetId      = assetId;//Verification.AssetIdValue;
                assetExtend.updateUserId = userId;

                RestClient  client = new RestClient("http://52.163.93.95:8080/FeatherAssets/");//("http://feather-assets.herokuapp.com/");
                RestRequest extend = new RestRequest("/api/asset/extend", Method.POST);

                var authToken = tokenvalue;
                extend.AddHeader("X-Auth-Token", authToken);
                extend.AddHeader("Content-Type", "application/json; charset=utf-8");
                extend.RequestFormat = DataFormat.Json;
                extend.AddBody(assetExtend);

                lblSubmittingInformation.Visible = true;
                this.Refresh();


                IRestResponse response = client.Execute(extend);
                lblSubmittingInformation.Visible = false;

                var content = response.Content;

                if (response.StatusCode == HttpStatusCode.OK)//if (response.IsSuccessStatusCode)
                {
                    JsonDeserializer        deserial   = new JsonDeserializer();
                    GlobalClass.GetSetClass restResult = deserial.Deserialize <GlobalClass.GetSetClass>(response);

                    if (restResult.result == "OK")
                    {
                        SaveTransaction(assetExtend.startDate, assetExtend.validUntil);
                        if (language.ToLower() == "japanese")
                        {
                            MessageBox.Show("アセットが正常に更新されました。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("ID successfully renewed.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        DialogResult = DialogResult.OK;
                        this.Dispose();
                    }
                    else
                    {
                        MessageBox.Show(restResult.result + restResult.message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show("Error Code " +
                                    response.StatusCode /*+ " : Message - " + response.ErrorMessage*/);
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 6
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                if (imgCapture1.Image == null || imgCapture2.Image == null || txtExplanationNotes.Text.Length == 0)
                {
                    if (language.ToLower() == "japanese")
                    {
                        MessageBox.Show("完全な情報は必要です.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    }
                    else
                    {
                        MessageBox.Show("Complete information is required.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    }
                    txtExplanationNotes.Focus();
                    return;
                }

                //For Web Service
                GlobalClass.GetSetClass transactDet = new GlobalClass.GetSetClass();

                //transactDet.companyId = companyId;//1;
                //transactDet.readerInfo = readerInfo;
                ////transactDet.readerId = 1;
                //transactDet.assetId = assetId;//Verification.AssetIdValue;
                //transactDet.notes = txtExplanationNotes.Text.Trim();
                //transactDet.imageUrls = newImgFileNames;//txtCapturedImagePath.Text;//txtImagePath.Text;
                //transactDet.type = "CREATE-Report";

                transactDet.companyId      = companyId;//1;
                transactDet.validityPeriod = "";
                transactDet.ownerName      = ownerName;
                //transactDet.position = position;
                //transactDet.email = email;
                //transactDet.userType = userType;
                transactDet.description = description;
                transactDet.takeOutNote = takeOutNote;
                transactDet.imageUrls   = newImgFileNames;
                //transactDet.ownerImageUrl = ownerImageUrl;
                //transactDet.assetImageUrl = newImgFileNames;
                transactDet.updatedBy  = userName;
                transactDet.readerInfo = readerInfo;
                transactDet.notes      = txtExplanationNotes.Text.Trim();
                transactDet.type       = "CREATE-Report";
                transactDet.assetId    = assetId;
                transactDet.location   = baseLcoation;
                transactDet.classType  = classification;

                RestClient  client   = new RestClient("http://52.163.93.95:8080/FeatherAssets/");//("http://feather-assets.herokuapp.com/");
                RestRequest transact = new RestRequest("/api/asset/transact", Method.POST);

                var authToken = tokenvalue;
                transact.AddHeader("X-Auth-Token", authToken);
                transact.AddHeader("Content-Type", "application/json; charset=utf-8");
                transact.RequestFormat = DataFormat.Json;
                transact.AddBody(transactDet);

                lblSubmittingInformation.Visible = true;
                this.Refresh();


                IRestResponse response = client.Execute(transact);
                lblSubmittingInformation.Visible = false;

                var content = response.Content;

                if (response.StatusCode == HttpStatusCode.OK)//if (response.IsSuccessStatusCode)
                {
                    JsonDeserializer        deserial   = new JsonDeserializer();
                    GlobalClass.GetSetClass restResult = deserial.Deserialize <GlobalClass.GetSetClass>(response);

                    if (restResult.result == "OK")
                    {
                        if (language.ToLower() == "japanese")
                        {
                            MessageBox.Show("レポートが正常に保存され", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("Report successfully saved.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        if (IsCameraConnected)
                        {
                            cam.Stop();
                        }
                        DialogResult = DialogResult.OK;
                        this.Dispose(); //ClearFields();
                    }
                    else
                    {
                        MessageBox.Show(restResult.result + " " + restResult.message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show("Error Code " +
                                    response.StatusCode /*+ " : Message - " + response.ErrorMessage*/);
                    return;
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }