private void BindData()
{

//为绑定的按钮选线增加单击事件

SourceGrid.Cells.Controllers.CustomEvents clickEvent = new SourceGrid.Cells.Controllers.CustomEvents();
clickEvent.Click += new EventHandler(clickEvent_Click);
//清除原有绑定的数据
this.grid1.Columns.Clear();
this.grid1.Rows.Clear();
grid1.BorderStyle = BorderStyle.FixedSingle;

grid1.ColumnsCount = 8;//设置要绑定的列数

//设置列的宽度
grid1.Columns[0].Width = 200;
grid1.Columns[1].Width = 200;
grid1.Columns[2].Width = 105;
grid1.Columns[3].Width = 105;
grid1.Columns[4].Width = 105;
grid1.Columns[5].Width = 105;
grid1.Columns[6].Width = 105;
//设置每次绑定一行数据
grid1.FixedRows = 1;

//开始绑定第一行数据也就是列标题
grid1.Rows.Insert(0);
//为第一行绑定列头
SourceGrid.Cells.ColumnHeader columnHeader;
columnHeader = new SourceGrid.Cells.ColumnHeader("服务名称");
grid1[0, 0] = columnHeader;
columnHeader = new SourceGrid.Cells.ColumnHeader("服务描述");
grid1[0, 1] = columnHeader;
columnHeader = new SourceGrid.Cells.ColumnHeader("日志文件");
grid1[0, 2] = columnHeader;
columnHeader = new SourceGrid.Cells.ColumnHeader("下载日志文件");
grid1[0, 3] = columnHeader;
columnHeader = new SourceGrid.Cells.ColumnHeader("配置文件");
grid1[0, 4] = columnHeader;
columnHeader = new SourceGrid.Cells.ColumnHeader("下载配置文件");
grid1[0, 5] = columnHeader;
columnHeader = new SourceGrid.Cells.ColumnHeader("上传配置文件");
grid1[0, 6] = columnHeader;
for (int i = 0; i < sendList.Count; i++)//SendList用来提供数据,它是一个泛型集合,里面包含多个服务的详细信息
{
grid1.Rows.Insert(i + 1);//为第i+1行增加数据,因为i是从0开始的,如果从i开始绑定数据会覆盖列头
grid1.Rows[i + 1].Height = 30;//设置行的高度
grid1[i + 1, 0] = new SourceGrid.Cells.Cell(sendList[i].ServiceName, typeof(string));
grid1[i + 1, 1] = new SourceGrid.Cells.Cell(sendList[i].ServiceDesc, typeof(string));
//判断是否存在配置文件,如果不存在标记为无,如果存在,可以下载并且可以上传替换该配置文件
if (sendList[i].Config == null)
{
grid1[i + 1, 4] = new SourceGrid.Cells.Cell("无");
grid1[i + 1, 5] = new SourceGrid.Cells.Cell("无");
grid1[i + 1, 6] = new SourceGrid.Cells.Cell("无");
}
else
{
string[] config = sendList[i].Config.Split(new char[] { '|' });//用来获得所有的配置文件

//用来绑定一个ComBox
SourceGrid.Cells.Editors.ComboBox cbEditor = new SourceGrid.Cells.Editors.ComboBox(typeof(string));
cbEditor.StandardValues = config;
cbEditor.EditableMode = SourceGrid.EditableMode.Focus | SourceGrid.EditableMode.SingleClick | SourceGrid.EditableMode.AnyKey;

//将Combox绑定到第5列
grid1[i + 1, 4] = new SourceGrid.Cells.Cell("", cbEditor);
grid1[i + 1, 4].View = SourceGrid.Cells.Views.ComboBox.Default;

//第6列绑定一个Button,用来点击下载配置文件
grid1[i + 1, 5] = new SourceGrid.Cells.Button("下载配置文件");
grid1[i + 1, 5].AddController(clickEvent);//为Button绑定单击事件
grid1[i + 1, 6] = new SourceGrid.Cells.Button("上传配置文件");
grid1[i + 1, 6].AddController(clickEvent);
}
//判断是否存在日志文件,如果不存在标记为无,如果存在,标记为下载按钮
if (sendList[i].Log == null)
{
grid1[i + 1, 2] = new SourceGrid.Cells.Cell("无");
grid1[i + 1, 3] = new SourceGrid.Cells.Cell("无");
}
else
{
string[] log = sendList[i].Log.Split(new char[] { '|' });
SourceGrid.Cells.Editors.ComboBox cbEditor = new SourceGrid.Cells.Editors.ComboBox(typeof(string));
cbEditor.StandardValues = log;
cbEditor.EditableMode = SourceGrid.EditableMode.Focus | SourceGrid.EditableMode.SingleClick | SourceGrid.EditableMode.AnyKey;
grid1[i + 1, 2] = new SourceGrid.Cells.Cell("", cbEditor);
grid1[i + 1, 2].View = SourceGrid.Cells.Views.ComboBox.Default;
grid1[i + 1, 3] = new SourceGrid.Cells.Button("下载日志文件");
grid1[i + 1, 3].AddController(clickEvent);
}
}
}

