码迷,mamicode.com
首页 > Windows程序 > 详细

C#行列转换

时间:2017-07-20 19:51:23      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:sel   nts   dial   turn   clear   ane   init   设置   ext   

public partial class Frm_DianjianRecord : Frm_Base
{
public Frm_DianjianRecord()
{
InitializeComponent();
}

/// <summary>
/// 列表列信息
/// </summary>
IList<ColClass> collist = new List<ColClass>();

/// <summary>
/// 初期化加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Frm_DianjianRecord_Load(object sender, EventArgs e)
{
#region 页面初始化
//tool工具栏加背景图
toolStrip_btn.BackgroundImage = RFIDMg.Properties.Resources.tooldown;
this.panel_cx.BackgroundImage = null;
//配置时间控件,默认为当天日期
this.dtpWorkDateFrom.Format = DateTimePickerFormat.Custom;
this.dtpWorkDateFrom.Text = DateTime.Now.ToString("yyyy-MM-dd");
this.dtpWorkDateTo.Format = DateTimePickerFormat.Custom;
this.dtpWorkDateTo.Text = DateTime.Now.ToString("yyyy-MM-dd");
//绑定下拉菜单
pubCombox.SetComboBoxByTable<T_Base_LineInfo>(cboLineCode, "T_Base_Line", "lineName", "lineCode", "所有");//绑定线体
pubCombox.SetComboBoxByTable<T_Base_BanciInfo>(cboBanciCode, "T_Base_Banci", "banciName", "banciCode", "所有");//绑定岗位
//初始化gird
//InitGrid();
//加载数据
//GetData();
#endregion
}

/// <summary>
/// 初始化gird
/// </summary>
public void InitGrid()
{
collist.Clear();
this.table_data.BeginUpdate();
#region 创建列标题
this.table_data.ColumnModel.Columns.Clear();
//第一列隐藏是自动增长列,便于修改/删除
pubtable.ColAddNew(table_data, collist, "txt", "key", "fkey", 50, false);
pubtable.ColAddNew(table_data, collist, "txt", "序号", "xuhao", 50, true);
pubtable.ColAddNew(table_data, collist, "txt", "工作日期", "workDate", 90, true);
pubtable.ColAddNew(table_data, collist, "txt", "线体", "lineName", 100, true);
pubtable.ColAddNew(table_data, collist, "txt", "站点", "zhandianName", 100, true);
pubtable.ColAddNew(table_data, collist, "txt", "岗位", "gangweiName", 100, true);
pubtable.ColAddNew(table_data, collist, "txt", "班次", "banciName", 100, true);
pubtable.ColAddNew(table_data, collist, "txt", "班组", "banzuName", 100, true);
pubtable.ColAddNew(table_data, collist, "txt", "点检顺序", "dianjianOrderNo", 70, true);
pubtable.ColAddNew(table_data, collist, "txt", "点检标准", "dianjianStr", 70, true);

//循环加载动态列
IList list = null;
T_TQM_DianjianRecordInfoImp imp = new T_TQM_DianjianRecordInfoImp();
//根据条件查询

string lineCode = this.cboLineCode.SelectedValue.ToString();
string zhandianCode = this.lblZhandianCode.Text;
string gangweiCode = this.lblGangweiCode.Text;
string banciCode = this.cboBanciCode.SelectedValue.ToString();

string workDateFrom = this.dtpWorkDateFrom.Text;
string workDateTo = this.dtpWorkDateTo.Text;

if (lineCode == "所有")
{
lineCode = "";
}
if (banciCode == "所有")
{
banciCode = "";
}
/*重点看*/

list = (IList)imp.GetListBysearchHour(lineCode, zhandianCode, gangweiCode, banciCode, workDateFrom, workDateTo);
foreach (T_TQM_DianjianRecordInfo info in list)
{
string fieldHour = "FABC"+info.DjTime;
pubtable.ColAddNew(table_data, collist, "txt", info.DjTime, fieldHour, 50, true);
pubtable.ColAddNew(table_data, collist, "txt", "点检时间", fieldHour + "Time", 140, true);
pubtable.ColAddNew(table_data, collist, "txt", "点检人", fieldHour + "User", 60, true);
}
#endregion

//设置属性
pubtable.TableInit(this.table_data);
this.table_data.EndUpdate();
}

/// <summary>
/// 加载数据
/// </summary>
public void GetData()
{
#region 根据查询条件获取数据

InitGrid();

IList list = null;
T_TQM_DianjianRecordInfoImp imp = new T_TQM_DianjianRecordInfoImp();
//根据条件查询

string lineCode = this.cboLineCode.SelectedValue.ToString();
string zhandianCode = this.lblZhandianCode.Text;
string gangweiCode = this.lblGangweiCode.Text;
string banciCode = this.cboBanciCode.SelectedValue.ToString();

string workDateFrom = this.dtpWorkDateFrom.Text;
string workDateTo = this.dtpWorkDateTo.Text;

if (lineCode == "所有")
{
lineCode = "";
}
if (banciCode == "所有")
{
banciCode = "";
}
list = (IList)imp.GetListBysearch(lineCode,zhandianCode,gangweiCode,banciCode,workDateFrom, workDateTo);
//数据加载到xptable中
LoadData(list);
//行数
toolStripStatusLabelcount.Text = " 记录数:" + list.Count.ToString();
this.table_data.TableModel.Selections.Clear();
#endregion
}

/// <summary>
/// 数据加载到xptable中
/// </summary>
/// <param name="list">数据链表</param>
public void LoadData(IList list)//重点看怎么加载数据
{
this.table_data.BeginUpdate();
this.table_data.TableModel.Rows.Clear();
int i = 1;
//定义特殊单元格的样式
CellStyle cellStyle = new CellStyle();
cellStyle.ForeColor = Color.Red;
cellStyle.Font = new Font("宋体", 9, FontStyle.Bold);
string fkey = "";

//循环数据集进行加载数据
foreach (T_TQM_DianjianRecordInfo info in list)
{
if (fkey != info.fkey)
{
//新增一行
fkey = info.fkey;

#region 动态加载每列数据
Type type = info.GetType();
Row row = new Row();
foreach (ColClass colinfo in collist)
{
Cell cellnew = new Cell();
if (colinfo.fcolstyle == "btn")
{
//按钮直接取ffield变量 不是从数据库读取
cellnew.Text = colinfo.ffield;
cellnew.ForeColor = ColorTranslator.FromHtml("#0052b3");
}
else
{
if (colinfo.ffield == "xuhao")
{
//序号为前台生成的
cellnew.Text = i.ToString();
cellnew.ForeColor = ColorTranslator.FromHtml("#0052b3");
}
else if (colinfo.ffield == "check")
{
//选择框前台 默认 否
cellnew.Checked = false;
cellnew.ForeColor = Color.Red;
}
else
{
//数据库字段 
if (colinfo.ffield.Substring(0, 4) =="FABC")
{
cellnew.Text = "";
}
else
{
string fvalue = type.GetProperty(colinfo.ffield).GetValue(info, null).ToString();
cellnew.Text = fvalue;
//cell 颜色控制
if (fvalue == "不合格")
{
cellnew.CellStyle = cellStyle;
}
}

}
}
row.Cells.Add(cellnew);
}
this.table_data.TableModel.Rows.Add(row);

//修改动态列的值
string fieldHour = "FABC" + info.DjTime;
int idIndex = pubtable.ColIndex(collist, fieldHour);

this.table_data.TableModel.Rows[i-1].Cells[idIndex].Text = info.dianjianResult;
if (info.dianjianResult == "不合格")
{
table_data.TableModel.Rows[i - 1].Cells[idIndex].CellStyle = cellStyle;
}
this.table_data.TableModel.Rows[i - 1].Cells[idIndex + 1].Text = info.createDate;
this.table_data.TableModel.Rows[i-1].Cells[idIndex+2].Text = info.dianjianUserName;

i = i + 1;
#endregion

}
else
{
//修改一行
string fieldHour = "FABC" + info.DjTime;
int idIndex = pubtable.ColIndex(collist, fieldHour);
this.table_data.TableModel.Rows[i-2].Cells[idIndex].Text = info.dianjianResult;
if (info.dianjianResult == "不合格")
{
table_data.TableModel.Rows[i - 2].Cells[idIndex].CellStyle = cellStyle;
}
this.table_data.TableModel.Rows[i-2].Cells[idIndex+1].Text = info.createDate;
this.table_data.TableModel.Rows[i-2].Cells[idIndex+2].Text = info.dianjianUserName;
}

}
this.table_data.EndUpdate();
}

/// <summary>
/// 查询信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsbtnSearch_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(dtpWorkDateTo.Text.Trim()) && !string.IsNullOrEmpty(dtpWorkDateFrom.Text.Trim()))
{
if (dtpWorkDateTo.Value < dtpWorkDateFrom.Value)
{
pubfunction.ShowError("开始时刻不能大于结束时刻!");
return;
}
}
//数据查询
GetData();
}

