暂停车辆的拖拽修改数据库表中的排序字段值

     #region 暂停车辆的拖拽
        /*
         *开始拖动节点时发生
         */
        private void tvPause_ItemDrag(object sender, ItemDragEventArgs e)
        {
            TreeNode tn = e.Item as TreeNode;
            //当按住鼠标左键拖动节点时移动节点。
            if (e.Button == MouseButtons.Left)//父节点不允许拖动
            {
                DoDragDrop(e.Item, DragDropEffects.Move);
            }
            else if (e.Button == MouseButtons.Right)//当按住鼠标右键拖动节点时复制节点
            {
                DoDragDrop(e.Item, DragDropEffects.Copy);
            }
        }
        /**
         * 拖放行为完成
         */
        private void tvPause_DragDrop(object sender, DragEventArgs e)
        {
            Point Position = new Point(0, 0);
            TreeNode myNode = null;//选中的节点
            if (e.Data.GetDataPresent(typeof(TreeNode)))
            {
                myNode = (TreeNode)(e.Data.GetData(typeof(TreeNode)));
            }
            else
            {
                MessageBox.Show("error");
            }
            Position.X = e.X;
            Position.Y = e.Y;
            Position = tvPause.PointToClient(Position);
            TreeNode DropNode = tvPause.GetNodeAt(Position);//落下的节点
            // 确定落下的节点不是被拖拽节点本身或者被拖拽节点的子节点
            if (!DropNode.Equals(myNode) && !ContainsNode(DropNode, myNode))
            {
                if (e.Effect == DragDropEffects.Move)
                {
                    DragNodeView(myNode, DropNode, 3);
                }
                else if (e.Effect == DragDropEffects.Copy)
                {
                    myNode.Nodes.Add((TreeNode)DropNode.Clone());
                }
                myNode.Expand();
            }

        }

        private void tvPause_DragOver(object sender, DragEventArgs e)
        {
            Point targetPoint = this.PointToClient(new Point(e.X, e.Y));
            tvPause.SelectedNode = tvPause.GetNodeAt(targetPoint);
        }

        private void tvPause_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = e.AllowedEffect;
        }
        #endregion

        /// <summary>
        /// 鼠标拖拽效果三个tv公用方法
        /// </summary>
        /// <param name="myNode">鼠标选中的节点</param>
        /// <param name="DropNode">要移动到那个节点下面或者上面的落下节点</param>
        ///  <param name="VehicleStateType_ID">车辆状态类型</param>
        private void DragNodeView(TreeNode myNode, TreeNode DropNode, int VehicleStateType_ID)
        {
            //1找到选中节点的排序
            string sqlmyNode = "SELECT VehicleOrder_ID from EMTinCar where NO='" + myNode.Text + "'";
            string myNodeValue = Common.Conn.SqlHelper.getSqlValue(sqlmyNode);
            //2找到落下的节点的排序
            string sqlDragNode = "SELECT VehicleOrder_ID from EMTinCar where NO='" + DropNode.Text + "'";
            string DragNodeValue = Common.Conn.SqlHelper.getSqlValue(sqlDragNode);
            int NodeValue = Convert.ToInt32(myNodeValue);
            int DragNodes = Convert.ToInt32(DragNodeValue);
             string JuageSql=string.Empty;
             string strupdateSql = string.Empty;
             string strMessage=string.Empty;
            if (NodeValue > DragNodes)
            {
                #region 上移
                //3 小于选中的,大于等于落下的排序加1
                JuageSql = string.Format("exec Up_EMTinCarinfo {0},{1},{2}", VehicleStateType_ID, NodeValue, DragNodes);
                strMessage = Common.Conn.SqlHelper.ExecSql(JuageSql);
                if (strMessage != string.Empty)
                {
                    return;
                }
                #endregion
            }
            else
            {
                #region  下移
                //3把落下的节点的排序,替换之前把之前的排序
                JuageSql = string.Format("exec Up_EMTinCarinfo1 {0},{1},{2}", VehicleStateType_ID, myNodeValue, DragNodeValue);
                strMessage = Common.Conn.SqlHelper.ExecSql(JuageSql);
                if (strMessage != string.Empty)
                {
                    return;
                }
                #endregion
            }

            //4选中节点的排序与落下的节点的排序互换
            DataTable dt = YieldTransitEditBus.getTinByNo(myNode.Text);
            if (dt != null && dt.Rows.Count > 0)
            {
                tin.ID = Convert.ToInt32(dt.Rows[0]["ID"].ToString());
            }
            tin.VehicleOrder_ID = Convert.ToInt32(DragNodeValue);
            tin.VehicleStateType_ID = 3;
            if (YieldTransitEditBus.updateemtin(tin))
            {
                BindDateQueuing();
                BindDatetvDeparture();
                BindDatetvPause();
            }

        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值