void deleteData(DataPesanan dp) { string request = JsonConvert.SerializeObject(dp); WebClient client = new WebClient(); client.Headers.Add(HttpRequestHeader.ContentType, "application/json"); string result = client.UploadString(address.basuri + "deletedata", request); }
void addData(DataPesanan pesanan) { //serialization : dari objek ke string json string request = JsonConvert.SerializeObject(pesanan); WebClient client = new WebClient(); client.Headers.Add(HttpRequestHeader.ContentType, "application/json"); string result = client.UploadString(address.basuri + "adddata", request); }
void getData(string inp) { DataPesanan pesanan = new DataPesanan(); string result = new WebClient().DownloadString(address.basuri + "getdata/id=" + inp); pesanan = JsonConvert.DeserializeObject <DataPesanan>(result); txt_psn.Text = pesanan.pesanan; txt_hrg.Text = pesanan.harga; }
private void del_btn_Click(object sender, EventArgs e) { int id = Convert.ToInt32(dgv.CurrentRow.Cells[0].Value); DataPesanan pesanan = new DataPesanan(); pesanan.id = id; deleteData(pesanan); getDataAll(); }
void getData(string inp) { DataPesanan pesanan = new DataPesanan(); string result = new WebClient().DownloadString(address.basuri + "getdata/id=" + inp); pesanan = JsonConvert.DeserializeObject <DataPesanan>(result); List <DataPesanan> pesananList = new List <DataPesanan>(); pesananList.Add(pesanan); dgv.DataSource = pesananList; }
private void button1_Click(object sender, EventArgs e) { DataPesanan input = new DataPesanan(); if (txt_psn.Text != "" && txt_hrg.Text != "") { try { input.pesanan = txt_psn.Text; input.harga = txt_hrg.Text; if (status == 1) { addData(input); Program.Form.getDataAll(); this.Close(); } else if (status == 2) { input.id = id; updateData(input); Program.Form.getDataAll(); this.Close(); } else { } } catch (Exception ee) { MessageBox.Show(ee.Message); } } else { MessageBox.Show("Silahkan isi semua data terlebih dahulu"); } }