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;
        }