📄 shitemlist.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using Jinrm.Data;
using GzglClient.ColumnStyles;
using GzglClient.Froms;
namespace GzglClient.Views
{
/// <summary>
/// SHItemList 的摘要说明。
/// </summary>
public class SHItemList : System.Windows.Forms.UserControl , IView
{
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.TreeView OrgTree;
private System.Windows.Forms.Splitter splitter1;
internal System.Windows.Forms.DataGrid YWItemListGrid;
private System.Windows.Forms.ContextMenu CMYWItemList;
private System.Windows.Forms.MenuItem miAdd;
private System.Windows.Forms.MenuItem miUpdate;
private System.Windows.Forms.MenuItem miDel;
private DoAccess conn = new DoAccess();
/// <summary>
/// 业务类别
/// </summary>
public string YWType = "所有业务";
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
/// <summary>
///
/// </summary>
public SHItemList()
{
// 该调用是 Windows.Forms 窗体设计器所必需的。
InitializeComponent();
// TODO: 在 InitializeComponent 调用后添加任何初始化
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.OrgTree = new System.Windows.Forms.TreeView();
this.panel2 = new System.Windows.Forms.Panel();
this.YWItemListGrid = new System.Windows.Forms.DataGrid();
this.splitter1 = new System.Windows.Forms.Splitter();
this.CMYWItemList = new System.Windows.Forms.ContextMenu();
this.miAdd = new System.Windows.Forms.MenuItem();
this.miUpdate = new System.Windows.Forms.MenuItem();
this.miDel = new System.Windows.Forms.MenuItem();
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.YWItemListGrid)).BeginInit();
this.SuspendLayout();
//
// panel1
//
this.panel1.Controls.Add(this.OrgTree);
this.panel1.Dock = System.Windows.Forms.DockStyle.Left;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(240, 488);
this.panel1.TabIndex = 0;
//
// OrgTree
//
this.OrgTree.Dock = System.Windows.Forms.DockStyle.Fill;
this.OrgTree.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.OrgTree.ImageIndex = -1;
this.OrgTree.Location = new System.Drawing.Point(0, 0);
this.OrgTree.Name = "OrgTree";
this.OrgTree.SelectedImageIndex = -1;
this.OrgTree.Size = new System.Drawing.Size(240, 488);
this.OrgTree.TabIndex = 14;
this.OrgTree.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.OrgTree_AfterSelect);
//
// panel2
//
this.panel2.Controls.Add(this.YWItemListGrid);
this.panel2.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel2.Location = new System.Drawing.Point(240, 0);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(460, 488);
this.panel2.TabIndex = 1;
//
// YWItemListGrid
//
this.YWItemListGrid.AllowDrop = true;
this.YWItemListGrid.BackgroundColor = System.Drawing.SystemColors.Window;
this.YWItemListGrid.CaptionVisible = false;
this.YWItemListGrid.ContextMenu = this.CMYWItemList;
this.YWItemListGrid.DataMember = "";
this.YWItemListGrid.Dock = System.Windows.Forms.DockStyle.Fill;
this.YWItemListGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.YWItemListGrid.Location = new System.Drawing.Point(0, 0);
this.YWItemListGrid.Name = "YWItemListGrid";
this.YWItemListGrid.ReadOnly = true;
this.YWItemListGrid.Size = new System.Drawing.Size(460, 488);
this.YWItemListGrid.TabIndex = 13;
this.YWItemListGrid.DoubleClick += new System.EventHandler(this.YWItemListGrid_DoubleClick);
//
// splitter1
//
this.splitter1.Location = new System.Drawing.Point(240, 0);
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(3, 488);
this.splitter1.TabIndex = 2;
this.splitter1.TabStop = false;
//
// CMYWItemList
//
this.CMYWItemList.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.miAdd,
this.miUpdate,
this.miDel});
//
// miAdd
//
this.miAdd.Index = 0;
this.miAdd.Text = "添加";
this.miAdd.Click += new System.EventHandler(this.miAdd_Click);
//
// miUpdate
//
this.miUpdate.Index = 1;
this.miUpdate.Text = "修改";
this.miUpdate.Click += new System.EventHandler(this.miUpdate_Click);
//
// miDel
//
this.miDel.Index = 2;
this.miDel.Text = "删除";
this.miDel.Click += new System.EventHandler(this.miDel_Click);
//
// YWItemList
//
this.Controls.Add(this.splitter1);
this.Controls.Add(this.panel2);
this.Controls.Add(this.panel1);
this.Name = "YWItemList";
this.Size = new System.Drawing.Size(700, 488);
this.Load += new System.EventHandler(this.YWItemList_Load);
this.panel1.ResumeLayout(false);
this.panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.YWItemListGrid)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void YWItemList_Load(object sender, System.EventArgs e)
{
BuildTopLevelTree();
YWItemListGrid.TableStyles.Add(YWItemListDgStyle.GetStyle());
}
private void OrgTree_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
if(OrgTree.SelectedNode != null)
{
TreeNode node = OrgTree.SelectedNode;
string[] temp = node.Tag.ToString().Split('|');
string tempType = temp[0].ToString();
string tempId = temp[1].ToString();
if(tempType == "XZ" || tempType == "SY")
{
DataSet ds = null;
if(YWType == "所有审核业务")
{
miAdd.Enabled = false;
miUpdate.Enabled = false;
miDel.Enabled = false;
ds = conn.GetDs("*","YWItem","WOrgBaseId = '"+ tempId +"' ","YWItem");
}
else
{
miAdd.Enabled = true;
miUpdate.Enabled = true;
miDel.Enabled = true;
ds = conn.GetDs("*","YWItem","WOrgBaseId = '"+ tempId +"' and YWItemType = '"+ YWType +"' ","YWItem");
}
YWItemListGrid.DataSource = ds.Tables[0].DefaultView;
}
}
}
// /// <summary>
// ///
// /// </summary>
// /// <returns></returns>
// public bool BuildDataGrid()
// {
// DataSet ds = null;
// if(YWType == "所有业务")
// {
// ds = conn.GetDs("SELECT *,(SELECT Name FROM Person WHERE YWItem.WPersonID = Person.PersonID) AS UserName FROM YWItem INNER JOIN Person ON Person.PersonId = YWItem.WPersonId where YWItem.WOrgBaseId = '"+ OrgBaseId +"' ","YWItem");
// }
// else
// {
// ds = conn.GetDs("*","YWItem","WOrgBaseId = '"+ OrgBaseId +"' and YWItemType = '"+ YWType +"' ","YWItem");
// }
// YWItemListGrid.DataSource = ds.Tables[0].DefaultView;
//
// return true;
// }
private void miAdd_Click(object sender, System.EventArgs e)
{
switch(YWType)
{
case "试用审核" :
frm_YW_SY f_y_s = new frm_YW_SY();
f_y_s.FuncType = "Add";
f_y_s.ShowDialog();
break;
}
}
private void miUpdate_Click(object sender, System.EventArgs e)
{
}
private void miDel_Click(object sender, System.EventArgs e)
{
}
private void YWItemListGrid_DoubleClick(object sender, System.EventArgs e)
{
string tempIDCard = GetSelectedIDCard();
if(tempIDCard != "-1" && tempIDCard != "")
{
string tempYWItemType = conn.GetValueFromName("YWItemType","YWItem","YWItemID = '"+ tempIDCard +"' ");
switch(tempYWItemType)
{
case "试用审核" :
frm_YW_SY f_y_s = new frm_YW_SY();
f_y_s.YWItemID = tempIDCard;
f_y_s.FuncType = "Update";
f_y_s.ShowDialog();
break;
}
}
}
/// <summary>
/// 获取当前Grid的选定项的IDCard
/// </summary>
/// <returns></returns>
private string GetSelectedIDCard()
{
if (YWItemListGrid.DataSource == null || !YWItemListGrid.TableStyles.Contains(YWItemListDgStyle.TableName))
return "-1";
try
{
int taskIDColumnIndex = 0;
foreach (DataGridColumnStyle dgColumnStyle in YWItemListGrid.TableStyles[YWItemListDgStyle.TableName].GridColumnStyles)
{
if (dgColumnStyle.HeaderText == "业务编号")
break;
else
taskIDColumnIndex++;
}
int currentRow = YWItemListGrid.CurrentRowIndex;
return (string) YWItemListGrid[currentRow, taskIDColumnIndex];
}
catch (Exception)
{
return "-1";
}
}
#region 树
private void BuildTopLevelTree()
{
DataSet ds = conn.GetDs("*","OrgBase","","");
InitTree(OrgTree.Nodes,"0",ds);
OrgTree.ExpandAll();
}
//建树的基本思路是:从根节点开始递归调用显示子树
private void InitTree(System.Windows.Forms.TreeNodeCollection Nds,string ParentId,DataSet ds)
{
DataView dv=new DataView();
dv.Table=ds.Tables[0];
dv.RowFilter="ParentId='" + ParentId + "'";
foreach(DataRowView drv in dv)
{
TreeNode tmpNd = null;
if(drv["WJGLXId"].ToString() != "EMUI000011" && drv["WJGLXId"].ToString() != "EMUI000012")//党政机关
{
tmpNd = new TreeNode(drv["OrgName"].ToString());
tmpNd.Tag = "XZ|" + drv["OrgBaseId"].ToString();
}
else//事业单位
{
tmpNd = new TreeNode(drv["OrgName"].ToString());
tmpNd.Tag = "SY|" + drv["OrgBaseId"].ToString();
}
Nds.Add(tmpNd);
InitTree(tmpNd.Nodes,tmpNd.Tag.ToString().Split('|')[1].ToString(),ds);
}
}
#endregion
#region IView 成员
public void Release()
{
Dispose();
}
public ViewType TheType
{
get {return ViewType.SHItemList;}
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -