public void UpdateClientAddress(ClientAddressModel address) { SqlConnection connection = null; try { connection = new SqlConnection(Properties.Resources.ConnectionString); connection.Open(); SqlCommand command = new SqlCommand("UpdateClientAddress", connection); command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@ClientAddressId", address.ClientAddressId)); command.Parameters.Add(new SqlParameter("@StreetName", address.StreetName)); command.Parameters.Add(new SqlParameter("@StreetNo", address.StreetNo)); command.Parameters.Add(new SqlParameter("@CityName", address.City.CityName)); command.Parameters.Add(new SqlParameter("@CountyName", address.County.CountyName)); command.ExecuteNonQuery(); } catch (SqlException e) { throw e; } finally { if (connection.State == ConnectionState.Open) { connection.Close(); } } }
public string Put(ClientAddressModel UpdateClientAddressModel) { try { using (SqlConnection connection = new SqlConnection(ConnectionString)) { //Create the command object SqlCommand cmd = new SqlCommand("[dbo].[UpdateAddressClient]", connection); cmd.CommandType = CommandType.StoredProcedure; //add input parameter cmd.Parameters.AddWithValue("@ClientAddressID", UpdateClientAddressModel.ClientAddressID); cmd.Parameters.AddWithValue("@ClientID", UpdateClientAddressModel.ClientID); cmd.Parameters.AddWithValue("@ClientAddressType", UpdateClientAddressModel.ClientAddressType); cmd.Parameters.AddWithValue("@ClientAddress", UpdateClientAddressModel.ClientAddress); cmd.Parameters.AddWithValue("@Street", UpdateClientAddressModel.Street); cmd.Parameters.AddWithValue("@City", UpdateClientAddressModel.City); cmd.Parameters.AddWithValue("@Province", UpdateClientAddressModel.Province); cmd.Parameters.AddWithValue("@PostCode", UpdateClientAddressModel.PostCode); connection.Open(); cmd.ExecuteNonQuery(); connection.Close(); } return("Updated Successfully!!"); } catch (Exception) { return("Failed to Update!!"); } }
public BindingList <ClientAddressModel> GetClientAddressBi(int clientId, int?clientAddressId) { DAClientAddress dac = new DAClientAddress(); DataTable dt = new DataTable(); dt = dac.GetClientAddress(clientId, clientAddressId); BindingList <ClientAddressModel> list = new BindingList <ClientAddressModel>(); for (int i = 0; i < dt.Rows.Count; i++) { ClientAddressModel address = new ClientAddressModel(); address.ClientAddressId = Convert.ToInt32(dt.Rows[i]["ClientAddressId"].ToString()); address.ClientId = Convert.ToInt32(dt.Rows[i]["ClientId"].ToString()); address.City = new CityModel { CityId = Convert.ToInt32(dt.Rows[i]["CityId"]), CityName = dt.Rows[i]["CityName"].ToString() }; address.County = new CountyModel { CountyId = Convert.ToInt32(dt.Rows[i]["CountyId"]), CountyName = dt.Rows[i]["CountyName"].ToString() }; address.StreetName = dt.Rows[i]["StreetName"].ToString(); address.StreetNo = dt.Rows[i]["StreetNo"].ToString(); address.unique = address.RandomString(8); list.Add(address); } return(list); }
public void UpdateDataGridAddress(ClientAddressModel address, ClientAddressForm ca) { if (!ca.IsAddedorModify()) { changeDataGridView = false; } if (address.status == 0) { dataGridClientAddress.Rows.Add(address.ClientAddressId, address.ClientId, address.City.CityName, address.County.CountyName, address.StreetName, address.StreetNo, address.unique, address.status); listAddress.Add(address); } else if (address.status == 1) { foreach (DataGridViewRow row in dataGridClientAddress.Rows) { if (row.Cells[6].Value.ToString() == address.unique.ToString() && row.Cells[0].Value.ToString() == address.ClientAddressId.ToString()) { row.Cells[2].Value = address.City.CityName.ToString(); row.Cells[3].Value = address.County.CountyName.ToString(); row.Cells[4].Value = address.StreetName.ToString(); row.Cells[5].Value = address.StreetNo.ToString(); bool verifyList = listAddress.Any(item => item.unique == address.unique && item.ClientAddressId == address.ClientAddressId); if (!verifyList) { listAddress.Add(address); } else { foreach (ClientAddressModel model in listAddress) { if (model.unique == address.unique && model.ClientAddressId == address.ClientAddressId) { model.City.CityName = address.City.CityName; model.County.CountyName = address.County.CountyName; model.StreetName = address.StreetName; model.StreetNo = address.StreetNo; break; } } } break; } } } }
public BindingList <ClientAddressModel> adressList(int id) { BindingList <ClientAddressModel> listAdrese = new BindingList <ClientAddressModel>(); DataTable dt = new DataTable(); DATotCeFolosescLaInvoice da = new DATotCeFolosescLaInvoice(); dt = da.getClientsAddress(id); for (int i = 0; i < dt.Rows.Count; i++) { ClientAddressModel adresa = new ClientAddressModel(); adresa.ClientAddressId = Convert.ToInt32(dt.Rows[i]["ClientAddressId"].ToString()); adresa.Adresa = dt.Rows[i]["Adresa"].ToString(); listAdrese.Add(adresa); } return(listAdrese); }
private void BtnDeleteAddress_Click(object sender, EventArgs e) { if (dataGridClientAddress.Rows.Count != 0) { int i = dataGridClientAddress.SelectedCells[0].RowIndex; int selectedId = Convert.ToInt32(dataGridClientAddress.Rows[i].Cells[0].Value.ToString()); ClientAddressModel deleteAddress = new ClientAddressModel() { ClientAddressId = selectedId, ClientId = clientId, City = new CityModel { CityId = 0, CityName = dataGridClientAddress.Rows[i].Cells[2].Value.ToString() }, County = new CountyModel { CountyId = 0, CountyName = dataGridClientAddress.Rows[i].Cells[3].Value.ToString() }, StreetName = dataGridClientAddress.Rows[i].Cells[4].Value.ToString(), StreetNo = dataGridClientAddress.Rows[i].Cells[5].Value.ToString(), status = 2, unique = dataGridClientAddress.Rows[i].Cells[6].Value.ToString(), }; if (listAddress.Count == 0) { listAddress.Add(deleteAddress); } else { foreach (ClientAddressModel model in listAddress) { if (model.unique == deleteAddress.unique && model.ClientAddressId != 0) { model.status = 2; break; } else if (model.unique == deleteAddress.unique && model.ClientAddressId == 0) { listAddress.Remove(model); break; } else if (deleteAddress.ClientAddressId != 0) { listAddress.Add(deleteAddress); break; } else { continue; } } } dataGridClientAddress.Rows.RemoveAt(i); } else { MessageBox.Show("Nu se poate sterge nicio adresa deoarece nu exista vreo adresa", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }