示例#1
0
 private void bt_dangbai_Click(object sender, EventArgs e)
 {
     if (tb_monan.Text!=""&&tb_gia.Text!="")
     {
         ThucDon thd = new ThucDon();
         thd.IdNhaHang = nh.Id;
         thd.MonAn = tb_monan.Text;
         thd.NguyenLieu = tb_nguyenlieu.Text;
         thd.PhuongPhap = tb_phuongphap.Text;
         thd.Gia = int.Parse(tb_gia.Text);
         try
         {
             ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
             client.DangThucDonCompleted += new EventHandler<ServiceReference1.DangThucDonCompletedEventArgs>(DangThucDonCallBack);
             client.DangThucDonAsync(thd);
         }
         catch
         {
             MessageBox.Show("Lỗi Dịch Vụ !", "Warning: ", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     else
     {
         MessageBox.Show("Bạn phải nhập tên và giá của món ăn");
     }
 }
示例#2
0
        internal static void DangThucDon(ThucDon menu)
        {
            conn = new SqlConnection();
            conn.ConnectionString = ConfigurationManager.ConnectionStrings["NH-CF"].ConnectionString;

            // Check connect SQL
            try
            {
                conn.Open();
            }
            catch
            {
                throw new ArgumentException("Không thể kết nối với database !");
            }
            // Gửi góp ý mới
            try
            {
                cmd = new SqlCommand("Insert into ThucDon values (@IdNhaHang,@MonAn,@NguyenLieu,@PhuongPhap,@Gia)", conn);
                cmd.Parameters.AddWithValue("@IdNhaHang", menu.IdNhaHang);
                cmd.Parameters.AddWithValue("@MonAn", menu.MonAn);
                cmd.Parameters.AddWithValue("@NguyenLieu", menu.NguyenLieu);
                cmd.Parameters.AddWithValue("@PhuongPhap", menu.PhuongPhap);
                cmd.Parameters.AddWithValue("@Gia", menu.Gia);
                cmd.ExecuteNonQuery();
                conn.Close();
            }
            catch
            {
                throw new ArgumentException("Không thể đăng thông tin thực đơn !");
            }
        }