private void deleting(object sender, EventArgs e) { DialogResult dr = ((Form)sender).DialogResult; if (dr == DialogResult.Yes) { //删除数据库中的机构记录 string cmd = string.Format("DELETE FROM tjigou WHERE id = {0}", trV.SelectedNode.Name); int rows = ClsMSSQL.ExecuteCmd(cmd, ClsDBCon.ConStrKj); if (rows != 1) { string s = string.Format("删除机构表命令影响的记录行数{0}不为1。", rows); ClsMsgBox.Cw(s); } else { //删除机构树中的结点 TreeNode tn = trV.SelectedNode; TreeNode tm = tn.NextNode != null ? tn.NextNode : tn.PrevNode != null ? tn.PrevNode : tn.Parent; trV.SelectedNode = tm; if (tn.Level == 0) { trV.Nodes.Remove(tn); } else { tn.Parent.Nodes.Remove(tn); } } } }
private void btnSave_Click(object sender, EventArgs e) { //获得所有选中的末端树节点(即功能模块)的id列表 funcsLst.Clear(); foreach (TreeNode node in trV.Nodes) { getAllCheckedIds(node); } //删除当前角色的缘由的功能模块 trolefuncsTableAdapter1 = new trolefuncsTableAdapter(); trolefuncsTableAdapter1.DeleteQuery(roleId); //向trolesfuncs表中插入所有选中的功能模块id //方法:构造一个可插入多条记录的INSERT语句 if (funcsLst.Count > 0) { string[] insLst = funcsLst.ConvertAll(delegate(int n) { string s = roleId + "," + n; return(ClsQ.Q0(s, '(')); }).ToArray(); string str = string.Join(",", insLst); string sql = "INSERT INTO trolefuncs (roleid, funcid) VALUES " + str; ClsMSSQL.ExecuteCmd(sql, ClsDBCon.ConStrKj); } this.DialogResult = DialogResult.OK; }
/// <summary> /// 获取给定角色的所有功能模块id /// </summary> /// <param name="aRoleId"></param> /// <returns></returns> private List <int> getFuncsList(int aRoleId) { string cmd = "SELECT funcid FROM trolefuncs WHERE roleid = " + roleId; DataTable dt = ClsMSSQL.GetDataTable(cmd, ClsDBCon.ConStrKj); //使用Linq将DataTable中的整数数据列funcid转换为一个更简洁的List<int> List <int> lst = (from r in dt.AsEnumerable() select r.Field <int>("funcid")).ToList <int>(); return(lst); }
private void button1_Click(object sender, EventArgs e) { lst.Items.Add(ClsDBCon.ConStrKj); string cmd = "SELECT * FROM tlogin"; DataTable dt = ClsMSSQL.GetDataTable(cmd, ClsDBCon.ConStrKj); dgv.DataSource = dt; tabControl1.SelectedTab = tpDgv; }
private void createFuncTree() { string cmd = @" SELECT id, mc, bm, jb, id0, mc0, bm0, id1, mc1, bm1, id2, mc2, bm2, id3, mc3, bm3, id4, mc4, bm4, id5, mc5, bm5 FROM vfuncsa WHERE jb > 0 ORDER BY xh0, xh1, xh2, xh3, xh4, xh5 "; DSjckja.vusersRow userRow = VWGContext.Current.Session["userRow"] as DSjckja.vusersRow; if (userRow.qx >= 1024) { string[] cmds = cmd.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); cmds[4] = string.Format(@"WHERE ID IN (SELECT funcid FROM trolefuncs where roleid={0})", userRow.roleid); cmd = string.Join(Environment.NewLine, cmds); } DataTable dt = ClsMSSQL.GetDataTable(cmd, ClsDBCon.ConStrKj); TreeNode tn, tp; TreeNode[] tns; int jb; string id; foreach (DataRow r in dt.Rows) { jb = Convert.ToInt32(r["jb"].ToString()); tp = null; for (int i = 1; i <= jb; i++) { id = "id" + i; //按照以r[id].ToString()为名查找具有指定键的树节点,可以选择搜索子节点,返回一个list[]。 tns = trV.Nodes.Find(r[id].ToString(), true); if (tns.Length > 0) { tp = tns[0]; } else { tn = createANode(r, i); if (tp == null) { trV.Nodes.Add(tn);//向trV控件添加节点 } else { tp.Nodes.Add(tn);//向父节点tp中添加节点 } tp = tn; } } } }
private void btnSave_Click(object sender, EventArgs e) { txtPW.Text.Trim(); if (txtPW.Text.Length < nUDMinPWLen.Value) { ClsMsgBox.Jg("Ô¤ÖÿÚÁ¶È²»×ã!"); return; } ClsMSSQL.SetConfigItem("MinPWLen", nUDMinPWLen.Value, ClsDBCon.ConStrKj); ClsMSSQL.SetConfigItem("DefaultPassWord", txtPW.Text, ClsDBCon.ConStrKj); }
private void fillCmbRole() { string cmd = @" SELECT id, mc FROM troles ORDER BY mc"; DataTable dt = ClsMSSQL.GetDataTable(cmd, ClsDBCon.ConStrKj); cmbRole.DataSource = dt; cmbRole.DisplayMember = "mc"; cmbRole.ValueMember = "id"; }
public void Prepare() { string cmd = "SELECT id FROM tfuncs WHERE bm = 'root'"; rootId = Convert.ToInt32(ClsMSSQL.GetValue(cmd, ClsDBCon.ConStrKj)); createFuncTree(); if (trV.Nodes.Count > 0) { trV.ExpandAll(); trV.SelectedNode = trV.Nodes[0]; } }
private void fillCmbBmlx() { string cmd = @" SELECT dm, mc, dmmc FROM voptionxm WHERE lbdm = 'bnlx' ORDER BY dm"; DataTable dt = ClsMSSQL.GetDataTable(cmd, ClsDBCon.ConStrKj); cmbBmlx.DataSource = dt; cmbBmlx.DisplayMember = "dmmc"; cmbBmlx.ValueMember = "dm"; }
private void createTableAndRelation() { string cmd; cmd = "SELECT id AS jhdid, hj FROM vjhdhj ORDER BY jhdid"; dtJhdHj = ClsMSSQL.GetDataTable(cmd, ClsDBCon.ConStrJxc); dtJhdHj.TableName = "vjhdhj"; dsJxc.Tables.Add(dtJhdHj); DataRelation rel; rel = new DataRelation("jhdhj", dtJhdHj.Columns["jhdid"], dsJxc.tjhd.idColumn); dsJxc.Relations.Add(rel); dsJxc.tjhd.hjaColumn.Expression = "Parent(jhdhj).hj"; }
private void fillCmbJgTree(TreeView trV) { string cmd = @" SELECT id, mc, jb, id0, mc0, id1, mc1, id2, mc2, id3, mc3, id4, mc4, id5, mc5 FROM vjigoua WHERE jb > 0 ORDER BY xh0, xh1, xh2, xh3, xh4, xh5 "; DataTable dt = ClsMSSQL.GetDataTable(cmd, ClsDBCon.ConStrKj); TreeNode tn, tp; TreeNode[] tns; int jb; string idFld, mcFld; foreach (DataRow r in dt.Rows) { jb = Convert.ToInt32(r["jb"].ToString()); tp = null; for (int i = 1; i <= jb; i++) { idFld = "id" + i; tns = trV.Nodes.Find(r[idFld].ToString(), true); if (tns.Length > 0) { tp = tns[0]; } else { mcFld = "mc" + i; tn = new TreeNode(r[idFld].ToString() + ":" + r[mcFld].ToString()); tn.Name = r[idFld].ToString(); tn.ImageIndex = 0; tn.SelectedImageIndex = 1; if (tp == null) { trV.Nodes.Add(tn); } else { tp.Nodes.Add(tn); } tp = tn; } } } }
private void btnDel_Click(object sender, EventArgs e) { //数据表为空时不执行本操作 if (bds.Current == null) { return; } Datasets.DSjckja.toptionlbRow r = (Datasets.DSjckja.toptionlbRow)(((DataRowView)bds.Current).Row); string cmd = "SELECT * FROM toptionxm WHERE lbdm =" + ClsQ.Q1(r.dm); if (ClsMSSQL.Exists(cmd, ClsDBCon.ConStrKj)) { ClsMsgBox.Jg("该类别下存在项目无法删除"); return; } ClsMsgBox.YesNo("确定要删除该记录吗?", deleting); }
private void createFuncTree() { string cmd = @" SELECT id, mc, bm, jb, id0, mc0, bm0, id1, mc1, bm1, id2, mc2, bm2, id3, mc3, bm3, id4, mc4, bm4, id5, mc5, bm5 FROM vfuncsa WHERE jb > 0 ORDER BY xh0, xh1, xh2, xh3, xh4, xh5 "; DataTable dt = ClsMSSQL.GetDataTable(cmd, ClsDBCon.ConStrKj); TreeNode tn, tp; TreeNode[] tns; int jb; string id; foreach (DataRow r in dt.Rows) { jb = Convert.ToInt32(r["jb"].ToString()); tp = null; for (int i = 1; i <= jb; i++) { id = "id" + i; //按照以r[id].ToString()为名查找具有指定键的树节点,可以选择搜索子节点,返回一个list[]。 tns = trV.Nodes.Find(r[id].ToString(), true); if (tns.Length > 0) { tp = tns[0]; } else { tn = createANode(r, i); if (tp == null) { trV.Nodes.Add(tn);//向trV控件添加节点 } else { tp.Nodes.Add(tn);//向父节点tp中添加节点 } } } } }
private void btnOK_Click(object sender, EventArgs e) { #region 账户或口令为空判断 txtLoginName.Text = txtLoginName.Text.Trim(); if (string.IsNullOrEmpty(txtLoginName.Text)) { ClsMsgBox.Jg("账号不能为空!"); return; } txtPassword.Text = txtPassword.Text.Trim(); if (string.IsNullOrEmpty(txtPassword.Text)) { ClsMsgBox.Jg("口令不能为空!"); return; } #endregion #region 账户、口令有效性判断 if (!ClsMSSQL.Exists("tlogin", "loginname", txtLoginName.Text, ClsDBCon.ConStrKj)) { ClsMsgBox.Jg("账户不存在!"); return; } #endregion string cmd = string.Format("SELECT * FROM tlogin WHERE loginname = '{0}' AND " + "password = '******'", txtLoginName.Text, txtPassword.Text); if (!ClsMSSQL.Exists(cmd, ClsDBCon.ConStrKj)) { ClsMsgBox.Jg("口令不正确"); return; } #region 是否保存到cookie if (chkAutoSave.Checked) { Context.Cookies["Account"] = txtLoginName.Text; Context.Cookies["Password"] = txtPassword.Text; } else { Context.Cookies["Account"] = ""; Context.Cookies["Password"] = ""; } #endregion this.Context.Session.IsLoggedOn = true; }
private void createTableAndRelation() { String cmd; cmd = "SELECT dm,mc FROM toptionxm WHERE lbdm='gwlx' ORDER BY dm"; DataTable dtGw = ClsMSSQL.GetDataTable(cmd, ClsDBCon.ConStrKj); cmd = "SELECT dm,mc FROM toptionxm WHERE lbdm='xllx' ORDER BY dm"; DataTable dtxl = ClsMSSQL.GetDataTable(cmd, ClsDBCon.ConStrKj); dSjckja1.Tables.Add(dtGw); dSjckja1.Tables.Add(dtxl); DataRelation rel; rel = new DataRelation("tyg_gwlx", dtGw.Columns["dm"], dSjckja1.tyg.gwColumn); dSjckja1.Relations.Add(rel); rel = new DataRelation("tyg_xllx", dtxl.Columns["dm"], dSjckja1.tyg.xlColumn); dSjckja1.Relations.Add(rel); dSjckja1.tyg.gwsColumn.Expression = "Parent(tyg_gwlx).mc"; dSjckja1.tyg.xlsColumn.Expression = "Parent(tyg_xllx).mc"; }
public void Prepare(EnumNED aNED, BindingSource aBds, DSjckja aDSJckja, tygTableAdapter atygTableAdapter1, DataGridView aDgv = null) { bds = aBds; fillCmbs(); binding(); NED = aNED; dsJckja1 = aDSJckja; tygTableAdapter1 = atygTableAdapter1; dgv = aDgv; ClsD.SetMaxLength(this, dsJckja1.tyg); defaultPassword = ClsMSSQL.GetConfigStr("DefaultPassword", ClsDBCon.ConStrKj); minPwLen = ClsMSSQL.GetConfigInt("MinPWLen", ClsDBCon.ConStrKj); if (NED == EnumNED.NEW) { bds.AddNew(); DSjckja.tygRow r = (DSjckja.tygRow)((DataRowView)bds.Current).Row; } else if (NED == EnumNED.DETALL) { this.btnSave.Visible = false; } }
private void refresh() { nUDMinPWLen.Value = ClsMSSQL.GetConfigInt("MinPWLen", ClsDBCon.ConStrKj); txtPW.Text = ClsMSSQL.GetConfigStr("DefaultPassWord", ClsDBCon.ConStrKj); }