using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using DBUtility; namespace BaseSet { public partial class Gy_Duty : Form { private int HItemIDCol = 0; private int HNumberCol = 0; public DBUtility.frm_B_BillQueryCondition_New frmCondition; public const string ViewName = "h_v_Gy_DutyList"; public string CheckProcName = "h_p_Gy_Duty"; //20141020 public string ModName = "组织架构"; public const string BillName = "Gy_Duty"; public const string ModRightNameEdit = BillName + "_Edit"; public const string ModRightNameDelete = BillName + "_Delete"; public DBUtility.ClsPub.Enum_InputMode InputMode; //录入状态标志(0-非录入状态 1-增加 2-修改) public long HItemID;//项目ID public string sCondition; //过滤条件 SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); DAL.ClsGy_Duty_Ctl Duty = new DAL.ClsGy_Duty_Ctl(); DAL.ClsGy_Duty_View DutyHlp = new DAL.ClsGy_Duty_View(); TreeNode CurNode = new TreeNode(); DBUtility.ClsPub oPub = new DBUtility.ClsPub(); public Gy_Duty() { InitializeComponent(); } //以下代码基本不需要修改 #region 固定代码 //保存GRID列宽 private void Gy_Duty_FormClosing(object sender, FormClosingEventArgs e) { DBUtility.ClsPub.SaveGridView(grdMain, this.Name, DBUtility.ClsPub.AppPath); } //窗体加载 private void Gy_Duty_Load(object sender, EventArgs e) { frmCondition = new DBUtility.frm_B_BillQueryCondition_New(); LoadTree(); initGrid(); InputMode = DBUtility.ClsPub.Enum_InputMode.InputMode_View; RefreshTool(); } //加载子结点 private void LoadAllNodes(TreeNode sNode) //Lock { if (sNode != null) { try { long sName = Convert.ToInt64(sNode.Name.Substring(1, sNode.Name.Length - 1)); sNode.Nodes.Clear(); DataSet Ds = oCn.RunProcReturn("select hitemid,hnumber,hname from Gy_Duty where HParentID='" + sName + "'", "Gy_Duty", ref DBUtility.ClsPub.sExeReturnInfo); for (int i = 0; i < Ds.Tables[0].Rows.Count; i++) { TreeNode oNode = sNode.Nodes.Add("T" + Ds.Tables[0].Rows[i]["HItemID"].ToString(), Ds.Tables[0].Rows[i]["HNumber"].ToString() + "-" + Ds.Tables[0].Rows[i]["HName"].ToString(), 0,1); } sNode.Expand(); } catch (Exception e) { MessageBox.Show("加载子项目失败!" + e.Message, "提示"); } } } //加载树形 private void LoadTree()//Lock { try { tv.Nodes.Clear(); tv.ImageList = imageList1; TreeNode sNode = tv.Nodes.Add("T0", this.Text, 0, 1); LoadAllNodes(sNode); } catch (Exception e ) { MessageBox.Show("加载树型失败!" + e.Message, "提示"); } } private bool AllowSave() { //全部判断 if (txtHNumber.Text.Trim() == "") { MessageBox.Show("项目代码不能为空!", "提示"); return false; } if (txtHName.Text.Trim() == "") { MessageBox.Show("项目名称不能为空!", "提示"); return false; } //---------------------非上级组判断 if (InputMode != Pub_Class.ClsPub.Enum_InputMode.InputMode_ModifyGroup && InputMode != Pub_Class.ClsPub.Enum_InputMode.InputMode_AddNewGroup) { //if (txtHRemark.Text.Trim() == "") //{ // MessageBox.Show("备注不能为空!", "提示"); // return false; //} } if (DBUtility.ClsPub.isLong(txtHUserGroupID.Tag) == 0) { MessageBox.Show("角色不能为空!", "提示"); return false; } //----------------------------------------- //审核代码是否合理 if (!DBUtility.ClsPub.AllowNumber(txtHNumber.Text.Trim())) { MessageBox.Show("代码中不能出现连续‘.’并且首位末位不能为‘.’!", "提示"); return false; } //是否重复代码 if (Duty.HavSameNumber(HItemID, txtHNumber.Text.Trim())) { MessageBox.Show("代码重复!不能保存!", "提示"); return false; } return true; } //新增 private void AddNew() { InputMode = Pub_Class.ClsPub.Enum_InputMode.InputMode_AddNew; Init(); } //退出模块 private void tc_Click(object sender, EventArgs e) { this.Close(); } //刷新 private void xs_Click(object sender, EventArgs e) { Display(); } //查询 private void cx_Click(object sender, EventArgs e) { frmCondition = new DBUtility.frm_B_BillQueryCondition_New(); frmCondition.Tag = ""; frmCondition.ViewName = ViewName; frmCondition.ModName = this.Name; frmCondition.ShowDialog(); if (frmCondition.Tag.ToString() == "OK") { Display(); } } //得到对应列 private Int32 Fun_GetCol(string sCol)//Lock { for (int c = 0; c 1) { sCondition =" Where " + ModName + "代码 like '" + s[0].Trim()+"%'"; // Display(); } else if (s.Length > 0) { sCondition = " Where " + ModName + "代码 like '%%'"; // Display(); } else { } } //删除 private void sc_Click(object sender, EventArgs e) { Delete(); } //新增按钮 private void xz_Click(object sender, EventArgs e) { InputMode = Pub_Class.ClsPub.Enum_InputMode.InputMode_AddNew; Init(); } //修改 private void Modify() { if (AllowRow()) { InputMode = Pub_Class.ClsPub.Enum_InputMode.InputMode_Modify; RefreshTool(); Init(); } } //修改按钮 private void xg_Click(object sender, EventArgs e) { Modify(); } //选中行是否正常 private bool AllowRow() //Lock { if (grdMain.CurrentRow!=null) return true; else return false; } // private void Sub_Copy() { txtHNumber.Text = ""; txtHHelpCode.Text = ""; HItemID = 0; if (InputMode == Pub_Class.ClsPub.Enum_InputMode.InputMode_Modify) { InputMode = Pub_Class.ClsPub.Enum_InputMode.InputMode_AddNew; } else if (InputMode == Pub_Class.ClsPub.Enum_InputMode.InputMode_ModifyGroup) { InputMode = Pub_Class.ClsPub.Enum_InputMode.InputMode_AddNewGroup; } } //初始化界面 private bool Init() { long sItemID; pother.Visible = true; if (InputMode == Pub_Class.ClsPub.Enum_InputMode.InputMode_AddNew) { Sub_Clear(); RefreshTool(); return true; } else if (InputMode == Pub_Class.ClsPub.Enum_InputMode.InputMode_AddNewGroup)//加组 { Sub_Clear(); RefreshTool(); pother.Visible = false; return true; } else { //得到HITEMID sItemID = DBUtility.ClsPub.isLong(grdMain.Rows[grdMain.CurrentRow.Index].Cells[HItemIDCol].Value); //检查是否存在 if (DutyHlp.GetInfoByID(sItemID)) { ShowData(sItemID); //txtHNumber.Focus(); return true; } else { MessageBox.Show("您选择的项目已经不存在!" + DBUtility.ClsPub.sExeReturnInfo, "提示"); return false; } } } //保存 private bool Save() { //判断权限 if (!ClsPub.Security_Log(ModRightNameEdit, 1, true, DBUtility.ClsPub.CurUserName)) { return false; } // if (InputMode == Pub_Class.ClsPub.Enum_InputMode.InputMode_AddNew || InputMode == Pub_Class.ClsPub.Enum_InputMode.InputMode_AddNewGroup) { if (Duty.AddNew()) { Init(); } else { return false; } Display(); } if (InputMode == Pub_Class.ClsPub.Enum_InputMode.InputMode_Modify || InputMode == Pub_Class.ClsPub.Enum_InputMode.InputMode_ModifyGroup) { if (!Duty.ModifyByID(HItemID)) { return false; } Display(); } return true; } //保存列宽 private void bclk_Click(object sender, EventArgs e) { DBUtility.ClsPub.SaveGridView(grdMain, this.Name, DBUtility.ClsPub.AppPath); } //默认列宽 private void mrlk_Click(object sender, EventArgs e)//Lock { DBUtility.ClsPub.DefaultGridView(grdMain); //参数解释 开始列 ,结束列,是否以最大列宽为准,最小列宽 DBUtility.ClsPub.SaveGridView(grdMain, this.Name, DBUtility.ClsPub.AppPath); } //时间控件 private void timer1_Tick(object sender, EventArgs e) { timer1.Enabled = false; Display(); } //双击GRID private void grdMain_DblClick(object sender, EventArgs e) { Modify(); } //初始化GRID private void initGrid() { grdMain.SelectionMode = DataGridViewSelectionMode.FullRowSelect; //选中模式--行选中 grdMain.ColumnHeadersVisible = true; //标题列显示--是 grdMain.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing; //标题列尺寸模式--(自动调整,可调整) grdMain.RowTemplate.Height = 18; grdMain.RowTemplate.MinimumHeight = 18; grdMain.ColumnHeadersHeight = 35; //标题行高 grdMain.RowHeadersVisible = false; //标题行可见--否 grdMain.AllowUserToAddRows = false; //是否允许自增--否 grdMain.AllowUserToDeleteRows = false; //是否允许删除--否 grdMain.ColumnCount = 0; //总列数--5 grdMain.RowCount = 0; grdMain.AllowUserToResizeColumns = true; //允许调整列宽--是 grdMain.AllowUserToResizeRows = false; //允许调整行高--否 grdMain.ReadOnly = true; //只读--是 grdMain.BackgroundColor = Color.White; grdMain.GridColor = Color.LightGray; grdMain.DefaultCellStyle.SelectionBackColor = Color.Black; grdMain.EnableHeadersVisualStyles = false; //网格标题 样式 grdMain.AlternatingRowsDefaultCellStyle.BackColor = Color.Bisque; } //显示列表 private void Display() // 幻心 { SQLHelper.ClsCN SubCn = new SQLHelper.ClsCN(); DataSet DSet; string sSql = ""; string sWhere = ""; //刷新树形 //LoadTree(); //过滤条件 if (DBUtility.ClsPub.isStrNull( sCondition)== "" && frmCondition.SqlStr.Trim().Length!= 0) { sSql = frmCondition.SqlStr + sWhere + " order by " + ModName +"代码"; } else if (DBUtility.ClsPub.isStrNull( sCondition)!= "" ) { sSql = "Select * from " + ViewName + sCondition + sWhere + " order by " + ModName + "代码"; } else { sSql = "Select * from " + ViewName + " order by " + ModName + "代码"; } //执行SQL DSet = SubCn.RunProcReturn(sSql, ViewName, ref DBUtility.ClsPub.sExeReturnInfo); // if (DSet == null) { MessageBox.Show("显示失败!原因:" + DBUtility.ClsPub.sExeReturnInfo); return; } grdMain.DataSource = DSet.Tables[0].DefaultView; //禁用 红色显示 20141020 Sub_ShowStopFlag(); //加载列宽 for (int i = 0; i < grdMain.ColumnCount; i++) { grdMain.Columns[i].Width = 100; if (grdMain.Columns[i].HeaderText.Substring(0, 1).ToLower() == "h") { grdMain.Columns[i].Visible = false; } else { grdMain.Columns[i].Visible = true; } } DBUtility.ClsPub.GetGridView(this.grdMain, this.Name, DBUtility.ClsPub.AppPath); // HItemIDCol = Fun_GetCol("HItemID"); //HNumberCol = Fun_GetCol(ModName + "代码"); sCondition = ""; } //复制按钮 private void fz_Click(object sender, EventArgs e) { Sub_Copy(); } #endregion #region 类的读写 //读取类 到 控件 private void ShowData(long sItemID) { if (DutyHlp.GetInfoByID(sItemID)) { BLL.ClsGy_UserGroup_View oUser = new BLL.ClsGy_UserGroup_View(); if (oUser.GetInfoByID(DutyHlp.omodel.HUserGroupID)) { txtHUserGroupID.Text = oUser.omodel.GroupName; txtHUserGroupID.Tag = oUser.omodel.GroupID.ToString(); } else { txtHUserGroupID.Text = ""; } txtHNumber.Text = DutyHlp.omodel.HNumber.ToString(); txtHHelpCode.Text = DutyHlp.omodel.HHelpCode.ToString(); txtHName.Text = DutyHlp.omodel.HName.ToString(); txtHRemark.Text = DutyHlp.omodel.HRemark; if (DutyHlp.omodel.HStopflag) chkHStopflag.Checked = true; else chkHStopflag.Checked = false; HItemID = DutyHlp.omodel.HItemID; } //判断是否是上级组 隐藏P2 if (DutyHlp.omodel.HEndFlag == false) { InputMode = Pub_Class.ClsPub.Enum_InputMode.InputMode_ModifyGroup; pother.Visible = false; } else { pother.Visible = true; } } //写入类 从控件 private bool WriteClass() { DAL.ClsGy_Duty_Ctl Dutyess = new DAL.ClsGy_Duty_Ctl(); DAL.ClsGy_Duty_View DutyHlp = new DAL.ClsGy_Duty_View(); //判断是否允许 保存 if (!AllowSave()) { return false; } //检查父级是否存在 string sParent; sParent = DBUtility.ClsPub.GetParentCode(txtHNumber.Text.Trim()); if (sParent.Trim() == "") { Duty.oModel.HParentID = 0; } else { if (Dutyess.HavParentCode(sParent.Trim(), HItemID)) { Duty.oModel.HParentID = Dutyess.oModel.HItemID; } else { MessageBox.Show("上级代码不存在或被禁用!", "提示"); return false; } } //得到短代码 string sShortNumber; sShortNumber = DBUtility.ClsPub.GetShortNumber(txtHNumber.Text.Trim()); if (sShortNumber.Trim() == "") { return false; } //保存原代码 if (DutyHlp.GetInfoByID(HItemID)) { Duty.HOldNumber = DutyHlp.oModel.HNumber; //是否新代码是自己子项目的 子项目 if (sParent.Length >= Duty.HOldNumber.Length) { if (sParent.Substring(0, Duty.HOldNumber.ToString().Length) == Duty.HOldNumber.Trim()) { MessageBox.Show("新代码不能是自己的下级的子项目!", "提示"); return false; } } } else { Duty.HOldNumber = ""; } //写入信息 Duty.oModel.HShortNumber = sShortNumber; if (InputMode == Pub_Class.ClsPub.Enum_InputMode.InputMode_ModifyGroup || InputMode == Pub_Class.ClsPub.Enum_InputMode.InputMode_AddNewGroup) { Duty.oModel.HEndFlag = false; } else { Duty.oModel.HEndFlag = true; } Duty.oModel.HLevel = DBUtility.ClsPub.GetLevel(txtHNumber.Text.Trim()); Duty.oModel.HNumber = txtHNumber.Text.Trim(); Duty.oModel.HHelpCode = txtHHelpCode.Text.Trim(); Duty.oModel.HName = txtHName.Text.Trim(); Duty.oModel.HStopflag = chkHStopflag.Checked; Duty.oModel.HRemark = txtHRemark.Text.Trim(); Duty.oModel.HUserGroupID = DBUtility.ClsPub.isLong(txtHUserGroupID.Tag); return true; } #endregion #region 界面控件处理 //新增时清空信息 private void Sub_Clear() //Lock { //清空界面控件 for 控件 foreach (Control ct in pother.Controls) { switch (ct.GetType().Name) { case "ListBox": ((ListBox)ct).Items.Clear(); break; case "CheckBox": ((CheckBox)ct).Checked = false; break; case "RadioButton": break; case "TextBox": ((TextBox)ct).Text = ""; break; case "DateTimePicker": ((DateTimePicker)ct).Value = DateTime.Today; break; default: break; } } foreach (Control ct in pmust.Controls) { switch (ct.GetType().Name) { case "ListBox": ((ListBox)ct).Items.Clear(); break; case "CheckBox": ((CheckBox)ct).Checked = false; break; case "RadioButton": break; case "TextBox": ((TextBox)ct).Text = ""; break; case "DateTimePicker": ((DateTimePicker)ct).Value = DateTime.Today; break; default: break; } } // HItemID = 0; //txtHNumber.Focus(); } // private void grdMain_DoubleClick(object sender, EventArgs e) { Modify(); } private void cmdLoadTree_Click(object sender, EventArgs e) { LoadTree(); } //加组按钮 private void sjz_Click(object sender, EventArgs e) { InputMode = Pub_Class.ClsPub.Enum_InputMode.InputMode_AddNewGroup; Init(); } #endregion private void cmdHAccountID_Click(object sender, EventArgs e) { BLL.ClsGy_UserGroup_View oUser = new BLL.ClsGy_UserGroup_View(); if (oUser.RefreshView("")) { txtHUserGroupID.Tag = oUser.oModel.HItemID.ToString(); txtHUserGroupID.Text = oUser.oModel.HName.ToString(); txtHName.Text = oUser.oModel.HName.ToString(); } else { txtHUserGroupID.Tag =""; txtHUserGroupID.Text = ""; } } private void txtHUserGroupID_TextChanged(object sender, EventArgs e) { if (txtHUserGroupID.Text.Trim() == "") { txtHUserGroupID.Tag = ""; } } //检测按钮 20141020 private void jc_Click(object sender, EventArgs e) { BLL.ClsPub_BLL.Sub_CheckUseStatus(grdMain, HItemIDCol, CheckProcName); Display(); } //禁用项目 红色字体 20141020 public void Sub_ShowStopFlag() { BLL.ClsPub_BLL.Sub_ShowStopFlag(grdMain, Fun_GetCol("禁用标记")); } } }