CEL_Payroll/Ease.UICreator/FrmMasterForm.cs

982 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.Drawing.Drawing2D;
using Ease.CoreV35.Model;
using Ease.CoreV35.Caching;
using Payroll.Report;
using Payroll.BO;
namespace Ease.UICreator
{
internal partial class FrmMasterForm : Form
{
#region variables
private MasterForm _masterForm;
private int _totColWid;
public event Ease.UICreator.UIConfiguration UpdateUIDesign;
#endregion
#region Constructor
public FrmMasterForm()
{
InitializeComponent();
}
#endregion
#region Property
public MasterForm UIBEMF
{
get
{
if (_masterForm == null)
{
_masterForm = new MasterForm();
}
return _masterForm;
}
set
{
_masterForm = value;
}
}
//public object[] RefreshMethodParams
//{
// get { return _refreshMethodParams; }
// set { _refreshMethodParams = value; }
//}
//public string RefreshMethodName
//{
// get { return _refreshMethod; }
// set { _refreshMethod = value; }
//}
#endregion
#region Functions
#region showDLg
public void showDLg(MasterForm UIBEMF)
{
try
{
_masterForm = UIBEMF;
_masterForm.Listviewcloumns.IsDuplicateCtlName();
if (CheckSpellListView())
{
this.Text = _masterForm.Caption;
CreateListView();
RefreshListview();
if (UpdateUIDesign != null)
{
this.Name = _masterForm.FormName;
UpdateUIDesign(this);
}
this.ShowDialog();
}
}
catch(Exception e)
{
MessageBox.Show("Error: " + e.Message, "For Devloper:");
}
}
public void showDLg()
{
try
{
_masterForm.Listviewcloumns.IsDuplicateCtlName();
if (CheckSpellListView())
{
this.Text = _masterForm.Caption;
CreateListView();
RefreshListview();
this.ShowDialog();
}
}
catch (Exception e)
{
MessageBox.Show("Error: " + e.Message, "For Devloper:");
}
}
#endregion
#region CreateListView
private void CreateListView()
{
_totColWid = 0;
int noOfCol = 0;
foreach (MasterFormlvw UIBEMFitem in _masterForm.Listviewcloumns)
{
_totColWid += UIBEMFitem.Width;
noOfCol++;
}
int imageIndex = 0;
if (_totColWid< this.lvwBEMF.Width-15)
{
int extraWidth = (this.lvwBEMF.Width-15) - _totColWid;
int devidedExtraWidth = (int)extraWidth / noOfCol;
foreach (MasterFormlvw UIBEMFitem in _masterForm.Listviewcloumns)
{
this.lvwBEMF.Columns.Add(UIBEMFitem.PropertyName, UIBEMFitem.Caption, UIBEMFitem.Width + devidedExtraWidth, UIBEMFitem.ColumnAlignment, imageIndex);
}
}
else
{
foreach (MasterFormlvw UIBEMFitem in _masterForm.Listviewcloumns)
{
this.lvwBEMF.Columns.Add(UIBEMFitem.PropertyName, UIBEMFitem.Caption, UIBEMFitem.Width, UIBEMFitem.ColumnAlignment, imageIndex);
}
}
}
#endregion
#region CheckSpellListView
private bool CheckSpellListView()
{
bool correct = true;
lvwBEMF.Items.Clear();
foreach (var item in _masterForm.SourceCollection)
{
int count = 0;
foreach (MasterFormlvw UIBEMFitem in _masterForm.Listviewcloumns)
{
count++;
System.Reflection.PropertyInfo dispMem = item.GetType().GetProperty(UIBEMFitem.PropertyName);
if (dispMem == null)
{
MessageBox.Show("The property name " + UIBEMFitem.PropertyName.ToString() + "\n" + "does not belong to the object " + (item.GetType()).Name.ToString());
correct = false;
break;
}
if (correct == false)
{
break;
}
}
}
return correct;
}
#endregion
#region RefreshListview
private void RefreshSourceCollection()
{
try
{
Type EnumPrpType = _masterForm.SingleForm.Source.GetType().GetProperty("Status").PropertyType;
object enumValue = Enum.Parse(EnumPrpType, Convert.ToString(0));
System.Type[] pararemterTypes = new System.Type[1];
pararemterTypes[0] = EnumPrpType;
System.Reflection.MethodInfo methodInfo=null;
if(_masterForm.GetFunctionName=="")
methodInfo = (_masterForm.SingleForm.Source.GetType()).GetMethod("Get", pararemterTypes);
else
methodInfo = (_masterForm.SingleForm.Source.GetType()).GetMethod(_masterForm.GetFunctionName, pararemterTypes);
object[] parameterValue = new object[1];
parameterValue[0] = enumValue;
object ox = methodInfo.Invoke(_masterForm.SingleForm.Source, parameterValue);
IList il = ox as IList;
this._masterForm.SourceCollection = new ObjectsTemplate<ObjectTemplate>();
foreach (var item in il)
{
this._masterForm.SourceCollection.Add((ObjectTemplate)item);
}
}
catch (Exception ex)
{
MessageBox.Show("failed to call the function: get(status). Actual reason:" + ex.Message, "failed to call", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
//this._masterForm.CopyCollList((ObjectsTemplate< ObjectTemplate > )ox);
//if (this.RefreshMethodName == "")
//{
// System.Reflection.MethodInfo methodInfo = (_masterForm.SingleForm.GetType()).GetMethod("Get", new Type[0]);
// object ox = methodInfo.Invoke(_masterForm.SingleForm, null);
// List<ObjectTemplate> items = (List < ObjectTemplate >) ox;
//}
//else
//{
// try
// {
// //System.Reflection.MethodInfo methodInfo = (_masterForm.SourceCollection.GetType()).GetMethod(RefreshMethodName);
// //_masterForm.SourceCollection = methodInfo.Invoke(_masterForm.SourceCollection, RefreshMethodParams);
// }
// catch (Exception e)
// {
// MessageBox.Show(e.Message + "For Developer");
// }
//}
}
private void RefreshListview()
{
lvwBEMF.Items.Clear();
foreach (var item in _masterForm.SourceCollection)
{
ListViewItem ListItem = null;
int i = 0;
foreach (MasterFormlvw UIBEMFitem in _masterForm.Listviewcloumns)
{
string str="";
if (UIBEMFitem.SourceCollection == null)
{
System.Reflection.PropertyInfo dispMem = item.GetType().GetProperty(UIBEMFitem.PropertyName);
if (dispMem.GetValue(item, null).GetType().FullName == "System.DateTime")
str =((DateTime)dispMem.GetValue(item, null)).ToString("dd MMM yyyy");
else str = dispMem.GetValue(item, null).ToString();
//lvwBEMF..BackColor = Color.Navy;
}
else
{
str = "";
}
str = str.Replace("\r\n", ", ");
str = str.Replace(",,", ",");
if (i == 0)
{
ListItem = new ListViewItem(str, 0);
}
else
{
ListItem.SubItems.Add(str);
}
i++;
}
ListItem.Tag = item;
this.lvwBEMF.Items.Add(ListItem);
}
}
#endregion
#endregion
#region Events
private void btnAdd_Click(object sender, EventArgs e)
{
FrmBasicEntryForm form = new FrmBasicEntryForm();
form.RefreshParent += new System.EventHandler(this.AddToColl);
form.IncpUIConfig += new UIConfiguration(this.SingleFormUIConfiguration);
form.ShowDialog(_masterForm.SingleForm, _masterForm.SingleForm.Source);
}
private void SingleFormUIConfiguration(System.Windows.Forms.Form frm)
{
if (UpdateUIDesign != null)
{
UpdateUIDesign(frm);
}
}
private void AddToColl(object sender, EventArgs e)
{
if (sender != null)
{
ObjectTemplate oTemplate = (ObjectTemplate)sender;
//_masterForm.SourceCollection.Add(oTemplate);
//RefreshSourceCollection();
//RefreshListview();
CollectAndLoadListView();
}
}
private void btnEdit_Click(object sender, EventArgs e)
{
if (!btnEdit.Enabled)
return;
if (lvwBEMF.SelectedItems.Count <=0)
{
MessageBox.Show("Select an Item", "Edit", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
ObjectTemplate oLocked = (ObjectTemplate)lvwBEMF.SelectedItems[0].Tag;
//object item = oLocked.GetType().GetProperty("Locked").GetValue(oLocked, null);
//object itemLocked = oLocked.GetType().GetProperty("Locked").GetValue(oLocked, null);
//if (!(bool)itemLocked)
//{
// MessageBox.Show("Inorder to edit first lock the record.", "Cannot Edit", MessageBoxButtons.OK, MessageBoxIcon.Stop);
// return;
//}
FrmBasicEntryForm form = new FrmBasicEntryForm();
form.IncpUIConfig += new UIConfiguration(this.SingleFormUIConfiguration);
form.ShowDialog(_masterForm.SingleForm,(ObjectTemplate)lvwBEMF.SelectedItems[0].Tag);
CollectAndLoadListView();
//RefreshSourceCollection();
//RefreshListview();
}
private void btnDel_Click(object sender, EventArgs e)
{
if (lvwBEMF.SelectedItems.Count <= 0)
{
MessageBox.Show("Select an Item", "Delete", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (MessageBox.Show("Are you sure to delete selected item.!", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
try
{
ObjectTemplate oDele =(ObjectTemplate) lvwBEMF.SelectedItems[0].Tag;
object[] obj = new object[1];
obj[0] = oDele.ID;
System.Reflection.MethodInfo methodInfoDel = (oDele.GetType()).GetMethod("Delete");
methodInfoDel.Invoke(oDele, obj);
_masterForm.SourceCollection.Remove(oDele.ID);
ListViewItem oLItem = lvwBEMF.SelectedItems[0];
lvwBEMF.Items.Remove(oLItem);
lvwBEMF.Refresh();
CollectAndLoadListView();
//RefreshSourceCollection();
//RefreshListview();
MessageBox.Show("Data deleted successfully. ", "Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception exp)
{
MessageBox.Show(exp.InnerException.Message, "Can't Delete", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void Active(object sender, EventArgs e)
{
//if (lvwBEMF.SelectedItems.Count <= 0)
//{
// MessageBox.Show("Select an Item", "Delete", MessageBoxButtons.OK, MessageBoxIcon.Information);
// return;
//}
//if (MessageBox.Show("Are you sure to delete selected item.!", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
//{
// return;
//}
//try
//{
// ObjectTemplate oDele = (ObjectTemplate)lvwBEMF.SelectedItems[0].Tag;
// object[] obj = new object[1];
// obj[0] = oDele.ID;
// Type EnumPrpType = _masterForm.SingleForm.Source.GetType().GetProperty("Status").PropertyType;
// object enumValue = Enum.Parse(EnumPrpType, Convert.ToString(1)); // 1 mean Active
// System.Reflection.PropertyInfo pinfo = (oDele.GetType()).GetProperty("Status");
// pinfo.SetValue(oDele, enumValue,null);
// System.Reflection.MethodInfo methodInfoDel = (oDele.GetType()).GetMethod("Save");
// methodInfoDel.Invoke(oDele, obj);
// _masterForm.SourceCollection.Remove(oDele.ID);
// lvwBEMF.Refresh();
// RefreshSourceCollection();
// RefreshListview();
// MessageBox.Show("Data deleted successfully. ", "Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information);
//}
//catch (Exception exp)
//{
// MessageBox.Show(exp.InnerException.Message, "Can't Delete", MessageBoxButtons.OK, MessageBoxIcon.Error);
//}
}
#endregion
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void lvwBEMF_ColumnClick(object sender, ColumnClickEventArgs e)
{
try
{
//object[] param = new object[2];
//param[0] = _masterForm.Listviewcloumns[e.Column].PropertyName;
//param[1] = System.Windows.Forms.SortOrder.Descending;
//System.Reflection.MethodInfo methodInfoDel = (_masterForm.SourceCollection.GetType()).GetMethod("Sort");
//if (methodInfoDel != null)
// methodInfoDel.Invoke(_masterForm.SourceCollection, param);
//RefreshListview();
ListViewSorter Sorter = new ListViewSorter();
lvwBEMF.ListViewItemSorter = Sorter;
if (!(lvwBEMF.ListViewItemSorter is ListViewSorter))
return;
Sorter = (ListViewSorter)lvwBEMF.ListViewItemSorter;
if (lvwBEMF.Sorting == SortOrder.Ascending)
lvwBEMF.Sorting = SortOrder.Descending;
else
lvwBEMF.Sorting = SortOrder.Ascending;
Sorter.ByColumn = e.Column;
lvwBEMF.Sort();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void lvwBEMF_SelectedIndexChanged(object sender, EventArgs e)
{
ObjectTemplate oDele = null;
try
{
if (lvwBEMF.SelectedItems.Count > 0)
{
oDele = (ObjectTemplate)lvwBEMF.SelectedItems[0].Tag;
object[] obj = new object[1];
obj[0] = oDele.ID;
object status = oDele.GetType().GetProperty("Status").GetValue(oDele, null);
//object oLocked = oDele.GetType().GetProperty("Locked").GetValue(oDele, null);
if (status.ToString() == "Active")
{
btnActive.Text = "InActive";
}
else
{
btnActive.Text = "Active";
}
//if (Convert.ToBoolean(oLocked))
//{
// btnLock.Text = "Unlock";
//}
//else
//{
// btnLock.Text = "Lock";
//}
}
}
catch (Exception exp)
{
MessageBox.Show(exp.InnerException.Message, "Active", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
//private void btnPreview_Click(object sender, EventArgs e)
//{
// Report report = new Report(_masterForm);
// report.ReportOutput(Ease.Report.Designer.OutputType.OutPutTypePreview);
//}
//private void btnPrint_Click(object sender, EventArgs e)
//{
// Report report = new Report(_masterForm);
// report.ReportOutput(Ease.Report.Designer.OutputType.OutPutTypePrint);
//}
//private void btnExport_Click(object sender, EventArgs e)
//{
// Report report = new Report(_masterForm);
// report.ReportOutput(Ease.Report.Designer.OutputType.OutPutTypeExportXL);
//}
private void FrmMasterForm_Load(object sender, EventArgs e)
{
}
/// <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.LightBlue, System.Drawing.Color.DarkBlue, LinearGradientMode.Vertical);
e.Graphics.FillRectangle(Gradient_Brush, BaseRectangle);
}
private void FrmMasterForm_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 btnActive_Click(object sender, EventArgs e)
{
if (lvwBEMF.SelectedItems.Count <= 0)
{
MessageBox.Show("Select an Item", "Active/InActive", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (MessageBox.Show("Are you sure to status change selected item.!", "Confirm Active/InActive", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
try
{
ObjectTemplate oActive = (ObjectTemplate)lvwBEMF.SelectedItems[0].Tag;
object[] obj = new object[1];
obj[0] = oActive.ID;
object status = oActive.GetType().GetProperty("Status").GetValue(oActive, null);
object enumValue = null;
if(status.ToString()=="Active")
{
Type EnumPrpType = _masterForm.SingleForm.Source.GetType().GetProperty("Status").PropertyType;
enumValue = Enum.Parse(EnumPrpType, Convert.ToString(2));
System.Reflection.PropertyInfo pinfo = (oActive.GetType()).GetProperty("Status");
pinfo.SetValue(oActive, enumValue, null);
System.Reflection.MethodInfo methodInfoDel = (oActive.GetType()).GetMethod("Save");
methodInfoDel.Invoke(oActive, null);
lvwBEMF.Refresh();
//RefreshSourceCollection();
//RefreshListview();
CollectAndLoadListView();
MessageBox.Show("Data InActive successfully. ", "InActive", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
//Modified By Chapal
//if (this._masterForm.FormName.ToLower() == "froles")
//{
// object createdBy = oActive.GetType().GetProperty("CreatedBy").GetValue(oActive, null);
// if (createdBy.ToString() == Payroll.BO.User.CurrentUser.ID.Integer.ToString())
// {
// MessageBox.Show("You cannot active this role.", "Failed to active", MessageBoxButtons.OK, MessageBoxIcon.Error);
// return;
// }
// System.Reflection.PropertyInfo pinfo1 = (oActive.GetType()).GetProperty("AuthorizedBy");
// pinfo1.SetValue(oActive, Payroll.BO.User.CurrentUser.ID, null);
//}
Type EnumPrpType = _masterForm.SingleForm.Source.GetType().GetProperty("Status").PropertyType;
enumValue = Enum.Parse(EnumPrpType, Convert.ToString(1));
System.Reflection.PropertyInfo pinfo = (oActive.GetType()).GetProperty("Status");
pinfo.SetValue(oActive, enumValue, null);
System.Reflection.MethodInfo methodInfoDel = (oActive.GetType()).GetMethod("Save");
methodInfoDel.Invoke(oActive, null);
lvwBEMF.Refresh();
//RefreshSourceCollection();
//RefreshListview();
CollectAndLoadListView();
MessageBox.Show("Data Activated successfully. ", "Activated", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception exp)
{
MessageBox.Show(exp.InnerException.Message, "Can't Active", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void btnUp_Click(object sender, EventArgs e)
{
try
{
if (lvwBEMF.SelectedItems.Count <= 0)
{
MessageBox.Show("Select an item to set sequence", "Can't Set Sequenct", MessageBoxButtons.OK, MessageBoxIcon.Warning);
lvwBEMF.Focus();
return;
}
if (lvwBEMF.Items.Count <= 1)
{
return;
}
int selectedRowIndex = lvwBEMF.Items.IndexOf(lvwBEMF.SelectedItems[0]);
if (selectedRowIndex < 1)
return;
ObjectTemplate oUp = (ObjectTemplate)lvwBEMF.SelectedItems[0].Tag;
ObjectTemplate oDown = (ObjectTemplate)lvwBEMF.Items[selectedRowIndex - 1].Tag;
//For Up Position
object UpsequenceNo = oUp.GetType().GetProperty("Sequence").GetValue(oUp, null);
object DWsequenceNo = oDown.GetType().GetProperty("Sequence").GetValue(oDown, null);
object TempSeq = UpsequenceNo;
UpsequenceNo = DWsequenceNo;
DWsequenceNo = TempSeq;
System.Reflection.PropertyInfo UPpinfo = (oUp.GetType()).GetProperty("Sequence");
UPpinfo.SetValue(oUp, UpsequenceNo, null);
System.Reflection.MethodInfo methodInfoUp = (oUp.GetType()).GetMethod("Save");
methodInfoUp.Invoke(oUp, null);
System.Reflection.PropertyInfo DWpinfo = (oDown.GetType()).GetProperty("Sequence");
UPpinfo.SetValue(oDown, DWsequenceNo, null);
System.Reflection.MethodInfo methodInfoDW = (oDown.GetType()).GetMethod("Save");
methodInfoDW.Invoke(oDown, null);
lvwBEMF.Refresh();
RefreshSourceCollection();
RefreshListview();
lvwBEMF.Items[selectedRowIndex - 1].Selected = true;
lvwBEMF.SelectedItems[0].BackColor = Color.Navy;
lvwBEMF.SelectedItems[0].ForeColor = Color.White;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Cannot Set Sequence", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
private void btnDown_Click(object sender, EventArgs e)
{
try
{
if (lvwBEMF.SelectedItems.Count <= 0)
{
MessageBox.Show("Select an item to set sequence", "Can't Set Sequenct", MessageBoxButtons.OK, MessageBoxIcon.Warning);
lvwBEMF.Focus();
return;
}
if (lvwBEMF.Items.Count <= 1)
{
return;
}
int selectedRowIndex = lvwBEMF.Items.IndexOf(lvwBEMF.SelectedItems[0]);
if (selectedRowIndex >= (lvwBEMF.Items.Count - 1))
return;
ObjectTemplate oUp = (ObjectTemplate)lvwBEMF.Items[selectedRowIndex + 1].Tag;
ObjectTemplate oDown = (ObjectTemplate)lvwBEMF.SelectedItems[0].Tag;
//For Down Position
object UpsequenceNo = oUp.GetType().GetProperty("Sequence").GetValue(oUp, null);
object DWsequenceNo = oDown.GetType().GetProperty("Sequence").GetValue(oDown, null);
object TempSeq = UpsequenceNo;
UpsequenceNo = DWsequenceNo;
DWsequenceNo = TempSeq;
System.Reflection.PropertyInfo UPpinfo = (oUp.GetType()).GetProperty("Sequence");
UPpinfo.SetValue(oUp, UpsequenceNo, null);
System.Reflection.MethodInfo methodInfoUp = (oUp.GetType()).GetMethod("Save");
methodInfoUp.Invoke(oUp, null);
System.Reflection.PropertyInfo DWpinfo = (oDown.GetType()).GetProperty("Sequence");
UPpinfo.SetValue(oDown, DWsequenceNo, null);
System.Reflection.MethodInfo methodInfoDW = (oDown.GetType()).GetMethod("Save");
methodInfoDW.Invoke(oDown, null);
lvwBEMF.Refresh();
RefreshSourceCollection();
RefreshListview();
lvwBEMF.Items[selectedRowIndex + 1].Selected = true;
lvwBEMF.SelectedItems[0].BackColor = Color.Navy;
lvwBEMF.SelectedItems[0].ForeColor = Color.White;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Cannot Set Sequence", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
private void CollectAndLoadListView()
{
Type EnumPrpType = _masterForm.SingleForm.Source.GetType().GetProperty("Status").PropertyType;
object enumValue;
if(chkActive.Checked==true)
enumValue = Enum.Parse(EnumPrpType, ((int)EnumStatus.Active).ToString());
else
enumValue = Enum.Parse(EnumPrpType, ((int)EnumStatus.Inactive).ToString());
System.Type[] pararemterTypes = new System.Type[1];
pararemterTypes[0] = EnumPrpType;
System.Reflection.MethodInfo methodInfo = null;
if (_masterForm.GetFunctionName == "")
{
methodInfo = (_masterForm.SingleForm.Source.GetType()).GetMethod("Get", pararemterTypes);
}
else
{
methodInfo = (_masterForm.SingleForm.Source.GetType()).GetMethod(_masterForm.GetFunctionName, pararemterTypes);
}
object[] parameterValue = new object[1];
parameterValue[0] = enumValue;
object ox = methodInfo.Invoke(_masterForm.SingleForm.Source, parameterValue);
IList il = ox as IList;
this._masterForm.SourceCollection = new ObjectsTemplate<ObjectTemplate>();
foreach (var item in il)
{
this._masterForm.SourceCollection.Add((ObjectTemplate)item);
}
RefreshListview();
}
private void chkActive_CheckedChanged(object sender, EventArgs e)
{
CollectAndLoadListView();
}
private void btnPreview_Click(object sender, EventArgs e)
{
DataSet dSet = new DataSet();
String RDLC = string.Empty;
ListView.ListViewItemCollection lsvCollection = this.lvwBEMF.Items;
DataTable oDataTable = null;
BasicReport oBasicReport = new BasicReport();
oDataTable = oBasicReport.CommonReport(lsvCollection);
oDataTable.TableName = "PayrollDataSet_BasicReport";
RDLC = "Payroll.Report.RDLC.BasicReport.rdlc";
dSet.Tables.Add(oDataTable);
fReportViewer form = new fReportViewer();
//_item = ReportItem.GetByReportType(Convert.ToInt32(_reportType));
//PrepareData();
form.ShowDlg(dSet, RDLC);
}
private void bttnClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnLock_Click(object sender, EventArgs e)
{
//if (lvwBEMF.SelectedItems.Count <= 0)
//{
// MessageBox.Show("Select an Item", "Lock/Unlock", MessageBoxButtons.OK, MessageBoxIcon.Information);
// return;
//}
//if (MessageBox.Show("Are you sure to lock selected item.!", "Confirm Lock/Unlock", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
//{
// return;
//}
//try
//{
// ObjectTemplate oLocked = (ObjectTemplate)lvwBEMF.SelectedItems[0].Tag;
// object[] obj = new object[1];
// obj[0] = oLocked.ID;
// object item = oLocked.GetType().GetProperty("Locked").GetValue(oLocked, null);
// object itemUSer = oLocked.GetType().GetProperty("ModifiedBy").GetValue(oLocked, null);
// object enumValue = null;
// if ((Boolean)item)
// {
// if (User.CurrentUser.ID.Integer ==Convert.ToInt16(itemUSer.ToString()))
// {
// Type EnumPrpType = _masterForm.SingleForm.Source.GetType().GetProperty("Locked").PropertyType;
// enumValue = false;
// System.Reflection.PropertyInfo pinfo = (oLocked.GetType()).GetProperty("Locked");
// pinfo.SetValue(oLocked, enumValue, null);
// System.Reflection.MethodInfo methodInfoDel = (oLocked.GetType()).GetMethod("Save");
// methodInfoDel.Invoke(oLocked, null);
// lvwBEMF.Refresh();
// RefreshSourceCollection();
// RefreshListview();
// MessageBox.Show("Data unlocked successfully. ", "Unlocked", MessageBoxButtons.OK, MessageBoxIcon.Information);
// }
// else
// {
// MessageBox.Show("This record is locked by another user\nYou cannot unlock this record. ", "Unlock Faild", MessageBoxButtons.OK, MessageBoxIcon.Error);
// }
// }
// else
// {
// Type EnumPrpType = _masterForm.SingleForm.Source.GetType().GetProperty("Locked").PropertyType;
// enumValue = true;
// System.Reflection.PropertyInfo pinfo = (oLocked.GetType()).GetProperty("Locked");
// pinfo.SetValue(oLocked, enumValue, null);
// System.Reflection.MethodInfo methodInfoDel = (oLocked.GetType()).GetMethod("Save");
// methodInfoDel.Invoke(oLocked, null);
// lvwBEMF.Refresh();
// RefreshSourceCollection();
// RefreshListview();
// MessageBox.Show("Data locked successfully. ", "Locked", MessageBoxButtons.OK, MessageBoxIcon.Information);
// }
//}
//catch (Exception exp)
//{
// MessageBox.Show(exp.InnerException.Message, "Can't Lock", MessageBoxButtons.OK, MessageBoxIcon.Error);
//}
}
private void btnAuthorized_Click(object sender, EventArgs e)
{
//if (lvwBEMF.SelectedItems.Count <= 0)
//{
// MessageBox.Show("Select an Item", "Authorize", MessageBoxButtons.OK, MessageBoxIcon.Information);
// return;
//}
//if (MessageBox.Show("Are you sure to authorize change selected item.!", "Confirm Authorize", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
//{
// return;
//}
//try
//{
// ObjectTemplate oAuthorizeed = (ObjectTemplate)lvwBEMF.SelectedItems[0].Tag;
// object[] obj = new object[1];
// obj[0] = oAuthorizeed.ID;
// object item = oAuthorizeed.GetType().GetProperty("Authorized").GetValue(oAuthorizeed, null);
// object itemLocked = oAuthorizeed.GetType().GetProperty("Locked").GetValue(oAuthorizeed, null);
// object enumValue = null;
// if ((bool)itemLocked)
// {
// MessageBox.Show("Selected item is locked,you canott authorize", "Authorization Failed", MessageBoxButtons.OK, MessageBoxIcon.Stop);
// return;
// }
// enumValue = true;
// System.Reflection.PropertyInfo pinfo = (oAuthorizeed.GetType()).GetProperty("Authorized");
// pinfo.SetValue(oAuthorizeed, enumValue, null);
// System.Reflection.MethodInfo methodInfoDel = (oAuthorizeed.GetType()).GetMethod("Save");
// methodInfoDel.Invoke(oAuthorizeed, null);
// lvwBEMF.Refresh();
// RefreshSourceCollection();
// RefreshListview();
// MessageBox.Show("Data authorized successfully. ", "Authorized", MessageBoxButtons.OK, MessageBoxIcon.Information);
//}
//catch (Exception exp)
//{
// MessageBox.Show(exp.InnerException.Message, "Can't Active", MessageBoxButtons.OK, MessageBoxIcon.Error);
//}
}
private void chkAuthorized_CheckedChanged(object sender, EventArgs e)
{
if (chkAuthorized.Checked == true)
{
chkAuthorized.Text = "Only Authorized";
Type EnumPrpType = _masterForm.SingleForm.Source.GetType().GetProperty("Authorized").PropertyType;
object enumValue = true;
System.Type[] pararemterTypes = new System.Type[1];
pararemterTypes[0] = EnumPrpType;
System.Reflection.MethodInfo methodInfo = null;
if (_masterForm.GetFunctionName == "")
{
methodInfo = (_masterForm.SingleForm.Source.GetType()).GetMethod("Get", pararemterTypes);
}
else
{
methodInfo = (_masterForm.SingleForm.Source.GetType()).GetMethod(_masterForm.GetFunctionName, pararemterTypes);
}
object[] parameterValue = new object[1];
parameterValue[0] = enumValue;
object ox = methodInfo.Invoke(_masterForm.SingleForm.Source, parameterValue);
IList il = ox as IList;
this._masterForm.SourceCollection = new ObjectsTemplate<ObjectTemplate>();
foreach (var item in il)
{
this._masterForm.SourceCollection.Add((ObjectTemplate)item);
}
}
else
{
chkAuthorized.Text = "All Data";
Type EnumPrpType = _masterForm.SingleForm.Source.GetType().GetProperty("Authorized").PropertyType;
object enumValue = false;
System.Type[] pararemterTypes = new System.Type[1];
pararemterTypes[0] = EnumPrpType;
System.Reflection.MethodInfo methodInfo = null;
if (_masterForm.GetFunctionName == "")
{
methodInfo = (_masterForm.SingleForm.Source.GetType()).GetMethod("Get", pararemterTypes);
}
else
{
methodInfo = (_masterForm.SingleForm.Source.GetType()).GetMethod(_masterForm.GetFunctionName, pararemterTypes);
}
object[] parameterValue = new object[1];
parameterValue[0] = enumValue;
object ox = methodInfo.Invoke(_masterForm.SingleForm.Source, parameterValue);
IList il = ox as IList;
this._masterForm.SourceCollection = new ObjectsTemplate<ObjectTemplate>();
foreach (var item in il)
{
this._masterForm.SourceCollection.Add((ObjectTemplate)item);
}
}
RefreshListview();
}
}
}
public class ListViewSorter : System.Collections.IComparer
{
public int Compare(object o1, object o2)
{
if (!(o1 is ListViewItem))
return (0);
if (!(o2 is ListViewItem))
return (0);
ListViewItem lvi1 = (ListViewItem)o2;
string str1 = lvi1.SubItems[ByColumn].Text;
ListViewItem lvi2 = (ListViewItem)o1;
string str2 = lvi2.SubItems[ByColumn].Text;
int result;
if (lvi1.ListView.Sorting == SortOrder.Ascending)
result = String.Compare(str1, str2);
else
result = String.Compare(str2, str1);
LastSort = ByColumn;
return (result);
}
public int ByColumn
{
get { return Column; }
set { Column = value; }
}
int Column = 0;
public int LastSort
{
get { return LastColumn; }
set { LastColumn = value; }
}
int LastColumn = 0;
}