public static bool Update(DTO.Mon m) { if (Connect.connection.State == ConnectionState.Closed) { Connect.connection.Open(); } else { Connect.connection.Open(); } SqlCommand dc = new SqlCommand(@"update Mon set tenmon = N'" + m.tenmon + "', tenloai = N'" + m.tenloai + "',gia = " + m.gia + " where id = " + m.id, Connect.connection); dc.ExecuteNonQuery(); Connect.connection.Close(); return(true); }
private void Button_Click_1(object sender, RoutedEventArgs e) { DTO.Mon m = new DTO.Mon { id = idselect, tenmon = tenmon.Text, tenloai = loaimon.Text, gia = Int32.Parse(gia.Text) }; if (ATO.Mon.Add(m) == true) { MessageBox.Show("Thêm Thành Công"); Loaddata(); } else { MessageBox.Show("Thêm Thất Bại, Trùng tên"); } }
private void Button_Click_3(object sender, RoutedEventArgs e) { DTO.Mon m = new DTO.Mon { id = idselect, tenmon = tenmon.Text, tenloai = loaimon.Text, gia = Int32.Parse(gia.Text) }; if (ATO.Mon.Update(m) == true) { MessageBox.Show("Sửa Thành Công"); Loaddata(); } else { MessageBox.Show("Sửa Thất Bại, mời chọn món muốn sửa."); } }
public static bool Add(DTO.Mon m) { try { if (Connect.connection.State == ConnectionState.Closed) { Connect.connection.Open(); } else { Connect.connection.Open(); } SqlCommand dc = new SqlCommand(@"insert Mon(tenmon, tenloai, gia) values(N'" + m.tenmon + "', N'" + m.tenloai + "'," + m.gia + ")", Connect.connection); dc.ExecuteNonQuery(); Connect.connection.Close(); return(true); } catch { return(false); } }