Ejemplo n.º 1
0
        private void sendButton_Click(object sender, EventArgs e)
        {
            WebHelper webHelper = new WebHelper();

            Cabang cb = new Cabang();

            cb.Nama_Cabang    = txtName.Text;
            cb.Alamat_Cabang  = txtAddress.Text;
            cb.Telepon_Cabang = txtTelephone.Text;

            string request = JsonConvert.SerializeObject(cb);

            //Uri url = new Uri(string.Format("http://192.168.19.140/8708/api/cabangs/store"));
            Uri url = new Uri(string.Format("http://atmauto.jasonfw.com/api/cabangs/store"));

            string response = webHelper.Post(url, request);

            Clear();

            if (response != null)
            {
                //Handle your reponse here
                string message = "Cabang Success";
                string title   = "Message";
                MessageBox.Show(message, title);
            }
            else
            {
                //No Response from the server
                string message = "Error Cabang";
                string title   = "Message";
                MessageBox.Show(message, title);
            }
            loadData();
        }
        public JsonResult CabangCreate(string Name, string Address)
        {
            try
            {
                using (var db = new LiteDatabase(@"Mineski.db"))
                {
                    // Get customer collection
                    var cabangs = db.GetCollection <Cabang>("cabangs");

                    var cabangData = new Cabang
                    {
                        Name    = Name,
                        Address = Address
                    };

                    // Insert new customer document (Id will be auto-incremented)
                    cabangs.Insert(cabangData);
                }
            }
            catch (Exception exception)
            {
                return(Json(new { success = false, responseText = exception.Message }));
            }

            return(Json(new { success = true }));
        }
Ejemplo n.º 3
0
        private void editButton_Click(object sender, EventArgs e)
        {
            string id = txtSearch.Text;

            foreach (DataGridViewRow row in dataGridViewTable.Rows)
            {
                if (row.Cells[1].Value.ToString().Equals(id))
                {
                    id = row.Cells[0].Value.ToString();
                    Debug.WriteLine("bind :" + id);

                    Cabang cb = new Cabang();
                    cb.Id_Cabang      = txtSearch.Text;
                    cb.Nama_Cabang    = txtName.Text;
                    cb.Alamat_Cabang  = txtAddress.Text;
                    cb.Telepon_Cabang = txtTelephone.Text;
                    try
                    {
                        DialogResult res = MessageBox.Show("Are you sure want to update this data?", "Confirmation",
                                                           MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                        if (res == DialogResult.OK)
                        {
                            string request = JsonConvert.SerializeObject(cb);
                            Uri    url     = new Uri(string.Format("http://192.168.19.140/8708/api/cabangs/update" + id));

                            //Uri url = new Uri(string.Format("http://10.53.4.85:8000/api/cabangs/update/" + id));
                            string response = webHelper.Update(url, request);

                            Clear();
                            loadData();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Update Error", "Message");
                    }
                }
                break;
            }
        }