RackUnit.xaml
来源:互联网 发布:linux arp缓存表 编辑:程序博客网 时间:2024/04/26 05:35
前半厂
<UserControl x:Class="ComputerDropDragControl.RackUnit"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Border x:Name="borderOne" BorderBrush="Black" BorderThickness="1" Width="130" HorizontalAlignment="Left"
VerticalAlignment="Bottom" Margin="10,0,0,0">
<Grid x:Name="LayoutRoot" Background="White" >
</Grid>
</Border>
</UserControl>
后半厂
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using System.Windows.Media.Imaging;
namespace ComputerDropDragControl
{
/// <summary>
/// “机架”单元
/// 创建人:吴兆娟
/// 创建时间:2011-10-26
/// </summary>
public partial class RackUnit : UserControl
{
#region <<页面加载>>
/// <summary>
/// 页面加载事件
/// </summary>
public RackUnit(RowFrameView entity)
{
InitializeComponent();
FrameMsg = entity;
//加载控件
LoadControl();
}
#endregion
#region <<控件事件>>
#region <<拖拽相关事件>>
/// <summary>
/// “开始拖拽”
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dropDragPanel_ItemDragStarting(object sender, ItemDragEventArgs e)
{
StaticClass.FromList = false;
StaticClass.DragPanel = (PanelDragDropTarget)sender;
Dictionary<string, object> dic = GetDropDragPanelContentValues(StaticClass.DragPanel);
StackPanel stackContent = (StackPanel)(StaticClass.DragPanel.Content);
CU = (ComputerUnit)(stackContent.Children[3]);
CU.ShowTip = false;
}
/// <summary>
/// “目标”即是“放”的对象Drop事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dropDragPanel_Drop(object sender, Microsoft.Windows.DragEventArgs e)
{
StaticClass.DropInHandCar = false;
//“放”
StaticClass.DropPanel = (PanelDragDropTarget)sender;
DropPanel = (PanelDragDropTarget)sender;
Dictionary<string, object> dicDrop = GetDropDragPanelContentValues((PanelDragDropTarget)sender);
//“放”对象的父对象
Grid fatherDropGrid = ((Grid)((PanelDragDropTarget)sender).Parent);
int tempDropCount = (fatherDropGrid.Children.Count() + 1) / 2;
PanelDragDropTarget dropPanelEnd = (PanelDragDropTarget)fatherDropGrid.Children[(tempDropCount - (int)dicDrop["RackUNo"]) * 2];
StackPanel stackDropEnd = (StackPanel)dropPanelEnd.Content;
TextBlock tbDropFrame = (TextBlock)stackDropEnd.Children[0];
if (!StaticClass.FromList)
{
bool normalCondition = true;
//“拖”
StackPanel stackContent = (StackPanel)(StaticClass.DragPanel.Content);
CU = (ComputerUnit)(stackContent.Children[3]);
Dictionary<string, object> dicDrag = GetDropDragPanelContentValues(StaticClass.DragPanel);
//“拖”
Grid fatherDragGrid = (Grid)(StaticClass.DragPanel.Parent);
int tempDragCount = (fatherDragGrid.Children.Count() + 1) / 2;
StackPanel stackDragEnd = (StackPanel)StaticClass.DragPanel.Content;
TextBlock tbDragFrame = (TextBlock)stackDragEnd.Children[0];
TextBlock tbDragUNo = (TextBlock)stackDragEnd.Children[1];
TextBlock tbExist = (TextBlock)stackDragEnd.Children[2];
if (tbDropFrame.Text == tbDragFrame.Text)//同一个机器架内拖拽的业务逻辑
{
List<PanelDragDropTarget> listNeighborUp = new List<PanelDragDropTarget>();
for (int i = 1; i < CU.ReturnNodeFrameView.NodeSize; i++)
{
if ((tempDropCount - (int)dicDrag["RackUNo"] - i) * 2 > 0)
{
PanelDragDropTarget panelTemp = (PanelDragDropTarget)fatherDragGrid.Children[(tempDropCount - (int)dicDrag["RackUNo"] - i) * 2];
StackPanel stackTemp = (StackPanel)panelTemp.Content;
TextBlock tbExistTemp = (TextBlock)stackTemp.Children[2];
TextBlock tbRackUNo = (TextBlock)stackTemp.Children[1];
if (tbExistTemp.Text == "false")
{
listNeighborUp.Add(panelTemp);
}
else
{
break;
}
}
}
foreach (PanelDragDropTarget panel in listNeighborUp)
{
if (panel == DropPanel)
{
normalCondition = false;
//MessageBox.Show("特殊的拆分模式!");
DepartUnit(StaticClass.DragPanel);
MergeUnit(StaticClass.DragPanel, dicDrop);
StaticClass.ExistPlace = true;
UpdateData();
return;
}
}
}
if (normalCondition)
{
//是否存在存储空间以及操作
WhetherExistPlace();
}
}
else
{
ListBox list = (ListBox)StaticClass.DragPanelList.Content;
ListBoxItem selectItem = (ListBoxItem)list.SelectedItem;
SelectItem = selectItem;
SelectIndex = list.SelectedIndex;
NodeFrameView entity = (NodeFrameView)selectItem.DataContext;
ComputerUnit cu = new ComputerUnit(entity);
cu.ShowTip = true;
CU = cu;
//是否存在存储空间以及操作
WhetherExistPlace();
}
}
/// <summary>
/// “拖对象放至目标对象后”发生的事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dropDragPanel_ItemDroppedOnTarget(object sender, ItemDragEventArgs e)
{
if (StaticClass.DropInHandCar)//置入“手推车”
{
DepartUnit(StaticClass.DragPanel);
ListBoxDragDropTarget listDropPanel = (ListBoxDragDropTarget)StaticClass.DrogPanelList;
ListBox lb = (ListBox)listDropPanel.Content;
int count = lb.Items.Count;
lb.Items.RemoveAt(count - 1);
}
else if (StaticClass.DropInRecyle)//置入“回收站”
{
DepartUnit(StaticClass.DragPanel);
ListBoxDragDropTarget listDropPanel = (ListBoxDragDropTarget)StaticClass.DrogPanelList;
ListBox lb = (ListBox)listDropPanel.Content;
int count = lb.Items.Count;
//StaticClass.CUStatic = (ComputerUnit)lb.Items[count - 1];
lb.Items.RemoveAt(count - 1);
}
else//“普通”情况
{
if (StaticClass.DropPanel != null)
{
if (StaticClass.DropPanel.AllowDrop)
{
if (!StaticClass.ExistPlace)
{
CancelBehavior();
}
}
}
CU.ShowTip = true;
}
}
#endregion
/// <summary>
/// “模态窗口关闭”时发生
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void cr_Closed(object sender, EventArgs e)
{
CWInRack cr = (CWInRack)sender;
if (StaticClass.DropPanel != null)
{
if (!StaticClass.DropPanel.AllowDrop)
{
((StackPanel)StaticClass.DropPanel.Content).Children.Remove(SelectItem);
if (cr.DialogResult == false)
{
//拆分单元格
DepartUnit(StaticClass.DropPanel);
((StackPanel)StaticClass.DropPanel.Content).Children.RemoveAt(3);
StaticClass.DropPanel.AllowDrop = true;
ListBox list = (ListBox)StaticClass.DragPanelList.Content;
list.Items.Insert(SelectIndex, SelectItem);
}
if (cr.DialogResult == true)
{
if (StaticClass.FromHandCar)
{
foreach (ListBoxItem item in StaticClass.HandCarList)//“手推车”
{
if (item.Name == SelectItem.Name)
{
StaticClass.HandCarList.Remove(item);
return;
}
}
}
//数据库交互
}
StaticClass.FromHandCar = false;
}
}
}
#endregion
#region <<辅助方法>>
/// <summary>
/// 打开模态窗口
/// </summary>
private void OpenChildWindow()
{
CWInRack cr = new CWInRack();
cr.OverlayOpacity = 0.1;
cr.Height = 300;
cr.Width = 500;
//cr.Content = tempFrame;
cr.Show();
cr.Closed += new EventHandler(cr_Closed);
}
/// <summary>
/// 更新数据库
/// </summary>
private void UpdateData()
{
#region <<数据库交互>>
StackPanel stackDrop = (StackPanel)DropPanel.Content;
CU.ReturnNodeFrameView.FrameID = ((TextBlock)stackDrop.Children[0]).Text;
CU.ReturnNodeFrameView.NodeEndUNo = int.Parse(((TextBlock)stackDrop.Children[1]).Text);
CU.ReturnNodeFrameView.NodeBeginUNo = int.Parse(((TextBlock)stackDrop.Children[1]).Text) - CU.ReturnNodeFrameView.NodeSize + 1;
//建立“设备”和“机架”新关系
MessageBox.Show(CU.ReturnNodeFrameView.FrameID + "------" + CU.ReturnNodeFrameView.NodeBeginUNo.ToString() + "-------" + CU.ReturnNodeFrameView.NodeEndUNo.ToString());
#endregion
}
/// <summary>
/// 判断是否存在存储空间以及相关操作
/// </summary>
private void WhetherExistPlace()
{
//“放”
Dictionary<string, object> dicDrop = GetDropDragPanelContentValues(DropPanel);
Grid fatherDropGrid = (Grid)(DropPanel.Parent);
int tempDropCount = (fatherDropGrid.Children.Count() + 1) / 2;
PanelDragDropTarget dropPanelEnd = (PanelDragDropTarget)fatherDropGrid.Children[(tempDropCount - (int)dicDrop["RackUNo"]) * 2];
StackPanel stackDropEnd = (StackPanel)dropPanelEnd.Content;
TextBlock tbDropFrame = (TextBlock)stackDropEnd.Children[0];
#region <<判断是否有足够空间>>
if (CU.ReturnNodeFrameView.NodeSize == 1)
{
if (((TextBlock)stackDropEnd.Children[2]).Text == "true")
{
MessageBox.Show("没有足够的空间!");
StaticClass.ExistPlace = false;
return;
}
else
{
StaticClass.ExistPlace = true;
MergeUnit(DropPanel, dicDrop);
if (!StaticClass.FromList)
{
DepartUnit(StaticClass.DragPanel);
}
else
{
stackDropEnd.Children.Add(CU);
//打开模态窗口填写信息
OpenChildWindow();
}
//数据库操作
UpdateData();
StaticClass.FromList = false;
}
}
else
{
for (int i = 1; i < CU.ReturnNodeFrameView.NodeSize; i++)
{
if ((tempDropCount - (int)dicDrop["RackUNo"] + i) * 2 <= tempDropCount * 2 - 1)
{
PanelDragDropTarget dropPanelTempOne = (PanelDragDropTarget)fatherDropGrid.Children[(tempDropCount - (int)dicDrop["RackUNo"] + i) * 2];
StackPanel stackDropPanelOne = (StackPanel)dropPanelTempOne.Content;
TextBlock tbExistComputer = (TextBlock)stackDropPanelOne.Children[2];
if (tbExistComputer.Text == "true")
{
MessageBox.Show("没有足够的空间!");
StaticClass.ExistPlace = false;
return;
}
}
if (i == CU.ReturnNodeFrameView.NodeSize - 1)
{
if ((tempDropCount - (int)dicDrop["RackUNo"] + i) * 2 > tempDropCount * 2 - 1)
{
MessageBox.Show("没有足够的空间!");
StaticClass.ExistPlace = false;
return;
}
else
{
StaticClass.ExistPlace = true;
//合并单元格
MergeUnit(DropPanel, dicDrop);
if (!StaticClass.FromList)
{
//拆分单元格
DepartUnit(StaticClass.DragPanel);
}
else
{
stackDropEnd.Children.Add(CU);
//打开模态窗口填写信息
OpenChildWindow();
}
//数据库操作
UpdateData();
StaticClass.FromList = false;
}
}
}
}
#endregion
}
/// <summary>
/// “合并单元格”
/// </summary>
/// <param name="panel"></param>
private void MergeUnit(PanelDragDropTarget panel, Dictionary<string, object> dicDrop)
{
Grid fatherDropGrid = (Grid)(panel.Parent);
int tempDropCount = (fatherDropGrid.Children.Count() + 1) / 2;
PanelDragDropTarget dropPanelEnd = (PanelDragDropTarget)fatherDropGrid.Children[(tempDropCount - (int)dicDrop["RackUNo"]) * 2];
dropPanelEnd.AllowDrop = false;
dropPanelEnd.SetValue(Grid.RowSpanProperty, CU.ReturnNodeFrameView.NodeSize);
StackPanel stackDropEnd = (StackPanel)dropPanelEnd.Content;
stackDropEnd.Height = 40 * CU.ReturnNodeFrameView.NodeSize;
TextBlock tbDropFrame = (TextBlock)stackDropEnd.Children[0];
for (int j = 1; j < CU.ReturnNodeFrameView.NodeSize; j++)
{
PanelDragDropTarget dropPanelTemp = (PanelDragDropTarget)fatherDropGrid.Children[(tempDropCount - (int)dicDrop["RackUNo"] + j) * 2];
dropPanelTemp.Visibility = Visibility.Collapsed;
dropPanelTemp.AllowDrop = false;
StackPanel stackTemp = (StackPanel)dropPanelTemp.Content;
((TextBlock)stackTemp.Children[2]).Text = "true";
}
#region <<修改偷藏值>>
((TextBlock)stackDropEnd.Children[2]).Text = "true";
#endregion
}
/// <summary>
/// “拆分单元格”
/// </summary>
/// <param name="panel"></param>
private void DepartUnit(PanelDragDropTarget panel)
{
//“拖”的父对象
Grid fatherDragGrid = (Grid)(panel.Parent);
int tempCount = (fatherDragGrid.Children.Count() + 1) / 2;
PanelDragDropTarget dragPanelEnd = (PanelDragDropTarget)fatherDragGrid.Children[(tempCount - CU.ReturnNodeFrameView.NodeEndUNo) * 2];
dragPanelEnd.AllowDrop = true;
dragPanelEnd.SetValue(Grid.RowSpanProperty, 1);
StackPanel stackDragEnd = (StackPanel)dragPanelEnd.Content;
stackDragEnd.Height = 40;//单位长度
for (int i = 1; i < CU.ReturnNodeFrameView.NodeSize; i++)
{
PanelDragDropTarget dropDragPanelTemp =
(PanelDragDropTarget)fatherDragGrid.Children[(tempCount - CU.ReturnNodeFrameView.NodeEndUNo + i) * 2];
dropDragPanelTemp.Visibility = Visibility.Visible;
dropDragPanelTemp.AllowDrop = true;
StackPanel stackTemp = (StackPanel)dropDragPanelTemp.Content;
((TextBlock)stackTemp.Children[2]).Text = "false";
}
#region <<修改偷藏值>>
((TextBlock)stackDragEnd.Children[2]).Text = "false";
#endregion
}
/// <summary>
/// “取消拖拽操作”
/// </summary>
private void CancelBehavior()
{
((StackPanel)StaticClass.DropPanel.Content).Children.RemoveAt(3);
((StackPanel)StaticClass.DragPanel.Content).Children.Add(CU);
StaticClass.DropPanel.AllowDrop = true;
StaticClass.DragPanel.AllowDrop = false;
}
/// <summary>
/// 获取DropDragPanel中值信息
/// </summary>
/// <param name="panel"></param>
/// <returns></returns>
private Dictionary<string, object> GetDropDragPanelContentValues(PanelDragDropTarget panel)
{
Dictionary<string, object> dic = new Dictionary<string, object>();
StackPanel aimStack = (StackPanel)panel.Content;
#region<<偷藏的一些设备以及机架信息赋值>>
string computerFrame = ((TextBlock)aimStack.Children[0]).Text;
int rackUNo = int.Parse(((TextBlock)aimStack.Children[1]).Text);
string existComputer = ((TextBlock)aimStack.Children[2]).Text;
#endregion
dic.Add("FrameID", computerFrame);
dic.Add("RackUNo", rackUNo);
dic.Add("ExistComputer", existComputer);
return dic;
}
#region <<加载界面相关>>
/// <summary>
/// 加载控件
/// </summary>
private void LoadControl()
{
ColumnDefinition c1 = new ColumnDefinition();
c1.Width = new GridLength(40);
ColumnDefinition c2 = new ColumnDefinition();
c2.Width = new GridLength(90);
LayoutRoot.ColumnDefinitions.Add(c1);
LayoutRoot.ColumnDefinitions.Add(c2);
LayoutRoot.Width = 130;
LayoutRoot.HorizontalAlignment = HorizontalAlignment.Left;
LayoutRoot.ShowGridLines = false;
LayoutRoot.Height = 40 * (FrameMsg.TotalUCount + 1);
borderOne.Height = 40 * (FrameMsg.TotalUCount + 1);
for (int i = FrameMsg.TotalUCount + 1; i >= 1; i--)
{
RowDefinition rd = new RowDefinition();
rd.Height = new GridLength(40);
LayoutRoot.RowDefinitions.Add(rd);
if (i == FrameMsg.TotalUCount + 1)
{
TextBlock tbHeader = new TextBlock();
tbHeader.Text = FrameMsg.FrameName;
tbHeader.Foreground = new SolidColorBrush(Colors.Black);
tbHeader.TextAlignment = TextAlignment.Center;
tbHeader.VerticalAlignment = VerticalAlignment.Center;
tbHeader.SetValue(Grid.RowProperty, 0);
tbHeader.SetValue(Grid.ColumnSpanProperty, 2);
LayoutRoot.Children.Add(tbHeader);
}
else
{
TextBlock tbRackNum = new TextBlock();
tbRackNum.Text = i.ToString();
tbRackNum.Foreground = new SolidColorBrush(Colors.Black);
tbRackNum.TextAlignment = TextAlignment.Center;
tbRackNum.VerticalAlignment = VerticalAlignment.Center;
tbRackNum.SetValue(Grid.RowProperty, FrameMsg.TotalUCount - i + 1);
tbRackNum.SetValue(Grid.ColumnProperty, 0);
LayoutRoot.Children.Add(tbRackNum);
PanelDragDropTarget dropDrapPanel = new PanelDragDropTarget();
dropDrapPanel.AllowDrop = true;
dropDrapPanel.SetValue(Grid.RowProperty, FrameMsg.TotalUCount - i + 1);
dropDrapPanel.SetValue(Grid.ColumnProperty, 1);
StackPanel stackOne = new StackPanel();
stackOne.Height = 40;
stackOne.Width = 90;
if ((i - 1) % 2 == 0)
{
stackOne.Background = new SolidColorBrush(Colors.LightGray);
}
else
{
stackOne.Background = new SolidColorBrush(Colors.DarkGray);
}
#region<<偷藏的一些设备以及机架信息>>
TextBlock hidFrameID = new TextBlock();//设备所在机架FrameID
hidFrameID.Visibility = Visibility.Collapsed;
hidFrameID.Text = FrameMsg.FrameName;
TextBlock hidUNo = new TextBlock();//机架U单位编号
hidUNo.Visibility = Visibility.Collapsed;
hidUNo.Text = tbRackNum.Text;
TextBlock hidExistComputer = new TextBlock();//机架U中是否存在设备
hidExistComputer.Visibility = Visibility.Collapsed;
hidExistComputer.Text = "false";
stackOne.Children.Add(hidFrameID);
stackOne.Children.Add(hidUNo);
stackOne.Children.Add(hidExistComputer);
#endregion
dropDrapPanel.Content = stackOne;
#region <<订阅拖拽事件>>
dropDrapPanel.ItemDroppedOnTarget += new EventHandler<ItemDragEventArgs>(dropDragPanel_ItemDroppedOnTarget);
dropDrapPanel.Drop += new Microsoft.Windows.DragEventHandler(dropDragPanel_Drop);
dropDrapPanel.ItemDragStarting += new EventHandler<ItemDragEventArgs>(dropDragPanel_ItemDragStarting);
#endregion
LayoutRoot.Children.Add(dropDrapPanel);
}
}
ReturnUI = LayoutRoot;
}
#endregion
#endregion
private ComputerUnit CU;
private PanelDragDropTarget DropPanel;
public UIElement ReturnUI { get; set; }
public NodeFrameView ReturnComputerMsg { get; set; }
private RowFrameView FrameMsg;
private ListBoxItem SelectItem;
private int SelectIndex;
}
}
- RackUnit.xaml
- RackUnit.xaml_New
- RackUnit.xaml_118
- XAML
- XAML
- XAML
- XAML
- XAML
- XAML
- XAML
- XAML - What is XAML?
- App.xaml & MainWindow.xaml
- XAML,XAML Overview And XAML Syntax
- 前瞻XAML
- XAML Overview
- 什么是XAML
- XAML Guidelines
- XAML Guidelines
- 在office中快速插入特殊符号
- Main后台
- P2P在NAT和防火墙上的穿透
- 无法删除文件和文件夹
- class
- RackUnit.xaml
- Recyle.xaml
- prototype
- RowFrameView.cs
- nm readelf objdump objcopy makefile ld.script
- javascript获取select的值全解
- SearchPanel.xaml
- StaticClass.cs
- TipWindow.xaml