Exemplo n.º 1
0
        public ActionResult ThemTietKiem(DateTime ngay, int sotien, string mucdich)
        {
            TietKiem tk = new TietKiem();

            tk.matv    = (string)Session[Ses_Admin.Admin];
            tk.ngay    = ngay;
            tk.sotien  = sotien;
            tk.mucdich = mucdich;
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(baseAddress);

                //HTTP POST
                var postTask = client.PostAsJsonAsync <TietKiem>("TietKiem", tk);
                postTask.Wait();

                var result = postTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("", "Không thêm được!");
                }
            }
            return(Redirect("~/Error/Error"));
        }
Exemplo n.º 2
0
        public ActionResult SuaTietKiem(int matk, DateTime ngay, int sotien, string mucdich)
        {
            TietKiem tk = new TietKiem();

            tk.matk    = matk;
            tk.ngay    = ngay;
            tk.sotien  = sotien;
            tk.mucdich = mucdich;
            //  tk.matv = (string)Session[Ses_Admin.Admin];
            //  tk.loai = loai;
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(baseAddress);

                //HTTP POST
                var postTask = client.PutAsJsonAsync <TietKiem>("TietKiem", tk);
                postTask.Wait();

                var result = postTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(Redirect("~/Error/Error"));
                }
            }
            //  return RedirectToAction("Index");
        }
Exemplo n.º 3
0
        public ActionResult SuaTietKiem(int matk)
        {
            LoadDataForMucDich((string)Session[Ses_Admin.Admin]);
            TietKiem resp = new TietKiem();

            resp = LayTKTheoMa(matk);
            return(View(resp));
        }
        private void btnThem_Click(object sender, EventArgs e)
        {
            if (TietKiem_Session.themhoacsua == 2)
            {
                TietKiem tk = new TietKiem();
                tk.matk    = TietKiem_Session.matk;
                tk.matv    = MySession.tendangnhap;
                tk.ngay    = dtpNgay.Value;
                tk.sotien  = Convert.ToInt32(txtSoTien.Text.Trim());
                tk.mucdich = (string)cboMucDich.SelectedValue;

                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(baseAddress);

                    //HTTP POST
                    var postTask = client.PutAsJsonAsync <TietKiem>("TietKiem", tk);
                    postTask.Wait();

                    var result = postTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        MessageBox.Show("Đã sửa!");
                    }
                    else
                    {
                        MessageBox.Show("404 Error");
                    }
                }
            }
            else
            {
                TietKiem tk = new TietKiem();
                tk.matk    = TietKiem_Session.matk;
                tk.matv    = MySession.tendangnhap;
                tk.ngay    = dtpNgay.Value;
                tk.sotien  = Convert.ToInt32(txtSoTien.Text.Trim());
                tk.mucdich = (string)cboMucDich.SelectedValue;

                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(baseAddress);
                    var postTask = client.PostAsJsonAsync <TietKiem>("TietKiem", tk);
                    postTask.Wait();

                    var result = postTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        MessageBox.Show("Đã thêm!");
                    }
                    else
                    {
                        MessageBox.Show("404 Error");
                    }
                }
            }
        }
Exemplo n.º 5
0
        public IHttpActionResult Get_TimKiem(int MaTK)
        {
            TietKiem resp = dao.SearchTietKiem(MaTK);

            if (resp == null)
            {
                return(NotFound());
            }
            return(Ok(resp));
        }
Exemplo n.º 6
0
        public IHttpActionResult PostTietKiem([FromBody] TietKiem tk)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Not a valid model"));
            }

            if (dao.PostTietKiem(tk) == false)
            {
                return(BadRequest("Not a valid model"));
            }

            return(Ok());
        }
        private void frmThemMoiHoacSuaTietKiem_Load(object sender, EventArgs e)
        {
            LoadDataForMucDich(thanhvien);

            if (TietKiem_Session.themhoacsua == 2) // click vào sửa bên UC
            {
                btnThem.Text = "Sửa";
                int      matk = TietKiem_Session.matk;
                TietKiem tk   = LayTKTheoMa(matk);
                cboMucDich.SelectedValue = tk.mucdich;
                dtpNgay.Value            = tk.ngay;
                txtSoTien.Text           = tk.sotien.ToString();
            }
            else
            {
                btnThem.Text = "Thêm";
            }
        }
Exemplo n.º 8
0
        public bool PutTietKiem(TietKiem tk)
        {
            const string        proc = "SP_SuaTietKiem";
            List <SqlParameter> para = new List <SqlParameter>()
            {
                new SqlParameter("MaTK", tk.matk),
                new SqlParameter("Ngay", tk.ngay),
                new SqlParameter("SoTien", tk.sotien),
                new SqlParameter("MucDich", tk.mucdich)
            };
            int res = DataProvider.ExecuteNonQuery(proc, para);

            if (res > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public TietKiem LayTKTheoMa(int matk)
        {
            TietKiem tk = new TietKiem();

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(baseAddress);
                //HTTP GET
                var responseTask = client.GetAsync($"TietKiem?MaTK={matk}");
                responseTask.Wait();

                var result = responseTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <TietKiem>();
                    readTask.Wait();

                    tk = readTask.Result;
                    return(tk);
                }
            }
            return(tk);
        }
Exemplo n.º 10
0
        public List <TietKiem> GetTietKiem(string matv)
        {
            const string        proc = "SP_XemTietKiem";
            List <SqlParameter> para = new List <SqlParameter>()
            {
                new SqlParameter("matv", matv)
            };
            IDataReader     reader = DataProvider.ExecuteReader(proc, para);
            List <TietKiem> result = new List <TietKiem>();
            TietKiem        tk;

            while (reader.Read())
            {
                tk         = new TietKiem();
                tk.matk    = Convert.ToInt32(reader["MaTK"]);
                tk.ngay    = Convert.ToDateTime(reader["Ngay"]);
                tk.sotien  = Convert.ToInt32(reader["SoTien"]);
                tk.matv    = Convert.ToString(reader["ThanhVien"]);
                tk.mucdich = Convert.ToString(reader["TenMucDich"]);
                result.Add(tk);
            }
            return(result);
        }
Exemplo n.º 11
0
        public TietKiem SearchTietKiem(int MaTK)
        {
            const string        proc = "SP_TimKiemTietKiem";
            List <SqlParameter> para = new List <SqlParameter>()
            {
                new SqlParameter("matk", MaTK)
            };
            IDataReader reader = DataProvider.ExecuteReader(proc, para);
            TietKiem    res    = new TietKiem();
            TietKiem    tk;

            while (reader.Read())
            {
                tk         = new TietKiem();
                tk.matk    = Convert.ToInt32(reader["MaTK"]);
                tk.ngay    = Convert.ToDateTime(reader["Ngay"]);
                tk.sotien  = Convert.ToInt32(reader["SoTien"]);
                tk.matv    = Convert.ToString(reader["ThanhVien"]);
                tk.mucdich = Convert.ToString(reader["MucDich"]);
                res        = tk;
            }
            return(res);
        }