Exemplo n.º 1
0
 protected void btnXoa_Click(object sender, EventArgs e)
 {
     try
     {
         if (txtIDKieu.Text.Length > 0)
         {
             tbl_Type type = db.tbl_Type.Find(int.Parse(txtIDKieu.Text));
             db.tbl_Type.Remove(type);
             db.SaveChanges();
             load();
             lbThongBao.Text      = "Bạn đã xóa kiểu sản phẩm thành công";
             lbThongBao.ForeColor = System.Drawing.Color.Green;
         }
         else
         {
             lbThongBao.Text      = "Bạn chưa chọn kiểu sản phẩm cần xóa";
             lbThongBao.ForeColor = System.Drawing.Color.Red;
         }
     }
     catch (Exception ex)
     {
         lbThongBao.Text      = "Đã có lỗi xảy ra. Vui lòng thử lại sau.";
         lbThongBao.ForeColor = System.Drawing.Color.Red;
     }
 }
Exemplo n.º 2
0
        public ActionResult Edit(int id)
        {
            try
            {
                var UserProfile = (UserProfileSessionData)this.Session["UserProfile"];
                if (UserProfile != null)
                {
                    DataOperations dataOperations = new DataOperations();
                    tbl_Type       typleDB        = dataOperations.GetTypeById(id);
                    TypeVM         viewModel      = new TypeVM()
                    {
                        ID          = typleDB.ID,
                        Name        = typleDB.Name,
                        ParentID    = typleDB.ParentID,
                        Description = typleDB.Description
                    };
                    viewModel = poulateParentList(viewModel);

                    return(View(viewModel));
                }
                return(null);
            }
            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Error", "Error")));
            }
        }
Exemplo n.º 3
0
        public ActionResult Create(TypeVM typeViewModel)
        {
            var UserProfile = (UserProfileSessionData)this.Session["UserProfile"];

            if (UserProfile != null)
            {
                tbl_Type typeItem = new tbl_Type()
                {
                    Name        = typeViewModel.Name,
                    Description = typeViewModel.Description,
                    InsertUser  = UserProfile.UserId
                };

                DataOperations dateOperation = new DataOperations();
                tbl_Type       typeDB        = dateOperation.AddType(typeItem);
                if (typeDB != null)
                {
                    TempData["success"] = "Ok";
                    TempData["message"] = "Məlumatlar uğurla əlavə olundu";
                }
                else
                {
                    TempData["success"] = "notOk";
                    TempData["message"] = "Məlumatlar əlavə olunarkən xəta baş verdi";
                }
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
        protected void btnThem_Click(object sender, EventArgs e)
        {
            tbl_Type type = new tbl_Type();

            try
            {
                if (txtKieu.Text.Length > 0)
                {
                    type.Type_Name = txtKieu.Text;
                    db.tbl_Type.Add(type);
                    db.SaveChanges();
                    load();
                    reset();
                    lbThongBao.Text      = "Bạn thêm thành công";
                    lbThongBao.ForeColor = System.Drawing.Color.Green;
                }
                else
                {
                    lbThongBao.Text      = "Chưa nhập dữ liệu";
                    lbThongBao.ForeColor = System.Drawing.Color.Red;
                }
            }
            catch
            {
                lbThongBao.Text      = "Đã có lỗi xảy ra. Vui lòng thử lại sau.";
                lbThongBao.ForeColor = System.Drawing.Color.Red;
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            tbl_Type tbl_Type = db.tbl_Type.Find(id);

            db.tbl_Type.Remove(tbl_Type);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 6
0
        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            Label    lblMa = (Label)GridView1.Rows[e.NewEditIndex].FindControl("lbMa");
            tbl_Type p     = db.tbl_Types.SingleOrDefault(c => c.Type_ID == int.Parse(lblMa.Text));

            txtMa.Text          = p.Type_ID.ToString();
            txttenML.Text       = p.Type_Name.ToString();
            GridView1.EditIndex = e.NewEditIndex;
            load();
        }
 public ActionResult Edit(tbl_Type tbl_Type)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tbl_Type).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.FK_CateID = new SelectList(db.tbl_Category, "Cat_Id", "Cat_Name", tbl_Type.FK_CateID);
     return(View(tbl_Type));
 }
Exemplo n.º 8
0
        protected void Button3_Click(object sender, EventArgs e)
        {
            tbl_Type t = db.tbl_Types.SingleOrDefault(c => c.Type_ID == int.Parse(txtMa.Text));

            db.tbl_Types.DeleteOnSubmit(t);
            db.SubmitChanges();
            load();
            Label1.Text = "Xoá thành công.";
            rong();
            txttenML.Focus();
        }
        public ActionResult Create(tbl_Type tbl_Type)
        {
            if (ModelState.IsValid)
            {
                db.tbl_Type.Add(tbl_Type);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.FK_CateID = new SelectList(db.tbl_Category, "Cat_Id", "Cat_Name", tbl_Type.FK_CateID);
            return(View(tbl_Type));
        }
Exemplo n.º 10
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            tbl_Type t = new tbl_Type();

            t.Type_Name = txttenML.Text;
            db.tbl_Types.InsertOnSubmit(t);
            db.SubmitChanges();
            load();
            Label1.Text = "Thêm thành công";
            rong();
            txttenML.Focus();
        }
        // GET: Admin/Type/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tbl_Type tbl_Type = db.tbl_Type.Find(id);

            if (tbl_Type == null)
            {
                return(HttpNotFound());
            }
            return(View(tbl_Type));
        }
        // GET: Admin/Type/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tbl_Type tbl_Type = db.tbl_Type.Find(id);

            if (tbl_Type == null)
            {
                return(HttpNotFound());
            }
            ViewBag.FK_CateID = new SelectList(db.tbl_Category, "Cat_Id", "Cat_Name", tbl_Type.FK_CateID);
            return(View(tbl_Type));
        }
