1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using System;
- using System.Data;
- using DevExpress.XtraEditors;
- using UAS_PLCDataReader.Entity;
- namespace UAS_PLCDataReader.CustomerControl.Button
- {
- public partial class ButtonSaveGrid : SimpleButton
- {
- private AutoDataGridControl.AutoDataGridControl grid;
- /// <summary>
- /// 设置是否优先处理用户自定义的Click事件
- /// </summary>
- private bool handlerOtherFirst = false;
- public AutoDataGridControl.AutoDataGridControl Grid
- {
- get
- {
- return grid;
- }
- set
- {
- grid = value;
- }
- }
- public bool HandlerOtherFirst
- {
- get
- {
- return handlerOtherFirst;
- }
- set
- {
- handlerOtherFirst = value;
- }
- }
- public string[] LastSaveID;
- public ButtonSaveGrid()
- {
- InitializeComponent();
- }
- /// <summary>
- /// 内部调用,重新刷新数据
- /// </summary>
- private void DoSave()
- {
- DataTable dt = ((DataTable)grid.DataSource).GetChanges();
- if (dt != null && dt.Rows.Count > 0)
- {
- SystemInf.dh.SaveDataTable(dt, grid.TableName, grid.ID, out LastSaveID, grid.InsertSQL);
- grid.RefreshData();
- XtraMessageBox.Show("保存成功", "提示");
- }
- else
- {
- XtraMessageBox.Show("没有修改过的数据", "提示");
- }
- }
- /// <summary>
- /// 外部调用,不重新刷新数据
- /// </summary>
- public void DoSaveAfterHandler(bool iMessageBoxAlert)
- {
- DataTable dt = ((DataTable)grid.DataSource).GetChanges();
- if (dt != null && dt.Rows.Count > 0)
- {
- SystemInf.dh.SaveDataTable(dt, grid.TableName, grid.ID, out LastSaveID, grid.InsertSQL);
- if (iMessageBoxAlert)
- XtraMessageBox.Show("保存成功", "提示");
- }
- else
- {
- if (iMessageBoxAlert)
- XtraMessageBox.Show("没有修改过的数据", "提示");
- }
- }
- private void ButtonSaveGrid_Click(object sender, EventArgs e)
- {
- if (!handlerOtherFirst)
- {
- DoSave();
- }
- }
- }
- }
|