//用来注册具体的单击事件,可以忽略不看

private void clickEvent_Click(object sender, EventArgs e)
{
SourceGrid.CellContext context = (SourceGrid.CellContext)sender;
//得到当前点击的行的服务的名称
string str = grid1[context.Position.Row, 0].ToString();
byte[] buffer;
//如果点击的是日志文件列的按钮,则向服务端发送消息提示
if (context.Position.Column == 3)
{
//判断是否选中了日志文件
string file = grid1[context.Position.Row, 2].ToString();
if (file == "")
{
MessageBox.Show("请选择要下载的日志文件");
return;
}
//当客户端向服务端发送0时,代表的时要下载日志文件
string s = "0";

s += str + "|" + file;
buffer = System.Text.Encoding.UTF8.GetBytes(s);
try
{
socket.Send(buffer);
}
catch
{ }

}
//如果点击的是配置文件列的按钮,则向服务端发送消息提示
if (context.Position.Column == 5)
{
//判断是否选中了配置文件
string file = grid1[context.Position.Row, 4].ToString();
if (file == "")
{
MessageBox.Show("请选择要下载的配置文件");
return;
}
//当客户端向服务端发送1时,代表的时要下载日志文件
string s = "1";
s += str + "|" + file;
buffer = System.Text.Encoding.UTF8.GetBytes(s);
try
{
socket.Send(buffer);
}
catch
{
}
}
//如果点击的是上传配置文件列的按钮,则向服务器发送一个配置文件替换掉原有的配置文件
if (context.Position.Column == 6)
{
//先检查是否选中要修改的配置文件
string file = grid1[context.Position.Row, 4].ToString();
if (file == "")
{
MessageBox.Show("请选择要替换的配置文件");
return;
}
try
{
//用来打开要上传的配置文件
OpenFileDialog ofd = new OpenFileDialog();
ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
ofd.Title = "要上传的配置文件";
ofd.Filter = "配置文件|*.xml|配置文件|*.txt|所有文件|*.*";
ofd.ShowDialog(this);
//获得选中文件的路径
string path = ofd.FileName;
//向服务器发送文件,向要发送的配置文件的开头添加2和服务名称的字节数组,方便服务器用来标识
using (FileStream fsRead = new FileStream(path, FileMode.Open, FileAccess.Read))
{
byte[] buffer2 = new byte[fsRead.Length];
//实际读取到的字节数
int r = fsRead.Read(buffer2, 0, buffer2.Length);
string s = "2";
s = s + str + "|" + file + "|";
//声明一个字节集合,用来连接标识和文件
List<byte> list = new List<byte>();
buffer = System.Text.Encoding.UTF8.GetBytes(s);
list.AddRange(buffer);
list.AddRange(buffer2);
//将组合好的字节集合转换为字节数组
byte[] newByte = list.ToArray();
socket.Send(newByte);
fsRead.Close();
}
MessageBox.Show("上传成功");
}
catch
{
}
}

}