Exemplo n.º 13
0
        public ActionResult Edit(TypeVM viewModel)
        {
            try
            {
                DataOperations dataOperations = new DataOperations();
                var            UserProfile    = (UserProfileSessionData)this.Session["UserProfile"];
                if (UserProfile != null)
                {
                    if (!ModelState.IsValid)
                    {
                        return(View(viewModel));
                    }
                    int parentID = viewModel.ParentID == null ? 0 : (int)viewModel.ParentID;

                    tbl_Type type = new tbl_Type()
                    {
                        ID          = (int)viewModel.ID,
                        ParentID    = parentID,
                        Name        = viewModel.Name,
                        Description = viewModel.Description,
                        UpdateUser  = UserProfile.UserId
                    };


                    tbl_Type updatedItemDB = dataOperations.UpdateType(type);
                    if (updatedItemDB != null)
                    {
                        TempData["success"] = "Ok";
                        TempData["message"] = "Məlumatlar uğurla dəyişdirildi";
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        TempData["success"] = "notOk";
                        TempData["message"] = "Məlumatlar dəyişdirilərkən xəta baş verdi";
                        return(RedirectToAction("Index"));
                    }
                }


                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Error", "Error")));
            }
        }
Exemplo n.º 14
0
        protected void btnThem_Click(object sender, EventArgs e)
        {
            tbl_Type type = new tbl_Type();

            try
            {
                if (txtKieu.Text.Length > 0)
                {
                    type.Type_Name = txtKieu.Text;
                    if (fileName != "")
                    {
                        type.Image = fileName;
                    }
                    else
                    {
                        string tenfile    = Image1.ImageUrl;
                        int    indexLast  = tenfile.LastIndexOf('/');
                        string tenfilemoi = tenfile.Substring(indexLast + 1);
                        type.Image = tenfilemoi;
                    }
                    db.tbl_Type.Add(type);
                    db.SaveChanges();
                    load();
                    reset();
                    lbThongBao.Text      = "Bạn thêm thành công";
                    lbThongBao.ForeColor = System.Drawing.Color.Green;
                }
                else
                {
                    lbThongBao.Text      = "Chưa nhập dữ liệu";
                    lbThongBao.ForeColor = System.Drawing.Color.Red;
                }
            }
            catch
            {
                lbThongBao.Text      = "Đã có lỗi xảy ra. Vui lòng thử lại sau.";
                lbThongBao.ForeColor = System.Drawing.Color.Red;
            }
        }
Exemplo n.º 15
0
 protected void btnSua_Click(object sender, EventArgs e)
 {
     try
     {
         if (txtIDKieu.Text.Length > 0)
         {
             tbl_Type type = db.tbl_Type.Find(int.Parse(txtIDKieu.Text));
             type.Type_Name = txtKieu.Text;
             if (fileName != "")
             {
                 type.Image = fileName;
             }
             else
             {
                 string tenfile    = Image1.ImageUrl;
                 int    indexLast  = tenfile.LastIndexOf('/');
                 string tenfilemoi = tenfile.Substring(indexLast + 1);
                 type.Image = tenfilemoi;
             }
             db.SaveChanges();
             load();
             reset();
             lbThongBao.Text      = "Sửa thành công";
             lbThongBao.ForeColor = System.Drawing.Color.Green;
         }
         else
         {
             lbThongBao.Text      = "Bạn chưa chọn kiểu cần xóa";
             lbThongBao.ForeColor = System.Drawing.Color.Red;
         }
     }
     catch (Exception ex)
     {
         lbThongBao.Text      = "Đã có lỗi xảy ra. Vui lòng thử lại sau.";
         lbThongBao.ForeColor = System.Drawing.Color.Red;
     }
 }