private void buttonEdit_Click(object sender, EventArgs e) { if (dataGridViewVehicles.SelectedRows.Count == 0 || dataGridViewVehicles.SelectedRows.Count > 1) { MessageBox.Show("Please select one item!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { VehicleViewModel vehicle = new VehicleViewModel() { Id = int.Parse(dataGridViewVehicles.SelectedRows[0].Cells["Id"].Value.ToString()), Available = dataGridViewVehicles.SelectedRows[0].Cells["Available"].Value as bool?, Category = dataGridViewVehicles.SelectedRows[0].Cells["Category"].Value.ToString(), Color = dataGridViewVehicles.SelectedRows[0].Cells["Color"].Value.ToString(), EngineSize = decimal.Parse(dataGridViewVehicles.SelectedRows[0].Cells["EngineSize"].Value.ToString()), FuelTypeName = dataGridViewVehicles.SelectedRows[0].Cells["FuelTypeName"].Value.ToString(), Make = dataGridViewVehicles.SelectedRows[0].Cells["Make"].Value.ToString(), MaxPassangers = int.Parse(dataGridViewVehicles.SelectedRows[0].Cells["MaxPassangers"].Value.ToString()), Mileage = int.Parse(dataGridViewVehicles.SelectedRows[0].Cells["Mileage"].Value.ToString()), Model = dataGridViewVehicles.SelectedRows[0].Cells["Model"].Value.ToString(), Plate = dataGridViewVehicles.SelectedRows[0].Cells["Plate"].Value.ToString(), TankCapacity = int.Parse(dataGridViewVehicles.SelectedRows[0].Cells["TankCapacity"].Value.ToString()), TransmissionTypeName = dataGridViewVehicles.SelectedRows[0].Cells["TransmissionTypeName"].Value.ToString(), TypeName = dataGridViewVehicles.SelectedRows[0].Cells["TypeName"].Value.ToString(), Vin = dataGridViewVehicles.SelectedRows[0].Cells["Vin"].Value.ToString(), Year = dataGridViewVehicles.SelectedRows[0].Cells["Year"].Value.ToString() }; CommonFormHelper.GetFormInstance(typeof(VehicleAdd), this.MdiParent, vehicle).Show(); // shows Vehicle Add Form } }
private void btnSubmit_Click(object sender, EventArgs e) { if (ValidateNewPassword() && ValidateConfirmPassword() && txtCurrentPassword.Text != "") { ChangePasswordViewModel passDetails = new ChangePasswordViewModel() { Username = GlobalInfo.CurrentUser.UserName, CurentPassword = DataHelper.EncryptString(txtCurrentPassword.Text.Trim()), NewPassword = DataHelper.EncryptString(txtNewPassword.Text.Trim()) }; HttpContent httpContent = new StringContent( JsonConvert.SerializeObject(passDetails), Encoding.UTF8, CommonConstants.DefaultContentType); Task <HttpResponseMessage> taskResponse = HttpClientHelper.WebApiClient .PostAsync(ApiUrlConstants.ChangePasswordBaseUrl, httpContent); HttpResponseMessage response = taskResponse.GetAwaiter().GetResult(); if (response.IsSuccessStatusCode) { MessageBox.Show("Password Changed Successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); CommonFormHelper.GetFormInstance(typeof(ChangePassword), this.MdiParent).Close();; } else { MessageBox.Show("Incorrect Current Password.", "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Form is invalid!", "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void buttonSave_Click_1(object sender, EventArgs e) { if (IsValidForm()) { HttpContent httpContent = new StringContent(JsonConvert.SerializeObject(SeedVehicleObject()), Encoding.UTF8, CommonConstants.DefaultContentType); HttpResponseMessage response = HttpClientHelper.WebApiClient.PostAsync(ApiUrlConstants.AddOrEditVehicleBaseUrl, httpContent).Result; if (response.IsSuccessStatusCode) { CommonFormHelper.GetFormInstance(typeof(Vehicles), MdiParent).Close(); CommonFormHelper.GetFormInstance(typeof(Vehicles), MdiParent).Show(); MessageBox.Show("Operation Successful.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Error Code" + response.StatusCode + " : Message - " + response.ReasonPhrase , "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Form Invalid!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void changePasswordToolStripMenuItem_Click(object sender, EventArgs e) { CommonFormHelper.GetFormInstance(typeof(ChangePassword), this).Show(); }
private void vehicleToolStripMenuItem_Click(object sender, EventArgs e) { CommonFormHelper.GetFormInstance(typeof(Vehicles), this).Show(); }
private void ChangePassword_FormClosing(object sender, FormClosingEventArgs e) { CommonFormHelper.HandleFormClosing(this.GetType()); }
private void Vehicles_FormClosing(object sender, FormClosingEventArgs e) { CommonFormHelper.HandleFormClosing(this.GetType()); }
private void buttonNew_Click(object sender, EventArgs e) { CommonFormHelper.GetFormInstance(typeof(VehicleAdd), this.MdiParent).Show(); // shows Vehicle Add Form }