/// <summary>
/// 导出excel
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsbtnExportExcel_Click(object sender, EventArgs e)
{
//导出excel
//判断当前是否有数据信息
if (this.table_data.TableModel.Rows.Count <= 0)
{
pubfunction.ShowError("没有数据信息!");
return;
}
pubexcel.XlsOutExcel(table_data, this.Text);
}

/// <summary>
/// 关闭页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsbtnExit_Click(object sender, EventArgs e)
{
this.Close();
}

/// <summary>
/// 设置时间控件的格式
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DateTimePicker_ValueChanged(object sender, EventArgs e)
{
DateTimePicker dtp = (DateTimePicker)sender;
dtp.Format = DateTimePickerFormat.Custom;
dtp.CustomFormat = "yyyy-MM-dd";
}

/// <summary>
/// 选择站点
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnZhanDian_Click(object sender, EventArgs e)
{
Frm_ComZhandianList formedit = new Frm_ComZhandianList();
string lineCode = "";
if (this.cboLineCode.SelectedValue == null)
{
lineCode = "";
}
else
{
lineCode = this.cboLineCode.SelectedValue.ToString();
}
string lineName = this.cboLineCode.Text;

formedit.f_lineCode= lineCode;
formedit.f_lineName = lineName;

formedit.StartPosition = FormStartPosition.CenterScreen;
formedit.ShowInTaskbar = false;
formedit.ShowDialog();
if (formedit.DialogResult == DialogResult.OK)
{
txtZhandianName.Text = formedit.f_zhandianName;
lblZhandianCode.Text = formedit.f_zhandianCode;
}
formedit.Close();
formedit.Dispose();
}

