private void btn_luu_Click(object sender, EventArgs e)
        {
            var kiemtra = from kt in db.Maus where kt.MaMau == txt_mamau.Text select kt;

            if (kiemtra.Count() > 0)
            {
                MessageBox.Show("Trùng khóa. Vui lòng nhập lại!!!");
                return;
            }

            if (txt_mamau.Text == "" || txt_tenmau.Text == "")
            {
                MessageBox.Show("Vui lòng nhập đầy đủ thông tin!!!");
            }
            else
            {
                Mau mau = new Mau();
                mau.MaMau  = txt_mamau.Text;
                mau.TenMau = txt_tenmau.Text;
                db.Maus.InsertOnSubmit(mau);
                db.SubmitChanges();
                frm_mau_Load(sender, e);
                MessageBox.Show("Thêm thành công");
            }
            txt_mamau.Enabled = false;
        }
示例#2
0
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        int  id  = Convert.ToInt32((sender as LinkButton).CommandArgument);
        bool res = false;

        try
        {
            Mau.Mau_Delete(id);
            res = true;
            Clear();
        }
        catch (SqlException ex)
        {
            Console.WriteLine(ex.Message);
            res = false;
        }

        if (res == true)
        {
            lbSuccess.Text = "Deleted successfully!!";
        }
        else
        {
            lbError.Text = "There's something wrong. We cannot save your work";
        }
    }
示例#3
0
        public ActionResult DeleteConfirmed(int id)
        {
            Mau mau = db.Maus.Find(id);

            db.Maus.Remove(mau);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#4
0
        public int Insert(Mau obj)
        {
            SqlParameter[] para =
            {
                new SqlParameter("Mau", obj.mauSP)
            };

            return(base.ExcuteSQL("MAU_Insert", para));
        }
示例#5
0
 public ActionResult Edit([Bind(Include = "Mamau,Tenmau")] Mau mau)
 {
     if (ModelState.IsValid)
     {
         db.Entry(mau).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(mau));
 }
示例#6
0
        public int Update(Mau obj)
        {
            SqlParameter[] para =
            {
                new SqlParameter("MaMau", obj.maMau),
                new SqlParameter("Mau",   obj.mauSP)
            };

            return(base.ExcuteSQL("MAU_Update", para));
        }
示例#7
0
        public ActionResult Create([Bind(Include = "Mamau,Tenmau")] Mau mau)
        {
            if (ModelState.IsValid)
            {
                db.Maus.Add(mau);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(mau));
        }
示例#8
0
 public bool insert(Mau mau)
 {
     try
     {
         mau.Code = "#" + mau.Code;
         db.Maus.Add(mau);
         db.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
示例#9
0
        // GET: Mau/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Mau mau = db.Maus.Find(id);

            if (mau == null)
            {
                return(HttpNotFound());
            }
            return(View(mau));
        }
示例#10
0
 public bool update(Mau mau)
 {
     try
     {
         var mauUpdate = db.Maus.Find(mau.ID);
         mauUpdate.Name = mau.Name;
         mauUpdate.Code = "#" + mau.Code;
         db.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
示例#11
0
 public JsonResult Save(Mau mau)
 {
     if (mau.ID > 0)
     {
         return(Json(new
         {
             //them danh muc
             status = new MauDAO().update(mau)
         }));
     }
     else
     {
         return(Json(new
         {
             //cap nhat danh muc
             status = new MauDAO().insert(mau)
         }));
     }
 }
示例#12
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        bool res = false;

        try
        {
            if (btnSave.Text == "Save")
            {
                Mau.Mau_Insert(tbTenMau.Text, 0);
            }
            else
            {
                Mau.Mau_Update(Convert.ToInt32(hfMauID.Value), tbTenMau.Text);
            }
            res = true;
            Clear();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            res = false;
        }

        if (res == true)
        {
            if (btnSave.Text == "Save")
            {
                lbSuccess.Text = "Saved successfully!!";
            }
            else if (btnSave.Text == "Update")
            {
                lbSuccess.Text = "Updated successfully!!";
            }
        }
        else
        {
            lbError.Text = "There's something wrong. We cannot save your work";
        }
    }
示例#13
0
        /// <summary>
        /// Models to entity.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns>Mau.</returns>
        protected virtual Mau ModelToEntity(MauModel model)
        {
            Mau a = MauService.GetById(model.ID);

            return(a == null ? null : model.ToEntity(a));
        }
示例#14
0
 public int Insert(Mau obj)
 {
     return(dal.Insert(obj));
 }
示例#15
0
 public int Update(Mau obj)
 {
     return(dal.Update(obj));
 }
示例#16
0
            public override string ToString()
            {
                String s = Tu.ToString() + "/" + Mau.ToString();

                return(s);
            }
 /// <summary>
 /// To the model.
 /// </summary>
 /// <param name="entity">The entity.</param>
 /// <returns>MauModel.</returns>
 public static MauModel ToModel(this Mau entity)
 {
     return(entity.MapTo <Mau, MauModel>());
 }
示例#18
0
 public void Insert(Mau entity)
 {
     repos.Insert(entity);
 }
示例#19
0
 public void Delete(Mau entity)
 {
     repos.Delete(entity);
 }
示例#20
0
 public void Update(Mau entity)
 {
     repos.Update(entity);
 }
 /// <summary>
 /// To the entity.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <param name="destination">The destination.</param>
 /// <returns>Mau.</returns>
 public static Mau ToEntity(this MauModel model, Mau destination)
 {
     return(model.MapTo(destination));
 }
 public bool ThemMau(string Mau)
 {
     Mau mau = new Mau();
     mau.TenMau = Mau;
     try
     {
         using (DBGiayDepEntities db = new DBGiayDepEntities())
         {
             db.Maus.Add(mau);
             db.SaveChanges();
             return true;
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
         return false;
     }
 }