protected void addButton_Click(object sender, EventArgs e) { MenuAndSubMenuDAO oMenuAndSubMenuDAO = new MenuAndSubMenuDAO(); for (int i = 0; i < menuItemDropDownList.Items.Count; i++) { MenuEntity oMenuEntity = new MenuEntity(); string condition = " where MenuNo='" + menuItemDropDownList.Items[i].Value + "'"; DataTable dt = oMenuAndSubMenuDAO.GetMenu(condition); oMenuEntity.MenuNo = menuItemDropDownList.Items[i].Value; oMenuEntity.MenuName = menuItemDropDownList.Items[i].Text; oMenuEntity.CreateBy = DateTime.Now.ToShortDateString(); oMenuEntity.LastModifiedBy = DateTime.Now.ToShortDateString(); if (dt.Rows.Count > 0) { int j = oMenuAndSubMenuDAO.DeleteMenu(oMenuEntity); } else { int j = oMenuAndSubMenuDAO.InsertMenu(oMenuEntity); } } for (int i = 0; i < GridView1.Rows.Count; i++) { SubMenuEntity oSubMenuEntity = new SubMenuEntity(); //oSubMenuEntity.ID =Convert.ToInt16(((Label)GridView1.Rows[i].FindControl("idLabel")).Text); oSubMenuEntity.SubMenuNo = ((Label)GridView1.Rows[i].FindControl("SubMenuNoLabel")).Text; oSubMenuEntity.SubMenuName = ((Label)GridView1.Rows[i].FindControl("SubMenuNameLabel")).Text; oSubMenuEntity.MenuNo = ((Label)GridView1.Rows[i].FindControl("MenuNoLabel")).Text; oSubMenuEntity.CreateBy = DateTime.Now.ToShortDateString(); oSubMenuEntity.LastModifiedBy = DateTime.Now.ToShortDateString(); string condition = " where SubMenuNo='" + oSubMenuEntity.SubMenuNo + "' and MenuNo='" + oSubMenuEntity.MenuNo + "'"; DataTable dt = oMenuAndSubMenuDAO.GetSubMenu(condition); if (dt.Rows.Count > 0) { int j = oMenuAndSubMenuDAO.DeleteSubMenu(oSubMenuEntity); } else { int j = oMenuAndSubMenuDAO.InsertSubMenu(oSubMenuEntity); } } }
protected void saveButton_Click(object sender, EventArgs e) { if (userNameDropDownList.SelectedValue == "" || userNameDropDownList.SelectedValue == null) { return; } oUserInfoEntity.UserID = userIdTextBox.Text; oUserInfoEntity.UserType = userTypeDropDownList.SelectedValue; oUserInfoEntity.Password = passwordTextBox.Text; oUserInfoEntity.ConfirmPassword = confirmPasswordTextBox.Text; oUserInfoEntity.Active = activeCheckBox.Checked; oUserInfoEntity.EmployeeID = userNameDropDownList.SelectedValue; oUserInfoEntity.CreateBy = DateTime.Now.ToShortDateString(); oUserInfoEntity.LastModifiedBy = DateTime.Now.ToShortDateString(); string message = ""; if (oUserInfoEntity.Password != oUserInfoEntity.ConfirmPassword) { message = "Password and confirmed password are not same"; ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "MessageBox", "alert('" + message + "')", true); return; } if (saveButton.Text == "Update") { if (Session["ID"] != null) { oUserInfoEntity.ID = Convert.ToInt16(Session["ID"]); int i = oUserInfoDAO.UpdateUserInfo(oUserInfoEntity); if (i == 1) { message = "User Updated Successfully"; Clear(); } else { message = "User Not Updated!"; } } } else { string condition = " where userId='" + oUserInfoEntity.UserID + "'"; DataTable dt = oUserInfoDAO.GetUserInfo(condition); if (dt.Rows.Count > 0) { message = "User Id already in Database"; ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "MessageBox", "alert('" + message + "')", true); return; } int i = oUserInfoDAO.InsertUserInfo(oUserInfoEntity); if (i == 1) { MenuAndSubMenuDAO oMenuAndSubMenuDAO = new MenuAndSubMenuDAO(); dt = oMenuAndSubMenuDAO.GetSubMenu(""); UserAssignRightDAO oUserAssignRightDAO = new UserAssignRightDAO(); for (int k = 0; k < dt.Rows.Count; k++) { UserAssignRightEntity oUserAssignRightEntity = new UserAssignRightEntity(); oUserAssignRightEntity.UserID = oUserInfoEntity.UserID; oUserAssignRightEntity.MenuNo = dt.Rows[k]["MenuNo"].ToString(); oUserAssignRightEntity.SubMenuNo = dt.Rows[k]["SubMenuNo"].ToString(); oUserAssignRightEntity.MenuRights = false; oUserAssignRightEntity.SubMenuRights = false; oUserAssignRightEntity.CreateBy = DateTime.Now.ToShortDateString(); oUserAssignRightEntity.LastModifiedBy = DateTime.Now.ToShortDateString(); int n = oUserAssignRightDAO.InsertUserAssignRight(oUserAssignRightEntity); } message = "User Created Successfully"; Clear(); } else { message = "User Not Created!"; } } gridViewBind(); ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "MessageBox", "alert('" + message + "')", true); }