/// <summary>
/// 选择岗位
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnGangwei_Click(object sender, EventArgs e)
{
#region
Frm_ComGangweiList formedit = new Frm_ComGangweiList();

string zhandianCode = "";
if (this.lblZhandianCode.Text == null||this.lblZhandianCode.Text =="")
{
zhandianCode = "";
}
else
{
zhandianCode = this.lblZhandianCode.Text;
}
string zhandianName = this.txtZhandianName.Text;

formedit.f_zhandianCode = zhandianCode;
formedit.f_zhandianName = zhandianName;


string lineCode = "";
if (this.cboLineCode.SelectedValue == null)
{
lineCode = "";
}
else
{
lineCode = this.cboLineCode.SelectedValue.ToString();
}
string lineName = this.cboLineCode.Text;

string banciCode = "";
if (this.cboBanciCode.SelectedValue == null)
{
banciCode = "";
}
else
{
banciCode = this.cboBanciCode.SelectedValue.ToString();
}
string banciName = this.cboBanciCode.Text;
formedit.lineCode = lineCode;
formedit.lineName = lineName;

formedit.StartPosition = FormStartPosition.CenterScreen;
formedit.ShowInTaskbar = false;
formedit.ShowDialog();
if (formedit.DialogResult == DialogResult.OK)
{
txtGangWeiName.Text = formedit.f_gangweiName;
lblGangweiCode.Text = formedit.f_gangweiCode;
}
formedit.Close();
formedit.Dispose();
#endregion
}

private void cboLineCode_TextChanged(object sender, EventArgs e)
{
txtZhandianName.Clear();
txtGangWeiName.Clear();
lblZhandianCode.Text = "";
lblGangweiCode.Text = "";
}

private void txtZhandianName_TextChanged(object sender, EventArgs e)
{
lblGangweiCode.Text = "";
txtGangWeiName.Clear();
}

}

 

C#行列转换

标签:sel   nts   dial   turn   clear   ane   init   设置   ext   

原文地址:http://www.cnblogs.com/kaifang1028/p/7213716.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!