modernsky2003

C#代码

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using rulebase;
using System.Data;
using WindControl;

namespace DNCMANAGER.UserSit
{
 /// <summary>
 /// FSystemSet 的摘要说明。
 /// </summary>
 public class FSystemSet : System.Windows.Forms.Form
 {
  private System.Windows.Forms.GroupBox groupBox1;
  private System.Windows.Forms.TreeView treeView1;
  private WindControl.UserConPlant userConPlant;
  private System.Windows.Forms.ImageList imageList1;
  private System.Windows.Forms.ToolTip toolTip1;
  private WindControl.UserControRole userControRole1;
  private WindControl.UserControEmp userControEmp;
  private System.Windows.Forms.ContextMenu contextMenu1;
  private System.Windows.Forms.MenuItem menuItem1;
  private System.ComponentModel.IContainer components;

  PbaseUpdate Pbase = new PbaseUpdate();
  public FSystemSet()
  {
   //
   // Windows 窗体设计器支持所必需的
   //
   InitializeComponent();

   //
   // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
   //
  }

  /// <summary>
  /// 清理所有正在使用的资源。
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if(components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

  #region Windows 窗体设计器生成的代码
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {
   this.components = new System.ComponentModel.Container();
   System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FSystemSet));
   this.groupBox1 = new System.Windows.Forms.GroupBox();
   this.treeView1 = new System.Windows.Forms.TreeView();
   this.imageList1 = new System.Windows.Forms.ImageList(this.components);
   this.userConPlant = new WindControl.UserConPlant();
   this.userControEmp = new WindControl.UserControEmp();
   this.userControRole1 = new WindControl.UserControRole();
   this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
   this.contextMenu1 = new System.Windows.Forms.ContextMenu();
   this.menuItem1 = new System.Windows.Forms.MenuItem();
   this.groupBox1.SuspendLayout();
   this.SuspendLayout();
   //
   // groupBox1
   //
   this.groupBox1.Controls.Add(this.treeView1);
   this.groupBox1.Controls.Add(this.userControEmp);
   this.groupBox1.Controls.Add(this.userControRole1);
   this.groupBox1.Controls.Add(this.userConPlant);
   this.groupBox1.ForeColor = System.Drawing.SystemColors.HotTrack;
   this.groupBox1.Location = new System.Drawing.Point(0, 8);
   this.groupBox1.Name = "groupBox1";
   this.groupBox1.Size = new System.Drawing.Size(712, 528);
   this.groupBox1.TabIndex = 0;
   this.groupBox1.TabStop = false;
   this.groupBox1.Text = "系统设置";
   //
   // treeView1
   //
   this.treeView1.ImageList = this.imageList1;
   this.treeView1.Location = new System.Drawing.Point(8, 32);
   this.treeView1.Name = "treeView1";
   this.treeView1.Size = new System.Drawing.Size(128, 480);
   this.treeView1.TabIndex = 0;
   this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect);
   //
   // imageList1
   //
   this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
   this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
   this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
   //
   // userConPlant
   //
   this.userConPlant.Location = new System.Drawing.Point(136, 16);
   this.userConPlant.Name = "userConPlant";
   this.userConPlant.Size = new System.Drawing.Size(568, 504);
   this.userConPlant.TabIndex = 1;
   //
   // userControEmp
   //
   this.userControEmp.Location = new System.Drawing.Point(136, 16);
   this.userControEmp.Name = "userControEmp";
   this.userControEmp.Size = new System.Drawing.Size(568, 504);
   this.userControEmp.TabIndex = 3;
   //
   // userControRole1
   //
   this.userControRole1.Cursor = System.Windows.Forms.Cursors.Hand;
   this.userControRole1.Location = new System.Drawing.Point(136, 16);
   this.userControRole1.Name = "userControRole1";
   this.userControRole1.Size = new System.Drawing.Size(568, 504);
   this.userControRole1.TabIndex = 2;
   //
   // contextMenu1
   //
   this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                       this.menuItem1});
   //
   // menuItem1
   //
   this.menuItem1.Index = 0;
   this.menuItem1.Text = "角色查看";
   this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
   //
   // FSystemSet
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.ClientSize = new System.Drawing.Size(722, 543);
   this.Controls.Add(this.groupBox1);
   this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
   this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
   this.MaximizeBox = false;
   this.Name = "FSystemSet";
   this.ShowInTaskbar = false;
   this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
   this.Text = "单位(人员)信息设置";
   this.Load += new System.EventHandler(this.FSystemSet_Load);
   this.groupBox1.ResumeLayout(false);
   this.ResumeLayout(false);

  }
  #endregion
  private void InitWind()
  {
   string sql="select Fid,Fname from DNC_Sys_Plant where Fid like '"+CGlobe.GFplantfid+"'";
   treeView1.Nodes.Clear();
   DataTable Dt;
   string NodeText="系统设置结构";
   int NodeTag = 0;  //根节点的tag
   TreeNode FRoot = new TreeNode(NodeText);
   FRoot.ImageIndex=4;
   FRoot.Tag=0;
   FRoot.SelectedImageIndex=5;
   this.treeView1.Nodes.Add(FRoot);
   ///////////////////////////////////
   #region  SystemSet.PlantSet:
   Dt = Pbase.GetDatetable(null,sql);
   NodeText="结构";
   NodeTag = 0;
   TreeNode Root;
//   if(CGlobe.Gfrole.Length> 1)
   if(CGlobe.Fduty==0)
   {
    this.userConPlant.btnAdd.Enabled=false;
    this.userConPlant.btnUpdate.Enabled=false;
    this.userConPlant.btnAdd.Enabled=false;
    this.userConPlant.btnUpdate.Enabled=false;
    this.userConPlant.btndel.Enabled = false;
    this.userConPlant.btndel.Enabled = false;
   }
   switch(Dt.Rows.Count)
   {
    case 0:
     Root = new TreeNode(NodeText);
     Root.Tag=NodeTag;
     Root.SelectedImageIndex=1;
     Root.ImageIndex=0;
     FRoot.Nodes.Add(Root);
     break;
    case 1:
     NodeText=Dt.Rows[0][1].ToString() + NodeText;
     Root = new TreeNode(NodeText);
     Root.Tag=NodeTag;
     Root.SelectedImageIndex=1;
     Root.ImageIndex=0;
     FRoot.Nodes.Add(Root);
     TreeNode subnode = new TreeNode(Dt.Rows[0][1].ToString());
     subnode.Tag=Dt.Rows[0][0].ToString();
     Root.Nodes.Add(subnode);
     break;
    default:
     Root = new TreeNode(NodeText);
     Root.Tag=NodeTag;
     Root.SelectedImageIndex=1;
     Root.ImageIndex=0;
     FRoot.Nodes.Add(Root);
     for(int i=0;i<Dt.Rows.Count;i++)
     {
      TreeNode node = new TreeNode(Dt.Rows[i][1].ToString());
      node.Tag=Dt.Rows[i][0].ToString();
      node.SelectedImageIndex=2;
      node.ImageIndex=3;
      Root.Nodes.Add(node);
     }
     break;
   }
   this.userConPlant.btnAdd.Click+=new EventHandler(PlantbtnClick);
   this.userConPlant.btnUpdate.Click+=new EventHandler(PlantbtnClick);
   this.userConPlant.btndel.Click +=new EventHandler(btndelClick);
   this.userConPlant.listView1.Click+=new EventHandler(PlantlistView1_Click);
   #endregion
   //////////
   //分厂角色设置
   //////////
   #region dnc_sys_role
   NodeText="角色设置";
   NodeTag = 1;
   TreeNode SubRoot;
   userControRole1.FroleContent = CGlobe.Gfrole;
   Nbase nbase = new Nbase();
//   if(CGlobe.Gfid.Length>2 && CGlobe.Gfrole!="%")
//   {
//    if(!nbase.Popedom("Btn_Role",CGlobe.Gfrole))
//    {
//     this.userControRole1.btnAdd.Visible=false;
//     this.userControRole1.btnUpdate.Visible=false;
//     this.userControRole1.btndel.Visible=false;
//     this.userControRole1.btnAdd.Enabled=false;
//     this.userControRole1.btnUpdate.Enabled=false;
//     this.userControRole1.btndel.Enabled=false;
//    }
//   }
   
   if(CGlobe.Fduty==0)
   {
    this.userControRole1.btnAdd.Enabled=false;
    this.userControRole1.btnUpdate.Enabled=false;
    this.userControRole1.btndel.Enabled=false;
    this.userControRole1.btnAdd.Enabled=false;
    this.userControRole1.btnUpdate.Enabled=false;
    this.userControRole1.btndel.Enabled=false;
   }
   
   switch(Dt.Rows.Count)
   {
    case 0:
     SubRoot = new TreeNode(NodeText);
     SubRoot.Tag=NodeTag;
     SubRoot.SelectedImageIndex=1;
     SubRoot.ImageIndex=0;
     FRoot.Nodes.Add(SubRoot);
     break;
    case 1:
     NodeText=Dt.Rows[0][1].ToString() + NodeText;
     SubRoot = new TreeNode(NodeText);
     SubRoot.Tag=NodeTag;
     SubRoot.SelectedImageIndex=1;
     SubRoot.ImageIndex=0;
     FRoot.Nodes.Add(SubRoot);
     TreeNode subnode = new TreeNode(Dt.Rows[0][1].ToString());
     subnode.Tag=Dt.Rows[0][0].ToString();
     SubRoot.Nodes.Add(subnode);
     this.userControRole1.combFplantfid.Items.Add(Dt.Rows[0][1].ToString());
     break;
    default:
     SubRoot = new TreeNode(NodeText);
     SubRoot.Tag=NodeTag;
     SubRoot.SelectedImageIndex=1;
     SubRoot.ImageIndex=0;
     FRoot.Nodes.Add(SubRoot);
     for(int i=0;i<Dt.Rows.Count;i++)
     {
      TreeNode node = new TreeNode(Dt.Rows[i][1].ToString());
      node.Tag=Dt.Rows[i][0].ToString();
      node.SelectedImageIndex=2;
      node.ImageIndex=3;
      SubRoot.Nodes.Add(node);//Fid,Fname
     }
     break;
   }
   //
   this.userControRole1.combFplantfid.DataSource=Dt;
   this.userControRole1.combFplantfid.ValueMember=Dt.Columns[0].ToString();
   this.userControRole1.combFplantfid.DisplayMember=Dt.Columns[1].ToString();
   //
   sql="select fname,fdesc,fmenu,fremark from dnc_sys_menu";
   DataTable dt = Pbase.GetDatetable(null,sql);
   this.userControRole1.listVPurview.Items.Clear();
   for(int i=0;i<dt.Rows.Count;i++)
   {
    string[] stritem = new string[4]
     {
      "(" + (1 + i).ToString() + ")",
      dt.Rows[i][0].ToString(),
      dt.Rows[i][1].ToString(),
      //         dt.Rows[i][2].ToString(),
      dt.Rows[i][3].ToString()
     };
    ListViewItem li = new ListViewItem(stritem,0);
    li.Checked=true;
    li.Tag=dt.Rows[i][2].ToString();
    this.userControRole1.listVPurview.Items.Add(li);
    this.userControRole1.listVPurview.MultiSelect=true;
   }
   userControRole1.listVPurview.CheckBoxes=true;
   dt.Dispose();
   this.userControRole1.btnAdd.Click+=new EventHandler(RolebtnClick);
   this.userControRole1.btnUpdate.Click+=new EventHandler(RolebtnClick);
   this.userControRole1.btndel.Click +=new EventHandler(btndelClick);
   this.userControRole1.listVRole.Click+=new EventHandler(RolelistViewClick);
   this.userControRole1.listVPurview.ColumnClick+=new ColumnClickEventHandler(listVPurview_ColumnClick);
   #endregion
   //////
   //人员增加
   //////
   #region dnc_sys_employee
   NodeText="分厂人员增加管理";
   NodeTag = 2;
   TreeNode ThirdbRoot;
   
   if(CGlobe.Fduty==0)
   {
    this.userControEmp.btnAdd.Enabled=false;
    this.userControEmp.btnUpdate.Enabled=false;
    this.userControEmp.btndel.Enabled=false;
    this.userControEmp.btnAdd.Enabled=false;
    this.userControEmp.btnUpdate.Enabled=false;
    this.userControEmp.btndel.Enabled=false;
   }
   
   switch(Dt.Rows.Count)
   {
    case 0:
     ThirdbRoot = new TreeNode(NodeText);
     ThirdbRoot.Tag=NodeTag;
     ThirdbRoot.SelectedImageIndex=1;
     ThirdbRoot.ImageIndex=0;
     FRoot.Nodes.Add(ThirdbRoot);
     break;
    case 1:
     NodeText=Dt.Rows[0][1].ToString() + NodeText;
     ThirdbRoot = new TreeNode(NodeText);
     ThirdbRoot.Tag=NodeTag;
     ThirdbRoot.SelectedImageIndex=1;
     ThirdbRoot.ImageIndex=0;
     FRoot.Nodes.Add(ThirdbRoot);
     TreeNode subnode = new TreeNode(Dt.Rows[0][1].ToString());
     subnode.Tag=Dt.Rows[0][0].ToString();
     ThirdbRoot.Nodes.Add(subnode);
     //     this.userControRole1.combFplantfid.Items.Add(Dt.Rows[0][1].ToString());
     break;
    default:
     ThirdbRoot = new TreeNode(NodeText);
     ThirdbRoot.Tag=NodeTag;
     ThirdbRoot.SelectedImageIndex=1;
     ThirdbRoot.ImageIndex=0;
     FRoot.Nodes.Add(ThirdbRoot);
     for(int i=0;i<Dt.Rows.Count;i++)
     {
      TreeNode node = new TreeNode(Dt.Rows[i][1].ToString());
      node.Tag=Dt.Rows[i][0].ToString();
      node.SelectedImageIndex=2;
      node.ImageIndex=3;
      ThirdbRoot.Nodes.Add(node);//Fid,Fname
     }
     break;
   }
   this.userControEmp.btnAdd.Click+=new EventHandler(btnClick);
   this.userControEmp.btnUpdate.Click+=new EventHandler(btnClick);
   this.userControEmp.btndel.Click+=new EventHandler(btndelClick);
   this.userControEmp.listView1.Click+=new EventHandler(listView1_Click);
   this.userControEmp.listView1.MouseUp += new MouseEventHandler(listView1_MouseUp);
   #endregion dnc_sys_employee
  }
  private void FSystemSet_Load(object sender, System.EventArgs e)
  {
     InitWind();  
  }
       TreeNode SelNode;
  string  PlantFid;
  #region plant
  private void PlantbtnClick(object sender, EventArgs e)
  {
            Button btn = (Button)sender;
   if(btn.Name=="btnAdd")
   {
    this.userConPlant.tbFname.Text="";
    this.userConPlant.tbFsit.Text="";
    this.userConPlant.tbFaddr.Text="";
    this.userConPlant.tbFEmail.Text="";
    this.userConPlant.tbFdesc.Text="";
    this.userConPlant.tbFtel.Text="";
    this.userConPlant.tbFcorporation.Text="";
    PlantFid="";
   }
   if(btn.Name=="btnUpdate")
   {
    
    if(this.userConPlant.tbFname.Text.Trim().Length == 0)
    {
     MessageBox.Show("没有填写企业名称,系统不允许保存!",CGlobe.Gmsg);
     return;
    }
    SaveOptionEnum SaveType;
    if(PlantFid!="")
    {
     SaveType = SaveOptionEnum.Update;
    }
    else
    {
     SaveType = SaveOptionEnum.Insert;
     PlantFid = Guid.NewGuid().ToString();
    }
    
    SortedList sl = new SortedList();
    sl.Add("FID",PlantFid);
    sl.Add("Fname",this.userConPlant.tbFname.Text.Trim());
    sl.Add("Fcorporation",this.userConPlant.tbFcorporation.Text.Trim());
    sl.Add("Faccount",this.userConPlant.tbFaccount.Text.Trim());
    sl.Add("Faddr",this.userConPlant.tbFaddr.Text.Trim());
    sl.Add("Ftel",this.userConPlant.tbFtel.Text.Trim());
    sl.Add("FEmail",this.userConPlant.tbFEmail.Text.Trim());
    sl.Add("Fsit",this.userConPlant.tbFsit.Text.Trim());
    sl.Add("Fisdelete","0");
    sl.Add("Fdesc",this.userConPlant.tbFdesc.Text.Trim());
    
    if(Pbase.Save(null,sl,EntityTypeEnum.DNC_Sys_Plant,"FID",SaveType))
    {
     if(SaveType == SaveOptionEnum.Insert)
     {
      if(SelNode != null)
      {
       TreeNode node = new TreeNode(this.userConPlant.tbFname.Text.Trim()) ;
       node.Tag=PlantFid;
       if(SelNode.Parent != null && SelNode.Tag.ToString()=="0")
       {
        SelNode.Nodes.Add(node);
       }
       if(SelNode.Parent == null)
        SelNode.Nodes[0].Nodes.Add(node);
       if(SelNode.Nodes.Count == 0 && SelNode.Tag.ToString() != "0")
        SelNode.Parent.Nodes.Add(node);
       node.ForeColor=Color.Red;
      }
     }
     //
     //fid,Fname,Fcorporation,Faccount,Ftel,FEmail,Fsit,Faddr,Fdesc
     if(SaveType == SaveOptionEnum.Update)
     {
                        ListViewItem Selitem = userConPlant.listView1.SelectedItems[0];
      userConPlant.listView1.Items.Remove(Selitem);
     }
     string[] str1 = new string[9]{
             sl["Fname"].ToString(),
             sl["Fcorporation"].ToString(),
             sl["Faccount"].ToString(),
             sl["Ftel"].ToString(),
             sl["FEmail"].ToString(),
             sl["Fsit"].ToString(),
             sl["Faddr"].ToString(),
             sl["Fdesc"].ToString(),
                                  PlantFid
            };
     ListViewItem item = new ListViewItem(str1,1);
     item.Tag=sl["FID"].ToString();
     this.userConPlant.listView1.Items.Add(item);
//     this.userConPlant.listView1.SelectedItems[0]=item;
     //
     MessageBox.Show("数据保存成功!",CGlobe.Gmsg);
     return;
    }
   }
  }

  private void PlantlistView1_Click(object sender, EventArgs e)
  {
             ListViewItem  item = this.userConPlant.listView1.SelectedItems[0];
   if(item == null)return;
//   item.BackColor= Color.Blue;
   this.toolTip1.SetToolTip(this.userConPlant.listView1,item.SubItems[0].Text.Trim());
   this.userConPlant.tbFname.Text=item.SubItems[0].Text.Trim();
   this.userConPlant.tbFsit.Text=item.SubItems[5].Text.Trim();
   this.userConPlant.tbFaddr.Text=item.SubItems[6].Text.Trim();
   this.userConPlant.tbFEmail.Text=item.SubItems[4].Text.Trim();
   this.userConPlant.tbFdesc.Text=item.SubItems[7].Text.Trim();
   this.userConPlant.tbFtel.Text=item.SubItems[3].Text.Trim();
   this.userConPlant.tbFcorporation.Text=item.SubItems[1].Text.Trim();
   this.userConPlant.tbFaccount.Text=item.SubItems[2].Text.Trim();
   PlantFid = item.Tag.ToString();
  }
  #endregion plant
  #region sys_role
  private void RolebtnClick(object sender, EventArgs e)
  {
    Button btn = (Button)sender;
   if(btn.Name==this.userControRole1.btnAdd.Name)
   {
    this.userControRole1.txtfdesc.Text="";
//    this.userControRole1.="";
    PlantFid="";
   }
   if(btn.Name==this.userControRole1.btnUpdate.Name)
   {
    if(this.userControRole1.txtFname.Text.Trim()=="" || this.userControRole1.combFplantfid.SelectedValue.ToString()=="")
    {
     MessageBox.Show("没有填写角色名称或者没有选择所属单位,系统不允许保存!",CGlobe.Gmsg);
     return;
    }
    string fcontent="";
    int purview = 0;
    for(int ii=0;ii<userControRole1.listVPurview.Items.Count;ii++)
    {
     ListViewItem PurItem = userControRole1.listVPurview.Items[ii];
     if(PurItem.Checked)purview++;
    }
    if(purview<=0)
    {
     MessageBox.Show("没有为所设计角色选择使用权限,系统不允许保存!",CGlobe.Gmsg);
     return;
    }
    else
    {
     for(int i=0;i<this.userControRole1.listVPurview.Items.Count;i++)
     {
      ListViewItem roleitem = this.userControRole1.listVPurview.Items[i];
      if(roleitem.Checked)
       fcontent += roleitem.Tag.ToString()+"|";
     }
     if(fcontent.IndexOf('|') != -1 )
     {
      fcontent = fcontent.Substring(0,fcontent.Length - 1);
     }
    }
    
    SortedList sl = new SortedList();
    SaveOptionEnum SaveType;
    if(PlantFid!=""  && PlantFid != null)
    {
     SaveType = SaveOptionEnum.Update;
    }
    else
    {
     SaveType = SaveOptionEnum.Insert;
     PlantFid = Guid.NewGuid().ToString();
    }
    sl.Add("FID",PlantFid);
    sl.Add("FNAME",this.userControRole1.txtFname.Text.Trim());
    sl.Add("FDESC",this.userControRole1.txtfdesc.Text.Trim());
    sl.Add("FPLANTFID",this.userControRole1.combFplantfid.SelectedValue.ToString());
    sl.Add("FCONTENT",fcontent);
    sl.Add("FISDELETE",0);
    if(Pbase.Save(null,sl,EntityTypeEnum.DNC_Sys_Role,"FID",SaveType))
    {
     if(SaveType == SaveOptionEnum.Insert)
     {
      string[] Listview = new string[6]
       {
        sl["FNAME"].ToString(),
           this.userControRole1.combFplantfid.SelectedText.ToString(),
           sl["FDESC"].ToString(),
           DateTime.Now.ToString(),
           "使用之中",
           sl["FCONTENT"].ToString()
       };
      ListViewItem li = new ListViewItem(Listview,0);
      li.ForeColor = Color.Red;
      this.userControRole1.listVRole.Items.Add(li);
      li.Tag = PlantFid;
      return;
     }
    }
    ///
    ///fid,Fname,Fdesc,FISDELETE,FTIME,FPLANTFID,fcontent
    if(SaveType == SaveOptionEnum.Update)
    {
     if(userControRole1.listVRole.SelectedItems.Count <= 0)return;
     this.userControRole1.listVRole.Items.Remove(userControRole1.listVRole.SelectedItems[0]);
    }
    string[] strrole = new string[6]
        {
         sl["FNAME"].ToString(),
         "",
         sl["FDESC"].ToString(),
         DateTime.Now.ToString(),
         "",
         ""
        };
    if(sl["FISDELETE"].ToString() == "0")
     strrole.SetValue("使用当中",4);
    else
     strrole.SetValue("已禁用",4);
    string sql="select Fname from dnc_sys_plant where fid='"+sl["FPLANTFID"].ToString()+"'";
    DataTable Dplant = Pbase.GetDatetable(null,sql);
    if(Dplant.Rows.Count>0)
     strrole.SetValue(Dplant.Rows[0][0].ToString(),1);
    strrole.SetValue(sl["FCONTENT"].ToString(),5);
    ListViewItem roleitem1 = new ListViewItem(strrole,2);
    roleitem1.Tag = sl["FID"].ToString();
    this.userControRole1.listVRole.Items.Add(roleitem1);
//    userControRole1.listVRole.SelectedItems[0] = roleitem1;
    ///
   }
  }
  private void RolelistViewClick(object sender, EventArgs e)
  {
   for(int ii=0;ii<this.userControRole1.listVPurview.Items.Count;ii++)
   {
    this.userControRole1.listVPurview.Items[ii].Checked = false;
    this.userControRole1.listVPurview.Items[ii].BackColor = Color.Silver;
   }
   ListViewItem li = this.userControRole1.listVRole.SelectedItems[0];
   PlantFid = li.Tag.ToString();
   this.userControRole1.txtFname.Text=li.SubItems[0].Text;
   this.userControRole1.txtfdesc.Text = li.SubItems[2].Text;
//   this.userControRole1.combFplantfid.Items.in
//   PbaseUpdate Pbase = new PbaseUpdate();
//   Object Obj = Pbase.ExecuteSql(null,"select Fplantfid from dnc_sys_role where fid='"+li.Tag.ToString()+"'",SqlResultEnum.Have) ;
//   if(Obj != null)
////    this.userControRole1.txtFname.Text = Obj.ToString();
//     
//   this.userControRole1.combFplantfid.SelectedText= Obj.ToString();
   string strdispose = li.SubItems[5].Text.ToString();
   string[] stritem = strdispose.Split('|');
   for(int i=0;i<stritem.Length;i++)
   {
    for(int ii=0;ii<this.userControRole1.listVPurview.Items.Count;ii++)
    {
     if(this.userControRole1.listVPurview.Items[ii].Tag.ToString() == stritem[i].ToString())
     {
      this.userControRole1.listVPurview.Items[ii].Checked = true;
      this.userControRole1.listVPurview.Items[ii].BackColor = Color.Snow;
     }
    }
   }
  }
  private void listVPurview_ColumnClick(object sender, ColumnClickEventArgs e)
  {
//   if(this.userControRole1.listVPurview.Columns[e].Text.ToString() == "功能序号")
   if(e.Column==0)
   {
    for(int ii=0;ii<this.userControRole1.listVPurview.Items.Count;ii++)
    {
     this.userControRole1.listVPurview.Items[ii].Checked = false;
//     this.userControRole1.listVPurview.Items[ii].BackColor = Color.Silver;
    }
   }
  }
  #endregion sys_role

  #region dnc_sys_employee
  private void btnClick(object sender, EventArgs e)
  {
   if(SelNode.Tag.ToString().Length<36)
   {
    MessageBox.Show("请选择单位后,在进行人员的增加!",CGlobe.Gmsg);
    return;
   }
            Button btn = (Button)sender;
   if(btn.Name == this.userControEmp.btnAdd.Name)
   {
    PlantFid="";
    this.userControEmp.txtfname.Text="";
    this.userControEmp.txtFduty.Text="";
    this.userControEmp.txtFWorkAge.Text="";
    this.userControEmp.txtFuser.Text="";
    this.userControEmp.txtFpwd.Text="";
    this.userControEmp.pwd.Text="";
    this.userControEmp.txtFEduLevel.Text="";
    this.userControEmp.txtFtel.Text="";
    this.userControEmp.txtFEmail.Text="";
    this.userControEmp.txtFFax.Text="";
    this.userControEmp.txtFaddr.Text="";
    this.userControEmp.txtFdesc.Text="";
    this.userControEmp.checkBox1.Checked=false;
    this.userControEmp.checkBox2.Checked=false;
    this.userControEmp.checkBox3.Checked=true;
   }
   if(btn.Name == this.userControEmp.btnUpdate.Name)
   {
    FileReslove FRes = new FileReslove(CGlobe.GFplantfid,CGlobe.Gfname,CGlobe.Gfid);
    string Fuser = userControEmp.txtFuser.Text.Trim();
    string Fpwd = userControEmp.txtFpwd.Text.Trim();
    if( Fpwd != this.userControEmp.pwd.Text.Trim())
    {
     MessageBox.Show("两次口令输入不同,请重新输入!",CGlobe.Gmsg);
     return;
    }
    if(this.userControEmp.txtfname.Text.Trim() == "" || Fuser == "" || Fpwd == "")
    {
     MessageBox.Show("用户名、登录口令不能为空!",CGlobe.Gmsg);
     return;
    }
    if(userControEmp.txtFWorkAge.Text.Trim()=="")
     userControEmp.txtFWorkAge.Text="0";
    if(!FRes.JudgeInt(userControEmp.txtFWorkAge.Text.Trim()))
    {
     MessageBox.Show("您填写的工龄存在问题,请重新填写!",CGlobe.Gmsg);
     userControEmp.txtFWorkAge.Text="";
     return;
    }
    string sql="select Fname from dnc_sys_employee where Fuser = '"+Fuser + "' and Fpwd = '" + Fpwd + "'";
    DataTable Dt = Pbase.GetDatetable(null,sql);
    if(Dt.Rows.Count>0 && PlantFid=="")
    {
     MessageBox.Show("系统已经出现了相同用户名和口令的用户!\r\n\r\n请修改用户名或者口令后再重新保存。",CGlobe.Gmsg);
     return;
    }
    Dt.Dispose();
    SortedList sl = new SortedList();
    SaveOptionEnum SaveType;
    if(PlantFid == ""  || PlantFid == null)
    {
     SaveType = SaveOptionEnum.Insert;
     PlantFid = Guid.NewGuid().ToString();
    }
    else
    {
     SaveType = SaveOptionEnum.Update;
    }
    sl.Add("FID",PlantFid);
    sl.Add("Fuser",Fuser);
    sl.Add("Fname",userControEmp.txtfname.Text.Trim());
    sl.Add("Fduty",userControEmp.txtFduty.Text.Trim());
    sl.Add("FWorkAge",Convert.ToInt32(userControEmp.txtFWorkAge.Text.Trim()));
    sl.Add("Fpwd",userControEmp.txtFpwd.Text.Trim());
    sl.Add("FEduLevel",userControEmp.txtFEduLevel.Text.Trim());
    sl.Add("Ftel",userControEmp.txtFtel.Text.Trim());
    sl.Add("FEmail",userControEmp.txtFEmail.Text.Trim());
    sl.Add("FFax",userControEmp.txtFFax.Text.Trim());
    sl.Add("Faddr",userControEmp.txtFaddr.Text.Trim());
    sl.Add("Fdesc",userControEmp.txtFdesc.Text.Trim());
    sl.Add("FPlantfid",SelNode.Tag.ToString());
    sl.Add("fisdelete",0);
    int fstop=0;
    int fchangepwd=0;
    if(userControEmp.checkBox1.Checked==true)fchangepwd=1;
    if(userControEmp.checkBox2.Checked==true)fstop=1;
    sl.Add("fchangepwd",fchangepwd);
    sl.Add("fstop",fstop);
    //
    try
    {
     if(Pbase.Save(null,sl,EntityTypeEnum.DNC_Sys_Employee,"FID",SaveType))
     {
      if(SaveType == SaveOptionEnum.Update)
      {
       this.userControEmp.listView1.Items.Remove(this.userControEmp.listView1.SelectedItems[0]);
      }
      //     if(SaveType == SaveOptionEnum.Insert)
      //     {
      string[] Listview = new string[13]
       {
        sl["Fname"].ToString(),
        sl["Fduty"].ToString(),
        "",
        sl["FWorkAge"].ToString(),
        sl["FEduLevel"].ToString(),
        sl["Ftel"].ToString(),
        sl["FEmail"].ToString(),
        sl["FFax"].ToString(),
        sl["Faddr"].ToString(),
        sl["Fdesc"].ToString(),
        "正常使用",
        "可改密码",
        ""
       };
      ListViewItem li = new ListViewItem(Listview,0);
      li.ForeColor = Color.Red;
      this.userControEmp.listView1.Items.Add(li);
      li.Tag = PlantFid;
      //     }
     }
    }
    catch(Exception ex)
    {
     MessageBox.Show(ex.Message,CGlobe.Gmsg);
     return;
    }
   }
  }
  private void listView1_Click(object sender, EventArgs e)
  {
//   this.userControEmp.listView1.BackColor = Color.Silver;
            ListViewItem li = this.userControEmp.listView1.SelectedItems[0];
   PlantFid = li.Tag.ToString();
//   li.BackColor = Color.Green;
   this.userControEmp.txtfname.Text=li.SubItems[0].Text;
   this.userControEmp.txtFduty.Text=li.SubItems[1].Text;
   this.userControEmp.txtFWorkAge.Text= li.SubItems[3].Text;
   this.userControEmp.txtFEduLevel.Text= li.SubItems[4].Text;
   this.userControEmp.txtFtel.Text= li.SubItems[5].Text;
   this.userControEmp.txtFEmail.Text= li.SubItems[6].Text;
   this.userControEmp.txtFFax.Text= li.SubItems[7].Text;
   this.userControEmp.txtFaddr.Text= li.SubItems[8].Text;
   this.userControEmp.txtFdesc.Text= li.SubItems[9].Text;
   if(li.SubItems[10].Text=="已禁用")this.userControEmp.checkBox2.Checked = true;
   else
    this.userControEmp.checkBox1.Checked = false;
   if(li.SubItems[11].Text == "可改密码") this.userControEmp.checkBox1.Checked = false;
   else this.userControEmp.checkBox2.Checked = true;
  }
  private void listView1_MouseUp(object sender, MouseEventArgs e)
  {
   if(e.Button==MouseButtons.Right)
   {
    this.userControEmp.listView1.ContextMenu=this.contextMenu1;
    Point point=new Point(e.X,e.Y);
    listitem = this.userControEmp.listView1.GetItemAt(point.X,point.Y);
    if(listitem == null)
    {
     menuItem1.Enabled=false;
     MessageBox.Show("您没有选中人员系统无法查看用户权限!",CGlobe.Gmsg);
     return;
    }
    else
     menuItem1.Enabled=true;
    CGlobe.GParm =listitem.Tag.ToString();
   }
  }
  ListViewItem listitem;
  private void menuItem1_Click(object sender, System.EventArgs e)
  {
   FEmpRoleSel FroleSel = new FEmpRoleSel();
   FroleSel.ShowDialog(this);
   FroleSel.Dispose();
  }
  #endregion dnc_sys_employee

  private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
  {
   string sql;
   SelNode = this.treeView1.SelectedNode;
   if(SelNode == null)return;
   int Etype = 0;
   if(SelNode.Tag.ToString().Length==1)
    Etype = Convert.ToInt32(SelNode.Tag.ToString());
   else
   {
    if(SelNode.Tag.ToString().Length>1)
    {
     Etype = Convert.ToInt32(SelNode.Parent.Tag.ToString());
    }
   }
   DataTable dt;
   switch(Etype)
   {
    case 0:
     #region plant
     this.userControRole1.SendToBack();
     this.userControEmp.SendToBack();
     this.userConPlant.listView1.Items.Clear();
     sql="select fid,Fname,Fcorporation,Faccount,Ftel,FEmail,Fsit,Faddr,Fdesc from DNC_Sys_Plant where fid like '"
//      +CGlobe.GFplantfid+"%'";
      +SelNode.Tag.ToString()+"%'";
     dt = Pbase.GetDatetable(null,sql);
     if(dt.Rows.Count>0)
     {
      for(int i=0;i<dt.Rows.Count;i++)
      {
       string[] str = new string[9]{
               dt.Rows[i][1].ToString(),
               dt.Rows[i][2].ToString(),
               dt.Rows[i][3].ToString(),
               dt.Rows[i][4].ToString(),
               dt.Rows[i][5].ToString(),
               dt.Rows[i][6].ToString(),
               dt.Rows[i][7].ToString(),
               dt.Rows[i][8].ToString(),
               dt.Rows[i][0].ToString()
              };
       ListViewItem item = new ListViewItem(str,1);
       item.Tag=dt.Rows[i][0].ToString();
       this.userConPlant.listView1.Items.Add(item);
      }
     }
     break;
     #endregion plant
    case 1:
     #region sys_role
     this.userConPlant.SendToBack();
     this.userControEmp.SendToBack();
     this.userControRole1.listVRole.Items.Clear();
     sql = "select fid,Fname,Fdesc,FISDELETE,FTIME,FPLANTFID,fcontent from dnc_sys_role where FPLANTFID like '"
//      +CGlobe.GFplantfid+"%'";
      +SelNode.Tag.ToString()+"%'";
     dt = Pbase.GetDatetable(null,sql);
     if(dt.Rows.Count>0)
     {
      for(int i=0;i<dt.Rows.Count;i++)
      {
       string[] strrole = new string[6]
        {
         dt.Rows[i][1].ToString(),
         "",
         dt.Rows[i][2].ToString(),
         dt.Rows[i][4].ToString(),
         "",
            ""
       };
       if(dt.Rows[i][3].ToString() == "0")
        strrole.SetValue("使用当中",4);
       else
        strrole.SetValue("已禁用",4);
       sql="select Fname from dnc_sys_plant where fid='"+dt.Rows[i][5].ToString()+"'";
       DataTable Dplant = Pbase.GetDatetable(null,sql);
       if(Dplant.Rows.Count>0)
        strrole.SetValue(Dplant.Rows[0][0].ToString(),1);
       strrole.SetValue(dt.Rows[i][6].ToString(),5);
       ListViewItem roleitem = new ListViewItem(strrole,2);
       roleitem.Tag = dt.Rows[i][0].ToString();
       this.userControRole1.listVRole.Items.Add(roleitem);
      }
     }
     break;
     #endregion sys_role
    case 2:
     #region dnc_sys_employee
     this.userConPlant.SendToBack();
     this.userControRole1.SendToBack();
     this.userControEmp.listView1.Items.Clear();
     sql = "select fid,Fname,Fduty,FWorkAge,FEduLevel,Ftel,FEmail,FFax,Faddr,Fdesc,fstop,fchangepwd,fplantfid,Frolefid from dnc_sys_employee where FPLANTFID like '"
      +SelNode.Tag.ToString()+"%'";
     dt = Pbase.GetDatetable(null,sql);
     if(dt.Rows.Count>0)
     {
      for(int i=0;i<dt.Rows.Count;i++)
      {
       string[] strrole = new string[12]
        {
         dt.Rows[i][1].ToString(),
         dt.Rows[i][2].ToString(),
         "",
         dt.Rows[i][3].ToString(),
         dt.Rows[i][4].ToString(),
         dt.Rows[i][5].ToString(),
         dt.Rows[i][6].ToString(),
            dt.Rows[i][7].ToString(),
            dt.Rows[i][8].ToString(),
            dt.Rows[i][9].ToString(),
         "",
            ""
        };
       if(dt.Rows[i][10].ToString() == "0")
        strrole.SetValue("正常使用",10);
       else
        strrole.SetValue("已禁用",10);
       if(dt.Rows[i][11].ToString() == "0")
        strrole.SetValue("可改密码",11);
       else
        strrole.SetValue("不可改密码",11);
       //
       string[] FroleFid = dt.Rows[i]["Frolefid"].ToString().Split('|');
       string RoleFid = "";
       for(int j=0;j<FroleFid.Length;j++)
       {
        if(FroleFid[j].Length<= 0)continue;
        if(j> 0 && j< (FroleFid.Length-1))
         RoleFid = RoleFid+"'" + FroleFid[j]+"',";
        else
         RoleFid = RoleFid + "'" + FroleFid[j]+"',";
       }
       if(RoleFid.LastIndexOf(',')!=-1)
        RoleFid = RoleFid.Substring(0,RoleFid.Length - 1);
       if(RoleFid.Length > 0)
       {
        sql="select Fname from DNC_Sys_Role where fid in ("+RoleFid+")";
        DataTable DtRole = Pbase.GetDatetable(null,sql);
        RoleFid = "";
        if(DtRole.Rows.Count>0)
        {
         for(int g=0;g<DtRole.Rows.Count;g++)
          RoleFid = RoleFid + "[" +DtRole.Rows[g][0].ToString()+"]";
        }
       }
       else
        RoleFid = "未赋角色";
       strrole.SetValue(RoleFid,2);
       //
       ListViewItem roleitem = new ListViewItem(strrole,2);
       roleitem.Tag = dt.Rows[i][0].ToString();
       this.userControEmp.listView1.Items.Add(roleitem);
      }
     }
     break;
     #endregion dnc_sys_employee
    default:
     break;
   }
  }

  private void btndelClick(object sender, EventArgs e)
  {
   DialogResult Result = MessageBox.Show("删除后系统无法进行恢复操作,您确定本次删除操作吗?",
    CGlobe.Gmsg,MessageBoxButtons.OKCancel,MessageBoxIcon.Question,MessageBoxDefaultButton.Button2);
   if(Result == DialogResult.OK)
   {
    Button btn = (Button)sender;
    string Fid="";
    string TableName="";
    ListView LV=null;
    PlantFid="";
    switch(btn.Parent.Parent.Name)
    {
     case "userConPlant":
      LV = (ListView)this.userConPlant.listView1;
      TableName= "DNC_SYS_PLANT";
      break;
     case "userControRole1":
      //     Fid = this.userControRole1.listVPurview.SelectedItems[0].Tag.ToString();
      LV = (ListView)this.userControRole1.listVRole;
      TableName= "DNC_SYS_ROLE";
      break;
     case "userControEmp":
      //     Fid = this.userControEmp.listView1.SelectedItems[0].Tag .ToString();
      LV = (ListView)this.userControEmp.listView1;
      TableName= "DNC_SYS_EMPLOYEE";
      break;
     default:
      break;
    }

    if(LV.SelectedItems.Count<= 0 || LV.SelectedItems.Count > 1)return;
    Fid = LV.SelectedItems[0].Tag.ToString();
    if(Fid == "" || Fid == null)return;
    string sql="delete from "+TableName+" where fid='"+Fid+"'";
    Pbase.ExecuteSql(null,sql,rulebase.SqlResultEnum.No);
    LV.Items.Remove(LV.SelectedItems[0]);
   }
  }

 }
}

posted on 2007-12-17 16:09  hekeneng  阅读(328)  评论(0编辑  收藏  举报

导航