public ActionResult ThemHanMuc(string loaikc, int hanmuc, string thoigian) { HanMucChi hmc = new HanMucChi(); hmc.matv = (string)Session[Ses_Admin.Admin]; hmc.loaikhoanchi = loaikc; hmc.hanmuc = hanmuc; hmc.thoigian = thoigian; using (var client = new HttpClient()) { client.BaseAddress = new Uri(baseAddress); //HTTP POST var postTask = client.PostAsJsonAsync <HanMucChi>("HanMucChi", hmc); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("IndexHanMuc")); } else { ModelState.AddModelError("", "Không thêm được!"); } } return(RedirectToAction("IndexHanMuc")); }
private HanMucChi LayHanMucTheoMa() { int mahm = HanMuc_Session.mahm; HanMucChi hmc = null; using (var client = new HttpClient()) { client.BaseAddress = new Uri(baseAddress); //HTTP GET var responseTask = client.GetAsync($"HanMucChi/{mahm}"); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <HanMucChi>(); readTask.Wait(); hmc = readTask.Result; return(hmc); } else { return(null); } } }
public ActionResult SuaHanMuc(int id) { LoadDataForComboLKC(); HanMucChi res = GetHanMucChiTheoId(id); return(View(res)); }
private void btnThem_Click(object sender, EventArgs e) { if (themhoacsua == 1) { HanMucChi hmc = new HanMucChi(); hmc.matv = MySession.tendangnhap; hmc.loaikhoanchi = (string)cboLoaKC.SelectedValue; hmc.hanmuc = Convert.ToInt32(txtHanMuc.Text.Trim()); hmc.thoigian = dtpThangHM.Text; using (var client = new HttpClient()) { client.BaseAddress = new Uri(baseAddress); //HTTP POST var postTask = client.PostAsJsonAsync <HanMucChi>("HanMucChi", hmc); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { MessageBox.Show("Đã thêm hạn mức!"); } else { MessageBox.Show("Lỗi Server :("); } } } else { HanMucChi hmc = new HanMucChi(); hmc.id = HanMuc_Session.mahm; hmc.matv = MySession.tendangnhap; hmc.loaikhoanchi = (string)cboLoaKC.SelectedValue; hmc.hanmuc = Convert.ToInt32(txtHanMuc.Text.Trim()); hmc.thoigian = dtpThangHM.Text; using (var client = new HttpClient()) { client.BaseAddress = new Uri(baseAddress); //HTTP POST var postTask = client.PutAsJsonAsync <HanMucChi>("HanMucChi", hmc); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { MessageBox.Show("Đã sửa hạn mức!"); } else { MessageBox.Show("Lỗi!"); } } } }
public IHttpActionResult PutHanMucChi([FromBody] HanMucChi hmc) { if (dao.Put_HanMucChi(hmc)) { return(Ok()); } else { return(BadRequest()); } }
private void frmThemHoacSuaHanMuc_Load(object sender, EventArgs e) { LoadDataForComboLoaiKhoanChi(); if (themhoacsua == 1) //đang thêm { btnThem.Text = "Thêm"; } else //đang sửa { btnThem.Text = "Sửa"; HanMucChi hmc = LayHanMucTheoMa(); cboLoaKC.SelectedValue = hmc.loaikhoanchi; txtHanMuc.Text = Convert.ToString(hmc.hanmuc); dtpThangHM.Text = hmc.thoigian; } }
public bool Post_HanMucChi(HanMucChi hmc) { const string proc = "SP_ThemHanMucChi"; List <SqlParameter> para = new List <SqlParameter>() { new SqlParameter("LoaiKhoanChi", hmc.loaikhoanchi), new SqlParameter("HanMuc", hmc.hanmuc), new SqlParameter("ThoiGian", hmc.thoigian), new SqlParameter("MaTV", hmc.matv) }; int res = DataProvider.ExecuteNonQuery(proc, para); if (res > 0) { return(true); } else { return(false); } }
public HanMucChi Get_HanMucChiTheoId(int id) { const string proc = "SP_XemHanMucChiTheoId"; List <SqlParameter> para = new List <SqlParameter>() { new SqlParameter("id", id), }; IDataReader reader = DataProvider.ExecuteReader(proc, para); HanMucChi res = new HanMucChi(); HanMucChi hmuc; while (reader.Read()) { hmuc = new HanMucChi(); hmuc.id = Convert.ToInt32(reader["id"]); hmuc.loaikhoanchi = Convert.ToString(reader["LoaiKhoanChi"]); hmuc.thoigian = Convert.ToString(reader["ThoiGian"]); hmuc.hanmuc = Convert.ToInt32(reader["HanMuc"]); res = hmuc; } return(res); }
public HanMucChi GetHanMucChiTheoId(int id) { HanMucChi hmc = null; using (var client = new HttpClient()) { client.BaseAddress = new Uri(baseAddress); //HTTP GET var responseTask = client.GetAsync($"HanMucChi/{id}"); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <HanMucChi>(); readTask.Wait(); hmc = readTask.Result; return(hmc); } return(null); } }
public IHttpActionResult GetHanMucTheoId(int id) { HanMucChi res = dao.Get_HanMucChiTheoId(id); return(Ok(res)); }