using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows.Forms;
using Lskj.MyControl;
using System.Drawing;
using System.Data.SqlClient;
using Lskj.Common;
using DevExpress.XtraEditors;
using ControlLib.inh;
using CommonLib;
using System.IO;
using Lskj.MyControl.LookUpAdd;
using Lskj.MyControl.LookUp;
using Lskj.PubUtils;
using DevExpress.Utils;
namespace Lskj.Common
{
public class MyCreateControl
{
///
/// 用户登录Id
///
public string LoginId { get; set; }
///
/// 用户登录名
///
public string LoginName { get; set; }
public string Space { get; set; }
public Control ParentCtr { get; set; }
public string[] otherParams { get; set; }
public string SpeciesField { get; set; }
///
/// 所有需要计算的字段
///
private DataRow[] dtSumRows { get; set; }
///
/// 基础档案表的原始列
///
public DataColumnCollection dtColumns;
public event EventHandler onRefreshClick;
public MyCreateControl()
{
}
public MyCreateControl(string LoginId, string LoginName)
{
this.LoginId = LoginId;
this.LoginName = LoginName;
}
private void myctr_TextChanged(object sender, EventArgs e)
{
if (sender is Control)
{
//MessageBox.Show((sender as Control).Name);
//if (sender is LabelLookUp)
// MessageBox.Show((sender as LabelLookUp).ReturnValue);
ControlModelTag cmTag = (sender as Control).Tag as ControlModelTag;
if ((sender as Control).Tag == null)
{
cmTag = (sender as Control).Parent.Tag as ControlModelTag;
}
if (cmTag == null || ParentCtr == null || cmTag.isSetText) return;
this.calcUnionFields(cmTag);
this.calcExpressFields(cmTag, sender);
if ((onRefreshClick != null) && (cmTag.refreshSource == 1))
{
onRefreshClick(sender, e);
}
}
}
private void myctr_CloseUp(object sender, EventArgs e)
{
if (sender is DateTimePicker)
{
var picker = (sender as DateTimePicker);
picker.CustomFormat = picker.Tag != null
? (picker.Tag as ControlModelTag).DateFormat
: "yyyy-MM-dd";
string date = picker.Value.ToString("yyyy-MM-dd");
picker.Value = DateTime.Parse(date);
}
}
private void myctr_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (sender is DateTimePicker)
{
var picker = (sender as DateTimePicker);
if (e.KeyCode == Keys.Delete)
{
picker.CustomFormat = " ";
}
else
{
if (PubClass.HasNumerCode((int)e.KeyCode))
{
picker.CustomFormat = picker.Tag != null
? (picker.Tag as ControlModelTag).DateFormat
: "yyyy-MM-dd";
}
}
}
if (!(sender is AutoSearcher))
{
if (e.KeyCode == Keys.Return)
{
Control ctl = (sender as Control).Parent.Parent;
if (ctl != null)
ctl.Parent.SelectNextControl(ctl, true, false, true, false);
}
}
}
#region 控件面板计算
///
/// 关联字段计算
///
private void calcUnionFields(ControlModelTag cmTag)
{
string unionFields = cmTag.unionFields;
string unionValue = cmTag.unionValue;
//根据设置关联字段赋值
if (!string.IsNullOrEmpty(unionFields.Trim()))
{
string[] fields = unionFields.Split(',');
//unionValue = unionValue.Replace("{loginid}", LoginId).Replace("{loginname}", LoginName);
unionValue = PubClass.ReqSqlParam(unionValue, LoginId, LoginName);
List sql_param = PubClass.GetParamValue(unionValue);
foreach (string item in sql_param)
{
string ctlName = item.Replace("{", "").Replace("}", "");
Control[] ctl = ParentCtr.Controls.Find("txt_" + ctlName, true);
if (ctl != null && ctl.Length > 0)
{
string ctValue = GetControlText(ctl[0]);
if (ctValue.Trim() == "")
ctValue = "0";
unionValue = unionValue.Replace(item, ctValue);
}
}
try
{
foreach (string singleField in fields)
{
Control[] ctl = ParentCtr.Controls.Find("txt_" + singleField, true);
if (ctl != null && ctl.Length > 0)
{
SetControlText(ctl[0], "");
}
}
DataTable dt = SqlHelper.ExecuteDataSet(unionValue).Tables[0];
if (dt.Rows.Count < 1) return;
foreach (string singleField in fields)
{
Control[] ctl = ParentCtr.Controls.Find("txt_" + singleField, true);
if (ctl != null && ctl.Length > 0)
{
if (dt.Columns.Contains(singleField))
SetControlText(ctl[0], dt.Rows[0][singleField].ToString());
}
}
}
catch (Exception ex)
{
}
}
}
///
/// 字段表达式计算
///
private void calcExpressFields(ControlModelTag cmTag, object sender)
{
if (dtSumRows.Count() == 0) return;
string fieldName = cmTag.fieldName;
string fieldValue = GetControlText(fieldName);
if (string.IsNullOrEmpty(fieldValue)) fieldValue = "0";
Control ctr = (sender as Control);
foreach (DataRow dRow in dtSumRows)
{
string calcName = dRow["fieldName"] + "";
string calcExpress = dRow["calcExpr"] + "";
if (calcExpress.Contains("{" + fieldName + "}"))
{
try
{
calcExpress = calcExpress.Replace("{" + fieldName + "}", fieldValue);
List calcParams = PubClass.GetParamValue(calcExpress);
foreach (string param in calcParams)
{
string fieldOtherName = param.Replace("{", "").Replace("}", "");
string filedValue = GetControlText(fieldOtherName);
if (string.IsNullOrEmpty(filedValue))
filedValue = "0";
calcExpress = calcExpress.Replace(param, filedValue);
}
calcExpress = calcExpress.Replace("=", "==").Replace("<>", "!=").Replace("and", "&&").Replace("or", "|");
Control calcControl = GetControl(calcName)[0];
string eval = Evaluator.Eval(calcExpress).ToString();
float feval = 0.0f;
if (!string.IsNullOrEmpty(eval) && float.TryParse(eval, out feval))
{
string dataFormat = string.Empty;
if (dRow.Table.Columns.Contains("dataformat"))
dataFormat = dRow["dataformat"] + "";
eval = string.IsNullOrEmpty(dataFormat) ? Math.Round(feval, 2).ToString() : string.Format("{0:" + dataFormat + "}", float.Parse(eval));
}
SetControlText(calcControl, eval);
}
catch (Exception ex)
{
}
}
}
}
#endregion
///
/// 创建控件
///
///
///
public int CreateControlByModel(CreateControlModel cmodel)
{
int yHeight = 0;
DataTable dTable = cmodel.dt;
if (dTable == null && dTable.Rows.Count == 0 && !string.IsNullOrEmpty(cmodel.sql))
dTable = SqlHelper.ExecuteDataSet(cmodel.sql).Tables[0];
this.dtSumRows = dTable.Rows.OfType()
.Where(x => !string.IsNullOrEmpty(x["calcExpr"] + ""))
.ToArray(); // 计算字段
foreach (DataRow row in dTable.Rows)
{
int fieldTypeId = Convert.ToInt32(row["fieldTypeId"]);
string edited = row["edited"] + "";
bool isSave = dtColumns == null || dtColumns.Contains(row["fieldName"] + "");
ControlModelTag cmodelTag = new ControlModelTag() { IsSave = isSave, IsClear = (edited != "1"), IsEmpt = Convert.ToBoolean(row["nullable"]), fieldTypeId = fieldTypeId, TipMsg = row["userName"] + "" };
cmodelTag.DefaultText = row["defaultValue"] + "";
cmodelTag.DefaultValue = row["defaultValue"] + "";
cmodelTag.unionFields = row["unionFields"] + "";
cmodelTag.unionValue = row["unionValue"] + "";
cmodelTag.fieldName = row["fieldName"] + "";
cmodelTag.DateFormat = "";
if (row.Table.Columns.Contains("dataformat"))
cmodelTag.DateFormat = row["dataformat"] + "";
cmodelTag.refreshSource = 0;
if (row.Table.Columns.Contains("refreshSource"))
cmodelTag.refreshSource = row["refreshSource"] + "" == "1" ? 1 : 0;
try
{
Control myctr = null;
//日期
if (fieldTypeId == ControlType.LabDate ||
fieldTypeId == ControlType.LabDateTime ||
fieldTypeId == ControlType.LabDateTimeShort ||
fieldTypeId == ControlType.LabTime ||
fieldTypeId == ControlType.LabShortTime)
{
LabelDateEx labelText = new LabelDateEx();
labelText.LabelText = row["userName"].ToString();
labelText.Name = "txt_" + row["fieldName"];
labelText.FormatType = cmodelTag.DateFormat = DateFormatType.GetFormatValue(fieldTypeId);
labelText.Text = GetDefaultValue(row["defaultValue"].ToString());
if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
labelText.GetDateTimePicker.Enabled = false;
myctr = labelText;
labelText.GetDateTimePicker.ShowUpDown = fieldTypeId == ControlType.LabTime || fieldTypeId == ControlType.LabShortTime ? true : false;
labelText.GetDateTimePicker.Tag = cmodelTag;
labelText.GetDateTimePicker.TextChanged += new EventHandler(myctr_TextChanged);
labelText.GetDateTimePicker.CloseUp += new EventHandler(myctr_CloseUp);
labelText.GetDateTimePicker.KeyDown += new KeyEventHandler(myctr_KeyDown);
labelText.GetDateTimePicker.GotFocus += new EventHandler(GotFocus);
labelText.GetDateTimePicker.LostFocus += new EventHandler(LostFocus);
}
//下拉框
else if (fieldTypeId == ControlType.LabComboxValue
|| fieldTypeId == ControlType.LabComboxText||fieldTypeId==ControlType.LabComboxInputParam)
{
LabelComboxEx labelText = new LabelComboxEx();
labelText.getComboBox.FlatStyle = FlatStyle.Flat;
labelText.LabelText = row["userName"].ToString();
labelText.Name = "txt_" + row["fieldName"];
string lookupSql = PubClass.ReqSqlParam(row["lookupSql"].ToString(), cmodel.loginid, cmodel.loginname);
lookupSql = lookupSql.Replace("{parent.key}", Space);
if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
{
labelText.getComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
labelText.getComboBox.Enabled = false;
}
if (!string.IsNullOrEmpty(lookupSql))
{
string keyField = row["lookupKeyField"] + "";
string resultField = row["lookupResult"] + "";
labelText.setDataSource(lookupSql, keyField, resultField);
}
if (fieldTypeId == ControlType.LabComboxValue)
{
labelText.getComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
string defaultValue = GetDefaultValue(row["defaultValue"].ToString());
//MessageBox.Show(defaultValue);
if (!string.IsNullOrEmpty(defaultValue))
labelText.getComboBox.SelectedValue = defaultValue;
labelText.getComboBox.SelectedIndexChanged += new EventHandler(myctr_TextChanged);
}
else
{
labelText.Text = GetDefaultValue(row["defaultValue"].ToString());
labelText.getComboBox.TextChanged += new EventHandler(myctr_TextChanged);
}
myctr = labelText;
labelText.getComboBox.Tag = cmodelTag;
labelText.getComboBox.KeyDown += new KeyEventHandler(myctr_KeyDown);
labelText.getComboBox.GotFocus += new EventHandler(GotFocus);
labelText.getComboBox.LostFocus += new EventHandler(LostFocus);
}
//下拉复选框
else if (fieldTypeId == ControlType.LabComboxCheckListValue
|| fieldTypeId == ControlType.LabComboxCheckListText)
{
LabelComboCheckList labelText = new LabelComboCheckList();
//labelText.getComboBox.FlatStyle = FlatStyle.Flat;
labelText.LabelText = row["userName"].ToString();
labelText.Name = "txt_" + row["fieldName"];
string lookupSql = PubClass.ReqSqlParam(row["lookupSql"].ToString(), cmodel.loginid, cmodel.loginname);
lookupSql = lookupSql.Replace("{parent.key}", Space);
if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
{
//labelText.getComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
labelText.getComboBox.Enabled = false;
}
if (!string.IsNullOrEmpty(lookupSql))
{
string keyField = row["lookupKeyField"] + "";
string resultField = row["lookupResult"] + "";
if (fieldTypeId == ControlType.LabComboxCheckListValue)
{
labelText.setDataSource(lookupSql, keyField, resultField);
}
else
{
labelText.setDataSource(lookupSql, resultField, resultField);
}
}
if (fieldTypeId == ControlType.LabComboxCheckListValue)
{
//labelText.getComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
string defaultValue = GetDefaultValue(row["defaultValue"].ToString());
//MessageBox.Show(defaultValue);
if (!string.IsNullOrEmpty(defaultValue))
labelText.getComboBox.SetEditValue(defaultValue);
labelText.getComboBox.Properties.EditValueChanged += new EventHandler(myctr_TextChanged);
}
else
{
string defaultValue = GetDefaultValue(row["defaultValue"].ToString());
if (!string.IsNullOrEmpty(defaultValue))
labelText.getComboBox.SetEditValue(defaultValue);
labelText.getComboBox.TextChanged += new EventHandler(myctr_TextChanged);
}
myctr = labelText;
labelText.getComboBox.Tag = cmodelTag;
labelText.getComboBox.KeyDown += new KeyEventHandler(myctr_KeyDown);
labelText.getComboBox.GotFocus += new EventHandler(GotFocus);
labelText.getComboBox.LostFocus += new EventHandler(LostFocus);
}
//自动搜索
else if (fieldTypeId == ControlType.LabAutoSeacherValue || fieldTypeId == ControlType.LabAutoSeacherText ||
fieldTypeId == ControlType.LabComboxValueParam || fieldTypeId == ControlType.LabComboxTextParam)
{
LabelAutoSearcherEx autSearch = new LabelAutoSearcherEx();
autSearch.LabelText = row["userName"].ToString();
ControlLib.inh.AutoSearcher txtUserName = autSearch.GetAutoSearcher;
ControlLib.inh.SearcherPropertyCollector searcherPropertyCollector1 = new ControlLib.inh.SearcherPropertyCollector();
ControlLib.inh.TFieldPropertyData tFieldPropertyData1 = new ControlLib.inh.TFieldPropertyData();
ControlLib.inh.TFieldPropertyData tFieldPropertyData2 = new ControlLib.inh.TFieldPropertyData();
ControlLib.inh.TFieldPropertyData tFieldPropertyData3 = new ControlLib.inh.TFieldPropertyData();
txtUserName.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Append;
txtUserName.Tag = cmodelTag;
//取下拉列表数据
txtUserName.MaxLength = 50;
txtUserName.Name = "txt_" + row["fieldName"];
txtUserName.searcherPropertyCollector = searcherPropertyCollector1;
txtUserName.TabIndex = 12;
tFieldPropertyData1.FieldCaption = "编码";
tFieldPropertyData1.FieldName = row["lookupKeyField"] + "";
tFieldPropertyData1.FieldWidth = 50;
tFieldPropertyData1.ShowColumn = true;
tFieldPropertyData2.FieldCaption = "名称";
tFieldPropertyData2.FieldName = row["lookupResult"] + "";
tFieldPropertyData2.FieldWidth = 150;
tFieldPropertyData2.ShowColumn = true;
string sql = row["lookupSql"].ToString();
sql = sql.Replace("{parent.key}", Space);
searcherPropertyCollector1.ConvertToChineseSpell = true;
searcherPropertyCollector1.FieldPropertyList = new ControlLib.inh.TFieldPropertyData[] { tFieldPropertyData1, tFieldPropertyData2 };
if (sql.IndexOf("remark", StringComparison.OrdinalIgnoreCase) != -1)
{
searcherPropertyCollector1.RemarkField = "remark";
tFieldPropertyData3.FieldCaption = "备注";
tFieldPropertyData3.FieldName = "remark";
tFieldPropertyData3.FieldWidth = 150;
tFieldPropertyData3.ShowColumn = true;
searcherPropertyCollector1.FieldPropertyList = new ControlLib.inh.TFieldPropertyData[] { tFieldPropertyData1, tFieldPropertyData2, tFieldPropertyData3 };
}
searcherPropertyCollector1.KeyField = row["lookupKeyField"] + "";
searcherPropertyCollector1.QueryField = row["lookupResult"] + "";
searcherPropertyCollector1.QuerySQL = PubClass.ReqSqlParam(sql, cmodel.loginid, cmodel.loginname);
//searcherPropertyCollector1.ReturnMaxCount = 50;
searcherPropertyCollector1.ReturnValueField = row["lookupKeyField"] + "";
searcherPropertyCollector1.SearchMatchWay = ControlLib.inh.TSearchMatchWay.swFuzzy;
searcherPropertyCollector1.ShowFormHeight = 230;
searcherPropertyCollector1.ShowFormWidth = 230;
searcherPropertyCollector1.InitSQL = searcherPropertyCollector1.SQL = PubClass.ReqSqlParam(row["lookupSql"].ToString(), cmodel.loginid, cmodel.loginname);
if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
{
autSearch.GetAutoSearcher.ReadOnly = true;
}
if (fieldTypeId == ControlType.LabAutoSeacherText)
autSearch.GetAutoSearcher.IsClear = false;
try
{
autSearch.GetAutoSearcher.addDllModuleId = row["AddModuleId"].ToString();
autSearch.GetAutoSearcher.addModuleCaption = row["addmodulename"].ToString();
autSearch.GetAutoSearcher.addDllName = row["adddllname"].ToString();
autSearch.GetAutoSearcher.OperatorId = LoginId;
autSearch.GetAutoSearcher.OperatorName = LoginName;
if (row.Table.Columns.Contains("addModuleSpec"))
{
string speciesSql = row["addModuleSpec"] + "";
speciesSql = PubClass.ReqSqlParam(speciesSql, LoginId, LoginName);
speciesSql = PubClass.ReqSql(ParentCtr, speciesSql);
object value = speciesSql;
if (speciesSql.IndexOf('@') != -1)
{
speciesSql = speciesSql.Replace('@', ' ');
value = SqlHelper.ExecuteScalar(CommandType.Text, speciesSql);
}
if (value != null)
autSearch.GetAutoSearcher.SpeciesNo = value.ToString();
}
if (row.Table.Columns.Contains("addModuleResult"))
{
string modResultSql = row["addModuleResult"] + "";
modResultSql = PubClass.ReqSqlParam(modResultSql, LoginId, LoginName);
//modResultSql = PubClass.ReqSql(ParentCtr, modResultSql);
autSearch.GetAutoSearcher.addResultValue = modResultSql;
}
//sql中存在 #
string tempsql = sql.Replace("{#", "");
int lIndex = tempsql.IndexOf("#", StringComparison.OrdinalIgnoreCase);
if (fieldTypeId == ControlType.LabComboxValueParam || fieldTypeId == ControlType.LabComboxTextParam || (lIndex >= 0))
{
autSearch.GetAutoSearcher.SearchControlPanel = cmodel.ctr;
autSearch.GetAutoSearcher.OnTextChangedBefore += new EventHandler(GetAutoSearcher_HandleSQL);
}
}
catch
{
}
myctr = autSearch;
//初始值单独进行
//string value = GetDefaultValue(row["defaultValue"].ToString());
//if (fieldTypeId == ControlType.LabAutoSeacherValue)
// autSearch.GetAutoSearcher.SetValueSilent(value,"");
//else
// autSearch.Text = value;
autSearch.GetAutoSearcher.TextChanged += new EventHandler(myctr_TextChanged);
autSearch.GetAutoSearcher.KeyDown += new KeyEventHandler(myctr_KeyDown);
autSearch.GetAutoSearcher.GotFocus += new EventHandler(GotFocus);
autSearch.GetAutoSearcher.LostFocus += new EventHandler(LostFocus);
}
//创建文本域
else if (fieldTypeId == ControlType.LabRemark)
{
LabelTextarea labelText = new LabelTextarea();
labelText.LabelText = row["userName"].ToString();
labelText.Location = new Point(Convert.ToInt32(row["ControlLeft"]), Convert.ToInt32(row["controlTop"]));
labelText.Parent = cmodel.ctr;
labelText.Name = "txt_" + row["fieldName"];
if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
{
labelText.Enabled = false;
}
myctr = labelText;
labelText.TextChanged += new EventHandler(myctr_TextChanged);
labelText.KeyDown += new KeyEventHandler(myctr_KeyDown);
labelText.getTextBox.GotFocus += new EventHandler(GotFocus);
labelText.getTextBox.LostFocus += new EventHandler(LostFocus);
}
//创建富文本框
else if (fieldTypeId == ControlType.LabRichEdit)
{
LabelRichEdit labelRichEdit = new LabelRichEdit();
labelRichEdit.LabelText = row["userName"].ToString();
labelRichEdit.Parent = cmodel.ctr;
labelRichEdit.Name = "txt_" + row["fieldName"];
myctr = labelRichEdit;
labelRichEdit.Text = GetDefaultValue(row["defaultValue"].ToString());
}
//创建QQ控件
else if (fieldTypeId == ControlType.LabQQ)
{
LabelTextQQEx labelText = new LabelTextQQEx();
labelText.LabelText = row["userName"].ToString();
labelText.Parent = cmodel.ctr;
labelText.Name = "txt_" + row["fieldName"];
myctr = labelText;
labelText.GetTextBox.Tag = cmodelTag;
labelText.Text = GetDefaultValue(row["defaultValue"].ToString());
labelText.GetTextBox.TextChanged += new EventHandler(myctr_TextChanged);
labelText.GetTextBox.KeyDown += new KeyEventHandler(myctr_KeyDown);
labelText.GetTextBox.GotFocus += new EventHandler(GotFocus);
labelText.GetTextBox.LostFocus += new EventHandler(LostFocus);
}
//创建网址控件
else if (fieldTypeId == ControlType.LabWWW)
{
LabelTextWwwEx labelText = new LabelTextWwwEx();
labelText.LabelText = row["userName"].ToString();
labelText.Parent = cmodel.ctr;
labelText.Name = "txt_" + row["fieldName"];
myctr = labelText;
labelText.Text = GetDefaultValue(row["defaultValue"].ToString());
labelText.GetTextBox.TextChanged += new EventHandler(myctr_TextChanged);
labelText.GetTextBox.KeyDown += new KeyEventHandler(myctr_KeyDown);
labelText.GetTextBox.GotFocus += new EventHandler(GotFocus);
labelText.GetTextBox.LostFocus += new EventHandler(LostFocus);
}
else if (fieldTypeId == ControlType.LabPic)
{
LabelPicEx labelText = new LabelPicEx();
labelText.LabelText = row["userName"].ToString();
labelText.Parent = cmodel.ctr;
labelText.Name = "txt_" + row["fieldName"];
myctr = labelText;
labelText.Text = GetDefaultValue(row["defaultValue"] + "");
labelText.TextChanged += new EventHandler(myctr_TextChanged);
labelText.KeyDown += new KeyEventHandler(myctr_KeyDown);
}
else if (fieldTypeId == ControlType.LabPicEx)
{
LabelPicFileEx labelText = new LabelPicFileEx();
labelText.LabelText = row["userName"].ToString();
labelText.Parent = cmodel.ctr;
labelText.Name = "txt_" + row["fieldName"];
myctr = labelText;
labelText.GetPictureBox.Tag = cmodelTag;
labelText.Text = GetDefaultValue(row["defaultValue"] + "");
}
//多选控件
else if ((fieldTypeId == ControlType.LabMultiSelectText) || (fieldTypeId == ControlType.LabMultiSelectValue) ||
fieldTypeId == ControlType.LabMultiSelectValueParam || fieldTypeId == ControlType.LabMultiSelectTextParam)
{
LabelLookUp labelLookup = new LabelLookUp();
labelLookup.LabelText = row["userName"].ToString();
labelLookup.Parent = cmodel.ctr;
labelLookup.Name = "txt_" + row["fieldName"];
string sql = PubClass.ReqSqlParam(row["lookupSql"].ToString(), cmodel.loginid, cmodel.loginname);
sql = sql.Replace("{parent.key}", Space);
labelLookup.SQL = sql;
labelLookup.ValueField = row["lookupKeyField"].ToString();
labelLookup.TextField = row["lookupResult"].ToString();
Dictionary Columns = new Dictionary();
Columns.Add(row["lookupKeyField"].ToString(), "编码");
Columns.Add(row["lookupResult"].ToString(), "名称");
if (labelLookup.SQL.IndexOf("Remark", StringComparison.OrdinalIgnoreCase) != -1)
{
string remarkField = labelLookup.SQL.Substring(labelLookup.SQL.IndexOf("Remark", StringComparison.OrdinalIgnoreCase), 6);
//MessageBox.Show(remarkField);
Columns.Add(remarkField, "备注");
}
labelLookup.Columns = Columns;
labelLookup.IsMultiple = true;
labelLookup.GetButton.Enabled = (edited != "1");
string defaultValue = GetDefaultValue(row["defaultValue"].ToString());
if (fieldTypeId == ControlType.LabMultiSelectText || fieldTypeId == ControlType.LabMultiSelectTextParam)
labelLookup.SetTextValue(defaultValue);
else
labelLookup.SetValueText(defaultValue);
myctr = labelLookup;
labelLookup.GetTextBox.Tag = cmodelTag;
labelLookup.Tag = cmodelTag;
labelLookup.TextChanged += new EventHandler(myctr_TextChanged);
labelLookup.GetTextBox.TextChanged += new EventHandler(myctr_TextChanged);
labelLookup.KeyDown += new KeyEventHandler(myctr_KeyDown);
}
else if (fieldTypeId == ControlType.LabCheckBox)
{
LabelCheckBox labelCheckbox = new LabelCheckBox();
labelCheckbox.Name = "txt_" + row["fieldName"];
labelCheckbox.LabelText = row["userName"].ToString();
string defaultValue = GetDefaultValue(row["defaultValue"].ToString());
labelCheckbox.Text = defaultValue;
labelCheckbox.GetCheckBox.Enabled = (edited != "1");
myctr = labelCheckbox;
labelCheckbox.GetCheckBox.GotFocus += new EventHandler(GotFocus);
labelCheckbox.GetCheckBox.LostFocus += new EventHandler(LostFocus);
}
// 创建Memo控件
else if (fieldTypeId == ControlType.LabMemoEdit)
{
LabelMemoEdit labelMemo = new LabelMemoEdit();
labelMemo.LabelText = row["userName"].ToString();
labelMemo.Location = new Point(Convert.ToInt32(row["ControlLeft"]), Convert.ToInt32(row["controlTop"]));
labelMemo.Parent = cmodel.ctr;
labelMemo.Name = "txt_" + row["fieldName"];
//if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
//{
// labelMemo.getMemoEx.Properties.ReadOnly = true;
//}
myctr = labelMemo;
labelMemo.TextChanged += new EventHandler(myctr_TextChanged);
labelMemo.KeyDown += new KeyEventHandler(myctr_KeyDown);
labelMemo.getMemoEx.GotFocus += new EventHandler(GotFocus);
labelMemo.getMemoEx.LostFocus += new EventHandler(LostFocus);
}
// 计算器
else if (fieldTypeId == ControlType.LabCalcText)
{
string defaultValue = GetDefaultValue(row["defaultValue"].ToString());
decimal value = 0;
Decimal.TryParse(defaultValue, out value);
LabelCalcTextEx labelText = new LabelCalcTextEx();
labelText.LabelText = row["userName"].ToString();
labelText.Name = "txt_" + row["fieldName"];
labelText.GetTextBox.Value = value;
myctr = labelText;
}
else if (fieldTypeId == ControlType.LabPassword)
{
// 创建密码框
string defaultValue = GetDefaultValue(row["defaultValue"].ToString());
LabelPasswordEx labelText = new LabelPasswordEx();
labelText.LabelText = row["userName"].ToString();
labelText.Name = "txt_" + row["fieldName"];
labelText.GetTextBox.Text = defaultValue;
myctr = labelText;
}
//文本
else
{
LabelTextEx labelText = new LabelTextEx();
labelText.LabelText = row["userName"].ToString();
labelText.Name = "txt_" + row["fieldName"];
//labelText.Text = GetDefaultValue(row["defaultValue"].ToString());
if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
labelText.GetTextBox.ReadOnly = true;
myctr = labelText;
myctr.Parent = cmodel.ctr;
myctr.Tag = cmodelTag;
labelText.GetTextBox.Tag = cmodelTag;
//labelText.Text = GetDefaultValue(row["defaultValue"].ToString());
labelText.GetTextBox.TextChanged += new EventHandler(myctr_TextChanged);
labelText.GetTextBox.KeyDown += new KeyEventHandler(myctr_KeyDown);
labelText.GetTextBox.GotFocus += new EventHandler(GotFocus);
labelText.GetTextBox.LostFocus += new EventHandler(LostFocus);
if (row.Table.Columns.Contains("LimitLen"))
labelText.GetTextBox.MaxLength = row["LimitLen"] + "" == "" ? 0 : Convert.ToInt32(row["LimitLen"] + "");
}
if (myctr != null)
{
int ControlLeft = 0;
int ControlTop = 0;
int controlWidth = 0;
int controlHeight = 0;
if (!string.IsNullOrEmpty(row["ControlLeft"] + ""))
ControlLeft = Convert.ToInt32(row["ControlLeft"]);
if (!string.IsNullOrEmpty(row["controlTop"] + ""))
ControlTop = Convert.ToInt32(row["controlTop"]);
if (!string.IsNullOrEmpty(row["controlWidth"] + ""))
controlWidth = Convert.ToInt32(row["controlWidth"]);
if (!string.IsNullOrEmpty(row["controlHeight"] + ""))
controlHeight = Convert.ToInt32(row["controlHeight"]);
if (controlWidth > 0)
myctr.Width = controlWidth;
if (controlHeight > 0)
myctr.Height = controlHeight;
myctr.Location = new Point(ControlLeft, ControlTop);
myctr.Tag = cmodelTag;
myctr.BackColor = Color.Transparent;
myctr.Parent = cmodel.ctr;
int hgt = myctr.Top + myctr.Height;
if (hgt > yHeight)
yHeight = hgt;
if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
{
//myctr.Enabled = false;
if (myctr is LabelTextEx)
{
(myctr as LabelTextEx).GetTextBox.ReadOnly = true;
}
else if (myctr is LabelAutoSearcherEx)
{
(myctr as LabelAutoSearcherEx).GetAutoSearcher.ReadOnly = true;
}
else if (myctr is AutoSearcher)
{
(myctr as AutoSearcher).ReadOnly = true;
}
else if (myctr is LabelMemoEdit)
{
(myctr as LabelMemoEdit).getMemoEx.Properties.ReadOnly = true;
}
else
myctr.Enabled = false;
}
int visible = Convert.ToInt32(row["visible"]);
if (visible == 1)
{
if (fieldTypeId == ControlType.LabDate ||
fieldTypeId == ControlType.LabDateTime ||
fieldTypeId == ControlType.LabDateTimeShort ||
fieldTypeId == ControlType.LabTime ||
fieldTypeId == ControlType.LabShortTime)
{
myctr.ForeColor = Color.White;
}
else
{
myctr.Text = "****";
}
}
// 树结构添加时隐藏
if (fieldTypeId == 3)
{
myctr.Visible = false;
}
//处理自动编号
if (!string.IsNullOrEmpty(row["autoNo"] + ""))
{
int autoNo = Convert.ToInt32(row["autoNo"]);
if (autoNo > 0)
{
myctr.Enabled = false;
}
}
if (Convert.ToBoolean(row["nullable"]))
myctr.ForeColor = Color.Blue;
if (row.Table.Columns.Contains("tabOrder"))
{
myctr.TabIndex = row["tabOrder"] + "" == "" ? 0 : Convert.ToInt32(row["tabOrder"] + "");
//MessageBox.Show(row["fieldName"] + "___" + myctr.TabIndex.ToString());
}
myctr.TextChanged += new EventHandler(myctr_TextChanged);
myctr.BringToFront();
//myctr.KeyDown += new KeyEventHandler(myctr_KeyDown);
}
}
catch (Exception ex)
{
throw new Exception(row["fieldName"] + "" + "配置错误");
}
}
//设置初始值
foreach (DataRow row in dTable.Rows)
{
string fieldName = row["fieldName"] + "";
Control[] ctl = ParentCtr.Controls.Find("txt_" + fieldName, true);
if ((ctl != null) && (ctl.Length > 0))
{
string value = GetDefaultValue(row["defaultvalue"].ToString());
if (!string.IsNullOrEmpty(value) && !value.Contains("{##"))
SetControlText(ctl[0], value);
}
}
yHeight = yHeight + 10;
return yHeight;
}
public int CreateControlByModel(CreateControlModel cmodel, string edited)
{
int yHeight = 0;
DataTable dTable = cmodel.dt;
if (dTable == null && dTable.Rows.Count == 0 && !string.IsNullOrEmpty(cmodel.sql))
dTable = SqlHelper.ExecuteDataSet(cmodel.sql).Tables[0];
this.dtSumRows = dTable.Rows.OfType()
.Where(x => !string.IsNullOrEmpty(x["calcExpr"] + ""))
.ToArray(); // 计算字段
foreach (DataRow row in dTable.Rows)
{
int fieldTypeId = Convert.ToInt32(row["fieldTypeId"]);
bool isSave = dtColumns == null || dtColumns.Contains(row["fieldName"] + "");
ControlModelTag cmodelTag = new ControlModelTag() { IsSave = isSave, IsClear = (edited != "1"), IsEmpt = Convert.ToBoolean(row["nullable"]), fieldTypeId = fieldTypeId, TipMsg = row["userName"] + "" };
cmodelTag.DefaultText = row["defaultValue"] + "";
cmodelTag.DefaultValue = row["defaultValue"] + "";
cmodelTag.unionFields = row["unionFields"] + "";
cmodelTag.unionValue = row["unionValue"] + "";
cmodelTag.fieldName = row["fieldName"] + "";
cmodelTag.DateFormat = "";
if (row.Table.Columns.Contains("dataformat"))
cmodelTag.DateFormat = row["dataformat"] + "";
try
{
Control myctr = null;
//日期
if (fieldTypeId == ControlType.LabDate ||
fieldTypeId == ControlType.LabDateTime ||
fieldTypeId == ControlType.LabDateTimeShort ||
fieldTypeId == ControlType.LabTime ||
fieldTypeId == ControlType.LabShortTime)
{
LabelDateEx labelText = new LabelDateEx();
labelText.LabelText = row["userName"].ToString();
labelText.Name = "txt_" + row["fieldName"];
labelText.FormatType = cmodelTag.DateFormat = DateFormatType.GetFormatValue(fieldTypeId);
labelText.Text = GetDefaultValue(row["defaultValue"].ToString());
if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
labelText.GetDateTimePicker.Enabled = false;
myctr = labelText;
labelText.GetDateTimePicker.ShowUpDown = fieldTypeId == ControlType.LabTime || fieldTypeId == ControlType.LabShortTime ? true : false;
labelText.GetDateTimePicker.Tag = cmodelTag;
labelText.GetDateTimePicker.TextChanged += new EventHandler(myctr_TextChanged);
labelText.GetDateTimePicker.CloseUp += new EventHandler(myctr_CloseUp);
labelText.GetDateTimePicker.KeyDown += new KeyEventHandler(myctr_KeyDown);
labelText.GetDateTimePicker.GotFocus += new EventHandler(GotFocus);
labelText.GetDateTimePicker.LostFocus += new EventHandler(LostFocus);
}
//下拉框
else if (fieldTypeId == ControlType.LabComboxValue
|| fieldTypeId == ControlType.LabComboxText || fieldTypeId == ControlType.LabComboxInputParam)
{
LabelComboxEx labelText = new LabelComboxEx();
labelText.getComboBox.FlatStyle = FlatStyle.Flat;
labelText.LabelText = row["userName"].ToString();
labelText.Name = "txt_" + row["fieldName"];
string lookupSql = PubClass.ReqSqlParam(row["lookupSql"].ToString(), cmodel.loginid, cmodel.loginname);
lookupSql = lookupSql.Replace("{parent.key}", Space);
if (edited == "1")
{
//labelText.getComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
labelText.getComboBox.Enabled = false;
}
if (!string.IsNullOrEmpty(lookupSql))
{
string keyField = row["lookupKeyField"] + "";
string resultField = row["lookupResult"] + "";
labelText.setDataSource(lookupSql, keyField, resultField);
}
if (fieldTypeId == ControlType.LabComboxValue)
{
labelText.getComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
string defaultValue = GetDefaultValue(row["defaultValue"].ToString());
//MessageBox.Show(defaultValue);
if (!string.IsNullOrEmpty(defaultValue))
labelText.getComboBox.SelectedValue = defaultValue;
labelText.getComboBox.SelectedIndexChanged += new EventHandler(myctr_TextChanged);
}
else
{
labelText.Text = GetDefaultValue(row["defaultValue"].ToString());
labelText.getComboBox.TextChanged += new EventHandler(myctr_TextChanged);
}
myctr = labelText;
labelText.getComboBox.Tag = cmodelTag;
labelText.getComboBox.KeyDown += new KeyEventHandler(myctr_KeyDown);
labelText.getComboBox.GotFocus += new EventHandler(GotFocus);
labelText.getComboBox.LostFocus += new EventHandler(LostFocus);
}
//下拉复选框
else if (fieldTypeId == ControlType.LabComboxCheckListValue
|| fieldTypeId == ControlType.LabComboxCheckListText)
{
LabelComboCheckList labelText = new LabelComboCheckList();
//labelText.getComboBox.FlatStyle = FlatStyle.Flat;
labelText.LabelText = row["userName"].ToString();
labelText.Name = "txt_" + row["fieldName"];
string lookupSql = PubClass.ReqSqlParam(row["lookupSql"].ToString(), cmodel.loginid, cmodel.loginname);
lookupSql = lookupSql.Replace("{parent.key}", Space);
if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
{
//labelText.getComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
labelText.getComboBox.Enabled = false;
}
if (!string.IsNullOrEmpty(lookupSql))
{
string keyField = row["lookupKeyField"] + "";
string resultField = row["lookupResult"] + "";
if (fieldTypeId == ControlType.LabComboxCheckListValue)
{
labelText.setDataSource(lookupSql, keyField, resultField);
}
else
{
labelText.setDataSource(lookupSql, resultField, resultField);
}
}
if (fieldTypeId == ControlType.LabComboxCheckListValue)
{
//labelText.getComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
string defaultValue = GetDefaultValue(row["defaultValue"].ToString());
//MessageBox.Show(defaultValue);
if (!string.IsNullOrEmpty(defaultValue))
labelText.getComboBox.SetEditValue(defaultValue);
labelText.getComboBox.Properties.EditValueChanged += new EventHandler(myctr_TextChanged);
}
else
{
string defaultValue = GetDefaultValue(row["defaultValue"].ToString());
if (!string.IsNullOrEmpty(defaultValue))
labelText.getComboBox.SetEditValue(defaultValue);
labelText.getComboBox.TextChanged += new EventHandler(myctr_TextChanged);
}
myctr = labelText;
labelText.getComboBox.Tag = cmodelTag;
labelText.getComboBox.KeyDown += new KeyEventHandler(myctr_KeyDown);
labelText.getComboBox.GotFocus += new EventHandler(GotFocus);
labelText.getComboBox.LostFocus += new EventHandler(LostFocus);
}
//自动搜索
else if (fieldTypeId == ControlType.LabAutoSeacherValue || fieldTypeId == ControlType.LabAutoSeacherText ||
fieldTypeId == ControlType.LabComboxValueParam || fieldTypeId == ControlType.LabComboxTextParam)
{
LabelAutoSearcherEx autSearch = new LabelAutoSearcherEx();
autSearch.LabelText = row["userName"].ToString();
ControlLib.inh.AutoSearcher txtUserName = autSearch.GetAutoSearcher;
ControlLib.inh.SearcherPropertyCollector searcherPropertyCollector1 = new ControlLib.inh.SearcherPropertyCollector();
ControlLib.inh.TFieldPropertyData tFieldPropertyData1 = new ControlLib.inh.TFieldPropertyData();
ControlLib.inh.TFieldPropertyData tFieldPropertyData2 = new ControlLib.inh.TFieldPropertyData();
ControlLib.inh.TFieldPropertyData tFieldPropertyData3 = new ControlLib.inh.TFieldPropertyData();
txtUserName.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Append;
txtUserName.Tag = cmodelTag;
//取下拉列表数据
txtUserName.MaxLength = 50;
txtUserName.Name = "txt_" + row["fieldName"];
txtUserName.searcherPropertyCollector = searcherPropertyCollector1;
txtUserName.TabIndex = 12;
tFieldPropertyData1.FieldCaption = "编码";
tFieldPropertyData1.FieldName = row["lookupKeyField"] + "";
tFieldPropertyData1.FieldWidth = 50;
tFieldPropertyData1.ShowColumn = true;
tFieldPropertyData2.FieldCaption = "名称";
tFieldPropertyData2.FieldName = row["lookupResult"] + "";
tFieldPropertyData2.FieldWidth = 150;
tFieldPropertyData2.ShowColumn = true;
string sql = row["lookupSql"].ToString();
sql = sql.Replace("{parent.key}", Space);
searcherPropertyCollector1.ConvertToChineseSpell = true;
searcherPropertyCollector1.FieldPropertyList = new ControlLib.inh.TFieldPropertyData[] { tFieldPropertyData1, tFieldPropertyData2 };
if (sql.IndexOf("remark", StringComparison.OrdinalIgnoreCase) != -1)
{
searcherPropertyCollector1.RemarkField = "remark";
tFieldPropertyData3.FieldCaption = "备注";
tFieldPropertyData3.FieldName = "remark";
tFieldPropertyData3.FieldWidth = 150;
tFieldPropertyData3.ShowColumn = true;
searcherPropertyCollector1.FieldPropertyList = new ControlLib.inh.TFieldPropertyData[] { tFieldPropertyData1, tFieldPropertyData2, tFieldPropertyData3 };
}
searcherPropertyCollector1.KeyField = row["lookupKeyField"] + "";
searcherPropertyCollector1.QueryField = row["lookupResult"] + "";
searcherPropertyCollector1.QuerySQL = PubClass.ReqSqlParam(sql, cmodel.loginid, cmodel.loginname);
//searcherPropertyCollector1.ReturnMaxCount = 50;
searcherPropertyCollector1.ReturnValueField = row["lookupKeyField"] + "";
searcherPropertyCollector1.SearchMatchWay = ControlLib.inh.TSearchMatchWay.swFuzzy;
searcherPropertyCollector1.ShowFormHeight = 230;
searcherPropertyCollector1.ShowFormWidth = 230;
searcherPropertyCollector1.InitSQL = searcherPropertyCollector1.SQL = PubClass.ReqSqlParam(row["lookupSql"].ToString(), cmodel.loginid, cmodel.loginname);
if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
{
autSearch.GetAutoSearcher.ReadOnly = true;
}
if (fieldTypeId == ControlType.LabAutoSeacherText)
autSearch.GetAutoSearcher.IsClear = false;
try
{
autSearch.GetAutoSearcher.addDllModuleId = row["AddModuleId"].ToString();
autSearch.GetAutoSearcher.addModuleCaption = row["addmodulename"].ToString();
autSearch.GetAutoSearcher.addDllName = row["adddllname"].ToString();
autSearch.GetAutoSearcher.OperatorId = LoginId;
autSearch.GetAutoSearcher.OperatorName = LoginName;
if (row.Table.Columns.Contains("addModuleSpec"))
{
string speciesSql = row["addModuleSpec"] + "";
speciesSql = PubClass.ReqSqlParam(speciesSql, LoginId, LoginName);
speciesSql = PubClass.ReqSql(ParentCtr, speciesSql);
object value = speciesSql;
if (speciesSql.IndexOf('@') != -1)
{
speciesSql = speciesSql.Replace('@', ' ');
value = SqlHelper.ExecuteScalar(CommandType.Text, speciesSql);
}
if (value != null)
autSearch.GetAutoSearcher.SpeciesNo = value.ToString();
}
if (row.Table.Columns.Contains("addModuleResult"))
{
string modResultSql = row["addModuleResult"] + "";
modResultSql = PubClass.ReqSqlParam(modResultSql, LoginId, LoginName);
//modResultSql = PubClass.ReqSql(ParentCtr, modResultSql);
autSearch.GetAutoSearcher.addResultValue = modResultSql;
}
//sql中存在 #
string tempsql = sql.Replace("{#", "");
int lIndex = tempsql.IndexOf("#", StringComparison.OrdinalIgnoreCase);
if (fieldTypeId == ControlType.LabComboxValueParam || fieldTypeId == ControlType.LabComboxTextParam || (lIndex >= 0))
{
autSearch.GetAutoSearcher.SearchControlPanel = cmodel.ctr;
autSearch.GetAutoSearcher.OnTextChangedBefore += new EventHandler(GetAutoSearcher_HandleSQL);
}
}
catch
{
}
myctr = autSearch;
//初始值单独进行
//string value = GetDefaultValue(row["defaultValue"].ToString());
//if (fieldTypeId == ControlType.LabAutoSeacherValue)
// autSearch.GetAutoSearcher.SetValueSilent(value,"");
//else
// autSearch.Text = value;
autSearch.GetAutoSearcher.TextChanged += new EventHandler(myctr_TextChanged);
autSearch.GetAutoSearcher.KeyDown += new KeyEventHandler(myctr_KeyDown);
autSearch.GetAutoSearcher.GotFocus += new EventHandler(GotFocus);
autSearch.GetAutoSearcher.LostFocus += new EventHandler(LostFocus);
}
//创建文本域
else if (fieldTypeId == ControlType.LabRemark)
{
LabelTextarea labelText = new LabelTextarea();
labelText.LabelText = row["userName"].ToString();
labelText.Location = new Point(Convert.ToInt32(row["ControlLeft"]), Convert.ToInt32(row["controlTop"]));
labelText.Parent = cmodel.ctr;
labelText.Name = "txt_" + row["fieldName"];
if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
{
labelText.Enabled = false;
}
myctr = labelText;
labelText.TextChanged += new EventHandler(myctr_TextChanged);
labelText.KeyDown += new KeyEventHandler(myctr_KeyDown);
labelText.getTextBox.GotFocus += new EventHandler(GotFocus);
labelText.getTextBox.LostFocus += new EventHandler(LostFocus);
}
//创建QQ控件
else if (fieldTypeId == ControlType.LabQQ)
{
LabelTextQQEx labelText = new LabelTextQQEx();
labelText.LabelText = row["userName"].ToString();
labelText.Parent = cmodel.ctr;
labelText.Name = "txt_" + row["fieldName"];
myctr = labelText;
labelText.GetTextBox.Tag = cmodelTag;
labelText.Text = GetDefaultValue(row["defaultValue"].ToString());
labelText.GetTextBox.TextChanged += new EventHandler(myctr_TextChanged);
labelText.GetTextBox.KeyDown += new KeyEventHandler(myctr_KeyDown);
labelText.GetTextBox.GotFocus += new EventHandler(GotFocus);
labelText.GetTextBox.LostFocus += new EventHandler(LostFocus);
}
//创建网址控件
else if (fieldTypeId == ControlType.LabWWW)
{
LabelTextWwwEx labelText = new LabelTextWwwEx();
labelText.LabelText = row["userName"].ToString();
labelText.Parent = cmodel.ctr;
labelText.Name = "txt_" + row["fieldName"];
myctr = labelText;
labelText.Text = GetDefaultValue(row["defaultValue"].ToString());
labelText.GetTextBox.TextChanged += new EventHandler(myctr_TextChanged);
labelText.GetTextBox.KeyDown += new KeyEventHandler(myctr_KeyDown);
labelText.GetTextBox.GotFocus += new EventHandler(GotFocus);
labelText.GetTextBox.LostFocus += new EventHandler(LostFocus);
}
else if (fieldTypeId == ControlType.LabPic)
{
LabelPicEx labelText = new LabelPicEx();
labelText.LabelText = row["userName"].ToString();
labelText.Parent = cmodel.ctr;
labelText.Name = "txt_" + row["fieldName"];
myctr = labelText;
labelText.Text = GetDefaultValue(row["defaultValue"].ToString());
labelText.TextChanged += new EventHandler(myctr_TextChanged);
labelText.KeyDown += new KeyEventHandler(myctr_KeyDown);
}
else if (fieldTypeId == ControlType.LabPicEx)
{
LabelPicFileEx labelText = new LabelPicFileEx();
labelText.LabelText = row["userName"].ToString();
labelText.Parent = cmodel.ctr;
labelText.Name = "txt_" + row["fieldName"];
myctr = labelText;
labelText.GetPictureBox.Tag = cmodelTag;
labelText.Text = GetDefaultValue(row["defaultValue"] + "");
}
//多选控件
else if ((fieldTypeId == ControlType.LabMultiSelectText) || (fieldTypeId == ControlType.LabMultiSelectValue) ||
fieldTypeId == ControlType.LabMultiSelectValueParam || fieldTypeId == ControlType.LabMultiSelectTextParam)
{
LabelLookUp labelLookup = new LabelLookUp();
labelLookup.LabelText = row["userName"].ToString();
labelLookup.Parent = cmodel.ctr;
labelLookup.Name = "txt_" + row["fieldName"];
string sql = PubClass.ReqSqlParam(row["lookupSql"].ToString(), cmodel.loginid, cmodel.loginname);
sql = sql.Replace("{parent.key}", Space);
labelLookup.SQL = sql;
labelLookup.ValueField = row["lookupKeyField"].ToString();
labelLookup.TextField = row["lookupResult"].ToString();
Dictionary Columns = new Dictionary();
Columns.Add(row["lookupKeyField"].ToString(), "编码");
Columns.Add(row["lookupResult"].ToString(), "名称");
if (labelLookup.SQL.IndexOf("Remark", StringComparison.OrdinalIgnoreCase) != -1)
{
string remarkField = labelLookup.SQL.Substring(labelLookup.SQL.IndexOf("Remark", StringComparison.OrdinalIgnoreCase), 6);
//MessageBox.Show(remarkField);
Columns.Add(remarkField, "备注");
}
labelLookup.Columns = Columns;
labelLookup.IsMultiple = true;
labelLookup.GetButton.Enabled = (edited != "1");
string defaultValue = GetDefaultValue(row["defaultValue"].ToString());
if (fieldTypeId == ControlType.LabMultiSelectText)
labelLookup.SetTextValue(defaultValue);
else
labelLookup.SetValueText(defaultValue);
myctr = labelLookup;
labelLookup.GetTextBox.Tag = cmodelTag;
labelLookup.Tag = cmodelTag;
labelLookup.TextChanged += new EventHandler(myctr_TextChanged);
labelLookup.GetTextBox.TextChanged += new EventHandler(myctr_TextChanged);
labelLookup.KeyDown += new KeyEventHandler(myctr_KeyDown);
}
else if (fieldTypeId == ControlType.LabCheckBox)
{
LabelCheckBox labelCheckbox = new LabelCheckBox();
labelCheckbox.Name = "txt_" + row["fieldName"];
labelCheckbox.LabelText = row["userName"].ToString();
string defaultValue = GetDefaultValue(row["defaultValue"].ToString());
labelCheckbox.Text = defaultValue;
labelCheckbox.GetCheckBox.Enabled = (edited != "1");
myctr = labelCheckbox;
labelCheckbox.GetCheckBox.GotFocus += new EventHandler(GotFocus);
labelCheckbox.GetCheckBox.LostFocus += new EventHandler(LostFocus);
}
// 创建Memo控件
else if (fieldTypeId == ControlType.LabMemoEdit)
{
LabelMemoEdit labelMemo = new LabelMemoEdit();
labelMemo.LabelText = row["userName"].ToString();
labelMemo.Location = new Point(Convert.ToInt32(row["ControlLeft"]), Convert.ToInt32(row["controlTop"]));
labelMemo.Parent = cmodel.ctr;
labelMemo.Name = "txt_" + row["fieldName"];
//if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
//{
// labelMemo.getMemoEx.Properties.ReadOnly = true;
//}
myctr = labelMemo;
labelMemo.TextChanged += new EventHandler(myctr_TextChanged);
labelMemo.KeyDown += new KeyEventHandler(myctr_KeyDown);
labelMemo.getMemoEx.GotFocus += new EventHandler(GotFocus);
labelMemo.getMemoEx.LostFocus += new EventHandler(LostFocus);
}
// 计算器
else if (fieldTypeId == ControlType.LabCalcText)
{
string defaultValue = GetDefaultValue(row["defaultValue"].ToString());
decimal value = 0;
Decimal.TryParse(defaultValue, out value);
LabelCalcTextEx labelText = new LabelCalcTextEx();
labelText.LabelText = row["userName"].ToString();
labelText.Name = "txt_" + row["fieldName"];
labelText.GetTextBox.Properties.DisplayFormat.FormatString = row["DataFormat"] + "";
labelText.GetTextBox.Properties.DisplayFormat.FormatType = FormatType.Numeric;
labelText.GetTextBox.Value = value;
myctr = labelText;
}
else if (fieldTypeId == ControlType.LabPassword)
{
// 创建密码框
string defaultValue = GetDefaultValue(row["defaultValue"].ToString());
LabelPasswordEx labelText = new LabelPasswordEx();
labelText.LabelText = row["userName"].ToString();
labelText.Name = "txt_" + row["fieldName"];
labelText.GetTextBox.Text = defaultValue;
myctr = labelText;
}
//文本
else
{
LabelTextEx labelText = new LabelTextEx();
labelText.LabelText = row["userName"].ToString();
labelText.Name = "txt_" + row["fieldName"];
//labelText.Text = GetDefaultValue(row["defaultValue"].ToString());
if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
labelText.GetTextBox.ReadOnly = true;
myctr = labelText;
myctr.Parent = cmodel.ctr;
myctr.Tag = cmodelTag;
labelText.GetTextBox.Tag = cmodelTag;
//labelText.Text = GetDefaultValue(row["defaultValue"].ToString());
labelText.GetTextBox.TextChanged += new EventHandler(myctr_TextChanged);
labelText.GetTextBox.KeyDown += new KeyEventHandler(myctr_KeyDown);
labelText.GetTextBox.GotFocus += new EventHandler(GotFocus);
labelText.GetTextBox.LostFocus += new EventHandler(LostFocus);
if (row.Table.Columns.Contains("LimitLen"))
labelText.GetTextBox.MaxLength = row["LimitLen"] + "" == "" ? 0 : Convert.ToInt32(row["LimitLen"] + "");
}
if (myctr != null)
{
int ControlLeft = 0;
int ControlTop = 0;
int controlWidth = 0;
int controlHeight = 0;
if (!string.IsNullOrEmpty(row["ControlLeft"] + ""))
ControlLeft = Convert.ToInt32(row["ControlLeft"]);
if (!string.IsNullOrEmpty(row["controlTop"] + ""))
ControlTop = Convert.ToInt32(row["controlTop"]);
if (!string.IsNullOrEmpty(row["controlWidth"] + ""))
controlWidth = Convert.ToInt32(row["controlWidth"]);
if (!string.IsNullOrEmpty(row["controlHeight"] + ""))
controlHeight = Convert.ToInt32(row["controlHeight"]);
if (controlWidth > 0)
myctr.Width = controlWidth;
if (controlHeight > 0)
myctr.Height = controlHeight;
myctr.Location = new Point(ControlLeft, ControlTop);
myctr.Tag = cmodelTag;
myctr.BackColor = Color.Transparent;
myctr.Parent = cmodel.ctr;
int hgt = myctr.Top + myctr.Height;
if (hgt > yHeight)
yHeight = hgt;
if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
{
//myctr.Enabled = false;
if (myctr is LabelTextEx)
{
(myctr as LabelTextEx).GetTextBox.ReadOnly = true;
}
else if (myctr is LabelAutoSearcherEx)
{
(myctr as LabelAutoSearcherEx).GetAutoSearcher.ReadOnly = true;
}
else if (myctr is AutoSearcher)
{
(myctr as AutoSearcher).ReadOnly = true;
}
else if (myctr is LabelMemoEdit)
{
(myctr as LabelMemoEdit).getMemoEx.Properties.ReadOnly = true;
}
else
myctr.Enabled = false;
}
int visible = Convert.ToInt32(row["visible"]);
if (visible == 1)
{
if (fieldTypeId == ControlType.LabDate ||
fieldTypeId == ControlType.LabDateTime ||
fieldTypeId == ControlType.LabDateTimeShort ||
fieldTypeId == ControlType.LabTime ||
fieldTypeId == ControlType.LabShortTime)
{
myctr.ForeColor = Color.White;
}
else
{
myctr.Text = "****";
}
}
// 树结构添加时隐藏
if (fieldTypeId == 3)
{
myctr.Visible = false;
}
//处理自动编号
if (!string.IsNullOrEmpty(row["autoNo"] + ""))
{
int autoNo = Convert.ToInt32(row["autoNo"]);
if (autoNo > 0)
{
myctr.Enabled = false;
}
}
if (Convert.ToBoolean(row["nullable"]))
myctr.ForeColor = Color.Blue;
if (row.Table.Columns.Contains("tabOrder"))
{
myctr.TabIndex = row["tabOrder"] + "" == "" ? 0 : Convert.ToInt32(row["tabOrder"] + "");
//MessageBox.Show(row["fieldName"] + "___" + myctr.TabIndex.ToString());
}
myctr.TextChanged += new EventHandler(myctr_TextChanged);
myctr.BringToFront();
//myctr.KeyDown += new KeyEventHandler(myctr_KeyDown);
}
}
catch (Exception ex)
{
throw new Exception(row["fieldName"] + "" + "配置错误");
}
}
//设置初始值
foreach (DataRow row in dTable.Rows)
{
string fieldName = row["fieldName"] + "";
Control[] ctl = ParentCtr.Controls.Find("txt_" + fieldName, true);
if ((ctl != null) && (ctl.Length > 0))
{
string value = GetDefaultValue(row["defaultvalue"].ToString());
if (!string.IsNullOrEmpty(value) && !value.Contains("{##"))
SetControlText(ctl[0], value);
}
}
yHeight = yHeight + 10;
return yHeight;
}
public void GotFocus(object obj, EventArgs e)
{
(obj as Control).BackColor = Color.SpringGreen;
if (obj is DateTimePicker)
{
(obj as DateTimePicker).Parent.Parent.BackColor = Color.SpringGreen;
}
}
public void LostFocus(object obj, EventArgs e)
{
if (obj is TextBox)
{
if ((obj as TextBox).ReadOnly)
(obj as Control).BackColor = SystemColors.InactiveBorder;
else
(obj as Control).BackColor = Color.White;
}
else if (obj is TextBoxEx)
{
if ((obj as TextBoxEx).ReadOnly)
(obj as Control).BackColor = SystemColors.InactiveBorder;
else
(obj as Control).BackColor = Color.White;
}
else if (obj is AutoSearcher)
{
if ((obj as AutoSearcher).ReadOnly)
(obj as Control).BackColor = SystemColors.InactiveBorder;
else
(obj as Control).BackColor = Color.White;
}
else if (obj is DateTimePicker)
{
(obj as DateTimePicker).Parent.Parent.BackColor = Color.Transparent;
}
else if (obj is CheckEdit)
{
(obj as CheckEdit).BackColor = Color.Transparent;
}
else
(obj as Control).BackColor = Color.White;
}
private void GetAutoSearcher_HandleSQL(object sender, EventArgs e)
{
if (sender is AutoSearcher)
{
AutoSearcher search = sender as AutoSearcher;
if (search.SearchControlPanel == null)
return;
var ctrs = search.SearchControlPanel.Controls;
//MessageBox.Show(search.SearchControlPanel.Name);
var sql = search.searcherPropertyCollector.InitSQL;
sql = sql.Replace("#", "").Replace("#", "");
var fields = PubClass.GetParamValue(sql);
if (fields != null && fields.Count > 0)
{
for (int i = 0; i < fields.Count; i++)
{
string field = fields[i];
string fieldName = field.Replace("{", "").Replace("}", "");
Control[] ctr = ctrs.Find("txt_" + fieldName, true);
if ((ctr == null) || (ctr.Length < 1))
continue;
Control control = ctr[0];
//Control control = ctrs.OfType().FirstOrDefault(x => (x.Tag as ControlModelTag).fieldName == fieldName);
if (control is LabelAutoSearcherEx) control = (control as LabelAutoSearcherEx).GetAutoSearcher;
string fieldValue = GetControlText(control);
sql = sql.Replace(field, fieldValue);
}
//search.searcherPropertyCollector.SQL = search.searcherPropertyCollector.QuerySQL = sql;
}
search.searcherPropertyCollector.SQL = search.searcherPropertyCollector.QuerySQL = sql;
}
}
///
/// 加载lable控件
///
///
///
///
///
///
public int CreateControlByModel2(CreateControlModel2 cmodel)
{
int xPos = cmodel.StartX;
int yPos = cmodel.StartY;
int yPos1 = cmodel.StartY;
Control ctr = cmodel.ctr;
int MaxHeight = 0;
for (int i = 0; i < cmodel.dt.Rows.Count; i++)
{
if (i % cmodel.ctrNum == 0)
{
if (i == 0)
ctr = cmodel.ctr;
else
{
int result = i / cmodel.ctrNum;
switch (result)
{
case 1:
ctr = cmodel.ctr1;
yPos = cmodel.StartY;
break;
case 2:
ctr = cmodel.ctr2;
yPos = cmodel.StartY;
break;
case 3:
ctr = cmodel.ctr3;
yPos = cmodel.StartY;
break;
}
}
}
DataRow row = cmodel.dt.Rows[i];
DataColumnCollection dcc = cmodel.dt.Columns;
int fieldTypeId = Convert.ToInt32(row["fieldTypeId"]);
ControlModelTag cmodelTag = new ControlModelTag() { IsSave = true, IsClear = (row["edited"] + "" != "1"), IsEmpt = Convert.ToBoolean(row["nullable"]), fieldTypeId = fieldTypeId, TipMsg = row["userName"] + "", DefaultValue = row["DefaultValue"] + "" };
Control myctr = null;
//日期
if (fieldTypeId == ControlType.LabDate ||
fieldTypeId == ControlType.LabDateTime ||
fieldTypeId == ControlType.LabDateTimeShort ||
fieldTypeId == ControlType.LabTime ||
fieldTypeId == ControlType.LabShortTime)
{
int visible = Convert.ToInt32(row["visible"]);
if (visible == 1)
{
LabelTextEx labelText = new LabelTextEx();
labelText.LabelText = row["userName"].ToString();
labelText.Name = "txt_" + row["fieldName"];
labelText.Text = GetDefaultValue(row["defaultValue"].ToString());
string edited = row["edited"] + "";
if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
labelText.GetTextBox.ReadOnly = true;
myctr = labelText;
}
else
{
LabelDateEx labelText = new LabelDateEx();
labelText.LabelText = row["userName"].ToString();
labelText.Name = "txt_" + row["fieldName"];
labelText.FormatType = cmodelTag.DateFormat = DateFormatType.GetFormatValue(fieldTypeId);
labelText.Text = GetDefaultValue(row["defaultValue"].ToString());
string edited = row["edited"] + "";
if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
labelText.GetDateTimePicker.Enabled = false;
myctr = labelText;
}
}
//文本
else if (fieldTypeId == ControlType.LabText)
{
LabelTextEx labelText = new LabelTextEx();
labelText.LabelText = row["userName"].ToString();
labelText.Name = "txt_" + row["fieldName"];
labelText.Text = GetDefaultValue(row["defaultValue"].ToString());
string edited = row["edited"] + "";
if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
labelText.GetTextBox.ReadOnly = true;
myctr = labelText;
}
// 计算器
else if (fieldTypeId == ControlType.LabCalcText)
{
string defaultValue = GetDefaultValue(row["defaultValue"].ToString());
decimal value = 0;
Decimal.TryParse(defaultValue, out value);
LabelCalcTextEx labelText = new LabelCalcTextEx();
labelText.LabelText = row["userName"].ToString();
labelText.Name = "txt_" + row["fieldName"];
labelText.GetTextBox.Value = value;
string edited = row["edited"] + "";
if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
labelText.GetTextBox.Enabled = false;
myctr = labelText;
}
//下拉框
else if (fieldTypeId == ControlType.LabComboxValue || fieldTypeId == ControlType.LabComboxText || fieldTypeId == ControlType.LabComboxInputParam)
{
LabelComboxEx labelText = new LabelComboxEx();
if (fieldTypeId == ControlType.LabComboxValue)
labelText.getComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
labelText.LabelText = row["userName"].ToString();
labelText.Name = "txt_" + row["fieldName"];
string lookupSql = PubClass.ReqSqlParam(row["lookupSql"].ToString(), cmodel.loginid, cmodel.loginname);
string edited = row["edited"] + "";
if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
{
labelText.getComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
labelText.getComboBox.Enabled = false;
}
if (!string.IsNullOrEmpty(lookupSql))
{
string keyField = row["lookupKeyField"] + "";
string resultField = row["lookupResult"] + "";
labelText.setDataSource(lookupSql, keyField, resultField);
}
myctr = labelText;
}
//下拉复选框
else if (fieldTypeId == ControlType.LabComboxCheckListValue || fieldTypeId == ControlType.LabComboxCheckListText)
{
LabelComboCheckList labelText = new LabelComboCheckList();
//if (fieldTypeId == ControlType.LabComboxCheckListValue)
// labelText.getComboBox.Properties.st = System.Windows.Forms.ComboBoxStyle.DropDownList;
labelText.LabelText = row["userName"].ToString();
labelText.Name = "txt_" + row["fieldName"];
string lookupSql = PubClass.ReqSqlParam(row["lookupSql"].ToString(), cmodel.loginid, cmodel.loginname);
string edited = row["edited"] + "";
if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
{
//labelText.getComboBox.Properties.drop = ComboBoxStyle.DropDownList;
labelText.getComboBox.Enabled = false;
}
if (!string.IsNullOrEmpty(lookupSql))
{
string keyField = row["lookupKeyField"] + "";
string resultField = row["lookupResult"] + "";
if (fieldTypeId == ControlType.LabComboxCheckListValue)
{
labelText.setDataSource(lookupSql, keyField, resultField);
}
else
{
labelText.setDataSource(lookupSql, resultField, resultField);
}
}
myctr = labelText;
}
//自动搜索
else if (fieldTypeId == ControlType.LabAutoSeacherValue || fieldTypeId == ControlType.LabAutoSeacherText)
{
LabelAutoSearcherEx autSearch = new LabelAutoSearcherEx();
autSearch.LabelText = row["userName"].ToString();
ControlLib.inh.AutoSearcher txtUserName = autSearch.GetAutoSearcher;
ControlLib.inh.SearcherPropertyCollector searcherPropertyCollector1 = new ControlLib.inh.SearcherPropertyCollector();
ControlLib.inh.TFieldPropertyData tFieldPropertyData1 = new ControlLib.inh.TFieldPropertyData();
ControlLib.inh.TFieldPropertyData tFieldPropertyData2 = new ControlLib.inh.TFieldPropertyData();
ControlLib.inh.TFieldPropertyData tFieldPropertyData3 = new ControlLib.inh.TFieldPropertyData();
txtUserName.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Append;
txtUserName.Tag = cmodelTag;
//取下拉列表数据
txtUserName.MaxLength = 50;
txtUserName.Name = "txt_" + row["fieldName"];
txtUserName.searcherPropertyCollector = searcherPropertyCollector1;
txtUserName.TabIndex = 12;
tFieldPropertyData1.FieldCaption = "编码";
tFieldPropertyData1.FieldName = row["lookupKeyField"] + "";
tFieldPropertyData1.FieldWidth = 50;
tFieldPropertyData1.ShowColumn = true;
tFieldPropertyData2.FieldCaption = "名称";
tFieldPropertyData2.FieldName = row["lookupResult"] + "";
tFieldPropertyData2.FieldWidth = 150;
tFieldPropertyData2.ShowColumn = true;
string sql = row["lookupSql"].ToString();
searcherPropertyCollector1.ConvertToChineseSpell = true;
searcherPropertyCollector1.FieldPropertyList = new ControlLib.inh.TFieldPropertyData[] { tFieldPropertyData1, tFieldPropertyData2 };
if (sql.IndexOf("remark", StringComparison.OrdinalIgnoreCase) != -1)
{
searcherPropertyCollector1.RemarkField = "remark";
tFieldPropertyData3.FieldCaption = "备注";
tFieldPropertyData3.FieldName = "remark";
tFieldPropertyData3.FieldWidth = 150;
tFieldPropertyData3.ShowColumn = true;
searcherPropertyCollector1.FieldPropertyList = new ControlLib.inh.TFieldPropertyData[] { tFieldPropertyData1, tFieldPropertyData2, tFieldPropertyData3 };
}
searcherPropertyCollector1.KeyField = row["lookupKeyField"] + "";
searcherPropertyCollector1.QueryField = row["lookupResult"] + "";
searcherPropertyCollector1.QuerySQL = PubClass.ReqSqlParam(row["lookupSql"].ToString(), cmodel.loginid, cmodel.loginname);
//searcherPropertyCollector1.ReturnMaxCount = 50;
searcherPropertyCollector1.ReturnValueField = row["lookupKeyField"] + "";
searcherPropertyCollector1.SearchMatchWay = ControlLib.inh.TSearchMatchWay.swFuzzy;
searcherPropertyCollector1.ShowFormHeight = 230;
searcherPropertyCollector1.ShowFormWidth = 230;
searcherPropertyCollector1.SQL = PubClass.ReqSqlParam(row["lookupSql"].ToString(), cmodel.loginid, cmodel.loginname);
string edited = row["edited"] + "";
if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
{
autSearch.GetAutoSearcher.ReadOnly = true;
}
myctr = autSearch;
}
//创建文本域
else if (fieldTypeId == ControlType.LabRemark)
{
LabelTextarea labelText = new LabelTextarea();
labelText.LabelText = row["userName"].ToString();
labelText.Location = new Point(Convert.ToInt32(row["ControlLeft"]), Convert.ToInt32(row["controlTop"]));
labelText.Name = "txt_" + row["fieldName"];
string edited = row["edited"] + "";
if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
labelText.Enabled = false;
myctr = labelText;
}
//创建QQ控件
else if (fieldTypeId == ControlType.LabQQ)
{
LabelTextQQEx labelText = new LabelTextQQEx();
labelText.LabelText = row["userName"].ToString();
labelText.Name = "txt_" + row["fieldName"];
myctr = labelText;
}
//创建网址控件
else if (fieldTypeId == ControlType.LabWWW)
{
LabelTextWwwEx labelText = new LabelTextWwwEx();
labelText.LabelText = row["userName"].ToString();
labelText.Name = "txt_" + row["fieldName"];
myctr = labelText;
}
else if (fieldTypeId == ControlType.LabCheckBox)
{
LabelCheckBox labelCheckbox = new LabelCheckBox();
labelCheckbox.Name = "txt_" + row["fieldName"];
labelCheckbox.LabelText = row["userName"].ToString();
string defaultValue = GetDefaultValue(row["defaultValue"].ToString());
labelCheckbox.Text = defaultValue;
string edited = row["edited"] + "";
labelCheckbox.GetCheckBox.Enabled = (edited != "1");
myctr = labelCheckbox;
labelCheckbox.GetCheckBox.GotFocus += new EventHandler(GotFocus);
labelCheckbox.GetCheckBox.LostFocus += new EventHandler(LostFocus);
}
//文本
else
{
LabelTextEx labelText = new LabelTextEx();
labelText.LabelText = row["userName"].ToString();
labelText.Name = "txt_" + row["fieldName"];
//labelText.Text = GetDefaultValue(row["defaultValue"].ToString());
string edited = row["edited"] + "";
if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
labelText.GetTextBox.ReadOnly = true;
myctr = labelText;
myctr.Parent = cmodel.ctr;
myctr.Tag = cmodelTag;
labelText.GetTextBox.Tag = cmodelTag;
//labelText.Text = GetDefaultValue(row["defaultValue"].ToString());
labelText.GetTextBox.TextChanged += new EventHandler(myctr_TextChanged);
labelText.GetTextBox.KeyDown += new KeyEventHandler(myctr_KeyDown);
}
if (myctr != null)
{
myctr.Location = new Point(xPos, yPos);
myctr.Tag = cmodelTag;
myctr.Parent = ctr;
if (!string.IsNullOrEmpty(row["controlWidth"] + ""))
myctr.Width = Convert.ToInt32(row["controlWidth"] + "");
int hgt = myctr.Top + myctr.Height;
string edited = row["edited"] + "";
if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
myctr.Enabled = false;
if (cmodel.isView == 1)
{
myctr.Enabled = false;
if (myctr is LabelTextQQEx)
{
myctr.Enabled = true;
LabelTextQQEx qq = myctr as LabelTextQQEx;
qq.Enabled = true;
qq.GetTextBox.Enabled = false;
}
if (myctr is LabelTextWwwEx)
{
myctr.Enabled = true;
LabelTextWwwEx www = myctr as LabelTextWwwEx;
www.Enabled = true;
www.GetTextBox.Enabled = false;
}
}
int visible = Convert.ToInt32(row["visible"]);
if (visible == 1)
myctr.Text = "****";
myctr.Text = GetDefaultValue(row["defaultValue"].ToString());
//处理自动编号
if (!string.IsNullOrEmpty(row["autoNo"] + ""))
{
int autoNo = Convert.ToInt32(row["autoNo"]);
if (autoNo > 0)
{
myctr.Enabled = false;
}
}
}
yPos += 28;
if (yPos > MaxHeight)
MaxHeight = yPos;
}
return MaxHeight;
}
///
/// 保存表单
///
///
public int SaveOrUpdateForm(MyControlText mctext, bool IsSaveOrUpdate, ref string msgs)
{
int result = 0;
try
{
int saveType = 1;
if (!IsSaveOrUpdate)
saveType = 2;
if (saveType == 1)
{
Control[] ctr_key = mctext.ctr.Controls.Find("txt_" + mctext.KeyFieldName, true);
if ((ctr_key != null) && (ctr_key.Length > 0))
{
ControlModelTag cmTag = ctr_key[0].Tag as ControlModelTag;
ctr_key[0].Text = GetDefaultValue(cmTag.DefaultValue);
}
}
List fieldList = new List();
DataTable dt = new DataTable();
if (mctext.dt != null && mctext.dt.Rows.Count > 0)
dt = mctext.dt;
else
dt = SqlHelper.ExecuteDataSet(mctext.sql).Tables[0];
string colums = string.Empty;
//获得自增长列
string Autogrowcolumn = SqlHelper.ExecuteScalar(string.Format("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME='{0}' AND COLUMNPROPERTY(OBJECT_ID('{0}'),COLUMN_NAME,'IsIdentity')=1", mctext.TableName)) + "";
foreach (DataRow row in dt.Rows)
{
if (Autogrowcolumn.ToLower() == row["fieldName"].ToString().ToLower()) continue;
string fieldName = "txt_" + row["fieldName"].ToString();
Control[] ctr = mctext.ctr.Controls.Find(fieldName, true);
FieldModel m = new FieldModel();
if (ctr.Length > 0)
{
Control c = ctr[0];
ControlModelTag cmTag = c.Tag as ControlModelTag;
if (cmTag != null)
{
//判断控件是否必填
if (cmTag.IsEmpt)
{
if (string.IsNullOrEmpty(c.Text))
{
XtraMessageBox.Show(cmTag.TipMsg + "不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
c.Focus();
c.Select();
return 0;
}
if ((c.Text).Trim() == "")
{
XtraMessageBox.Show(cmTag.TipMsg + "不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
c.Focus();
c.Select();
return 0;
}
}
//字段不保存
if (!cmTag.IsSave)
continue;
//自动搜索条件
if (cmTag.fieldTypeId == ControlType.LabAutoSeacherText)
{
m.FiledName = c.Name.Replace("txt_", "");
m.DataType = FieldType.VarChar;
m.FiledValue = c.Text;
}
else if (cmTag.fieldTypeId == ControlType.LabAutoSeacherValue || cmTag.fieldTypeId == ControlType.LabComboxValueParam)
{
AutoSearcher te = c as AutoSearcher;
m.FiledName = c.Name.Replace("txt_", "");
m.DataType = FieldType.VarChar;
m.FiledValue = te.ReturnValue.ToString();
}
else if (cmTag.fieldTypeId == ControlType.LabComboxValue)
{
LabelComboxEx Cb = c as LabelComboxEx;
m.FiledName = c.Name.Replace("txt_", "");
m.DataType = FieldType.VarChar;
m.FiledValue = Cb.getComboBox.SelectedValue + "";
}
else if ((cmTag.fieldTypeId == ControlType.LabComboxCheckListValue) || (cmTag.fieldTypeId == ControlType.LabComboxCheckListText))
{
LabelComboCheckList Cb = c as LabelComboCheckList;
m.FiledName = c.Name.Replace("txt_", "");
m.DataType = FieldType.VarChar;
string retValue = Cb.getComboBox.EditValue + "";
retValue = retValue.Replace(", ", ",");
m.FiledValue = retValue;
}
else if (cmTag.fieldTypeId == ControlType.LabMultiSelectValue || cmTag.fieldTypeId == ControlType.LabMultiSelectValueParam)
{
LabelLookUp Cb = c as LabelLookUp;
m.FiledName = c.Name.Replace("txt_", "");
m.DataType = FieldType.VarChar;
m.FiledValue = Cb.ReturnValue + "";
}
else if (cmTag.fieldTypeId == ControlType.LabComboxText)
{
LabelComboxEx Cb = c as LabelComboxEx;
m.FiledName = c.Name.Replace("txt_", "");
m.DataType = FieldType.VarChar;
m.FiledValue = Cb.getComboBox.Text;
}
else if (cmTag.fieldTypeId == ControlType.LabDate ||
cmTag.fieldTypeId == ControlType.LabDateTime ||
cmTag.fieldTypeId == ControlType.LabDateTimeShort ||
cmTag.fieldTypeId == ControlType.LabTime ||
cmTag.fieldTypeId == ControlType.LabShortTime)
{
LabelDateEx Cb = c as LabelDateEx;
m.FiledName = c.Name.Replace("txt_", "");
m.DataType = FieldType.VarChar;
m.FiledValue = Cb.GetDateTimePicker.Value.ToString("yyyy-MM-dd HH:mm:ss");
if (string.IsNullOrEmpty(Cb.GetDateTimePicker.CustomFormat.Trim()))
m.FiledValue = "null";
}
else
{
if (cmTag.fieldTypeId != 99 || cmTag.fieldTypeId != 100)
{
if ((cmTag.fieldTypeId == ControlType.LabTextInt) && (c.Text != "****"))
{
if (string.IsNullOrEmpty(c.Text))
c.Text = "0";
double rtDouble = 0.00;
bool convSucc = Double.TryParse(c.Text, out rtDouble);
if (convSucc == false)
{
MessageBox.Show(cmTag.TipMsg + " 未填写正确的数字");
return 0;
}
}
m.FiledName = c.Name.Replace("txt_", "");
m.DataType = FieldType.VarChar;
m.FiledValue = c.Text;
}
}
if (mctext.IsAdd)
{
//处理自动编号
if (Convert.ToInt32(row["autoNo"]) == 1)
{
m.FiledValue = GetDefaultValue(row["defaultValue"] + "");
}
}
colums += m.FiledName + ",";
if (c.Text != "****" && cmTag.fieldTypeId != ControlType.LabPic)
{
fieldList.Add(m);
}
}
else
{
if (c != null)
{
if (c.Tag + "" == "888")
{
m.FiledName = c.Name.Replace("txt_", "");
m.DataType = FieldType.VarChar;
m.FiledValue = c.Text;
fieldList.Add(m);
}
}
}
}
}
Control[] ctr_SpeciesNo = mctext.ctr.Controls.Find("txt_SpeciesNo", true);
if (SpeciesField == "")
SpeciesField = "SpeciesNo";
if (ctr_SpeciesNo.Length > 0)
{
if (colums.IndexOf(SpeciesField + ",", StringComparison.OrdinalIgnoreCase) == -1)
{
FieldModel m = new FieldModel();
m.FiledName = SpeciesField;//ctr_SpeciesNo[0].Name.Replace("txt_", "");
m.DataType = FieldType.VarChar;
m.FiledValue = ctr_SpeciesNo[0].Text;
fieldList.Add(m);
}
}
Control[] ctr_OperatorName = mctext.ctr.Controls.Find("txt_OperatorName", true);
if (ctr_OperatorName.Length > 0)
{
if (colums.IndexOf("OperatorName,", StringComparison.OrdinalIgnoreCase) == -1)
{
FieldModel m = new FieldModel();
m.FiledName = ctr_OperatorName[0].Name.Replace("txt_", "");
m.DataType = FieldType.VarChar;
m.FiledValue = ctr_OperatorName[0].Text;
fieldList.Add(m);
}
}
Control[] ctr_Remark = mctext.ctr.Controls.Find("txt_Remark", true);
if (ctr_Remark.Length > 0)
{
if (colums.IndexOf("Remark,", StringComparison.OrdinalIgnoreCase) == -1)
{
FieldModel m = new FieldModel();
m.FiledName = ctr_Remark[0].Name.Replace("txt_", "");
m.DataType = FieldType.VarChar;
m.FiledValue = ctr_Remark[0].Text;
fieldList.Add(m);
}
}
//modified by dl 2015-1-9 晚20:40
//if (IsSaveOrUpdate) {
// result = SqlHelper.Add(mctext.TableName, fieldList);
//}
//else {
// result = SqlHelper.Update(mctext.TableName, fieldList, mctext.where);
//}
//added by dl 2015-1-9 晚20:40
string filed = string.Empty;
string value = string.Empty;
string strSql = string.Empty;
if (IsSaveOrUpdate)
{
foreach (FieldModel m in fieldList)
{
filed += m.FiledName + ",";
if (m.FiledValue == "null")
value += m.FiledValue + ",";
else
value += "'" + m.FiledValue.Replace("'", "''") + "',";
}
filed = filed.Trim(',');
value = value.Trim(',');
strSql = string.Format("insert into {0}({1}) values ({2})",
mctext.TableName, filed.Replace("@", ""),
value);
}
else
{
foreach (FieldModel m in fieldList)
{
if (m.FiledValue == "null")
filed += m.FiledName + "=" + m.FiledValue + ",";
else
filed += m.FiledName + "='" + m.FiledValue.Replace("'", "''") + "',";
}
filed = filed.Trim(',');
strSql = string.Format("update {0} set {1} where {2}",
mctext.TableName, filed,
mctext.where);
}
SqlParameter pMsg = new SqlParameter("@msg", SqlDbType.VarChar, 2000);
pMsg.Direction = ParameterDirection.Output;
SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int, 4);
returnValue.Direction = ParameterDirection.ReturnValue;
SqlParameter[] param =
{
new SqlParameter("@baseSql",SqlDbType.VarChar,5000),
new SqlParameter("@saveType",SqlDbType.Int),
new SqlParameter("@modid",SqlDbType.VarChar,20),
new SqlParameter("@tablename",SqlDbType.VarChar,50),
new SqlParameter("@keyfield",SqlDbType.VarChar,50),
new SqlParameter("@keyvalue",SqlDbType.VarChar,50),
new SqlParameter("@Operatorid",SqlDbType.Int),
new SqlParameter("@operatorname",SqlDbType.VarChar,50),
pMsg,
returnValue
};
param[0].Value = strSql;
param[1].Value = saveType;// --1新增,2为修改
param[2].Value = mctext.modid;
param[3].Value = mctext.TableName;
param[4].Value = mctext.KeyFieldName;
Control[] ctr_key1 = mctext.ctr.Controls.Find("txt_" + mctext.KeyFieldName, true);
if ((ctr_key1 != null) && (ctr_key1.Length > 0))
{
//if (saveType == 1)
//{
// ControlModelTag cmTag = ctr_key[0].Tag as ControlModelTag;
// ctr_key[0].Text = GetDefaultValue(cmTag.DefaultValue);
//}
param[5].Value = ctr_key1[0].Text;
}
else
{
XtraMessageBox.Show("保存数据出现错误,没有配置关键字段");
return 0;
//string cxsql = string.Format("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME='{0}' AND COLUMNPROPERTY(OBJECT_ID('{0}'),COLUMN_NAME,'IsIdentity')=1", mctext.TableName);
//DataTable SelfGrowth = SqlHelper.ExecuteDataTable(cxsql);
//DataRow[] dataRows = SelfGrowth.Select("COLUMN_NAME='"+ mctext.KeyFieldName + "'");
//if (dataRows.Length == 0)
//{
//}
}
param[6].Value = LoginId;
param[7].Value = LoginName;
DataSet ds = SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "P_BaseSave", "baseSave", param);
string msg = pMsg.Value.ToString();
msgs = msg;
int rVaule = Convert.ToInt32(returnValue.Value.ToString());
result = rVaule;
if (rVaule == 1)
{
return 1;
}
else
{
if (msg.IndexOf("数据库中已经存在") > 0)
{
ControlModelTag cmTag = ctr_key1[0].Tag as ControlModelTag;
ctr_key1[0].Text = GetDefaultValue(cmTag.DefaultValue);
XtraMessageBox.Show("数据保存失败[(" + rVaule + ")" + msg + "],系统已经为您重新生成新的编号,请重新保存");
}
else
{
XtraMessageBox.Show("数据保存失败[(" + rVaule + ")" + msg + "]");
}
return 0;
}
}
catch (Exception ex)
{
MessageBox.Show("保存数据出现如下错误:\n" + ex.Message);
return 0;
}
return result;
}
public int SaveOrUpdateForm(MyControlText mctext, bool IsSaveOrUpdate)
{
int result = 0;
try
{
int saveType = 1;
if (!IsSaveOrUpdate)
saveType = 2;
if (saveType == 1)
{
Control[] ctr_key = mctext.ctr.Controls.Find("txt_" + mctext.KeyFieldName, true);
if ((ctr_key != null) && (ctr_key.Length > 0))
{
ControlModelTag cmTag = ctr_key[0].Tag as ControlModelTag;
ctr_key[0].Text = GetDefaultValue(cmTag.DefaultValue);
}
}
List fieldList = new List();
DataTable dt = new DataTable();
if (mctext.dt != null && mctext.dt.Rows.Count > 0)
dt = mctext.dt;
else
dt = SqlHelper.ExecuteDataSet(mctext.sql).Tables[0];
string colums = string.Empty;
//获得自增长列
string Autogrowcolumn = SqlHelper.ExecuteScalar(string.Format("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME='{0}' AND COLUMNPROPERTY(OBJECT_ID('{0}'),COLUMN_NAME,'IsIdentity')=1", mctext.TableName)) + "";
foreach (DataRow row in dt.Rows)
{
if (Autogrowcolumn.ToLower() == row["fieldName"].ToString().ToLower()) continue;
string fieldName = "txt_" + row["fieldName"].ToString();
Control[] ctr = mctext.ctr.Controls.Find(fieldName, true);
FieldModel m = new FieldModel();
if (ctr.Length > 0)
{
Control c = ctr[0];
ControlModelTag cmTag = c.Tag as ControlModelTag;
if (cmTag.fieldName == "SpeciesNo") continue;
if (cmTag != null)
{
//判断控件是否必填
if (cmTag.IsEmpt)
{
if (string.IsNullOrEmpty(c.Text))
{
XtraMessageBox.Show(cmTag.TipMsg + "不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
c.Focus();
c.Select();
return 0;
}
if ((c.Text).Trim() == "")
{
XtraMessageBox.Show(cmTag.TipMsg + "不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
c.Focus();
c.Select();
return 0;
}
}
//字段不保存
if (!cmTag.IsSave)
continue;
//自动搜索条件
if (cmTag.fieldTypeId == ControlType.LabAutoSeacherText)
{
m.FiledName = c.Name.Replace("txt_", "");
m.DataType = FieldType.VarChar;
m.FiledValue = c.Text;
}
else if (cmTag.fieldTypeId == ControlType.LabAutoSeacherValue || cmTag.fieldTypeId == ControlType.LabComboxValueParam)
{
AutoSearcher te = c as AutoSearcher;
m.FiledName = c.Name.Replace("txt_", "");
m.DataType = FieldType.VarChar;
m.FiledValue = te.ReturnValue.ToString();
}
else if (cmTag.fieldTypeId == ControlType.LabComboxValue)
{
LabelComboxEx Cb = c as LabelComboxEx;
m.FiledName = c.Name.Replace("txt_", "");
m.DataType = FieldType.VarChar;
m.FiledValue = Cb.getComboBox.SelectedValue + "";
}
else if ((cmTag.fieldTypeId == ControlType.LabComboxCheckListValue) || (cmTag.fieldTypeId == ControlType.LabComboxCheckListText))
{
LabelComboCheckList Cb = c as LabelComboCheckList;
m.FiledName = c.Name.Replace("txt_", "");
m.DataType = FieldType.VarChar;
string retValue = Cb.getComboBox.EditValue + "";
retValue = retValue.Replace(", ", ",");
m.FiledValue = retValue;
}
else if (cmTag.fieldTypeId == ControlType.LabMultiSelectValue || cmTag.fieldTypeId == ControlType.LabMultiSelectValueParam)
{
LabelLookUp Cb = c as LabelLookUp;
m.FiledName = c.Name.Replace("txt_", "");
m.DataType = FieldType.VarChar;
m.FiledValue = Cb.ReturnValue + "";
}
else if (cmTag.fieldTypeId == ControlType.LabComboxText)
{
LabelComboxEx Cb = c as LabelComboxEx;
m.FiledName = c.Name.Replace("txt_", "");
m.DataType = FieldType.VarChar;
m.FiledValue = Cb.getComboBox.Text;
}
else if (cmTag.fieldTypeId == ControlType.LabDate ||
cmTag.fieldTypeId == ControlType.LabDateTime ||
cmTag.fieldTypeId == ControlType.LabDateTimeShort ||
cmTag.fieldTypeId == ControlType.LabTime ||
cmTag.fieldTypeId == ControlType.LabShortTime)
{
LabelDateEx Cb = c as LabelDateEx;
m.FiledName = c.Name.Replace("txt_", "");
m.DataType = FieldType.VarChar;
m.FiledValue = Cb.GetDateTimePicker.Value.ToString("yyyy-MM-dd HH:mm:ss");
if (string.IsNullOrEmpty(Cb.GetDateTimePicker.CustomFormat.Trim()))
m.FiledValue = "null";
}
else
{
if (cmTag.fieldTypeId != 99 || cmTag.fieldTypeId != 100)
{
if ((cmTag.fieldTypeId == ControlType.LabTextInt) && (c.Text != "****"))
{
if (string.IsNullOrEmpty(c.Text))
c.Text = "0";
double rtDouble = 0.00;
bool convSucc = Double.TryParse(c.Text, out rtDouble);
if (convSucc == false)
{
MessageBox.Show(cmTag.TipMsg + " 未填写正确的数字");
return 0;
}
}
m.FiledName = c.Name.Replace("txt_", "");
m.DataType = FieldType.VarChar;
m.FiledValue = c.Text;
}
}
if (mctext.IsAdd)
{
//处理自动编号
if (Convert.ToInt32(row["autoNo"]) == 1)
{
m.FiledValue = GetDefaultValue(row["defaultValue"] + "");
}
}
colums += m.FiledName + ",";
if (c.Text != "****" && cmTag.fieldTypeId != ControlType.LabPic)
{
fieldList.Add(m);
}
}
else
{
if (c != null)
{
if (c.Tag + "" == "888")
{
m.FiledName = c.Name.Replace("txt_", "");
m.DataType = FieldType.VarChar;
m.FiledValue = c.Text;
fieldList.Add(m);
}
}
}
}
}
Control[] ctr_SpeciesNo = mctext.ctr.Controls.Find("txt_SpeciesNo", true);
if (SpeciesField == "")
SpeciesField = "SpeciesNo";
if (ctr_SpeciesNo.Length > 0)
{
for (int i = 0; i < ctr_SpeciesNo.Length; i++)
{
string speciesValue = ctr_SpeciesNo[i].Text;
if (!string.IsNullOrEmpty(speciesValue))
{
if (colums.IndexOf(SpeciesField + ",", StringComparison.OrdinalIgnoreCase) == -1)
{
FieldModel m = new FieldModel();
m.FiledName = SpeciesField;//ctr_SpeciesNo[0].Name.Replace("txt_", "");
m.DataType = FieldType.VarChar;
m.FiledValue = speciesValue;
fieldList.Add(m);
}
}
}
}
Control[] ctr_OperatorName = mctext.ctr.Controls.Find("txt_OperatorName", true);
if (ctr_OperatorName.Length > 0)
{
if (colums.IndexOf("OperatorName,", StringComparison.OrdinalIgnoreCase) == -1)
{
FieldModel m = new FieldModel();
m.FiledName = ctr_OperatorName[0].Name.Replace("txt_", "");
m.DataType = FieldType.VarChar;
m.FiledValue = ctr_OperatorName[0].Text;
fieldList.Add(m);
}
}
Control[] ctr_Remark = mctext.ctr.Controls.Find("txt_Remark", true);
if (ctr_Remark.Length > 0)
{
if (colums.IndexOf("Remark,", StringComparison.OrdinalIgnoreCase) == -1)
{
FieldModel m = new FieldModel();
m.FiledName = ctr_Remark[0].Name.Replace("txt_", "");
m.DataType = FieldType.VarChar;
m.FiledValue = ctr_Remark[0].Text;
fieldList.Add(m);
}
}
//modified by dl 2015-1-9 晚20:40
//if (IsSaveOrUpdate) {
// result = SqlHelper.Add(mctext.TableName, fieldList);
//}
//else {
// result = SqlHelper.Update(mctext.TableName, fieldList, mctext.where);
//}
//added by dl 2015-1-9 晚20:40
string filed = string.Empty;
string value = string.Empty;
string strSql = string.Empty;
if (IsSaveOrUpdate)
{
foreach (FieldModel m in fieldList)
{
if (!IsSaveOrUpdate && m.FiledName.Equals("SpeciesNo", StringComparison.OrdinalIgnoreCase))
continue;
filed += m.FiledName + ",";
if (m.FiledValue == "null")
value += m.FiledValue + ",";
else
value += "'" + m.FiledValue.Replace("'", "''") + "',";
}
filed = filed.Trim(',');
value = value.Trim(',');
strSql = string.Format("insert into {0}({1}) values ({2})",
mctext.TableName, filed.Replace("@", ""),
value);
}
else
{
foreach (FieldModel m in fieldList)
{
if (!IsSaveOrUpdate && m.FiledName.Equals("SpeciesNo", StringComparison.OrdinalIgnoreCase))
continue;
if (m.FiledValue == "null")
filed += m.FiledName + "=" + m.FiledValue + ",";
else
filed += m.FiledName + "='" + m.FiledValue.Replace("'", "''") + "',";
}
filed = filed.Trim(',');
strSql = string.Format("update {0} set {1} where {2}",
mctext.TableName, filed,
mctext.where);
}
SqlParameter pMsg = new SqlParameter("@msg", SqlDbType.VarChar, 2000);
pMsg.Direction = ParameterDirection.Output;
SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int, 4);
returnValue.Direction = ParameterDirection.ReturnValue;
SqlParameter[] param =
{
new SqlParameter("@baseSql",SqlDbType.VarChar,5000),
new SqlParameter("@saveType",SqlDbType.Int),
new SqlParameter("@modid",SqlDbType.VarChar,20),
new SqlParameter("@tablename",SqlDbType.VarChar,50),
new SqlParameter("@keyfield",SqlDbType.VarChar,50),
new SqlParameter("@keyvalue",SqlDbType.VarChar,50),
new SqlParameter("@Operatorid",SqlDbType.Int),
new SqlParameter("@operatorname",SqlDbType.VarChar,50),
pMsg,
returnValue
};
param[0].Value = strSql;
param[1].Value = saveType;// --1新增,2为修改
param[2].Value = mctext.modid;
param[3].Value = mctext.TableName;
param[4].Value = mctext.KeyFieldName;
Control[] ctr_key1 = mctext.ctr.Controls.Find("txt_" + mctext.KeyFieldName, true);
if ((ctr_key1 != null) && (ctr_key1.Length > 0))
{
//if (saveType == 1)
//{
// ControlModelTag cmTag = ctr_key[0].Tag as ControlModelTag;
// ctr_key[0].Text = GetDefaultValue(cmTag.DefaultValue);
//}
param[5].Value = ctr_key1[0].Text;
}
else
{
XtraMessageBox.Show("保存数据出现错误,没有配置关键字段");
return 0;
}
param[6].Value = LoginId;
param[7].Value = LoginName;
DataSet ds = SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "P_BaseSave", "baseSave", param);
string msg = pMsg.Value.ToString();
int rVaule = Convert.ToInt32(returnValue.Value.ToString());
result = rVaule;
if (rVaule == 1)
{
return 1;
}
else
{
if (msg.IndexOf("数据库中已经存在") > 0)
{
ControlModelTag cmTag = ctr_key1[0].Tag as ControlModelTag;
ctr_key1[0].Text = GetDefaultValue(cmTag.DefaultValue);
XtraMessageBox.Show("数据保存失败[(" + rVaule + ")" + msg + "],系统已经为您重新生成新的编号,请重新保存");
}
else
{
XtraMessageBox.Show("数据保存失败[(" + rVaule + ")" + msg + "]");
}
return 0;
}
}
catch (Exception ex)
{
MessageBox.Show("保存数据出现如下错误:\n" + ex.Message);
return 0;
}
return result;
}
public void setControlState(Control c, bool isTrue)
{
if (isTrue)
{
//c[0].Enabled = true;
if (c is LabelTextEx)
{
(c as LabelTextEx).GetTextBox.ReadOnly = false;
}
else if (c is LabelAutoSearcherEx)
{
(c as LabelAutoSearcherEx).GetAutoSearcher.ReadOnly = false;
}
else if (c is AutoSearcher)
{
(c as AutoSearcher).ReadOnly = false;
}
else
c.Enabled = true;
}
else
{
//c[0].Enabled = false;
if (c is LabelTextEx)
{
(c as LabelTextEx).GetTextBox.ReadOnly = true;
}
else if (c is LabelAutoSearcherEx)
{
(c as LabelAutoSearcherEx).GetAutoSearcher.ReadOnly = true;
}
else if (c is AutoSearcher)
{
(c as AutoSearcher).ReadOnly = true;
}
else
c.Enabled = false;
}
}
///
/// 清除表单
///
///
public void ClearForm(MyControlText mctext)
{
DataTable dt = new DataTable();
if (mctext.dt != null && mctext.dt.Rows.Count > 0)
dt = mctext.dt;
else
dt = SqlHelper.ExecuteDataSet(mctext.sql).Tables[0];
foreach (DataRow row in dt.Rows)
{
if ((row["unionFields"].ToString().Trim()) != "")
continue;
string fieldName = "txt_" + row["fieldName"].ToString();
Control[] ctr = mctext.ctr.Controls.Find(fieldName, true);
if (ctr.Length > 0)
{
Control c = ctr[0];
ControlModelTag cmTag = c.Tag as ControlModelTag;
if (cmTag != null)
{
//if (cmTag.IsClear) {
if (!string.IsNullOrEmpty(row["defaultvalue"] + ""))
{
if (cmTag.fieldTypeId == ControlType.LabAutoSeacherValue)
{
AutoSearcher te = c as AutoSearcher;
//te.ReturnValue = "0";
te.SetValueSilent(GetDefaultValue(row["defaultvalue"].ToString()), "");
}
else if (cmTag.fieldTypeId == ControlType.LabComboxValue)
{
LabelComboxEx lab = c as LabelComboxEx;
lab.getComboBox.SelectedValue = GetDefaultValue(row["defaultvalue"].ToString());
}
else
{
//c.Text = "";
c.Text = GetDefaultValue(row["defaultvalue"].ToString());
}
}
else
{
if (cmTag.fieldTypeId == ControlType.LabAutoSeacherValue || cmTag.fieldTypeId == ControlType.LabComboxValueParam)
{
AutoSearcher te = c as AutoSearcher;
te.ReturnValue = "0";
te.Text = "";
}
else if (cmTag.fieldTypeId == ControlType.LabComboxValue)
{
LabelComboxEx lab = c as LabelComboxEx;
lab.getComboBox.SelectedValue = "0";
}
else if ((cmTag.fieldTypeId == ControlType.LabComboxCheckListValue) || (cmTag.fieldTypeId == ControlType.LabComboxCheckListText))
{
LabelComboCheckList lab = c as LabelComboCheckList;
lab.getComboBox.SetEditValue("");
}
else if (cmTag.fieldTypeId == ControlType.LabDate ||
cmTag.fieldTypeId == ControlType.LabDateTime ||
cmTag.fieldTypeId == ControlType.LabDateTimeShort ||
cmTag.fieldTypeId == ControlType.LabTime ||
cmTag.fieldTypeId == ControlType.LabShortTime)
{
LabelDateEx lde = c as LabelDateEx;
lde.GetDateTimePicker.Value = DateTime.Now;
}
else
{
c.Text = "";
}
}
// }
}
else
{
if (c.Tag + "" != "888")
c.Text = "";
}
string edited = row["edited"] + "";
Boolean isTrue = edited != "1";
//if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
// c.Enabled = false;
//else
// c.Enabled = true;
setControlState(c, isTrue);
}
}
//处理关联字段
foreach (DataRow row in dt.Rows)
{
if ((row["unionFields"].ToString().Trim()) == "")
continue;
// if ((row["defaultvalue"].ToString().Trim()) == "")
// continue;
string fieldName = "txt_" + row["fieldName"].ToString();
Control[] ctr = mctext.ctr.Controls.Find(fieldName, true);
if ((ctr != null) && (ctr.Length > 0))
{
string value = GetDefaultValue(row["defaultvalue"].ToString());
SetControlText(ctr[0], "");
SetControlText(ctr[0], value);
}
string edited = row["edited"] + "";
Boolean isTrue = edited != "1";
//if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
// ctr[0].Enabled = false;
//else
// ctr[0].Enabled = true;
setControlState(ctr[0], isTrue);
}
}
///
/// 清除表单
///
///
public void ClearFormEnabledForInfo(MyControlText mctext)
{
DataTable dt = new DataTable();
if (mctext.dt != null && mctext.dt.Rows.Count > 0)
dt = mctext.dt;
else
dt = SqlHelper.ExecuteDataSet(mctext.sql).Tables[0];
foreach (DataRow row in dt.Rows)
{
if ((row["unionFields"].ToString().Trim()) != "")
continue;
string fieldName = "txt_" + row["fieldName"].ToString();
Control[] ctr = mctext.ctr.Controls.Find(fieldName, true);
if (ctr.Length > 0)
{
Control c = ctr[0];
ControlModelTag cmTag = c.Tag as ControlModelTag;
if (cmTag != null)
{
//if (cmTag.IsClear)
//{
if (!string.IsNullOrEmpty(row["defaultvalue"] + ""))
{
if (cmTag.fieldTypeId == ControlType.LabAutoSeacherValue)
{
AutoSearcher te = c as AutoSearcher;
//te.ReturnValue = "0";
te.SetValueSilent(GetDefaultValue(row["defaultvalue"].ToString()), "");
}
else if (cmTag.fieldTypeId == ControlType.LabComboxValue)
{
LabelComboxEx lab = c as LabelComboxEx;
lab.getComboBox.SelectedValue = GetDefaultValue(row["defaultvalue"].ToString());
}
else
{
//c.Text = "";
c.Text = GetDefaultValue(row["defaultvalue"].ToString());
}
}
else
{
if (cmTag.fieldTypeId == ControlType.LabAutoSeacherValue)
{
AutoSearcher te = c as AutoSearcher;
te.ReturnValue = "0";
te.Text = "";
}
else if (cmTag.fieldTypeId == ControlType.LabComboxValue)
{
LabelComboxEx lab = c as LabelComboxEx;
lab.getComboBox.SelectedValue = "0";
}
else if (cmTag.fieldTypeId == ControlType.LabDate ||
cmTag.fieldTypeId == ControlType.LabDateTime ||
cmTag.fieldTypeId == ControlType.LabDateTimeShort ||
cmTag.fieldTypeId == ControlType.LabTime ||
cmTag.fieldTypeId == ControlType.LabShortTime)
{
LabelDateEx lde = c as LabelDateEx;
lde.GetDateTimePicker.Value = DateTime.Now;
}
else if (cmTag.fieldTypeId == ControlType.LabPic)
{
LabelPicEx lle = c as LabelPicEx;
if (lle != null)
{
lle.GetPictureBox.Image = null;
}
}
else
{
c.Text = "";
}
}
//}
}
else
{
if (c.Tag + "" != "888")
c.Text = "";
}
string edited = row["edit"] + "";
Boolean isTrue = edited != "1";
//if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
// c.Enabled = false;
//else
// c.Enabled = true;
setControlState(c, isTrue);
}
}
//处理关联字段
foreach (DataRow row in dt.Rows)
{
if ((row["unionFields"].ToString().Trim()) == "")
continue;
string fieldName = "txt_" + row["fieldName"].ToString();
Control[] ctr = mctext.ctr.Controls.Find(fieldName, true);
if ((ctr != null) && (ctr.Length > 0))
{
var modelTag = ctr[0].Tag as ControlModelTag;
if (modelTag != null && modelTag.IsClear)
{
string value = GetDefaultValue(row["defaultvalue"].ToString());
SetControlText(ctr[0], "");
SetControlText(ctr[0], value);
}
}
string edited = row["edit"] + "";
//if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
// ctr[0].Enabled = false;
//else
// ctr[0].Enabled = true;
Boolean isTrue = edited != "1";
setControlState(ctr[0], isTrue);
}
}
///
/// 清除表单
///
///
public void ClearFormEnabled(MyControlText mctext)
{
DataTable dt = new DataTable();
if (mctext.dt != null && mctext.dt.Rows.Count > 0)
dt = mctext.dt;
else
dt = SqlHelper.ExecuteDataSet(mctext.sql).Tables[0];
foreach (DataRow row in dt.Rows)
{
if ((row["unionFields"].ToString().Trim()) != "")
continue;
string fieldName = "txt_" + row["fieldName"].ToString();
string fieldSqlTag = row["fieldtypeId"] + "";
Control[] ctr = mctext.ctr.Controls.Find(fieldName, true);
if (ctr.Length > 0 && fieldSqlTag != "3")
{
Control c = ctr[0];
ControlModelTag cmTag = c.Tag as ControlModelTag;
if (cmTag != null)
{
//if (cmTag.IsClear)
//{
if (!string.IsNullOrEmpty(row["defaultvalue"] + ""))
{
if (cmTag.fieldTypeId == ControlType.LabAutoSeacherValue)
{
AutoSearcher te = c as AutoSearcher;
//te.ReturnValue = "0";
te.SetValueSilent(GetDefaultValue(row["defaultvalue"].ToString()), "");
}
else if (cmTag.fieldTypeId == ControlType.LabComboxValue)
{
LabelComboxEx lab = c as LabelComboxEx;
lab.getComboBox.SelectedValue = GetDefaultValue(row["defaultvalue"].ToString());
}
else
{
//c.Text = "";
c.Text = GetDefaultValue(row["defaultvalue"].ToString());
}
}
else
{
if (cmTag.fieldTypeId == ControlType.LabAutoSeacherValue)
{
AutoSearcher te = c as AutoSearcher;
te.ReturnValue = "0";
te.Text = "";
}
else if (cmTag.fieldTypeId == ControlType.LabComboxValue)
{
LabelComboxEx lab = c as LabelComboxEx;
lab.getComboBox.SelectedValue = "0";
}
else if (cmTag.fieldTypeId == ControlType.LabDate ||
cmTag.fieldTypeId == ControlType.LabDateTime ||
cmTag.fieldTypeId == ControlType.LabDateTimeShort ||
cmTag.fieldTypeId == ControlType.LabTime ||
cmTag.fieldTypeId == ControlType.LabShortTime)
{
LabelDateEx lde = c as LabelDateEx;
lde.GetDateTimePicker.Value = DateTime.Now;
}
else if (cmTag.fieldTypeId == ControlType.LabPic)
{
LabelPicEx lle = c as LabelPicEx;
if (lle != null)
{
lle.GetPictureBox.Image = null;
}
}
else
{
c.Text = "";
}
}
//}
}
else
{
if (c.Tag + "" != "888")
c.Text = "";
}
string edited = row["edited"] + "";
Boolean isTrue = edited != "1";
//if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
// c.Enabled = false;
//else
// c.Enabled = true;
setControlState(c, isTrue);
}
}
//处理关联字段
foreach (DataRow row in dt.Rows)
{
if ((row["unionFields"].ToString().Trim()) == "")
continue;
string fieldName = "txt_" + row["fieldName"].ToString();
Control[] ctr = mctext.ctr.Controls.Find(fieldName, true);
if ((ctr != null) && (ctr.Length > 0))
{
var modelTag = ctr[0].Tag as ControlModelTag;
if (modelTag != null && modelTag.IsClear)
{
string value = GetDefaultValue(row["defaultvalue"].ToString());
SetControlText(ctr[0], "");
SetControlText(ctr[0], value);
}
}
string edited = row["edited"] + "";
//if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
// ctr[0].Enabled = false;
//else
// ctr[0].Enabled = true;
Boolean isTrue = edited != "1";
setControlState(ctr[0], isTrue);
}
}
///
/// 复制单据头设置状态
///
///
public void SetFormEnabled(MyControlText mctext)
{
DataTable dt = new DataTable();
if (mctext.dt != null && mctext.dt.Rows.Count > 0)
dt = mctext.dt;
else
dt = SqlHelper.ExecuteDataSet(mctext.sql).Tables[0];
foreach (DataRow row in dt.Rows)
{
//if ((row["unionFields"].ToString().Trim()) != "")
// continue;
string fieldName = "txt_" + row["fieldName"].ToString();
Control[] ctr = mctext.ctr.Controls.Find(fieldName, true);
if (ctr.Length > 0)
{
Control c = ctr[0];
string edited = row["edited"] + "";
//if (edited.IndexOf("1", StringComparison.OrdinalIgnoreCase) != -1)
// c.Enabled = false;
//else
// c.Enabled = true;
Boolean isTrue = edited != "1";
setControlState(c, isTrue);
}
}
}
public void SetFormCopyAdd(MyControlText mctext)
{
Control[] ctr_key = mctext.ctr.Controls.Find("txt_" + mctext.KeyFieldName, true);
if ((ctr_key != null) && (ctr_key.Length > 0))
{
ControlModelTag cmTag = ctr_key[0].Tag as ControlModelTag;
ctr_key[0].Text = GetDefaultValue(cmTag.DefaultValue);
}
foreach (DataRow row in mctext.dt.Rows)
{
string fieldName = "txt_" + row["fieldName"].ToString();
Control[] ctr = mctext.ctr.Controls.Find(fieldName, true);
if (fieldName == "txt_" + mctext.KeyFieldName || ctr == null || ctr.Length == 0) continue;
if (string.IsNullOrEmpty(row["canCopy"] + "") || row["canCopy"] + "" == "0")
{
// 不允许复制,清空数据
SetControlText(ctr[0], "");
}
else
{
// 允许复制,假如为空则使用默认值
if (string.IsNullOrEmpty(GetControlText(ctr[0])))
{
ControlModelTag cmTags = ctr[0].Tag as ControlModelTag;
SetControlText(ctr[0], GetDefaultValue(cmTags.DefaultValue));
}
}
// 特殊处理:
// 1. 登录ID、登录名称、操作时间3个字段重置设置为当前人员和时间.
// 2. 允许复制的字段才赋值,否则无视.
if (fieldName.ToLower().EndsWith("operatorid"))
{
SetControlText(ctr[0], ERPInfo.Instance.EmployeeId + "");
}
if (fieldName.ToLower().EndsWith("operatorname"))
{
SetControlText(ctr[0], ERPInfo.Instance.EmployeeName);
}
if (fieldName.ToLower().EndsWith("operatedate"))
{
SetControlText(ctr[0], DateTime.Now.ToString());
}
}
}
///
/// 设置默认值
///
///
///
public void SetControlText(Control control, string value)
{
if (control == null)
return;
ControlModelTag cmTag = control.Tag as ControlModelTag;
if (cmTag.fieldTypeId == ControlType.LabAutoSeacherText)
{
control.Text = value;
}
else if ((cmTag.fieldTypeId == ControlType.LabAutoSeacherValue) ||
(cmTag.fieldTypeId == ControlType.LabComboxValueParam))
{
AutoSearcher te = control as AutoSearcher;
te.ReturnValue = value;
te.SetValueSilent(value, "");
}
else if (cmTag.fieldTypeId == ControlType.LabComboxValue)
{
LabelComboxEx Cb = control as LabelComboxEx;
if (value != "")
Cb.getComboBox.SelectedValue = value;
else
{
Cb.getComboBox.SelectedValue = 0;
}
}
else if ((cmTag.fieldTypeId == ControlType.LabComboxCheckListValue) || (cmTag.fieldTypeId == ControlType.LabComboxCheckListText))
{
LabelComboCheckList Cb = control as LabelComboCheckList;
if (value != "")
Cb.getComboBox.SetEditValue(value);
else
{
Cb.getComboBox.SetEditValue("");
}
}
else if (cmTag.fieldTypeId == ControlType.LabComboxText)
{
LabelComboxEx Cb = control as LabelComboxEx;
Cb.getComboBox.Text = value;
}
else if (cmTag.fieldTypeId == ControlType.LabDate ||
cmTag.fieldTypeId == ControlType.LabDateTime ||
cmTag.fieldTypeId == ControlType.LabDateTimeShort ||
cmTag.fieldTypeId == ControlType.LabTime ||
cmTag.fieldTypeId == ControlType.LabShortTime)
{
LabelDateEx Cb = control as LabelDateEx;
if (string.IsNullOrEmpty(value.Trim()))
value = DateTime.Today.ToShortDateString();
Cb.Text = value;
Cb.GetDateTimePicker.Value = Convert.ToDateTime(value);
}
else if (cmTag.fieldTypeId == ControlType.LabMultiSelectValue)
{
LabelLookUp lookup = control as LabelLookUp;
lookup.SetValueText(value);
}
else if (cmTag.fieldTypeId == ControlType.LabMultiSelectText)
{
LabelLookUp lookup = control as LabelLookUp;
lookup.SetTextValue(value);
}
else
{
if (cmTag.fieldTypeId != 99 || cmTag.fieldTypeId != 100)
{
control.Text = value;
}
}
if (cmTag.fieldTypeId == ControlType.LabTextInt)
{
if (string.IsNullOrEmpty(control.Text))
control.Text = "0";
control.Text = string.Format("{0:" + cmTag.DateFormat + "}", Convert.ToDecimal(control.Text));
}
return;
}
public void SetControlText(MyControlText mctext)
{
DataTable dt = new DataTable();
if (mctext.dt != null && mctext.dt.Rows.Count > 0)
dt = mctext.dt;
else
dt = SqlHelper.ExecuteDataSet(mctext.sql).Tables[0];
foreach (DataRow row in dt.Rows)
{
try
{
if (mctext.dtData != null && mctext.dtData.Rows.Count > 0)
{
DataColumn dc = mctext.dtData.Columns[row["fieldName"] + ""];
if (dc == null)
{
continue;
}
}
string ctrName = "txt_" + row["fieldName"].ToString();
Control[] ctr = mctext.ctr.Controls.Find(ctrName, true);
if (ctr.Length > 0)
{
Control c = ctr[0];
ControlModelTag cmTag = c.Tag as ControlModelTag;
if (cmTag == null)
continue;
if (cmTag.fieldTypeId == ControlType.LabComboxValue)
{
LabelComboxEx cbe = c as LabelComboxEx;
string lookupSql = PubClass.ReqSqlParam(row["lookupSql"].ToString(), LoginId, LoginName);
cbe.setDataSource(lookupSql, row["lookupKeyField"] + "", row["lookupResult"] + "");
if (!string.IsNullOrEmpty(row["defaultValue"] + ""))
cbe.Text = row["defaultValue"] + "";
cbe.getComboBox.SelectedValue = mctext.dr[row["fieldName"].ToString()].ToString();
}
else if (cmTag.fieldTypeId == ControlType.LabComboxText)
{
LabelComboxEx Cb = c as LabelComboxEx;
Cb.getComboBox.Text = mctext.dr[row["fieldName"] + ""] + "";
}
else if ((cmTag.fieldTypeId == ControlType.LabComboxCheckListValue))
{
LabelComboCheckList cbe = c as LabelComboCheckList;
string lookupSql = PubClass.ReqSqlParam(row["lookupSql"].ToString(), LoginId, LoginName);
cbe.setDataSource(lookupSql, row["lookupKeyField"] + "", row["lookupResult"] + "");
if (!string.IsNullOrEmpty(row["defaultValue"] + ""))
cbe.Text = row["defaultValue"] + "";
cbe.getComboBox.SetEditValue(mctext.dr[row["fieldName"].ToString()].ToString());
}
else if ((cmTag.fieldTypeId == ControlType.LabComboxCheckListText))
{
LabelComboCheckList cbe = c as LabelComboCheckList;
string lookupSql = PubClass.ReqSqlParam(row["lookupSql"].ToString(), LoginId, LoginName);
cbe.setDataSource(lookupSql, row["lookupResult"] + "", row["lookupResult"] + "");
if (!string.IsNullOrEmpty(row["defaultValue"] + ""))
cbe.Text = row["defaultValue"] + "";
cbe.getComboBox.SetEditValue(mctext.dr[row["fieldName"].ToString()].ToString());
}
else if (cmTag.fieldTypeId == ControlType.LabAutoSeacherText || cmTag.fieldTypeId == ControlType.LabComboxTextParam)
{
AutoSearcher te = c as AutoSearcher;
te.SetValueSilent("", mctext.dr[row["fieldName"].ToString()].ToString());
}
else if (cmTag.fieldTypeId == ControlType.LabAutoSeacherValue ||
cmTag.fieldTypeId == ControlType.LabComboxValueParam)
{
AutoSearcher te = c as AutoSearcher;
te.SetValueSilent(mctext.dr[row["fieldName"].ToString()].ToString(), "");
te.ReturnValue = mctext.dr[row["fieldName"].ToString()].ToString();
}
else if (cmTag.fieldTypeId == ControlType.LabMultiSelectValue || cmTag.fieldTypeId == ControlType.LabMultiSelectValueParam)
{
LabelLookUp lookup = c as LabelLookUp;
lookup.SetValueText(mctext.dr[row["fieldName"].ToString()].ToString());
}
else if (cmTag.fieldTypeId == ControlType.LabMultiSelectText)
{
LabelLookUp lookup = c as LabelLookUp;
lookup.SetTextValue(mctext.dr[row["fieldName"].ToString()].ToString());
}
else if (cmTag.fieldTypeId == ControlType.LabPic)
{
LabelPicEx pic = c as LabelPicEx;
try
{
byte[] bmp = (byte[])mctext.dr[row["fieldName"].ToString()];
if (bmp.Length > 0)
{
pic.GetPictureBox.Image = PubClass.ReadImage(bmp);
}
}
catch
{
pic.GetPictureBox.Image = null;
}
}
else
{
c.Text = mctext.dr[row["fieldName"].ToString()].ToString();
if (cmTag.fieldTypeId == ControlType.LabTextInt)
{
if (string.IsNullOrEmpty(c.Text))
c.Text = "0";
if ((row.Table.Columns.Contains("DataFormat")) && (c.Text != ""))
{
string dfmt = row["dataformat"].ToString();
if (dfmt == "")
dfmt = "0.00";
c.Text = string.Format("{0:" + dfmt + "}", Convert.ToDecimal(c.Text));
}
}
if (cmTag.fieldTypeId == ControlType.LabDateTime)
{
if (string.IsNullOrEmpty(c.Text))
c.Text = "";
if ((row.Table.Columns.Contains("DataFormat")) && (c.Text != ""))
{
string dfmt = row["dataformat"].ToString();
if (dfmt == "")
dfmt = "yyyy-MM-dd";
c.Text = string.Format("{0:" + dfmt + "}", Convert.ToDateTime(c.Text));
}
}
}
if (!String.IsNullOrEmpty(row["visible"] + ""))
{
int visible = Convert.ToInt32(row["visible"]);
if (visible == 1)
{
if (cmTag.fieldTypeId == ControlType.LabDate ||
cmTag.fieldTypeId == ControlType.LabDateTime ||
cmTag.fieldTypeId == ControlType.LabDateTimeShort ||
cmTag.fieldTypeId == ControlType.LabTime ||
cmTag.fieldTypeId == ControlType.LabShortTime)
{
c.ForeColor = Color.White;
}
else
{
c.Text = "****";
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show("错误字段->" + row["fieldName"] + "->" + ex.Message);
}
}
}
///
/// 取指定组件值
///
///
///
public string GetControlText(Control control)
{
if (control == null)
return "";
ControlModelTag cmTag = control.Tag as ControlModelTag;
if (cmTag == null)
return control.Text;
if (cmTag.fieldTypeId == ControlType.LabAutoSeacherText)
{
return control.Text;
}
else if ((cmTag.fieldTypeId == ControlType.LabAutoSeacherValue) ||
(cmTag.fieldTypeId == ControlType.LabComboxValueParam))
{
AutoSearcher te = control as AutoSearcher;
return te.ReturnValue.ToString();
}
else if (cmTag.fieldTypeId == ControlType.LabComboxValue)
{
LabelComboxEx Cb = control as LabelComboxEx;
return Cb.getComboBox.SelectedValue + "";
}
else if ((cmTag.fieldTypeId == ControlType.LabComboxCheckListValue) || (cmTag.fieldTypeId == ControlType.LabComboxCheckListText))
{
LabelComboCheckList Cb = control as LabelComboCheckList;
string retValue = Cb.getComboBox.EditValue + "";
retValue = retValue.Replace(", ", ",");
return Cb.getComboBox.EditValue + "";
}
else if (cmTag.fieldTypeId == ControlType.LabComboxText)
{
LabelComboxEx Cb = control as LabelComboxEx;
return Cb.getComboBox.Text;
}
else if (cmTag.fieldTypeId == ControlType.LabDate ||
cmTag.fieldTypeId == ControlType.LabDateTime ||
cmTag.fieldTypeId == ControlType.LabDateTimeShort ||
cmTag.fieldTypeId == ControlType.LabTime ||
cmTag.fieldTypeId == ControlType.LabShortTime)
{
LabelDateEx Cb = control as LabelDateEx;
return Cb.GetDateTimePicker.Value.ToString("yyyy-MM-dd HH:mm:ss");
}
else if (cmTag.fieldTypeId == ControlType.LabTextInt)
{
if ((control.Text.Trim() == ""))
return "0";
else
return control.Text;
}
else if (cmTag.fieldTypeId == ControlType.LabMultiSelectValue || cmTag.fieldTypeId == ControlType.LabMultiSelectValueParam)
{
LabelLookUp lookup = control as LabelLookUp;
return lookup.ReturnValue;
}
else
{
if (cmTag.fieldTypeId != 99 || cmTag.fieldTypeId != 100)
{
return control.Text;
}
}
return "0";
}
///
/// 通过FieldName获取控件值
///
///
///
public string GetControlText(string fieldName)
{
Control[] ctl = GetControl(fieldName);
if (ctl != null && ctl.Length > 0)
{
return GetControlText(ctl[0]);
}
return "";
}
///
/// 通过字段获取控件
///
///
///
public Control[] GetControl(string fieldName)
{
return ParentCtr.Controls.Find("txt_" + fieldName, true);
}
///
/// 获取默认值
///
///
///
public string GetDefaultValue(string defaultValue, DataRow tmpDataRow = null)
{
string result = defaultValue;
if (result.Trim() == "")
return result;
//defaultValue = PubClass.GetDefaultValue(defaultValue, ERPInfo.Instance.EmployeeId + "", ERPInfo.Instance.EmployeeName);
List parlist = PubClass.GetParamValue(defaultValue);
foreach (string s in parlist)
{
string tmpValue = "";
if ((s.IndexOf("{#", StringComparison.OrdinalIgnoreCase) != -1) && (ParentCtr != null))
{
Control[] ctr = ParentCtr.Controls.Find("txt_" + s.Replace("{#", "").Replace("}", ""), true);
if (ctr.Length > 0)
{
Control c = ctr[0];
if (c != null)
{
ControlModelTag cmt = c.Tag as ControlModelTag;
if (ctr[0].Text.Trim() != "")
tmpValue = GetControlText(ctr[0]);
else
tmpValue = ctr[0].Text;
result = result.Replace(s, tmpValue);
}
}
}
if (tmpDataRow != null)
{
if (tmpDataRow.Table.Columns.Contains(s.Replace("{", "").Replace("}", "")))
result = result.Replace(s, tmpDataRow[s.Replace("{", "").Replace("}", "")] + "");
}
}
if (defaultValue.IndexOf("loginid", StringComparison.OrdinalIgnoreCase) != -1)
{
List list = PubClass.GetParamValue(defaultValue);
foreach (string s in list)
{
if (s.IndexOf("loginid", StringComparison.OrdinalIgnoreCase) != -1)
result = result.Replace(s, ERPInfo.Instance.EmployeeId + "");
}
}
if (defaultValue.IndexOf("groupid", StringComparison.OrdinalIgnoreCase) != -1)
{
List list = PubClass.GetParamValue(defaultValue);
foreach (string s in list)
{
if (s.IndexOf("groupid", StringComparison.OrdinalIgnoreCase) != -1)
result = result.Replace(s, ERPInfo.Instance.GroupId);
}
}
if (defaultValue.IndexOf("loginname", StringComparison.OrdinalIgnoreCase) != -1)
{
List list = PubClass.GetParamValue(defaultValue);
foreach (string s in list)
{
if (s.IndexOf("loginname", StringComparison.OrdinalIgnoreCase) != -1)
result = result.Replace(s, ERPInfo.Instance.EmployeeName);
}
}
if (result.IndexOf("guid", StringComparison.OrdinalIgnoreCase) != -1)
{
result = result.Replace("{guid}", Guid.NewGuid().ToString());
}
if (result.IndexOf("parent.key", StringComparison.OrdinalIgnoreCase) != -1)
{
result = result.Replace("{parent.key}", Space);
}
if (result.IndexOf('@') != -1)
{
object obj = SqlHelper.ExecuteScalar(CommandType.Text, result.Replace("@", ""));
if (obj != null)
{
result = obj.ToString();
}
return result;
}
if (defaultValue.IndexOf("!", StringComparison.OrdinalIgnoreCase) != -1)
{
List list = PubClass.GetParamValue(defaultValue);
foreach (string s in list)
{
if (s.IndexOf("parent.key", StringComparison.OrdinalIgnoreCase) != -1)
{
result = result.Replace(s, Space);
}
if (s.IndexOf("loginid", StringComparison.OrdinalIgnoreCase) != -1)
{
result = result.Replace(s, LoginId);
}
if (s.IndexOf("loginname", StringComparison.OrdinalIgnoreCase) != -1)
{
result = result.Replace(s, LoginName);
}
}
result = result.Replace("!", "").Replace("(", " ").Replace(")", "");
DataTable dt = SqlHelper.ExecuteDataSet(CommandType.Text, "exec " + result, "temp").Tables[0];
if (dt != null && dt.Rows.Count > 0)
{
result = dt.Rows[0][0] + "";
}
}
if (defaultValue.IndexOf("#", StringComparison.OrdinalIgnoreCase) != -1)
{
//代表传入其他参数格式{#p_1},{#p_2}..{#p_10}
if (defaultValue.IndexOf("#p_", StringComparison.OrdinalIgnoreCase) != -1)
{
List list = PubClass.GetParamValue(defaultValue);
foreach (string s in list)
{
string idx = s.Replace("{#p_", "").Replace("}", "");
int i = 0;
if (int.TryParse(idx, out i))
{
if (otherParams == null)
result = "";
else
result = result.Replace(s, otherParams[i - 1]);
}
}
}
else
if (ParentCtr != null)
{
defaultValue = defaultValue.Replace("{#", "").Replace("}", "");
Control[] ctr = ParentCtr.Controls.Find("txt_" + defaultValue, true);
if (ctr.Length > 0)
{
Control c = ctr[0];
if (c != null)
{
ControlModelTag cmt = c.Tag as ControlModelTag;
if (ctr[0].Text.Trim() != "")
result = GetControlText(ctr[0]);
else
result = ctr[0].Text;
}
}
}
}
return result;
}
}
}