CEL_Payroll/Ease.UICreator/FrmBasicEntryForm.cs

799 lines
39 KiB
C#
Raw Permalink Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.Security;
using System.Drawing.Drawing2D;
using Ease.CoreV35.Model;
using Ease.CoreV35.Caching;
namespace Ease.UICreator
{
internal partial class FrmBasicEntryForm : Form
{
#region Declaration
private SingleForm _singleForm;
private ObjectTemplate _Source;
private ObjectTemplate _parentSource;
public event System.EventHandler RefreshParent;
public Ease.UICreator.UIConfiguration IncpUIConfig;
#endregion
#region Function
public FrmBasicEntryForm()
{
InitializeComponent();
_parentSource = null;
}
public bool ShowDialog(SingleForm UIBESF, ObjectTemplate SourceObject)
{
try
{
_singleForm = UIBESF;
_Source = SourceObject;
System.Reflection.PropertyInfo dispMem = (_Source.GetType()).GetProperty("IsNew");
bool isNew = Convert.ToBoolean(dispMem.GetValue(_Source, null).ToString());
if (isNew == true)
{
this.Text = " Add New " + _singleForm.Caption;
}
else
{
this.Text = " Edit " + _singleForm.Caption;
}
_singleForm.Controls.IsDuplicateCtlName();
if (CheckSpell())
{
DesignControl();
RefreshControl();
ResizeFrom();
if (IncpUIConfig != null)
{
this.Name = _singleForm.FormName;
IncpUIConfig(this);
}
this.ShowDialog();
}
return true;
}
catch (Exception e)
{
MessageBox.Show("Error: " + e.Message, "For Developer:");
return false;
}
}
public ObjectTemplate ParentObject
{
set
{
_parentSource = value;
}
}
private void TreeViewUpdate()
{
try
{
if (_parentSource == null) return;
object ovalue = new object();
ovalue = _parentSource.ID;
_Source.GetType().GetProperty("ParentID").SetValue(_Source, ovalue, null);
ovalue = _parentSource.GetType().GetProperty("Tier").GetValue(_parentSource, null);
ovalue = Convert.ToInt32(ovalue) + 1;
_Source.GetType().GetProperty("Tier").SetValue(_Source, ovalue, null);
}
catch (Exception ex)
{
MessageBox.Show("falied to load object from controls. Check control and object datatypes are same. Error:" + ex.Message, "Tree view refresh object", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
public void ResizeFrom()
{
//int nControlCount = 1;
int controlIndex = 0;
int prospectWidth = 0;
//int formWidth = this.Controls[controlIndex].Width + this.Controls[controlIndex + 1].Width;
//int formHeight = this.Controls[controlIndex+1].Height;
//while(nControlCount <this.Controls.Count)
//{
// if (nControlCount != 1)
// {
// prospectWidth=this.Controls[controlIndex].Width + this.Controls[controlIndex + 1].Width;
// if (prospectWidth > formWidth)
// {
// formWidth = prospectWidth;
// }
// formHeight += this.Controls[controlIndex+1].Height;
// }
// nControlCount++;
// controlIndex++;
//}
int formWidth = 0;
int formHeight = 0;
while (controlIndex < this.Controls.Count - 1)
{
if (controlIndex % 2 == 1)
{
prospectWidth = this.Controls[controlIndex].Width + this.Controls[controlIndex + 1].Width;
if (prospectWidth > formWidth)
{
formWidth = prospectWidth;
}
//Old Code for Form Height
//formHeight += 12;
//New Code for Form Height. Updated by Ashifur Rahaman. Date: 21 Dec 2008
formHeight += 7;
}
else
{
formHeight += this.Controls[controlIndex].Height;
}
controlIndex++;
}
this.FormBorderStyle = FormBorderStyle.Sizable;
//Old code for form height
//this.Height = 35 + formHeight;
//New code for form height. Upadted by Ashifur Rahaman. Date: 21 Dec 2008
this.Height = 100 + _singleForm.Controls[_singleForm.Controls.Count - 1].PositionY;
// this.Width = 45 + formWidth;
this.FormBorderStyle = FormBorderStyle.FixedDialog;
this.StartPosition = FormStartPosition.CenterParent;
}
public void DesignControl()
{
int TabIndex = 0;
foreach (SingleFormControl UIBESFItem in _singleForm.Controls)
{
switch (UIBESFItem.ControlType)
{
case BESFControlEnum.Lebel:
System.Windows.Forms.Label label = new Label();
label.Text = UIBESFItem.Caption;
label.Name = UIBESFItem.Name;
label.BackColor = Color.Transparent;
label.AutoSize = true;
label.Location = new System.Drawing.Point(UIBESFItem.PositionX, UIBESFItem.PositionY);
label.Size = new System.Drawing.Size(UIBESFItem.Width, UIBESFItem.Height);
label.BorderStyle = System.Windows.Forms.BorderStyle.None;
label.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
label.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
label.AutoSize = false;
this.Controls.Add(label);
break;
case BESFControlEnum.Text:
System.Windows.Forms.TextBox txtBox = new TextBox();
//Old code for textBox Caption
//txtBox.Text = "";
//New Code for TextBox Caption. Updated by Ashifur Rahaman. Date: 21 Dec 2008
txtBox.Text = UIBESFItem.Caption;
txtBox.Name = UIBESFItem.Name;
if (txtBox.Name.ToLower().Contains("Qty") || txtBox.Name.ToLower().Contains("Quantity") || txtBox.Name.ToLower().Contains("amount"))
{
txtBox.TextAlign = HorizontalAlignment.Right;
}
if (UIBESFItem.Height > 20)
txtBox.Multiline = true;
txtBox.BorderStyle = BorderStyle.FixedSingle;
txtBox.Location = new System.Drawing.Point(UIBESFItem.PositionX, UIBESFItem.PositionY);
txtBox.Size = new System.Drawing.Size(UIBESFItem.Width, UIBESFItem.Height);
txtBox.ReadOnly = UIBESFItem.IsReadOnly;
txtBox.MaxLength = UIBESFItem.MaxLength;
//updated by Ashifur Rahaman. Date: 21 Dec 2008
//for setting background color and tab stop to a control
if (txtBox.ReadOnly)
{
//txtBox.BackColor = UIBESFItem.BackColor;
txtBox.BackColor = Color.Ivory;
}
if (UIBESFItem.IsTabStop) txtBox.TabStop = true;
if (UIBESFItem.IsFocused) txtBox.Focus();
this.Controls.Add(txtBox);
break;
case BESFControlEnum.Combo:
System.Windows.Forms.ComboBox cboBox = new ComboBox();
cboBox.Name = UIBESFItem.Name;
cboBox.Location = new System.Drawing.Point(UIBESFItem.PositionX, UIBESFItem.PositionY);
cboBox.Size = new System.Drawing.Size(UIBESFItem.Width, UIBESFItem.Height);
cboBox.DropDownStyle = (UIBESFItem.CboBox.ComboType == enmComboType.CBTDropDown) ?
System.Windows.Forms.ComboBoxStyle.DropDown : System.Windows.Forms.ComboBoxStyle.DropDownList;
cboBox.FormattingEnabled = true;
// Type type = UIBESFItem.CboBox.ComboSource.GetType();
if (UIBESFItem.CboBox.PopulatedFrom == enmCboPopulatedFrom.Enum)
{
char[] delimiter = new char[1];
delimiter[0] = '|';
string strEnum = UIBESFItem.CboBox.DisplayName.ToString();
string[] strValues = strEnum.Split(delimiter);
foreach (string strItem in strValues)
{
cboBox.Items.Add(strItem.Substring(0, strItem.IndexOf('=')));
}
}
else
{
foreach (var item in UIBESFItem.CboBox.ComboSource)
{
string str = "";
System.Reflection.PropertyInfo dispMem = item.GetType().GetProperty(UIBESFItem.CboBox.DisplayName);
str = dispMem.GetValue(item, null).ToString();
cboBox.Items.Add(str);
}
}
this.Controls.Add(cboBox);
break;
case BESFControlEnum.Check:
System.Windows.Forms.CheckBox ochkBox = new CheckBox();
ochkBox.Text = UIBESFItem.Caption;
ochkBox.Name = UIBESFItem.Name;
ochkBox.BackColor = Color.Transparent;
ochkBox.Location = new System.Drawing.Point(UIBESFItem.PositionX, UIBESFItem.PositionY);
ochkBox.Size = new System.Drawing.Size(UIBESFItem.Width, UIBESFItem.Height);
ochkBox.UseVisualStyleBackColor = true;
this.Controls.Add(ochkBox);
break;
case BESFControlEnum.DTPicker:
System.Windows.Forms.DateTimePicker dtPicker = new DateTimePicker();
dtPicker.CustomFormat = "dd MMM yyyy";
dtPicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
dtPicker.Location = new System.Drawing.Point(UIBESFItem.PositionX, UIBESFItem.PositionY);
dtPicker.Name = UIBESFItem.Name;
dtPicker.Size = new System.Drawing.Size(UIBESFItem.Width, UIBESFItem.Height);
//dtPicker.Value = DateTime.Now;
this.Controls.Add(dtPicker);
break;
case BESFControlEnum.NumText:
Ease.Controls.EaseNum ctlNum = new Ease.Controls.EaseNum();
ctlNum.Format = "0.00";
ctlNum.InputType = Ease.Controls.NumberType.Currency;
ctlNum.Location = new System.Drawing.Point(UIBESFItem.PositionX, UIBESFItem.PositionY);
ctlNum.Name = UIBESFItem.Name;
ctlNum.Size = new System.Drawing.Size(UIBESFItem.Width, UIBESFItem.Height);
ctlNum.Value = new decimal(new int[] { 0, 0, 0, 131072 });
this.Controls.Add(ctlNum);
break;
case BESFControlEnum.IntNumText:
Ease.Controls.EaseNum ctlNum1 = new Ease.Controls.EaseNum();
ctlNum1.Format = "0";
ctlNum1.InputType = Ease.Controls.NumberType.Integer;
ctlNum1.Location = new System.Drawing.Point(UIBESFItem.PositionX, UIBESFItem.PositionY);
ctlNum1.Name = UIBESFItem.Name;
ctlNum1.Size = new System.Drawing.Size(UIBESFItem.Width, UIBESFItem.Height);
ctlNum1.Value = new decimal(new int[] { 0, 0, 0, 131072 });
this.Controls.Add(ctlNum1);
break;
}
this.Controls[UIBESFItem.Name].TabIndex = TabIndex;
TabIndex = TabIndex + 1;
}
tstrBottom.TabIndex = TabIndex;
TabIndex = TabIndex + 1;
this.Refresh();
}
public bool CheckSpell()
{
bool correct = true;
//int count = 0;
foreach (SingleFormControl UIBESFItem in _singleForm.Controls)
{
System.Reflection.PropertyInfo dispMem = (_Source.GetType()).GetProperty(UIBESFItem.PropertyName);
switch (UIBESFItem.ControlType)
{
case BESFControlEnum.Text:
if (dispMem == null)
{
MessageBox.Show("The property name " + UIBESFItem.PropertyName.ToString() + "\n" + "does not belong to the object " + (_Source.GetType()).Name.ToString());
correct = false;
}
break;
case BESFControlEnum.DTPicker:
if (dispMem == null)
{
MessageBox.Show("The property name " + UIBESFItem.PropertyName.ToString() + "\n" + "does not belong to the object " + (_Source.GetType()).Name.ToString());
correct = false;
}
break;
case BESFControlEnum.Combo:
if (dispMem == null)
{
MessageBox.Show("The property name " + UIBESFItem.PropertyName.ToString() + "\n" + "does not belong to the object " + (_Source.GetType()).Name.ToString());
correct = false;
}
break;
case BESFControlEnum.Check:
if (dispMem == null)
{
MessageBox.Show("The property name " + UIBESFItem.PropertyName.ToString() + "\n" + "does not belong to the object " + (_Source.GetType()).Name.ToString());
correct = false;
}
break;
case BESFControlEnum.NumText:
if (dispMem == null)
{
MessageBox.Show("The property name " + UIBESFItem.PropertyName.ToString() + "\n" + "does not belong to the object " + (_Source.GetType()).Name.ToString());
correct = false;
}
break;
case BESFControlEnum.IntNumText:
if (dispMem == null)
{
MessageBox.Show("The property name " + UIBESFItem.PropertyName.ToString() + "\n" + "does not belong to the object " + (_Source.GetType()).Name.ToString());
correct = false;
}
break;
}
if (correct == false)
{
break;
}
}
return correct;
}
public void RefreshControl()
{
foreach (SingleFormControl UIBESFItem in _singleForm.Controls)
{
System.Reflection.PropertyInfo dispMem = (_Source.GetType()).GetProperty(UIBESFItem.PropertyName);
string str = "";
bool Istierfound = false;
int tier = 0;
ID ParentID = ID.FromInteger(0);
switch (UIBESFItem.ControlType)
{
case BESFControlEnum.Text:
#region Text Box
//str = dispMem.GetValue(_Source, null).ToString();
//this.Controls[UIBESFItem.Name].Text = str;
//check Auto code generate required
// if object state is new, get max code from database through object
// else get value from object property
System.Reflection.PropertyInfo IsNewdispMem = (_Source.GetType()).GetProperty("IsNew");
bool isNew = Convert.ToBoolean(IsNewdispMem.GetValue(_Source, null).ToString());
if (isNew == true && UIBESFItem.IsCodeAutoGenerated == true)
{
try
{
PropertyInfo myPropInfo = _Source.GetType().GetProperty("Tier");
if (myPropInfo != null)
{
if (_parentSource != null)
{
tier = Convert.ToInt32(_parentSource.GetType().GetProperty("Tier").GetValue(_parentSource, null));
tier = tier + 1;
ParentID = (ID)_parentSource.GetType().GetProperty("ID").GetValue(_parentSource, null);
}
else
{
tier = 1;
}
object[] obj = new object[2];
obj[0] = tier;
obj[1] = ParentID.Integer;
Type[] types = new Type[2];
types[0] = ((int)obj[1]).GetType();
types[1] = tier.GetType();
System.Reflection.MethodInfo methodInfo = (_Source.GetType()).GetMethod("GetNextCode", types);
if (methodInfo == null) MessageBox.Show("Method not found in the object", "method not exist", MessageBoxButtons.OK, MessageBoxIcon.Information);
str = (string)methodInfo.Invoke(_Source, obj);
this.Controls[UIBESFItem.Name].Enabled = false;
}
else
{
System.Reflection.MethodInfo methodInfo = (_Source.GetType()).GetMethod("GetNextCode", new Type[0]);
if (methodInfo == null) MessageBox.Show("Method not found in the object", "method not exist", MessageBoxButtons.OK, MessageBoxIcon.Information);
str = (string)methodInfo.Invoke(_Source, null);
this.Controls[UIBESFItem.Name].Enabled = false;
}
}
catch (NullReferenceException ex) { }
}
else
{
if (UIBESFItem.IsCodeAutoGenerated == true)
this.Controls[UIBESFItem.Name].Enabled = false;
object ovalue = dispMem.GetValue(_Source, null);
str = "";
if (ovalue != null)
str = ovalue.ToString();
}
this.Controls[UIBESFItem.Name].Text = str;
#endregion
break;
case BESFControlEnum.DTPicker:
#region Date-Time Picker
str = dispMem.GetValue(_Source, null).ToString();
if (Convert.ToDateTime(str) == DateTime.MinValue)
{
str = DateTime.Now.ToString();
}
((System.Windows.Forms.DateTimePicker)this.Controls[UIBESFItem.Name]).Value = Convert.ToDateTime(str);
#endregion
break;
case BESFControlEnum.Combo:
#region Combo Box
if (UIBESFItem.CboBox.PopulatedFrom == enmCboPopulatedFrom.Enum)
{
#region Enum
// Get value from the object
int nValue = Convert.ToInt32((dispMem.GetValue(_Source, null)));
char[] delimiter = new char[1];
delimiter[0] = '|';
string strEnum = UIBESFItem.CboBox.DisplayName.ToString();
string[] strValues = strEnum.Split(delimiter);
int index = -1;
foreach (string strItem in strValues)
{
index = index + 1;
int nEnumValue = Convert.ToInt32(strItem.Substring(strItem.IndexOf('=') + 1, strItem.Length - strItem.IndexOf('=') - 1));
if (nEnumValue == nValue) break;
}
if (index > -1)
{
((System.Windows.Forms.ComboBox)this.Controls[UIBESFItem.Name]).SelectedIndex = index;
}
#endregion
}
else
{
//ObjectTemplate otmp = UIBESFItem.CboBox.ComboSource.GetItem(cboIndex);
//PropertyValue = otmp.GetType().GetProperty(UIBESFItem.CboBox.DataPropertyName).GetValue(otmp, null);
#region Combo populated from a collection
// extract property value throuth the reflextion
object[] obj = new object[1];
obj[0] = dispMem.GetValue(_Source, null);
//if object type is ID then convert it to int
if (obj[0] is int)
{
obj[0] = ID.FromInteger(Convert.ToInt32(obj[0].ToString()));
}
int index = 0;
// Find the number of items in the combo source to give the selected index
System.Reflection.PropertyInfo oCountProperty = (UIBESFItem.CboBox.ComboSource.GetType()).GetProperty("Count");
index = Convert.ToInt32(oCountProperty.GetValue(UIBESFItem.CboBox.ComboSource, null));
if (index == 0)
{
index = -1;
}
else index = 0;
// If property value not zero it's mean form is edited mode
// and combo selected index should come from source collection
try
{
if (Convert.ToInt32(obj[0].ToString()) != 0)
{
System.Reflection.MethodInfo methodInfo = (UIBESFItem.CboBox.ComboSource.GetType()).GetMethod("GetIndex");
if (methodInfo != null)
{
index = Convert.ToInt32(methodInfo.Invoke(UIBESFItem.CboBox.ComboSource, obj).ToString());
}
}
if (index > -1)
{
((System.Windows.Forms.ComboBox)this.Controls[UIBESFItem.Name]).SelectedIndex = index;
}
}
catch (Exception ex)
{
}
#endregion
}
#endregion
break;
case BESFControlEnum.Check:
#region Check Box
bool bol = Convert.ToBoolean(dispMem.GetValue(_Source, null));
((System.Windows.Forms.CheckBox)this.Controls[UIBESFItem.Name]).Checked = bol;
#endregion
break;
case BESFControlEnum.NumText:
#region Numeric Text Control
if (((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).InputType == Ease.Controls.NumberType.Currency)
{
((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).Value = dispMem.GetValue(_Source, null).ToString();
}
else if (((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).InputType == Ease.Controls.NumberType.Decimal)
{
decimal dbl = Convert.ToDecimal(dispMem.GetValue(_Source, null).ToString());
((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).Value = dbl;
}
else if (((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).InputType == Ease.Controls.NumberType.Double)
{
double dbl = Convert.ToDouble(dispMem.GetValue(_Source, null).ToString());
((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).Value = dbl;
}
else if (((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).InputType == Ease.Controls.NumberType.Integer)
{
Int32 dbl = Convert.ToInt32(dispMem.GetValue(_Source, null).ToString());
((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).Value = dbl;
}
else if (((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).InputType == Ease.Controls.NumberType.LargeInteger)
{
Int64 dbl = Convert.ToInt64(dispMem.GetValue(_Source, null).ToString());
((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).Value = dbl;
}
else if (((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).InputType == Ease.Controls.NumberType.Single)
{
Single dbl = Convert.ToSingle(dispMem.GetValue(_Source, null).ToString());
((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).Value = dbl;
}
else if (((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).InputType == Ease.Controls.NumberType.SmallInteger)
{
Int16 dbl = Convert.ToInt16(dispMem.GetValue(_Source, null).ToString());
((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).Value = dbl;
}
#endregion
break;
case BESFControlEnum.IntNumText:
#region Numeric Text Control
if (((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).InputType == Ease.Controls.NumberType.Currency)
{
((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).Value = dispMem.GetValue(_Source, null).ToString();
}
else if (((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).InputType == Ease.Controls.NumberType.Decimal)
{
decimal dbl = Convert.ToDecimal(dispMem.GetValue(_Source, null).ToString());
((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).Value = dbl;
}
else if (((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).InputType == Ease.Controls.NumberType.Double)
{
double dbl = Convert.ToDouble(dispMem.GetValue(_Source, null).ToString());
((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).Value = dbl;
}
else if (((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).InputType == Ease.Controls.NumberType.Integer)
{
Int32 dbl = Convert.ToInt32(dispMem.GetValue(_Source, null).ToString());
((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).Value = dbl;
}
else if (((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).InputType == Ease.Controls.NumberType.LargeInteger)
{
Int64 dbl = Convert.ToInt64(dispMem.GetValue(_Source, null).ToString());
((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).Value = dbl;
}
else if (((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).InputType == Ease.Controls.NumberType.Single)
{
Single dbl = Convert.ToSingle(dispMem.GetValue(_Source, null).ToString());
((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).Value = dbl;
}
else if (((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).InputType == Ease.Controls.NumberType.SmallInteger)
{
Int16 dbl = Convert.ToInt16(dispMem.GetValue(_Source, null).ToString());
((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).Value = dbl;
}
#endregion
break;
}
if (UIBESFItem.IsFocused)
{
this.Controls[UIBESFItem.Name].Focus();
}
}
}
public void RefreshObject()
{
try
{
foreach (SingleFormControl UIBESFItem in _singleForm.Controls)
{
System.Reflection.PropertyInfo dispMem = (_Source.GetType()).GetProperty(UIBESFItem.PropertyName);
switch (UIBESFItem.ControlType)
{
case BESFControlEnum.Text:
dispMem.SetValue(_Source, this.Controls[UIBESFItem.Name].Text, null);
break;
case BESFControlEnum.DTPicker:
dispMem.SetValue(_Source, ((System.Windows.Forms.DateTimePicker)this.Controls[UIBESFItem.Name]).Value, null);
break;
case BESFControlEnum.Combo:
int cboIndex = ((System.Windows.Forms.ComboBox)this.Controls[UIBESFItem.Name]).SelectedIndex;
object PropertyValue;
if (UIBESFItem.CboBox.PopulatedFrom == enmCboPopulatedFrom.Enum)
{
char[] delimiter = new char[1];
delimiter[0] = '|';
string strEnum = UIBESFItem.CboBox.DisplayName.ToString();
string[] strValues = strEnum.Split(delimiter);
int nEnumValue = Convert.ToInt32(strValues[cboIndex].Substring(strValues[cboIndex].IndexOf('=') + 1,
strValues[cboIndex].Length - strValues[cboIndex].IndexOf('=') - 1));
Type EnumType = dispMem.PropertyType;
PropertyValue = Enum.Parse(EnumType, nEnumValue.ToString());
}
else
{
ObjectTemplate otmp = UIBESFItem.CboBox.ComboSource.GetItem(cboIndex);
PropertyValue = otmp.GetType().GetProperty(UIBESFItem.CboBox.DataPropertyName).GetValue(otmp, null);
}
dispMem.SetValue(_Source, PropertyValue, null);
break;
case BESFControlEnum.Check:
int boolValue = Convert.ToInt32(((CheckBox)this.Controls[UIBESFItem.Name]).Checked);
dispMem.SetValue(_Source, ((CheckBox)this.Controls[UIBESFItem.Name]).Checked, null);
//Type EnumPrpType = dispMem.PropertyType;
//object desiredPropertyValue = Enum.Parse(EnumPrpType, boolValue.ToString());
//dispMem.SetValue(_Source, desiredPropertyValue, null);
break;
case BESFControlEnum.NumText:
dispMem.SetValue(_Source, Convert.ToDouble((((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).Value)), null);
break;
case BESFControlEnum.IntNumText:
dispMem.SetValue(_Source, Convert.ToInt32((((Ease.Controls.EaseNum)this.Controls[UIBESFItem.Name]).Value)), null);
break;
}
}
}
catch (Exception ex)
{
MessageBox.Show("falied to load object from controls. Check control and object datatypes are same. Error:" + ex.Message, "refresh object", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private bool InputValidation()
{
string[] inputValidation = new string[2];
System.Reflection.MethodInfo methodInfo = (_Source.GetType()).GetMethod("InputValidator");
if (methodInfo == null) MessageBox.Show("'InputValidator' function not exist in the source object.", "Input validator", MessageBoxButtons.OK, MessageBoxIcon.Information);
inputValidation = (string[])methodInfo.Invoke(_Source, null);
if (inputValidation != null)
{
//this.Controls[_singleForm.Controls.GetControl(inputValidation[1]).Name].Focus();
MessageBox.Show(inputValidation[0], this.Text + ": Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
return true;
}
#endregion
#region Events
private void btnSave_Click(object sender, EventArgs e)
{
try
{
this.RefreshObject();
this.TreeViewUpdate();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, ":Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
try
{
if (this.InputValidation() == false)
{
return;
}
System.Reflection.MethodInfo methodInfo = (_Source.GetType()).GetMethod("Save");
methodInfo.Invoke(_Source, null);
}
catch (Exception Ex)
{
Type[] types = new Type[1];
ConstructorInfo constructorInfoObj = _Source.GetType().GetConstructor(new Type[0]);
constructorInfoObj.Invoke(_Source, null);
MessageBox.Show("Failed to save into database: Error:" + Ex.InnerException.Message, ":Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
try
{
System.Reflection.PropertyInfo dispMem = (_Source.GetType()).GetProperty("IsNew");
bool isNew = Convert.ToBoolean(dispMem.GetValue(_Source, null).ToString());
if (isNew == true)
{
RefreshParent(_Source, e);
Type[] types = new Type[1];
ConstructorInfo constructorInfoObj = _Source.GetType().GetConstructor(new Type[0]);
constructorInfoObj.Invoke(_Source, null);
if (_singleForm.PropertyValue != null)
{
for (int i = 0; i <= _singleForm.PropertyValue.GetUpperBound(0); i++)
{
System.Reflection.PropertyInfo oProperty = (_Source.GetType()).GetProperty(_singleForm.PropertyValue[i, 0]);
if (oProperty.PropertyType.ToString() == "System.Int32")
{
oProperty.SetValue(_Source, Convert.ToInt32(_singleForm.PropertyValue[i, 1]), null);
}
}
}
this.RefreshControl();
}
else
{
this.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, ":Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void btnCncl_Click(object sender, EventArgs e)
{
this.Close();
}
#endregion
/// <summary>
/// Paint the bottom of the panel
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pnlBottom_Paint(object sender, PaintEventArgs e)
{
Rectangle BaseRectangle = new Rectangle(0, 0, this.pnlBottom.Width, this.pnlBottom.Height);
Brush Gradient_Brush = new LinearGradientBrush(BaseRectangle, System.Drawing.Color.DarkBlue, System.Drawing.Color.LightBlue, LinearGradientMode.Horizontal);
e.Graphics.FillRectangle(Gradient_Brush, BaseRectangle);
}
private void FrmBasicEntryForm_Paint(object sender, PaintEventArgs e)
{
//Rectangle BaseRectangle = new Rectangle(0, 0, this.Width, this.Height);
//Brush Gradient_Brush = new LinearGradientBrush(BaseRectangle, System.Drawing.Color.WhiteSmoke, System.Drawing.Color.Gainsboro, LinearGradientMode.Horizontal);
//e.Graphics.FillRectangle(Gradient_Brush, BaseRectangle);
}
private void FrmBasicEntryForm_Load(object sender, EventArgs e)
{
}
}
}