private async void m_btnNew_Click(object sender, EventArgs e) { DetailStore detailStore = new DetailStore(null); if (detailStore.ShowDialog() == DialogResult.OK) { if (m_dtStores.Rows.Count > 0) { DataRow newStore = m_dtStores.NewRow(); newStore["StoreId"] = detailStore.Store.StoreId; newStore["Name"] = detailStore.Store.Name; newStore["Address"] = detailStore.Store.Address; newStore["StatusId"] = detailStore.Store.StatusId; m_dtStores.Rows.Add(newStore); } else { // If is the first row, datatable does not have column definition, then call get api await Retrieve(); } detailStore.Dispose(); } }
private async void m_btnEdit_Click(object sender, EventArgs e) { try { if (m_dgvStoreList.SelectedRows.Count == 0) { MessageBox.Show("No hay una tienda seleccionada", "AVISO"); return; } int StoreId = Convert.ToInt32(m_dgvStoreList.SelectedRows[0].Cells["StoreId"].Value); Response response = await APIUtilities.Get("services/stores/" + StoreId); if (response != null) { if (response.Success) { Store store = (Store)JsonConvert.DeserializeObject(response.Component.ToString(), (typeof(Store))); DetailStore detailStore = new DetailStore(store); if (detailStore.ShowDialog() == DialogResult.OK) { DataRow StoreRow = m_dtStores.Rows.Find(StoreId); StoreRow["Name"] = detailStore.Store.Name; StoreRow["Address"] = detailStore.Store.Address; detailStore.Dispose(); } } else { MessageBox.Show(response.ErrorMessage, "ERROR"); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR DE SISTEMA"); } }