/// <summary> /// 插入新的一级菜单 /// </summary> /// <param name="newMenuID"></param> /// <param name="mf"></param> public void insertNewFirstMenu(string form) { Dictionary<string, string> formDictionary = JsonTools.jsonToDictionary(form); MenuFirst menuFirst = new MenuFirst(); menuFirst = JsonTools.PopulateEntityFromCollection(menuFirst, formDictionary); DataTable dtSameMenuName = gd.getSameNameMenu(menuFirst.firstMenuName,0); if (dtSameMenuName.Rows.Count > 0) { gd.UpdateFirstMenu(menuFirst); } else { int newID = gd.GetNewMenuID(); gd.insertNewFirstMenu(newID, menuFirst); } }
/// <summary> /// 更新一级菜单 /// </summary> /// <param name="newMenuID"></param> public void UpdateFirstMenu(MenuFirst mf) { MySqlConnection connection = new MySqlConnection(connectionString); connection.Open(); try { MySqlCommand cmd = connection.CreateCommand(); cmd.CommandText = @"UPDATE `sh_data`.`menu` SET `menu_cn_name`=?menuCnName, `menu_power`=?menuPower, `menu_url`=?menuUrl, `freeze`=?freeze WHERE `menu_cn_name`=?menuCnName;"; cmd.Parameters.Add("?menuCnName", MySqlDbType.VarChar).Value = mf.firstMenuName; cmd.Parameters.Add("?menuPower", MySqlDbType.VarChar).Value = mf.firstMenuPower; cmd.Parameters.Add("?menuUrl", MySqlDbType.VarChar).Value = mf.firstMenuNameUrl; cmd.Parameters.Add("?freeze", MySqlDbType.Int16).Value = mf.freezeMenu; cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { if (connection.State == ConnectionState.Open) { connection.Close(); } } }
/// <summary> /// 插入新的一级菜单 /// </summary> /// <param name="newMenuID"></param> public void insertNewFirstMenu(int newMenuID,MenuFirst mf) { MySqlConnection connection = new MySqlConnection(connectionString); connection.Open(); try { MySqlCommand cmd = connection.CreateCommand(); cmd.CommandText = @"INSERT INTO `sh_data`.`menu` (`menu_id`, `menu_parent_id`, `menu_cn_name`, `menu_power`, `menu_url`) VALUES (?newMenuID, '0', ?menuCnName, ?menuPower, ?menuUrl);"; cmd.Parameters.Add("?newMenuID", MySqlDbType.Int32).Value = newMenuID; cmd.Parameters.Add("?menuCnName", MySqlDbType.VarChar).Value = mf.firstMenuName; cmd.Parameters.Add("?menuPower", MySqlDbType.VarChar).Value = mf.firstMenuPower; cmd.Parameters.Add("?menuUrl", MySqlDbType.VarChar).Value = mf.firstMenuNameUrl; cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { if (connection.State == ConnectionState.Open) { connection.Close(); } } }