public string PostLoadVe(ObjectPostHuyVe objhuyve) { string JSONresult; DataTable dt = busHuyVe.LoadDataGridViewHuyVe(objhuyve.dtoKhachHang, objhuyve.dtoVeChuyenBay); JSONresult = JsonConvert.SerializeObject(dt); return(JSONresult); }
private async void TimKiemBtn_Click(object sender, EventArgs e) { if (CMNDTxt.Text != "" && MaVeChuyenBayTxt.Text != "") { dtoKhachHang.CMND = CMNDTxt.Text; dtoVeChuyenbay.MaVeChuyenBay = MaVeChuyenBayTxt.Text; try { ObjectPostHuyVe Obj = new ObjectPostHuyVe { dtoKhachHang = dtoKhachHang, dtoVeChuyenBay = dtoVeChuyenbay }; //start get value String JSONresult = "{}"; // init HttpResponseMessage response = await client.PostAsJsonAsync("huyve/load-ve-may-bay-huy", Obj); //Get, Post, Put, Delete method if (response.IsSuccessStatusCode) //response success { JSONresult = await response.Content.ReadAsStringAsync(); } JSONresult = JsonConvert.DeserializeObject <string>(JSONresult); // remove backslash from json string DataTable dtHuyVe = (DataTable)JsonConvert.DeserializeObject(JSONresult, (typeof(DataTable))); //fill json to datatable //end HuyVeDataGridView.DataSource = dtHuyVe; } catch { MessageBox.Show("Không có vé như thông tin"); } } else { MessageBox.Show("Vui lòng điền đầy đủ thông tin!!!"); } }