using Gs.DevApp.Entity;
using Gs.DevApp.ToolBox;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;
namespace Gs.DevApp.DevFrm
{
public partial class Frm_MesSysPageview : DevExpress.XtraEditors.XtraForm
{
string _webServiceName = "MesSysPageviewManager/";
public Frm_MesSysPageview()
{
InitializeComponent();
this.toolBarMenu1.btnAddClick += ToolBarMenu1_btnAddClick;
this.toolBarMenu1.btnEdtClick += ToolBarMenu1_btnEdtClick;
this.toolBarMenu1.btnSaveClick += ToolBarMenu1_btnSaveClick;
this.toolBarMenu1.btnLoadClick += ToolBarMenu1_btnLoadClick;
this.toolBarMenu1.btnDelClick += ToolBarMenu1_btnDelClick1;
this.toolBarMenu1.btnEscClick += ToolBarMenu1_btnEscClick;
this.toolBarMenu1.getXmlConfig();
Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameter(gridView1, null, null, "", "", (value) =>
{
Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 0);
}, tips);
Gs.DevApp.ToolBox.UtilityHelper.SetTabParameter(gridView1, xtraTabControl1, pageBar1, (value) =>
{
getModel(value);
}, (value) =>
{
getPageList(this.pageBar1.CurrentPage);
}, lbGuid);
getPageList(1);
pageBar1.PagerEvent += PageBar1_PagerEvent;
}
///
/// 分页事件
///
///
///
private void PageBar1_PagerEvent(int curPage, int pageSize)
{
getPageList(curPage);
}
///
/// 取消事件
///
///
///
private void ToolBarMenu1_btnEscClick(object sender, EventArgs e)
{
Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 1);
}
///
/// 删除事件
///
///
///
private void ToolBarMenu1_btnDelClick1(object sender, EventArgs e)
{
string rowGuid = "", rowName = "";
(rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_pageView, gridView1);
if (string.IsNullOrEmpty(rowGuid))
{
ToolBox.MsgHelper.Warning("请先选择你要操作的行!");
return;
}
if (!MsgHelper.AskQuestion("你选择了【" + rowName + "】,确定删除吗?"))
return;
List lst = new List();
lst.Add(rowGuid);
var _obj = lst;
try
{
string strJson = UtilityHelper.HttpPost("", _webServiceName + "DeleteModel", JsonConvert.SerializeObject(_obj));
ReturnModel _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson);
if (_rtn.rtnCode > 0)
{
if (xtraTabControl1.SelectedTabPageIndex == 0)
{ }
else
Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 2);
getPageList(this.pageBar1.CurrentPage);
}
ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg);
}
catch (Exception ex)
{
ToolBox.MsgHelper.Warning("提示:" + ex.Message);
}
}
///
/// 刷新事件
///
///
///
private void ToolBarMenu1_btnLoadClick(object sender, EventArgs e)
{
if (xtraTabControl1.SelectedTabPageIndex == 1)
getModel(lbGuid.Text.Trim());
else
{
//_filterList.Clear();
//if (gridView1.ActiveFilter.Count > 0)
//{
// gridView1.ColumnFilterChanged -= GridView1_ColumnFilterChanged;
// gridView1.ActiveFilter.Clear();
// gridView1.ColumnFilterChanged += GridView1_ColumnFilterChanged;
//}
//getPageList(1);
getPageList(this.pageBar1.CurrentPage);
}
}
///
/// 修改事件
///
///
///
private void ToolBarMenu1_btnEdtClick(object sender, EventArgs e)
{
string rowGuid = "", rowName = "";
(rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_pageView, gridView1);
if (string.IsNullOrEmpty(rowGuid))
{
ToolBox.MsgHelper.Warning("请先选择你要操作的行!");
return;
}
Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 3);
if (xtraTabControl1.SelectedTabPageIndex == 1)
{
getModel(rowGuid);
}
else
{
UtilityHelper.ChangeEnableByControl(this.layoutMx1.Controls, true);
}
}
///
/// 新增事件
///
///
///
private void ToolBarMenu1_btnAddClick(object sender, EventArgs e)
{
lbGuid.Text = "";
Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 4);
UtilityHelper.CleanValueByControl(this.layoutMx1.Controls, true);
}
///
/// 保存事件
///
///
///
private void ToolBarMenu1_btnSaveClick(object sender, EventArgs e)
{
toolBarMenu1.isSetBtn = false;
if (string.IsNullOrEmpty(txt_pageView.Text.Trim()))
{
Gs.DevApp.ToolBox.MsgHelper.Warning("页面名称不能为空!");
txt_pageView.Focus();
return;
}
if (string.IsNullOrEmpty(txt_path.Text.Trim()))
{
Gs.DevApp.ToolBox.MsgHelper.Warning("路径不能为空!");
txt_path.Focus();
return;
}
if (string.IsNullOrEmpty(txt_pageGroup.Text.Trim()))
{
Gs.DevApp.ToolBox.MsgHelper.Warning("组别不能为空!");
txt_pageGroup.Focus();
return;
}
var _obj = new
{
guid = UtilityHelper.ToGuid(lbGuid.Text.Trim()), //主建
PageView = txt_pageView.Text.Trim(),
Path = txt_path.Text.Trim(),
PageGroup = txt_pageGroup.Text.Trim(),
PageIdx = txt_pageIdx.Text.Trim(),
PageStatus = txt_pageStatus.Checked
};
try
{
string strJson = UtilityHelper.HttpPost("", _webServiceName + "EditModel", JsonConvert.SerializeObject(_obj));
ReturnModel _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson);
ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg);
if (_rtn.rtnCode > 0)
{
lbGuid.Text = _rtn.rtnData;
toolBarMenu1.isSetBtn = true;
UtilityHelper.ChangeEnableByControl(this.layoutMx1.Controls, false);
toolBarMenu1.currentAction = "";
Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 6);
}
}
catch (Exception ex)
{
ToolBox.MsgHelper.Warning("提示:" + ex.Message);
}
}
///
///
///
/// 第几页
/// 每页几条
private void getPageList(int curPage)
{
var _sbSqlWhere ="";
PageQueryModel pgq = new PageQueryModel(curPage, this.pageBar1.RowsCount, "a.PAGE_GROUP", "desc", "", _sbSqlWhere.ToString());
string json = JsonConvert.SerializeObject(pgq);
try
{
string strReturn = UtilityHelper.HttpPost("", _webServiceName + "GetListPage", json);
ReturnModel dd = UtilityHelper.ReturnToTablePage(strReturn);
if (dd.rtnCode > 0)
{
DataTable dt = dd.rtnData.list;
gcMain1.BindingContext = new BindingContext();
gcMain1.DataSource = dt;
gcMain1.ForceInitialize();
int dddd = dd.rtnData.pages;//总页
pageBar1.TotalPages = dddd;
pageBar1.RecordCount = dd.rtnData.total;//记录总数
pageBar1.CurrentPage = curPage;//当前页
gridView1.BestFitColumns();
}
else
{
ToolBox.MsgHelper.ShowError("提示:" + dd.rtnMsg);
}
}
catch (Exception ex)
{
ToolBox.MsgHelper.Warning("提示:" + ex.Message);
}
}
///
///
///
/// 主键
/// 是否可编辑
/// 选项卡序号
private void getModel(string strGuid)
{
bool isEdit = false;
if (toolBarMenu1.currentAction == "add") return;
if (toolBarMenu1.currentAction == "edit") isEdit = true;
if (string.IsNullOrEmpty(strGuid))
{
ToolBox.MsgHelper.Warning("请先选择你要操作的行!");
return;
}
var _obj = new
{
guid = strGuid,//主建
};
try
{
string strJson = UtilityHelper.HttpPost("", _webServiceName + "GetModel", JsonConvert.SerializeObject(_obj));
ReturnModel _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson);
if (_rtn.rtnCode > 0)
{
dynamic dy = _rtn.rtnData;
lbGuid.Text = strGuid;
UtilityHelper.SetValueByObj(this.layoutMx1.Controls, dy, isEdit);
}
else
ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg);
}
catch (Exception ex)
{
ToolBox.MsgHelper.Warning("提示:" + ex.Message);
}
}
///
/// 上传按钮
///
///
///
private void repositoryItemButtonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
var rowhandle = gridView1.FocusedRowHandle;
if (rowhandle < 0)
return;
if (e.Button.Index == 0)
{
var dr = gridView1.GetDataRow(rowhandle);
var mxGuid = dr["guid"].ToString();
Gs.DevApp.UserControl.ShowUp frm = new Gs.DevApp.UserControl.ShowUp(mxGuid);
frm.UpdateParent += (ss, ee) =>
{
Gs.DevApp.ToolBox.MsgHelper.ShowInformation("上传成功!");
getPageList(this.pageBar1.CurrentPage);
};
frm.ShowDialog();
}
}
}
}