#region
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Reflection;
using System.Windows.Forms;
using CSFramework.DB;
using CSFrameworkV5.Common;
using CSFrameworkV5.Core;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;
using GSBase.BaseFrom;
using GSBase.Control;
#endregion
namespace CSFrameworkV5.Library.CommonClass
{
///
/// 用于绑定输入控件的数据源
///
public class DataBinder
{
public static DatabaseMSSQL mSSQL;
///
/// 插入一条空记录到表的第一行记录。
///
///
public static void AddEmptyRow(DataTable dt)
{
dt.Rows.InsertAt(dt.NewRow(), 0);
}
///
/// 绑定CheckedComboBoxEdit的数据源
///
///
///
///
///
public static void BindingCheckedComboBoxSource(
CheckedComboBoxEdit edit, DataTable dataSource,
string displayMember, string valueMember)
{
edit.Properties.DisplayMember = displayMember;
edit.Properties.ValueMember = valueMember;
edit.Properties.DataSource = dataSource;
}
///
/// 绑定CheckEdit的数据源
///
/// CheckEdit
/// 数据源
/// 取值字段
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)
{
Msg.ShowException(ex);
}
}
///
/// 绑定CheckedListBox的数据源
///
/// CheckedListBox
/// 数据源
/// 取值字段
public static void BindingCheckedListBox(Control control,
object dataSource, string bindField)
{
try
{
control.DataBindings.Clear();
var b = new Binding("EditValue", dataSource, bindField);
control.DataBindings.Add(b);
}
catch (Exception ex)
{
Msg.ShowException(ex);
}
}
///
/// 绑定CheckedListBoxControl的数据源
///
///
///
///
///
public static void BindingCheckedListBoxSource(
CheckedListBoxControl edit, DataTable dataSource,
string displayMember, string valueMember)
{
edit.DisplayMember = displayMember;
edit.ValueMember = valueMember;
edit.DataSource = dataSource;
}
///
/// 绑定ComboBoxEdit的数据源
///
/// ComboBoxEdit
/// 数据源
/// 取值字段
public static void BindingComboEdit(ComboBoxEdit edit,
object dataSource, string bindField)
{
try
{
edit.DataBindings.Clear();
var b = new Binding("EditValue", dataSource, bindField);
edit.DataBindings.Add(b);
}
catch (Exception ex)
{
Msg.ShowException(ex);
}
}
///
/// 绑定ComboBoxEdit的数据源
///
/// ComboBoxEdit
/// 数据源
/// 取值字段
public static void BindingComboEditDataSource(ComboBoxEdit edit,
DataTable dataSource, string bindField)
{
try
{
edit.Properties.Items.Clear();
foreach (DataRow dr in dataSource.Rows)
edit.Properties.Items.Add(dr[bindField]);
}
catch (Exception ex)
{
Msg.ShowException(ex);
}
}
///
/// 绑定ComboBoxEdit的数据源
///
/// ComboBoxEdit
/// 数据源
/// 取值字段
public static void BindingComboEditDataSource(
RepositoryItemComboBox edit, DataTable dataSource,
string bindField)
{
try
{
edit.Items.Clear();
foreach (DataRow dr in dataSource.Rows)
edit.Items.Add(dr[bindField]);
}
catch (Exception ex)
{
Msg.ShowException(ex);
}
}
///
/// 绑定输入控件的数据源
///
/// 支持输入功能的控件
/// 数据源
/// 取值字段
/// 控件的取值属性
public static void BindingControl(Control ctl, object dataSource,
string bindField, string propertyName)
{
try
{
ctl.DataBindings.Clear();
var b = new Binding(propertyName, dataSource, bindField);
ctl.DataBindings.Add(b);
}
catch (Exception ex)
{
Msg.ShowException(ex);
}
}
///
/// 绑定日期选择控件(DateEdit)的EditValueChanged事件.
/// 原因请叁考OnDateEditValueChange方法描述.
///
public static void BindingDateEditValueChangeEvent(DateEdit dateEdit)
{
dateEdit.EditValueChanged += OnDateEditValueChange;
}
///
/// 自动绑定编辑区域的数据源。规则:txt+字段名,或者chk+字段名,其它类型可以扩展
///
/// Panel容器
/// 数据源
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)
{
LogUserOperate.Write(ex);
Msg.Warning("字段:" + fieldName + "\r\n" + ex.Message);
}
}
///
/// 自动绑定编辑区域的数据源。重载,增加子表项 2022-5-1 liujiao
///
/// Panel容器
/// 数据源
public static void BindingEditorPanel(Control editorPanel,
DataTable dataSource, string ChilddataName)
{
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 GridControl)
{
DataTable Childdata = null;
var CdataColumnsName =
ChilddataName.Substring(ChilddataName.Length - 3) +
"001"; //子表主建
var edit = editorPanel.Controls[i] as GridControl;
foreach (DataRow dr in dataSource.Rows)
for (var j = 0; j < dataSource.Columns.Count; j++)
{
var str = dataSource.Columns[j].ColumnName;
if (str.Substring(str.Length - 3) == "001")
{
var con =
" Data Source=.;Initial Catalog=CSFrameworkV5_Normal;User ID=sa;Password =563593659liu;Persist Security Info=True;Connect Timeout=15;;Connection TimeOut=15;";
mSSQL = new DatabaseMSSQL(con);
var sql = string.Format(
@" SELECT * FROM {0} WHERE {1}='{2}' ",
ChilddataName, CdataColumnsName, dr[j]);
Childdata =
mSSQL.GetTable(sql, ChilddataName);
}
}
edit.DataSource = Childdata;
}
if (editorPanel.Controls[i] is AdvButtonText)
{
var ButtonText =
editorPanel.Controls[i] as AdvButtonText;
ButtonText.lbCaption.Text =
ButtonText.CaptionT; //"到货单号";
//ButtonText.ButtonClick += ButtonText_ButtonClick;
//ButtonText.TextValidated += ButtonText_TextValidated;
//ButtonText.textEdit.TextChanged -= new EventHandler(textEdit_TextChanged);
//ButtonText.textEdit.TextChanged += new EventHandler(textEdit_TextChanged);
}
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)
{
LogUserOperate.Write(ex);
Msg.Warning("字段:" + fieldName + "\r\n" + ex.Message);
}
}
///
/// 绑定图像控件的数据源
///
/// PictureEdit
/// 数据源
/// 取值字段
public static void BindingImageEdit(PictureEdit edit, object dataSource,
string bindField)
{
try
{
edit.DataBindings.Clear();
var b = new Binding("EditValue", dataSource, bindField);
//b.Parse += new ConvertEventHandler(ParseImageToByteArray);
//b.Format += new ConvertEventHandler(FormatByteArrayToImage);
edit.DataBindings.Add(b);
}
catch (Exception ex)
{
Msg.ShowException(ex);
}
}
///
/// 绑定参照字段的数据源
///
/// 参照字段输入控件
/// 数据源
/// 显示字段
/// 取值字段
public static void BindingLookupEditDataSource(LookUpEdit edit,
object dataSource, string displayMember,
string valueMember)
{
BindingLookupEditDataSource(edit.Properties, dataSource,
displayMember, valueMember);
}
///
/// 绑定表格内列参照字段的数据源
///
/// 参照字段控件
/// 数据源
/// 显示字段
/// 取值字段
public static void BindingLookupEditDataSource(
RepositoryItemLookUpEdit edit, object dataSource,
string displayMember, string valueMember)
{
edit.DisplayMember = displayMember;
edit.ValueMember = valueMember;
edit.DataSource = dataSource;
}
///
/// 绑定RadioGroup组控件的数据源
///
/// RadioGroup组控件
/// 数据源
/// 取值字段
public static void BindingRadioEdit(RadioGroup edit, object dataSource,
string bindField)
{
try
{
edit.DataBindings.Clear();
var b = new Binding("EditValue", dataSource, bindField);
edit.DataBindings.Add(b);
}
catch (Exception ex)
{
Msg.ShowException(ex);
}
}
///
/// 绑定RadioGroup组控件的数据源
///
/// RadioGroup组控件
/// 数据源
/// 取值字段
public static void BindingRadioEdit(RadioGroup edit,
DataTable dataSource, string displayMember,
string valueMember)
{
foreach (DataRow dr in dataSource.Rows)
{
var strName = ConvertEx.ToString(dr[displayMember]); //获取名称
var strVaule = ConvertEx.ToString(dr[valueMember]); //获取值
var rgItem = new RadioGroupItem();
rgItem.Description = strName;
rgItem.Value = strVaule;
edit.Properties.Items.Add(rgItem);
}
}
///
/// 绑定输入控件的数据源
///
/// 控件框
/// 数据源
/// 取值字段
public static void BindingTextEdit(TextEdit edit, object dataSource,
string bindField)
{
try
{
edit.DataBindings.Clear();
var b = new Binding("EditValue", dataSource, bindField);
edit.DataBindings.Add(b);
}
catch (Exception ex)
{
Msg.ShowException(ex);
}
}
///
/// 绑定输入控件的数据源
///
///
///
///
///
public static void BindingTextEdit(TextEdit edit, object dataSource,
string bindField, int rowPosition)
{
try
{
edit.DataBindings.Clear();
var b = new Binding("EditValue", dataSource, bindField);
edit.DataBindings.Add(b);
//指定资料行序号
if (rowPosition >= 0)
edit.BindingContext[dataSource].Position = rowPosition;
}
catch (Exception ex)
{
Msg.ShowException(ex);
}
}
///
/// 绑定金额输入控件的数据源
///
/// PictureEdit
/// 数据源
/// 取值字段
public static void BindingTextEditAmount(TextEdit edit,
object dataSource, string bindField)
{
try
{
edit.DataBindings.Clear();
var b = new Binding("EditValue", dataSource, bindField);
b.NullValue = null;
b.Parse += CurrencyStringToDecimal;
b.Format += DecimalToCurrencyString;
edit.DataBindings.Add(b);
}
catch (Exception ex)
{
Msg.ShowException(ex);
}
}
///
/// 绑定输入控件的数据源
///
/// 控件框
/// 数据源
/// 取值字段
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)
{
Msg.ShowException(ex);
}
}
///
/// 绑定日期输入控件的数据源
///
/// 日期输入控件TimeEdit
/// 数据源
/// 取值字段
public static void BindingTextEditDateTime(TimeEdit edit,
object dataSource, string bindField)
{
try
{
edit.DataBindings.Clear();
//不能绑定日期控件的DateTime属性. 只能为EditValue!
var b = new Binding("EditValue", dataSource, bindField);
b.NullValue = null;
b.Parse += DateStringToDate;
b.Format += DateToDateString;
edit.DataBindings.Add(b);
}
catch (Exception ex)
{
Msg.ShowException(ex);
}
}
///
/// 绑定日期输入控件的数据源
///
/// 日期输入控件DateEdit
/// 数据源
/// 取值字段
public static void BindingTextEditDateTime(DateEdit edit,
object dataSource, string bindField)
{
try
{
edit.DataBindings.Clear();
//不能绑定日期控件的DateTime属性. 只能为EditValue!
var b = new Binding("EditValue", dataSource, bindField);
b.NullValue = null;
b.Parse += DateStringToDate;
b.Format += DateToDateString;
edit.DataBindings.Add(b);
}
catch (Exception ex)
{
Msg.ShowException(ex);
}
}
///
/// 将INT类型转换为Boolean
///
///
///
public static void BoolBitToBool(object sender, ConvertEventArgs cevent)
{
try
{
if (cevent.DesiredType != typeof(int)) return;
cevent.Value = bool.Parse(cevent.Value.ToStringEx());
}
catch (Exception ex)
{
ShowError("数据转换错误!/n" + ex.Message, "错误");
}
}
///
/// 将Bool转换为INT
///
///
///
public static void BoolToBoolBit(object sender, ConvertEventArgs cevent)
{
try
{
if (cevent.DesiredType != typeof(bool)) return;
if (cevent.Value.ToStringEx() == string.Empty)
cevent.Value = false;
cevent.Value = (bool)cevent.Value;
}
catch (Exception ex)
{
ShowError("数据转换错误!/n" + ex.Message, "错误");
}
}
///
/// 将字符串转换为数字
///
///
///
public static void CurrencyStringToDecimal(object sender,
ConvertEventArgs cevent)
{
try
{
if (cevent.DesiredType != typeof(decimal)) return;
if (string.Empty == cevent.Value.ToStringEx())
cevent.Value = 0;
else
cevent.Value = decimal.Parse(cevent.Value.ToStringEx(),
NumberStyles.Currency, null);
}
catch (Exception ex)
{
ShowError("数据转换错误!/n" + ex.Message, "错误");
}
}
///
/// 日期字符串转换为日期类型
///
///
///
public static void DateStringToDate(object sender,
ConvertEventArgs cevent)
{
try
{
var type = cevent.DesiredType;
//对泛型数据特殊处理.
if (cevent.DesiredType.IsGenericType)
type = cevent.DesiredType.GetGenericArguments()[0];
if (cevent.Value == null || type != typeof(DateTime) ||
cevent.Value.ToStringEx() == string.Empty)
cevent.Value = null;
else
cevent.Value = DateTime.Parse(cevent.Value.ToStringEx(),
DateTimeFormatInfo.CurrentInfo);
}
catch (Exception ex)
{
ShowError("数据转换错误!/n" + ex.Message, "错误");
}
}
///
/// 将日期类型转换为带格式的日期字符串
///
///
///
public static void DateToDateString(object sender,
ConvertEventArgs cevent)
{
try
{
if (cevent.Value == null ||
cevent.DesiredType != typeof(string) ||
cevent.Value.ToStringEx() == string.Empty)
cevent.Value = null;
else
cevent.Value =
((DateTime)cevent.Value).ToString(
Globals.DEF_DATE_FORMAT,
DateTimeFormatInfo.CurrentInfo);
}
catch (Exception ex)
{
ShowError("数据转换错误!/n" + ex.Message, "错误");
}
}
///
/// 将数字类型转换为带格式的字符串
///
///
///
public static void DecimalToCurrencyString(object sender,
ConvertEventArgs cevent)
{
try
{
if (cevent != null && cevent.Value != null &&
cevent.DesiredType == typeof(string))
cevent.Value =
((decimal)cevent.Value).ToString("n"); //10,446.56
}
catch (Exception ex)
{
ShowError("数据转换错误!/n" + ex.Message, "错误");
}
}
///
/// Byte[] to Image
///
public static void FormatByteArrayToImage(object sender,
ConvertEventArgs e)
{
try
{
if (e.Value != null)
{
var img =
(Image)ZipTools.DecompressionObject((byte[])e.Value);
e.Value = img;
}
else
{
e.Value = null;
}
}
catch
{
e.Value = null;
}
}
private void GetMapp(string v1, string v2, string val)
{
SetValueControlProperty(this, v1, v2, val);
}
public static void GetSelectT(string sql, string filt)
{
DataRow datarow = null;
try
{
var SelectItemDlg = new SelectQueryDlg(sql, filt);
if (SelectItemDlg.ShowDialog() == DialogResult.OK)
datarow = SelectItemDlg.ReturnRow == null
? null
: SelectItemDlg.ReturnRow;
else
datarow = null;
//SelectItemDlg.ShowDialog();
//datarow = Search.GetQueryRow(ButtonText.DatacatalogID, SqlFilterHelper(ButtonText.Filter));
}
catch (Exception ex)
{
//WriteLog(Format("调用出现错误:{0}", GetErrorMsg(ex)), true);
//return;
}
}
private static string[] GetSplitString(string strValue)
{
if (strValue == null) return null;
if (strValue.Length == 0) return null;
strValue = strValue.Replace("[", "").Replace("]", "");
var strArray = strValue.Split(';', '=');
return strArray;
}
///
/// 日期控件(DateEdit)的EditValueChanged事件.
/// 对象内定义为Nullable
///
/// 数据类型的属性,进行数据绑定后不能将值
/// 保存在对象内,所以实现这个方法做特殊处理
///
public static void OnDateEditValueChange(object sender, EventArgs e)
{
try
{
var edit = (DateEdit)sender;
if (edit.DataBindings.Count <= 0) return; //无绑定数据源.
var bindingObj = edit.DataBindings[0].DataSource; //取绑定的对象.
if (bindingObj != null)
{
var bindingField = edit.DataBindings[0].BindingMemberInfo
.BindingField; //取绑定的成员字段.
DataConverter.SetValueOfObject(bindingObj, bindingField,
edit.EditValue); //给对象的字段赋值
}
}
catch (Exception ex)
{
Msg.ShowException(ex);
}
}
///
/// Image to byte[]
///
public static void ParseImageToByteArray(object sender,
ConvertEventArgs e)
{
try
{
if (e.Value != null)
e.Value = ZipTools.CompressionObject(e.Value as Image);
else
e.Value = DBNull.Value;
}
catch
{
e.Value = DBNull.Value;
}
}
///
/// 设置容器内所有可输入控件的状态.ReadOnly or Enable = false/true
///
/// 容器
/// false/true
public static void SetControlAccessable(Control container, bool value)
{
if (container is Label) return;
if (container is LabelControl) return;
if (container is UserControl) return;
if (container.HasChildren == false) return; //没有子控件,不处理
foreach (Control c in container.Controls)
//最常用组件,首先处理
if (c is BaseEdit) //输入框
(c as BaseEdit).Properties.ReadOnly = !value;
else if (c is GridControl) //表格
((c as GridControl).Views[0] as GridView).OptionsBehavior
.Editable = value;
else
SetControlAccessableByProp(container,
value); //其它组件,反射属性设置状态
}
///
/// 设置一个控件的可用状态,通过反射ReadOnly,Properties属性
///
/// 控件
/// 值
public static void SetControlAccessableByProp(Control control,
bool value)
{
var type = control.GetType();
var infos = type.GetProperties();
foreach (var info in infos)
{
if (info.Name == "ReadOnly") //Properties.ReadOnly
{
info.SetValue(control, !value, null);
return;
}
if (info.Name == "Properties")
{
var o = info.GetValue(control, null);
//处理特殊组件
if (o is RepositoryItemButtonEdit &&
(o as RepositoryItemButtonEdit).Buttons.Count >
0) //ButtonEdit
(o as RepositoryItemButtonEdit).Buttons[0].Enabled =
value;
else if (o is RepositoryItemDateEdit &&
(o as RepositoryItemDateEdit).Buttons.Count >
0) //DateEdit
(o as RepositoryItemDateEdit).Buttons[0].Enabled =
value;
if (o is RepositoryItem)
(o as RepositoryItem).ReadOnly = !value;
return;
}
}
}
///
/// 设置容器内所有可输入控件的状态 .ReadOnly or Enable . (递归)循环控制
///
/// 容器
/// false/true
public static void SetControlAccessableCycle(Control container,
bool value)
{
if (container.HasChildren)
foreach (Control ctrl in container.Controls)
//DevExpress的内部(Inner)控件
if (ctrl.Name == string.Empty)
SetControlAccessable(container, value);
else
SetControlAccessableCycle(ctrl, value);
else
SetControlAccessable(container, value);
}
///
/// 设置容器内的控件可用状态, Control.Enable = false/true
///
/// 容器
/// false/true
public static void SetControlEnable(Control container, bool value)
{
if (container is Label) return;
if (container is LabelControl) return;
if (container.Name == "") return;
if (container.Controls.Count > 0)
foreach (Control c in container.Controls)
{
c.Enabled = value;
SetControlEnable(c, value);
}
}
///
/// 给绑定数据源的输入控件赋值
///
public static void SetEditorBindingValue(Control bindingControl,
object value)
{
SetEditorBindingValue(bindingControl, value, false);
}
public static void SetEditorBindingValue(Control bindingControl,
object value, bool setEditorValue)
{
try
{
object temp = null;
if (value != DBNull.Value) temp = value;
if (bindingControl.DataBindings.Count > 0)
{
var dataSource = bindingControl.DataBindings[0].DataSource;
var field = bindingControl.DataBindings[0].BindingMemberInfo
.BindingField;
if (dataSource is DataTable)
(dataSource as DataTable).Rows[0][field] = value;
else
DataConverter.SetValueOfObject(dataSource, field,
value);
}
if (setEditorValue)
DataConverter.SetValueOfObject(bindingControl, "EditValue",
value);
bindingControl.Refresh();
}
catch
{
} //这里不用显示异常信息.
}
///
/// 设置输入组件只读及背景色
///
/// 输入组件
/// 可写/只读
/// 是否设置背景色
public static void SetEditorEnable(TextEdit editor, bool enable,
bool setBackgroundColor)
{
if (enable && setBackgroundColor) editor.BackColor = Color.White;
if (!enable && setBackgroundColor)
editor.BackColor = SystemColors.ButtonFace;
editor.Properties.ReadOnly = !enable;
}
//private void GetMapp()
//{
// SetValueControlProperty(this, mapping[0], mapping[1], val);
//}
public static void SetValueControlProperty(object ClassInstance,
string ControlName, string PropertyName,
object Value)
{
var myType = ClassInstance.GetType();
var myFieldInfo = myType.GetField(ControlName,
BindingFlags.NonPublic
| BindingFlags.Instance);
if (myFieldInfo == null) return;
var properties =
TypeDescriptor.GetProperties(myFieldInfo.FieldType);
var myProperty =
properties.Find(PropertyName, false); //这里设为True就不用区分大小写了
if (myProperty == null) return;
object ctr;
ctr = myFieldInfo.GetValue(ClassInstance); //取得控件实例
try
{
myProperty.SetValue(ctr, Value.ToString());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
///
/// 显示错误
///
/// 消息
/// 标题
private static void ShowError(string msg, string title)
{
MessageBox.Show(msg, title, MessageBoxButtons.OK,
MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
}
public static DataRow TTT(object sender, EventArgs e)
{
var ButtonText = sender as AdvButtonText;
ButtonText.lbCaption.Text = ButtonText.CaptionT;
//if (_UpdateType != UpdateType.Add)
//{
// Msg.Warning("请先打开新增状态!");
// return;
//}
//点选前检测
//if (ButtonTextBeforeClickCheck(ButtonText) == false)
// return;
//判断控件的SearchEntity是否是有赋值;
//if (ButtonText.SearchEntity == null)
//{
// WriteLog(Format("此控件的查询实体为空"), true);
// return;
//}
////判断控件的SearchEntity是否是EntityClass,若是则将其查询实体赋值
//if (ButtonText.SearchEntity is EntityClass)
//{
// Search.SelectEntity = (EntityClass)ButtonText.SearchEntity;
//}
//查询数据.SqlFilterHelper负责进行将条件转换为实际的条件
DataRow datarow = null;
try
{
var SelectItemDlg = new SelectQueryDlg(ButtonText.DatacatalogID,
ButtonText.Filter);
if (SelectItemDlg.ShowDialog() == DialogResult.OK)
datarow = SelectItemDlg.ReturnRow == null
? null
: SelectItemDlg.ReturnRow;
else
datarow = null;
//SelectItemDlg.ShowDialog();
//datarow = Search.GetQueryRow(ButtonText.DatacatalogID, SqlFilterHelper(ButtonText.Filter));
}
catch (Exception ex)
{
//WriteLog(Format("调用出现错误:{0}", GetErrorMsg(ex)), true);
//return;
}
//若行为空则返回.
if (datarow == null)
//WriteLog(Format("没有找到合适的{0}",ButtonText.Caption), true);
return null;
//对文本框进行赋值
//if (ButtonText.TextField.Length == 0)
//{
// WriteLog(Format("请完善控件文本对应的字段编号"), true);
// return;
//}
////对文本框中的字段编号进行判断,是否在查询表中存在
//if (!datarow.Table.Columns.Contains(ButtonText.TextField))
//{
// WriteLog(Format("文本对应字段在查询集中无法找到此列"), true);
// return;
//}
//对查询出来结果进行赋值
ButtonText.textEdit.EditValue = datarow[ButtonText.TextField];
//ControlHelper.SetValueControlProperty(this, ButtonText.Name, "EditValue", datarow[ButtonText.TextField].ToString());
//对备注字段进行赋值,若备注字段为空、文本模式为BeRemark,且数据表中存在字段才执行
if (ButtonText.TextType == ShowStyle.BeRemark &&
ButtonText.RemarkField.Length > 0 &&
datarow.Table.Columns.Contains(ButtonText.RemarkField))
ButtonText.lbRemark.Text =
datarow[ButtonText.RemarkField].ToString();
//ControlHelper.SetValueControlProperty(this, ButtonText.Name, "Remark", datarow[ButtonText.RemarkField].ToString());
#region 点选结果返回变更
ButtonText.Tag = datarow;
//ButtonText.FireButtonDataChanged(sender, e);
#endregion
//通过函数将其他映射关系转换.
var strMapping = GetSplitString(ButtonText.OtherMapping);
try
{
if (strMapping == null) return datarow;
//对其他映射关系进行赋值
for (var i = 0; i < strMapping.Length; i += 2)
{
if (!strMapping[i].Contains(".")) continue;
var mapping = strMapping[i].Split('.');
//转译DataRow的值之后设定给控件属性。Table.Columns不包设定列,则表示为用户设定了固定值。
//注意,例如:如果为DateTime控件,而用户设定的值为非日期格式,系统同样会提示出设值错误。
var val = datarow.Table.Columns.Contains(strMapping[i + 1])
? datarow[strMapping[i + 1]].ToString()
: strMapping[i + 1];
//GetMapp(mapping[0], mapping[1], val);
}
}
finally
{
// GridCheckError = "";
//ResultManger.Clear(ButtonText.Caption);
//ogf modify by 2012-05-26这样处理的原因是离开这个控件,以便控件把值提交到Datarow中,并触发列变化事件。
ButtonText.strOldText = ButtonText.textEdit.Text;
ButtonText.textEdit.Focus();
//this.SelectNextControl(this.ActiveControl, true, false, true, true);
ButtonText.textEdit.Focus();
}
return datarow;
}
public static DataRow LIANS(string SQL, string Filter)
{
DataRow datarow = null;
try
{
var SelectItemDlg = new SelectQueryDlg(SQL, Filter);
if (SelectItemDlg.ShowDialog() == DialogResult.OK)
datarow = SelectItemDlg.ReturnRow == null
? null
: SelectItemDlg.ReturnRow;
else
datarow = null;
//SelectItemDlg.ShowDialog();
//datarow = Search.GetQueryRow(ButtonText.DatacatalogID, SqlFilterHelper(ButtonText.Filter));
}
catch (Exception ex)
{
//WriteLog(Format("调用出现错误:{0}", GetErrorMsg(ex)), true);
//return;
}
//若行为空则返回.
if (datarow == null)
//WriteLog(Format("没有找到合适的{0}",ButtonText.Caption), true);
return null;
#region 点选结果返回变更
#endregion
return datarow;
}
}
}