private async void Button_Cari_Click(object sender, EventArgs e) { buttonCari.Enabled = false; if (!string.IsNullOrEmpty(boxIDBarang.Text) && buttonCari.Text == "Cari") { loadingDialog = new LoadingDialog(); loadingDialog.Show(); //loadingDialog.Focus(); loadingDialog.Activate(); var html = await HttpClient.GetStringAsync(url + boxIDBarang.Text); var result = Datas.FromJson(html); boxNamaBarang.Text = result.Products[0].nama; boxMitra.Text = result.Products[0].mitra; boxKategori.Text = result.Products[0].kategori; boxSatuanInt.Text = result.Products[0].satuan; boxHarga.Text = result.Products[0].harga; boxDeskripsi.Text = result.Products[0].desc; boxJumlah.Text = result.Products[0].jumlah; filename = result.Products[0].url.Replace("https://kitku.id/productpic/", "").Replace(".jpeg", ""); //Console.WriteLine(filename); // download image WebClient client = new WebClient(); Stream stream = client.OpenRead(result.Products[0].url); Bitmap bitmap; bitmap = new Bitmap(stream); if (bitmap != null) { productPicture.Image = bitmap; } stream.Flush(); stream.Close(); client.Dispose(); loadingDialog.dismiss(); buttonPilihGambar.Enabled = true; buttonCari.Text = "Reset"; boxIDBarang.ReadOnly = true; } else { boxIDBarang.Text = ""; boxIDBarang.ReadOnly = false; boxNamaBarang.Text = ""; boxMitra.Text = ""; boxKategori.Text = ""; boxJumlah.Text = ""; boxSatuanInt.Text = ""; boxHarga.Text = ""; boxDeskripsi.Text = ""; productPicture.Image = null; buttonCari.Text = "Cari"; } buttonCari.Enabled = true; }
public void PostExecute(String json) { var result = Datas.FromJson(json); //Console.WriteLine(result.Pemesanans[0].IdPemesanan); tabelRingkasanPemesanan.ColumnCount = 19; tabelRingkasanPemesanan.Columns[0].Name = "id_pemesanan"; tabelRingkasanPemesanan.Columns[1].Name = "id_pelanggan"; tabelRingkasanPemesanan.Columns[2].Name = "nama_pelanggan"; tabelRingkasanPemesanan.Columns[3].Name = "id_barang"; tabelRingkasanPemesanan.Columns[4].Name = "nama_barang"; tabelRingkasanPemesanan.Columns[5].Name = "id_supplier"; tabelRingkasanPemesanan.Columns[6].Name = "nama_supplier"; tabelRingkasanPemesanan.Columns[7].Name = "jumlah"; tabelRingkasanPemesanan.Columns[8].Name = "diskon_id"; tabelRingkasanPemesanan.Columns[9].Name = "diskon"; tabelRingkasanPemesanan.Columns[10].Name = "harga"; tabelRingkasanPemesanan.Columns[11].Name = "ongkir"; tabelRingkasanPemesanan.Columns[12].Name = "waktu_pemesanan"; tabelRingkasanPemesanan.Columns[13].Name = "waktu_pengiriman"; tabelRingkasanPemesanan.Columns[14].Name = "catatan"; tabelRingkasanPemesanan.Columns[15].Name = "koor"; tabelRingkasanPemesanan.Columns[16].Name = "status"; tabelRingkasanPemesanan.Columns[17].Name = "info"; tabelRingkasanPemesanan.Columns[18].Name = "last_update"; //if (pilihanUrut.Text == "Pelanggan") for (int i = 0; i < result.Pemesanans.Length; i++) { string[] row = new string[] { result.Pemesanans[i].IdPemesanan, result.Pemesanans[i].IdPelanggan, result.Pemesanans[i].NamaPelanggan, result.Pemesanans[i].IdBarang, result.Pemesanans[i].NamaBarang, result.Pemesanans[i].IdSupplier, result.Pemesanans[i].NamaSupplier, result.Pemesanans[i].Jumlah, result.Pemesanans[i].DiskonId, result.Pemesanans[i].Diskon, result.Pemesanans[i].Harga, result.Pemesanans[i].Ongkir, result.Pemesanans[i].WaktuPemesanan, result.Pemesanans[i].WaktuPengiriman, result.Pemesanans[i].Catatan, result.Pemesanans[i].Koor, result.Pemesanans[i].Status, result.Pemesanans[i].Info, result.Pemesanans[i].LastUpdate }; tabelRingkasanPemesanan.Rows.Add(row); } }
private void ButtonSimpan_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(boxIDBarang.Text)) { Datas products = new Datas(); products.id_barang = boxIDBarang.Text; products.nama = boxNamaBarang.Text; products.kategori = boxKategori.Text; products.satuan = boxSatuanInt.Text; products.harga = boxHarga.Text; products.jumlah = boxJumlah.Text; products.deskripsi = boxDeskripsi.Text; var ser = products.ToJson(); Console.WriteLine(ser); // Specify requirement to POST //var stringData = await _httpClient.GetStringAsync(); var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://kitku.id/produk/update"); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; // write data using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { //string json = sr.ReadToEnd(); streamWriter.Write(ser); } // get response var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var res = Datas.FromJson(streamReader.ReadToEnd()); //Console.WriteLine(res.id_supplier); // if data gotten if (res.message.Contains("updated")) { MessageBox.Show("Berhasil mengupdate data barang!", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Gagal mengupdate data barang!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("Silakan masukan ID barang dan lakukan pengeditan pada bagian yang ingin dirubah.", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void ButtonCekMitra_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(boxMitra.Text)) { buttonCekMitra.Enabled = false; Datas datas = new Datas(); var stream1 = new MemoryStream(); datas.nama_supplier = boxMitra.Text; var ser = datas.ToJson(); // Specify requirement to POST //var stringData = await _httpClient.GetStringAsync(); var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://kitku.id/supplier/byname"); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; //String result = ".."; // POST data try { using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { streamWriter.Write(ser); } // get response var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var res = Datas.FromJson(streamReader.ReadToEnd()); //Console.WriteLine(res.id_supplier); // if data gotten if (res.id_supplier != null) { id_supplier = res.id_supplier; boxIDSupplier.Text = id_supplier; } else { MessageBox.Show("Tidak ditemukan supplier dengan nama ini.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception) { } buttonCekMitra.Enabled = true; } }
private void LoginButton_Click(object sender, EventArgs e) { loginButton.Enabled = false; // This line will yield control to the UI as the request // from the web service is happening. // // The UI thread is now free to perform other work. if (string.IsNullOrWhiteSpace(boxUser.Text) || string.IsNullOrWhiteSpace(boxPass.Text)) { MessageBox.Show("Mohon isi user dan/atau password.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { // refer to BackgroundTask.cs for more detail //UserData userData = new UserData(); /*string result = new UserData().execute(userBox.Text, passBox.Text); * // compare response * if (result.Contains("PEL-")) * { * // initialize MainForm * //mainForm = new MainForm(); * this.Hide(); * using (MainForm = new MainForm()) * { * MainForm.FormClosing += MainForm_Closing; * //mainForm.ShowDialog(); * if (MainForm.ShowDialog() == DialogResult.OK) * { * //Console.WriteLine("user " + result); * MainForm.UserLogged = result; * } * } * } * else * MessageBox.Show("Login gagal! Silakan periksa kembali data anda.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); */ Datas datas = new Datas(); datas.id_supplier = boxUser.Text; datas.password = boxPass.Text; var ser = datas.ToJson(); // Specify requirement to POST //var stringData = await _httpClient.GetStringAsync(); var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://kitku.id/pelanggan/login"); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; // write data using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { //string json = sr.ReadToEnd(); streamWriter.Write(ser); } // get response var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var res = Datas.FromJson(streamReader.ReadToEnd()); //Console.WriteLine(res.id_supplier); // if data gotten if (res.message != null) { // initialize MainForm //mainForm = new MainForm(); this.Hide(); using (MainForm = new MainForm()) { MainForm.FormClosing += MainForm_Closing; //mainForm.ShowDialog(); if (MainForm.ShowDialog() == DialogResult.OK) { //Console.WriteLine("user " + result); MainForm.UserLogged = res.message; } } } else { MessageBox.Show("Tidak ditemukan supplier dengan nama ini.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } loginButton.Enabled = true; }
private void ButtonSimpan_Click(object sender, EventArgs e) { buttonSimpan.Enabled = false; if (string.IsNullOrEmpty(boxIDSupplier.Text)) { MessageBox.Show("Silakan dapatkan kode mitra terlebih dahulu dengan mengecek nama mitra", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if ( !string.IsNullOrEmpty(boxKategori.Text) || !string.IsNullOrEmpty(boxKodeBarang.Text) || !string.IsNullOrEmpty(boxNamaBarang.Text) || !string.IsNullOrEmpty(boxSatuanInt.Text) || !string.IsNullOrEmpty(boxHarga.Text) || !string.IsNullOrEmpty(boxDeskripsi.Text) || fileDialog != null ) { // convert to json Datas datas = new Datas(); datas.kategori = boxKategori.Text; datas.id_barang = boxKodeBarang.Text; datas.id_supplier = id_supplier; datas.nama = boxNamaBarang.Text; datas.deskripsi = boxDeskripsi.Text; datas.satuan = boxSatuanInt.Text; datas.harga = boxHarga.Text; var ser = datas.ToJson(); Console.WriteLine(ser); bool dbSuccess = false, imageSuccess = false; // Specify requirement to POST //var stringData = await _httpClient.GetStringAsync(); var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://kitku.id/produk/add"); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; // write data using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { //string json = sr.ReadToEnd(); streamWriter.Write(ser); } // get response var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var res = Datas.FromJson(streamReader.ReadToEnd()); //Console.WriteLine(res.id_supplier); // if data gotten if (res.message != null) { dbSuccess = true; boxIDBarang.Text = res.id_barang; } } string imageUploadMessage = UploadImage.HttpUploadFile("https://kitku.id/produk/updatepic/" + datas.nama.Replace(" ", ""), fileDialog.FileName, null); if (imageUploadMessage.Contains("Success")) { imageSuccess = true; } if (dbSuccess && imageSuccess) { MessageBox.Show("Produk berhasil ditambahkan!", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { if (!dbSuccess) { MessageBox.Show("Produk gagal ditambahkan!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (!imageSuccess) { MessageBox.Show("Gambar gagal diupload!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("Silakan lengkapi data dan gambar untuk menambah produk.", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information); } buttonSimpan.Enabled = true; }