using DevExpress.XtraEditors;
|
using DevExpress.XtraTab;
|
using Gs.DevApp.Entity;
|
using Gs.DevApp.Query;
|
using Gs.DevApp.Service;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Data;
|
using System.Drawing;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using System.Windows.Forms;
|
|
namespace Gs.DevApp.DevFrm.BasicData
|
{
|
public partial class FrmMesItems : DevExpress.XtraEditors.XtraForm
|
{
|
DataTable MesItemsDT = new DataTable();
|
MesItemServices mesItemServices = new MesItemServices();
|
|
public FrmMesItems()
|
{
|
InitializeComponent();
|
toolBarMenu1.btnLoadClick += ToolBarMenu1_btnLoadClick;
|
pageBar1.PagerEvent += PageBar1_PagerEvent;
|
gcSummary.DataSource = MesItemsDT;
|
}
|
|
private void PageBar1_PagerEvent(int curPage, int pageSize)
|
{
|
GetPageList(curPage, pageSize);
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void ToolBarMenu1_btnLoadClick(object sender, EventArgs e)
|
{
|
GetPageList(1, 10);
|
}
|
|
private void GetPageList(int v1, int v2)
|
{
|
MesItemQuery pgq = new MesItemQuery();
|
pgq.currentPage = v1;
|
pgq.everyPageSize = v2;
|
ReturnModel<PageListModel> dd = mesItemServices.GetPageList(pgq);
|
MesItemsDT = dd.rtnData.list;
|
gcSummary.BindingContext = new BindingContext();
|
gcSummary.DataSource = MesItemsDT;
|
gcSummary.ForceInitialize();
|
int dddd = dd.rtnData.pages;//总页
|
pageBar1.TotalPages = dddd;
|
pageBar1.RecordCount = dd.rtnData.total;//记录总数
|
pageBar1.CurrentPage = v1;//当前页
|
pageBar1.RowsCount = v2;//每页显示
|
pageBar1.setTxt();
|
}
|
|
public static void BindingEditorPanel(Control editorPanel, DataTable dataSource)
|
{
|
var fieldName = "";
|
|
try
|
{
|
for (var i = 0; i <= editorPanel.Controls.Count - 1; i++)
|
{
|
if (editorPanel.Controls[i] is BaseEdit)
|
{
|
var edit = editorPanel.Controls[i] as BaseEdit;
|
if (edit.Name.Substring(0, 3) == "txt")
|
{
|
fieldName = edit.Name.Substring(3, edit.Name.Length - 3);
|
BindingTextEditBase(edit, dataSource, fieldName);
|
}
|
}
|
|
if (editorPanel.Controls[i] is CheckEdit)
|
{
|
var edit = editorPanel.Controls[i] as CheckEdit;
|
if (edit.Name.Substring(0, 3) == "chk")
|
{
|
fieldName = edit.Name.Substring(3, edit.Name.Length - 3);
|
BindingCheckEdit(edit, dataSource, fieldName);
|
}
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
ToolBox.MsgHelper.Warning("提示:" + "字段:" + fieldName + "\r\n" + ex.Message);
|
}
|
}
|
|
/// <summary>
|
/// 绑定输入控件的数据源
|
/// </summary>
|
/// <param name="edit">控件框</param>
|
/// <param name="dataSource">数据源</param>
|
/// <param name="bindField">取值字段</param>
|
public static void BindingTextEditBase(BaseEdit edit, object dataSource, string bindField)
|
{
|
try
|
{
|
edit.DataBindings.Clear();
|
var b = new Binding("EditValue", dataSource, bindField);
|
edit.DataBindings.Add(b);
|
b.ReadValue();
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
/// <summary>
|
/// 绑定CheckEdit的数据源
|
/// </summary>
|
/// <param name="edit">CheckEdit</param>
|
/// <param name="dataSource">数据源</param>
|
/// <param name="bindField">取值字段</param>
|
public static void BindingCheckEdit(CheckEdit edit, object dataSource, string bindField)
|
{
|
try
|
{
|
edit.DataBindings.Clear();
|
var b = new Binding("EditValue", dataSource, bindField);
|
b.NullValue = "N";
|
edit.DataBindings.Add(b);
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
|
|
/// <summary>
|
/// 跳转到指定name的tab
|
/// </summary>
|
/// <param name="tabName"></param>
|
private void JumpToTabByName(string tabName)
|
{
|
foreach (XtraTabPage page in xtraTabControl1.TabPages)
|
{
|
if (page.Name == tabName)
|
{
|
xtraTabControl1.SelectedTabPage = page;
|
break;
|
}
|
}
|
}
|
|
private void gvSummary_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
|
{
|
// 获取当前行的数据的ID
|
int rowHandle = gvSummary.FocusedRowHandle;
|
int rowId = Convert.ToInt32( gvSummary.GetRowCellValue(rowHandle, "id"));
|
|
MesItemQuery pgq = new MesItemQuery();
|
pgq.id = rowId;
|
pgq.currentPage = 1;
|
pgq.everyPageSize = 1;
|
ReturnModel<PageListModel> dd = mesItemServices.GetPageList(pgq);
|
DataTable rowDatable = dd.rtnData.list;
|
|
BindingEditorPanel(pcDetailEditor, rowDatable);
|
|
// 跳转到指定的XtraTabPage
|
JumpToTabByName("xtraTabPage2");
|
}
|
}
|
}
|