Beispiel #1
0
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            foreach (TreeNode tnParent in treeView2.Nodes)
            {
                tnParent.Checked = false;
            }
            string strsql = "select * from tbOperDept where cnnOperID={0}";

            if (e.Node.Name.StartsWith("oper-"))
            {
                string    operid = e.Node.Name.Substring("oper-".Length);
                DataTable dt     = Helper.Query(string.Format(strsql, operid));
                foreach (DataRow dr in dt.Rows)
                {
                    OperDept   of  = new OperDept(dr);
                    TreeNode[] tns = treeView2.Nodes.Find(of.cnnDeptID.ToString(), true);

                    if (tns.Length > 0)
                    {
                        for (int i = 0; i < tns.Length; i++)
                        {
                            tns[i].Checked = true;
                        }
                    }
                }
            }
        }
        public void ModifyOperDept(List <Dept> alOperDeptList, string iOperID)
        {
            try
            {
                conn  = ConnectionPool.BorrowConnection();
                trans = conn.BeginTransaction();
                SqlHelper.ExecuteNonQuery(trans, CommandType.Text, "delete from tbOperDept where cnnOperID = " + iOperID);
                for (int i = 0; i < alOperDeptList.Count; i++)
                {
                    Dept     dept     = alOperDeptList[i] as Dept;
                    OperDept operdept = new OperDept();
                    operdept.cnnOperID = Convert.ToInt32(iOperID);
                    operdept.cnnDeptID = dept.cnnDeptID;

                    EntityMapping.Create(operdept, trans);
                }

                trans.Commit();
            }
            catch (BusinessException bex) //业务异常
            {
                //LogAdapter.WriteBusinessException(bex);
                trans.Rollback();
                throw new BusinessException(bex.Type, bex.Message);
            }
            catch (SqlException sex)   //数据库异常
            {
                //事务回滚
                trans.Rollback();
                //LogAdapter.WriteDatabaseException(sex);
                throw new BusinessException("数据库异常", sex.Message);
            }
            catch (Exception ex)                 //其他异常
            {
                //事务回滚
                trans.Rollback();
                //LogAdapter.WriteFeaturesException(ex);
                throw new BusinessException("其它异常", ex.Message);
            }
            finally
            {
                ConnectionPool.ReturnConnection(conn);
            }
        }