private void btnSubmit_Click(object sender, EventArgs e) { Company company = new Company(); company.companyName = txtCompanyName.Text; company.address = txtAddress.Text; company.website = txtWebsite.Text; RestClient client = new RestClient("http://52.163.93.95:8080/FeatherAssets/");//("http://feather-assets.herokuapp.com/"); RestRequest regCompany = new RestRequest("/company", Method.POST); regCompany.AddHeader("Content-Type", "application/json; charset=utf-8"); regCompany.RequestFormat = DataFormat.Json; regCompany.AddBody(company); IRestResponse response = client.Execute(regCompany); var content = response.Content; if (response.StatusCode == HttpStatusCode.OK) { JsonDeserializer deserial = new JsonDeserializer(); RestResult restResult = deserial.Deserialize <RestResult>(response); if (restResult.result == "OK") { MessageBox.Show("Company Saved", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(restResult.result + " " + restResult.message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Failed to connect to server.. please try again later..", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void btnSubmit_Click(object sender, EventArgs e) { try { if (txtRFIDTag.Text.Length == 0 || /* txtAssetName.Text.Length == 0 ||*/ txtDescription.Text.Length == 0 || txtTakeOutNote.Text.Length == 0 || imgCapture1.Image == null) { MessageBox.Show("Complete information is required.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Stop); //btnBrowseImage.Focus(); btnGetRFIDTag.Focus(); return; } #region old code /*if (!CheckDuplicateRFID()) * { * MessageBox.Show("RFID Tag is already assigned.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); * txtRFIDTag.Focus(); * return; * }*/ //For MySqlConnection //MySqlConnection con = new MySqlConnection(connectionString); //con.Open(); //MySqlCommand cmd = new MySqlCommand("insert into asset(rfid_tag,company_id,name,description,images,take_out_allowed,take_out_info,created_at,updated_at) values (@rfid_tag,@company_id,@name,@description,@images,@take_out_allowed,@take_out_info,@created_at,@updated_at)", con); //cmd.Parameters.AddWithValue("@rfid_tag", txtRFIDTag.Text); ////cmd.Parameters.AddWithValue("@owner_id", 1); //cmd.Parameters.AddWithValue("@company_id", 1); //cmd.Parameters.AddWithValue("@name", txtAssetName.Text); //cmd.Parameters.AddWithValue("@description", txtDescription.Text); //if (radbtnYes.Checked) //{ // cmd.Parameters.AddWithValue("@take_out_allowed", 1); //} //else //{ // cmd.Parameters.AddWithValue("@take_out_allowed", 0); //} //cmd.Parameters.AddWithValue("@take_out_info", txtTakeOutNote.Text); ////cmd.Parameters.AddWithValue("@Section", combosec.SelectedItem.ToString()); //cmd.Parameters.AddWithValue("@created_at", DateTime.Now); //cmd.Parameters.AddWithValue("@updated_at", DateTime.Now); //cmd.Parameters.AddWithValue("@images", txtImagePath.Text); //cmd.ExecuteNonQuery(); //con.Close(); //MessageBox.Show("Asset successfully saved.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); //ClearFields(); #endregion //For Web Service Asset asset = new Asset(); //int oId; //bool parseOK = Int32.TryParse(comboOwner.SelectedValue.ToString(), out oId); //int currentOwnerId = Convert.ToInt32(((Owner)comboOwner.SelectedItem).userId); asset.tag = txtRFIDTag.Text; asset.tagType = 1; asset.companyId = 1; //asset.ownerId = currentOwnerId;//oId; asset.name = txtDescription.Text.Trim();//txtAssetName.Text; asset.description = txtDescription.Text.Trim(); //if (radbtnYes.Checked) //{ // asset.takeOutAllowed = true; //} //else //{ //asset.takeOutAllowed = false; //} asset.takeOutInfo = txtTakeOutNote.Text.Trim(); asset.imageUrls = newImgFileNames; //txtCapturedImagePath.Text;//txtImagePath.Text; asset.registerUserId = userId; //lblLoginUserName.Text.Substring(lblLoginUserName.Text.IndexOf(":") + 2); //For Validity Expiration if (rbtnValidToday.Checked) { validUntilValue = DateTime.UtcNow.ToString("yyyy-MM-dd T") + "17:00"; } else if (rbtnValidUntil.Checked) { 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"; } } else { validUntilValue = null; } DateTime?dt = null; asset.validUntil = validUntilValue != null?Convert.ToDateTime(validUntilValue) : dt; RestClient client = new RestClient("http://52.163.93.95:8080/FeatherAssets/");//("http://feather-assets.herokuapp.com/"); RestRequest register = new RestRequest("/api/asset/add", Method.POST); var authToken = tokenvalue; register.AddHeader("X-Auth-Token", authToken); register.AddHeader("Content-Type", "application/json; charset=utf-8"); register.RequestFormat = DataFormat.Json; register.AddBody(asset); lblSubmittingInformation.Visible = true; this.Refresh(); IRestResponse response = client.Execute(register); lblSubmittingInformation.Visible = false; var content = response.Content; if (response.StatusCode == HttpStatusCode.OK)//if (response.IsSuccessStatusCode) { JsonDeserializer deserial = new JsonDeserializer(); RestResult restResult = deserial.Deserialize <RestResult>(response); if (restResult.result == "OK") { MessageBox.Show("Record successfully saved.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); 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); } }