private void btnSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtVesselName.Text)) { txtVesselName.BackColor = Color.LightCoral; My.MyProject.Forms.MessageBoxCeresOK.ShowDialog("The Vessel Name field cannot be empty.", "", this); return; } if (string.IsNullOrEmpty(txtVesselCapacity.Text)) { txtVesselCapacity.Text = "0"; } if (string.IsNullOrEmpty(txtVesselYear.Text)) { txtVesselYear.Text = "0"; } if (VesselId == 0) { if (VesselService.Insert(txtVesselName.Text, txtVesselOwner.Text, txtVesselManager.Text, Convert.ToDecimal(txtVesselCapacity.Text), Convert.ToInt32(txtVesselYear.Text), cboFlag.Text, ckbActive.Checked)) { if (EmployeeActivityLogService.Insert(My.MyProject.Forms.FrmLoginWindow._userID, VesselService.GetLastVesselId().ToString(), "INSERT", "VESSEL", "Insert of vessel information")) { } My.MyProject.Forms.MessageBoxCeresOK.ShowDialog("The Vessel has been successfully inserted.", "Inserted!", this); My.MyProject.Forms.frmVesselList.LoadFormAddItem(VesselService.GetLastVesselId(), txtVesselName.Text, txtVesselOwner.Text, txtVesselManager.Text, Convert.ToDecimal(txtVesselCapacity.Text), Convert.ToInt32(txtVesselYear.Text), cboFlag.Text, ckbActive.Checked); My.MyProject.Forms.frmVesselList.SearchByColumn(); } else { My.MyProject.Forms.MessageBoxCeresOK.ShowDialog("Error inserting the vessel, try again if the error persists inform the IT department. #1351", "Error", this); } } else if (VesselService.Update(VesselId, txtVesselName.Text, txtVesselOwner.Text, txtVesselManager.Text, Convert.ToDecimal(txtVesselCapacity.Text), Convert.ToInt32(txtVesselYear.Text), cboFlag.Text, ckbActive.Checked)) { if (EmployeeActivityLogService.Insert(My.MyProject.Forms.FrmLoginWindow._userID, VesselId.ToString(), "UPDATE", "VESSEL", "Edition of vessel information")) { } My.MyProject.Forms.MessageBoxCeresOK.ShowDialog("Vessel has been updated successfully.", "Updated!", this); My.MyProject.Forms.frmVesselList.LoadForm(); My.MyProject.Forms.frmVesselList.SearchByColumn(); } else { My.MyProject.Forms.MessageBoxCeresOK.ShowDialog("Error updating the vessel, try again if the error persists inform the IT department. #1352", "Error", this); } Close(); }
private void SyncSave() { int countRow = 0; int IdVessel = 0; bool isActive = false; foreach (DataGridViewRow row in dgvVesselCSV.Rows) { countRow += 1; try { if (countRow < dgvVesselCSV.Rows.Count) { string VesselName = Conversions.ToString(row.Cells[0].Value); string Owner = Conversions.ToString(row.Cells[1].Value); string Manager = Conversions.ToString(row.Cells[2].Value); string Capacity = Conversions.ToString(row.Cells[3].Value); string Year = Conversions.ToString(row.Cells[4].Value); string Flag = Conversions.ToString(row.Cells[5].Value); string Active = Conversions.ToString(row.Cells[6].Value); IdVessel = VesselService.GetVesselIdByVesselName(VesselName); if (string.IsNullOrEmpty(Owner)) { Owner = ""; } if (string.IsNullOrEmpty(Manager)) { Manager = ""; } if (string.IsNullOrEmpty(Flag)) { Flag = ""; } if (Active.ToUpper().Equals("TRUE")) { isActive = true; } else { isActive = false; } if (string.IsNullOrEmpty(Capacity) | string.IsNullOrWhiteSpace(Capacity)) { Capacity = "0"; } if (string.IsNullOrEmpty(Year) | string.IsNullOrWhiteSpace(Year)) { Year = "0"; } if (IdVessel == 0) { if (VesselService.Insert(VesselName, Owner, Manager, Convert.ToDecimal(Capacity), Convert.ToInt32(Year), Flag, isActive)) { dgvVesselCSV.Rows.Remove((DataGridViewRow)row); } else { pnlMessage.Visible = true; } } else if (VesselService.Update(IdVessel, VesselName, Owner, Manager, Convert.ToDecimal(Capacity), Convert.ToInt32(Year), Flag, isActive)) { dgvVesselCSV.Rows.Remove((DataGridViewRow)row); } else { pnlMessage.Visible = true; } } } catch (Exception ex) { string a = ex.ToString(); pnlMessage.Visible = true; } } if (pnlMessage.Visible == false) { My.MyProject.Forms.MessageBoxCeresOK.ShowDialog("", "Vessel updated successfully.", this); ClearDataGridView(); Close(); } }