private void BtnXoa_Click(object sender, EventArgs e) { if (conn.State == ConnectionState.Open) { conn.Close(); } DialogResult = MessageBox.Show("Are you sure want to delete", "Norther says", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (DialogResult == DialogResult.Yes) { try { conn.Open(); SqlCommand command = new SqlCommand("Delete from Providers where ProviderID = @pro", conn); command.Parameters.Add("@pro", SqlDbType.Int).Value = int.Parse(LstTenNCC.SelectedValue.ToString()); command.ExecuteNonQuery(); conn.Close(); GetListProvider(); LstTenNCC.Refresh(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Norther says", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
private void BtnCapNhat_Click(object sender, EventArgs e) { if (conn.State == ConnectionState.Open) { conn.Close(); } try { conn.Open(); SqlCommand command = new SqlCommand("Update Providers set Name = @p1,Address =@p2,Tel=@p3,TypeName=@p4 where ProviderID = " + Int32.Parse(LstTenNCC.SelectedValue.ToString()) + "", conn); command.Parameters.Add("@p1", SqlDbType.NVarChar, 50).Value = TxtName.Text.ToString(); command.Parameters.Add("@p2", SqlDbType.NVarChar, 50).Value = TxtDiachi.Text.ToString(); command.Parameters.Add("@p3", SqlDbType.NVarChar, 10).Value = TxtDienThoai.Text.ToString(); command.Parameters.Add("@p4", SqlDbType.NVarChar, 50).Value = TxtMatHangCC.Text.ToString(); int i = command.ExecuteNonQuery(); if (i > 0) { MessageBox.Show("Cập nhật thay đổi thành công", "Norther says", MessageBoxButtons.OK, MessageBoxIcon.Information); } GetListProvider(); GetProviderInfo(); LstTenNCC.Refresh(); conn.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Norther says", MessageBoxButtons.OK, MessageBoxIcon.Warning); } finally { conn.Close(); } }