Пример #1
0
 public int add(HangSX obj)
 {
     this._db.ds_hangsx.Add(obj);
     //commit
     this.save();
     //return ma moi nhat
     return this._db.ds_hangsx.Max(x => x.id);
 }
Пример #2
0
 public Boolean delete(HangSX obj)
 {
     try
     {
         //get entity
         obj = this.get_by_id(obj.id);
         //remove
         this._db.ds_hangsx.Remove(obj);
         //commit
         return this.save();
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.ToString());
         return false;
     }
 }
Пример #3
0
 public List<string> validate(HangSX obj)
 {
     List<String> re = new List<string>();
     if (obj.ten.Equals(""))
     {
         re.Add("ten_fail");
     }
     return re;
 }
Пример #4
0
 public void change(HangSX hsx)
 {
     ten = hsx.ten;
     active = hsx.active;
 }
 private void btThem_Click(object sender, EventArgs e)
 {
     btXoa.Enabled = false;
     btSua.Enabled = false;
     gbThongTin.Enabled = true;
     ThongTinFormHangSX = new HangSX();
 }
 private void btSua_Click(object sender, EventArgs e)
 {
     if (dtgvHangSX.SelectedRows.Count == 0) return;
     btXoa.Enabled = false;
     btThem.Enabled = false;
     gbThongTin.Enabled = true;
     ThongTinFormHangSX = (HangSX)dtgvHangSX.SelectedRows[0].DataBoundItem;
 }
Пример #7
0
 public int timkiem_count(String id = "", String masp = "", String ten = "", String mota = "", int gia_from = 0, int gia_to = 0, HangSX hangsx = null, String active = "")
 {
     return timkiem(id, masp, ten, mota, gia_from, gia_to, hangsx ,active).Count;
 }
Пример #8
0
        public List<SanPham> timkiem(String id = "", String masp = "", String ten = "", String mota = "", int gia_from = 0, int gia_to = 0, HangSX hangsx = null, String active = "", String order_by = "id", Boolean order_desc = true, int start_point = 0, int count = -1)
        {
            List<SanPham> obj_list = new List<SanPham>();
            //find by LIKE element
            obj_list = this._db.ds_sanpham.Where(x =>
                x.masp.Contains(masp)
                && x.ten.Contains(ten)
                && x.mota.Contains(mota)
                ).ToList();

            //filter by id
            if (!id.Equals(""))
            {
                int id_i = TextLibrary.ToInt(id);
                obj_list = obj_list.Where(x => x.id == id_i).ToList();
            }
            //Filter by gia
            if (gia_from>0 || gia_to>0)
            {
                obj_list = obj_list.Where(x => x.gia >= gia_from && x.gia<=gia_to).ToList();
            }
            //filter by HangSX List
            if (hangsx != null)
            {
                obj_list = obj_list.Where(x => x.hangsx.id == hangsx.id).ToList();
            }

            //Filter again by by active
            if (!active.Equals(""))
            {
                Boolean active_b = TextLibrary.ToBoolean(active);
                obj_list = obj_list.Where(x => x.active == active_b).ToList();
            }

            //order
            if (order_by.Equals("id"))
            {
                if (order_desc)
                {
                    obj_list = obj_list.OrderByDescending(x => x.id).ToList();
                }
                else
                {
                    obj_list = obj_list.OrderBy(x => x.id).ToList();
                }
            }
            else if (order_by.Equals("gia"))
            {
                if (order_desc)
                {
                    obj_list = obj_list.OrderByDescending(x => x.gia).ToList();
                }
                else
                {
                    obj_list = obj_list.OrderBy(x => x.gia).ToList();
                }
            }

            //limit
            if (count >= 0)
            {
                obj_list = obj_list.Skip(start_point).Take(count).ToList();
            }
            //FINAL return
            return obj_list;
        }