/// <summary> /// 插入数据 /// </summary> public static void Insert(MenuCfgChild menuCfgChild) { string strSqlInsert = "insert into T_MenuCfgChild(MainMenuId,SubMenu,ShortCut,OrderIndex) values({0},'{1}','{2}',{3})"; strSqlInsert = string.Format(strSqlInsert, menuCfgChild.MainMenuId, menuCfgChild.SubMenu, menuCfgChild.ShortCut, menuCfgChild.OrderIndex); (new SqlDBConnect()).ExecuteNonQuery(strSqlInsert); }
/// <summary> /// 根据SysId更新数据 /// </summary> public static void UpdateBySysId(MenuCfgChild menuCfgChild, int intSysId) { string strSql = "update T_MenuCfgChild set MainMenuId={0},SubMenu='{1}',ShortCut='{2}',OrderIndex={3} " + "where SysId={4}"; strSql = string.Format(strSql, menuCfgChild.MainMenuId, menuCfgChild.SubMenu, menuCfgChild.ShortCut, menuCfgChild.OrderIndex, intSysId); (new SqlDBConnect()).ExecuteNonQuery(strSql); }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, EventArgs e) { DBUtil dbUtil = new DBUtil(); int intMainMenuOrderIndex; string strMainMenuOrderIndex = dbUtil.Get_Single_val("T_MenuCfgMain", "OrderIndex", "MainMenu", this.comboBoxMainMenu.Text.Trim()); if (strMainMenuOrderIndex != "") intMainMenuOrderIndex = Convert.ToInt32(strMainMenuOrderIndex); else intMainMenuOrderIndex = this.menuStipMain.Items.Count-1;//空值时,默认为最后一个位置 int intSubMenuOrderIndex = (this.menuStipMain.Items[intMainMenuOrderIndex] as ToolStripMenuItem).DropDownItems.Count + 1; #region 验证 if (this.comboBoxMainMenu.SelectedIndex == 0) { MessageBox.Show("主菜单项不能为空,请选择!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (this.comboBoxReceName.SelectedIndex == 0) { MessageBox.Show("子菜单项不能为空,请选择!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (this.n_OrderIndex.Text.Trim() != "" && !Util.IsNumberic(this.n_OrderIndex)) { MessageBox.Show("顺序号输入有误,请输入数值!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (Util.LessOneNumber(this.n_OrderIndex, intSubMenuOrderIndex) == false) { MessageBox.Show("顺序号只能输入大于0,小于等于" + intSubMenuOrderIndex + "的整数,请输入数值!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (this.n_OrderIndex.Text.Trim() != "" && Convert.ToInt32(this.n_OrderIndex.Text.Trim()) <= 0) { MessageBox.Show("顺序号只能输入大于0,小于等于" + intSubMenuOrderIndex + "的整数,请输入数值!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } #endregion SqlDBConnect db = new SqlDBConnect(); InitFuncs initFuncs = new InitFuncs(); int intMainMenuId = -1; string strMainMenuId = dbUtil.Get_Single_val("T_MenuCfgMain", "Sysid", "MainMenu", this.comboBoxMainMenu.Text.Trim()); if (strMainMenuId != "") intMainMenuId = Convert.ToInt32(strMainMenuId); string strSubMenu = dbUtil.Get_Single_val("T_ReceiptModal", "ReceTypeID", "ReceName", this.comboBoxReceName.Text.Trim()); MenuCfgChild menuCfgChild = new MenuCfgChild(); menuCfgChild.MainMenuId = intMainMenuId; menuCfgChild.SubMenu = strSubMenu; menuCfgChild.ShortCut = this.s_ShortCut.Text.Trim(); menuCfgChild.OrderIndex = Convert.ToInt32(this.n_OrderIndex.Text.Trim()); string strSql = ""; string strSql_ = ""; if (this.isAdd == true) //新增 { //插入之前的判断 strSql_ = "select * from T_MenuCfgChild where MainMenuId={0} and SubMenu='{1}'"; strSql_ = string.Format(strSql_, intMainMenuId, strSubMenu); //插入 strSql = initFuncs.Build_Insert_Sql(this.panelMenuChild, "T_MenuCfgChild"); } else //修改 { if (this.txtSysid.Text.Trim() == "") return; int intSysIdMenuChild = Convert.ToInt32(this.txtSysid.Text.Trim()); strSql_ = "select * from T_MenuCfgChild where SysId!={0} and MainMenuId={1} and SubMenu='{2}'"; strSql_ = string.Format(strSql_, intSysIdMenuChild, intMainMenuId, strSubMenu); //更新 string strWhere = string.Format("where SysId={0}", intSysIdMenuChild); strSql = initFuncs.Build_Update_Sql(this.panelMenuChild, "T_MenuCfgChild", strWhere); } bool isExist = dbUtil.yn_exist_data(strSql_); if (isExist == true) { MessageBox.Show("该记录已存在!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } (new SqlDBConnect()).ExecuteNonQuery(strSql); MessageBox.Show("保存成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); InitDataGridView(); }