public void AccessUserForm_Sua(int idForm, int idUser, bool active) { admin_AccessUserForm update = db.admin_AccessUserForms.Where(x => x.form_id == idForm && x.username_id == idUser).FirstOrDefault(); update.uf_active = active; try { db.SubmitChanges(); } catch { } }
public void AccessUserForm_Them(int idForm, int idUser) { admin_AccessUserForm insert = new admin_AccessUserForm(); insert.username_id = idUser; insert.form_id = idForm; insert.uf_active = true; db.admin_AccessUserForms.InsertOnSubmit(insert); try { db.SubmitChanges(); } catch { } }
protected void btnAccessUF_Click(object sender, EventArgs e) { int _idUser = Convert.ToInt32(grvUser.GetRowValues(grvUser.FocusedRowIndex, new string[] { "username_id" })); int _idForm = Convert.ToInt32(grvUserForm.GetRowValues(grvUserForm.FocusedRowIndex, new string[] { "form_id" })); var checkUF = from tb in db.admin_AccessUserForms where tb.username_id == _idUser && tb.form_id == _idForm select tb; if (checkUF.Count() > 0) { admin_AccessUserForm update = checkUF.FirstOrDefault(); if (update.uf_active == true) { update.uf_active = false; } else { update.uf_active = true; } } else { admin_AccessUserForm insert = new admin_AccessUserForm(); insert.username_id = _idUser; insert.form_id = _idForm; insert.uf_active = true; db.admin_AccessUserForms.InsertOnSubmit(insert); } try { db.SubmitChanges(); ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "Alert", "swal('Cập nhật thành công','','success').then(function(){grvUserForm.Refresh();})", true); } catch { ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "Alert", "swal('Cập nhật thất bại','','error')", true); } }
protected void btnLuF_Click(object sender, EventArgs e) { int _idGUser = Convert.ToInt32(grvGUser.GetRowValues(grvGUser.FocusedRowIndex, new string[] { "groupuser_id" })); //int _idUser = Convert.ToInt32(grvUser.GetRowValues(grvUser.FocusedRowIndex, new string[] { "username_id" })); //Lấy idForm string checkidF = txtId.Value; string[] getcheckid = checkidF.Split(','); foreach (var item in getcheckid) { var checkGUF = from tb in db.admin_AccessGroupUserForms where tb.groupuser_id == _idGUser && tb.form_id == Convert.ToInt32(item) select tb; if (checkGUF.Count() > 0) { admin_AccessGroupUserForm update = checkGUF.FirstOrDefault(); if (update.guf_active == true) { update.guf_active = false; } else { update.guf_active = true; } } else { admin_AccessGroupUserForm insert = new admin_AccessGroupUserForm(); insert.groupuser_id = _idGUser; insert.form_id = Convert.ToInt32(item); insert.guf_active = true; db.admin_AccessGroupUserForms.InsertOnSubmit(insert); } try { db.SubmitChanges(); ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "Alert", "swal('Cập nhật thành công','','success').then(function(){grvForm.Refresh();grvUserForm.Refresh();})", true); } catch { ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "Alert", "swal('Cập nhật thất bại','','error')", true); } string checkidUser = txtIdUser.Value; string[] getcheckidU = checkidUser.Split(','); //Insert value vào admin_AccessUserForm foreach (var _idUser in getcheckidU) { var checkUF = from tb in db.admin_AccessUserForms where tb.username_id == Convert.ToInt32(_idUser) && tb.form_id == Convert.ToInt32(item) select tb; if (checkUF.Count() > 0) { admin_AccessUserForm update = checkUF.FirstOrDefault(); if (update.uf_active == true) { update.uf_active = false; } else { update.uf_active = true; } } else { admin_AccessUserForm insert = new admin_AccessUserForm(); insert.username_id = Convert.ToInt32(_idUser); insert.form_id = Convert.ToInt32(item); insert.uf_active = true; db.admin_AccessUserForms.InsertOnSubmit(insert); } try { db.SubmitChanges(); ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "Alert", "swal('Cập nhật thành công','','success').then(function(){grvUserForm.Refresh();})", true); } catch { ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "Alert", "swal('Cập nhật thất bại','','error')", true); } } } txtId.Value = ""; txtCountId.Value = "0"; //txtIdUser.Value = ""; //txtCountIdUser.Value = "0"; //btnLuF.Visible = true; }