SourceGrid之Grid绑定数据的更多相关文章

  1. miniUI Grid添加汇总行,Grid绑定数据,IDEA免编译设置

    坑1: 2017-6-5周二,上午解决了昨天摸索一下午的问题,使用miniui显示汇总行数据,要点有这么几个 在创建Grid div的时候一定要加上以下两个属性: //显示汇总行开关 showSumm ...

  2. extjs__(grid Panel绑定数据)

    1.修改面板名称 双击My Panel  就可以进行修改 2拖入一个grid  panel绑定数据 3.创建一个model  只是为了创建一个模型  相当于java中的模型层  只是数据的一个标准 4 ...

  3. ASPxGridView中如何对主从表绑定数据

    注:在从表的aspxgridview中的(OnDataBinding()事件中绑定数据)-----代码如下 //绑定属性值表protected void grid2_sonTable_DataBind ...

  4. WPF中利用控件的DataContext属性为多个TextBox绑定数据

    工作上需要从给定的接口获取数据,然后显示在界面的编辑框中,以往肯定会一个一个的去赋值,但这样太麻烦而且效率很低,不利于维护,于是想到了数据绑定这一方法,数据绑定主要利用INotifyPropertyC ...

  5. 使用 MVVMLight 绑定数据(转)

    MVVMLight绑定数据示例 好了,我们在新建了两个项目,分别是“MVVMLight的主程序” 与  “Model层”,运行的效果及解决方案结构如下: 其实很简单,就是绑定了一个数据源而已,编写的代 ...

  6. 使用 MVVMLight 绑定数据

    如果你还不知道如何在VS中加入MVVMLight的引用,那么建议你先翻阅这篇文章:在VS中安装/使用 MVVMLight 这篇文章主要是介绍如何使用MVVMLight来绑定数据到界面中(View),以 ...

  7. WPF (DataGridRowHeaderStyle)实现自义定行样式 并绑定数据

    原文:WPF (DataGridRowHeaderStyle)实现自义定行样式 并绑定数据 功能阐述 就上面那图片 刚开始 考虑使用 RowHeaderTemplate 来实现  发现总绑定不上数据  ...

  8. WPF DataGrid 绑定数据及时更新的处理

    原文:WPF DataGrid 绑定数据及时更新的处理 默认情况下datagrid 绑定数据源后,在界面编辑某一列后,数据不会及时更新到内存对象中.如在同一行上有一个命令对来获取 当前选中行(内存对象 ...

  9. WPF (DataGridColumnHeader)实现自义定列头样式 并绑定数据

    原文:WPF (DataGridColumnHeader)实现自义定列头样式 并绑定数据 实现功能是这样的 自定义列头 样式 样式里的 数据来源于后台绑定 这篇就说头样式 和头样式数据绑定 思路 1) ...

随机推荐

  1. 【EOJ Monthly 2018.2 (Good bye 2017)】

    23333333333333333 由于情人节要回家,所以就先只放代码了. 此题是与我胖虎过不去. [E. 出老千的 xjj] #include<cstdio> #include<c ...

  2. springMVC之HttpServletRequest的getParameterMap()

    request.getParameterMap()的返回类型是Map类型的对象,也就是符合key-value的对应关系,但这里要注意的是,value的类型是String[],而不是String. 得到 ...

  3. JavaScript-Tool:jquery.vaidate.js

    ylbtech-JavaScript-Tool:jquery.vaidate.js 1.返回顶部 1. 2. 3. 2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部 0. https ...

  4. sublime 设置像IDE一样的 ctrl+鼠标左键 跳转到定义方法

    鼠标点击菜单栏的Preferences,选择Browse Packages ,进入文件加之后,选择User 点击进入User,在User里面添加文件名为 Default (Windows).subli ...

  5. JVM 内存区域

    JVM 将内存区域划分为: Method Area(Non-Heap)(方法区) ,Heap(堆) , Program Counter Register(程序计数器) , VM Stack(虚拟机栈, ...

  6. opencv 笔记

    http://docs.opencv.org/ opencv 2.x API opencv包含以下模块 core    基本数据机构 imgproc    图像处理方法 video    视频处理方法 ...

  7. jQuery获取table当前所在行

    $("div tbody tr").click(function() {         var rows = $(this).prevAll().length + 1;//行号  ...

  8. F#周报2019年第20期

    新闻 2019年理事会活动 "实用的F#挑战"意见截止日期接近,不要忘记提交博客文章或者其它作品 接口中的默认实现 .NET Core 3.0里的性能增强 使用Try .NET创建 ...

  9. PhpStorm插件之Api Debugger

    安装插件 File->Setting->Pluugins   搜索  Api Debugger 如何使用 安装完插件后,RESTART IDE,在编辑器右侧 即可找到最新安装的 Api D ...

  10. HDU3433 【时间的二分+DP最优解】

    题意: 有n个人,X个任务A,Y个任务B, 给出每个人做A做B的时间,一个人只能在某个时刻做一个工作, 问最短时间完成所有工作. 思路: 二分n个人用的时间,判断最优条件用DP. 可以二分就是因为时间 ...