ab56a9bcf7
SVN-Revision: r240
412 lines
15 KiB
C#
412 lines
15 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using Lskj.Control;
|
|
using Lskj.Control.Model;
|
|
using Lskj.Util;
|
|
using Lskj.Data;
|
|
using Lskj.Model;
|
|
using DevExpress.XtraScheduler;
|
|
using Lskj.Business.Impl;
|
|
using DevExpress.Utils.Menu;
|
|
using Lskj.Control.Model.MenuStrip;
|
|
|
|
namespace Lskj.Gantt
|
|
{
|
|
public partial class FrmMain : BaseForm
|
|
{
|
|
|
|
#region 公有字段
|
|
/// <summary>
|
|
/// 系统模块模型
|
|
/// </summary>
|
|
public DynamicGanttModel SysModel;
|
|
/// <summary>
|
|
/// 基础模型
|
|
/// </summary>
|
|
public ModuleModel ModuleObj;
|
|
/// <summary>
|
|
/// 搜索框
|
|
/// </summary>
|
|
public MyControl SearchObj;
|
|
#endregion
|
|
|
|
#region 私有字段
|
|
/// <summary>
|
|
/// 映射字段
|
|
/// </summary>
|
|
private DataColumnCollection _dtMapping;
|
|
/// <summary>
|
|
/// 当前任务Id
|
|
/// </summary>
|
|
private string _currentId;
|
|
/// <summary>
|
|
/// 映射字段串
|
|
/// </summary>
|
|
private string _mappingStr;
|
|
/// <summary>
|
|
/// 菜单数据
|
|
/// </summary>
|
|
private DataTable dtMenuList;
|
|
#endregion
|
|
|
|
public FrmMain()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
/// <summary>
|
|
/// <para>说明:窗体加载时</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-23 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
protected override void OnLoad(EventArgs e)
|
|
{
|
|
WaitForm.ShowForm();
|
|
try
|
|
{
|
|
this.SysModel.Privilege = SysModel.ModuleId > 0 ? BaseImpl.GetUserPurviewsByMenuId(SysModel.ModuleId + "") + "" : BaseImpl.GetUserPurviewsByMenuCode(SysModel.ModuleCode) + "";
|
|
if (!this.SysModel.HasPrivilege())
|
|
{
|
|
MessageUtil.Show(ResourceKeys.UnPurview);
|
|
this.Close();
|
|
}
|
|
else
|
|
{
|
|
this.splitContainerControl.Visible = false;
|
|
this.ModuleObj = new ModuleModel(MainImpl.GetSystemdllTab(this.SysModel.ModuleCode));
|
|
this.InitializeSetting();
|
|
this.InitializeView();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Instance.WriteError(ex, ResourceKeys.BaseModuleAudit);
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message,ex.Message);
|
|
}
|
|
finally
|
|
{
|
|
Lskj.Control.Model.AutoSizeChange.ControllInitializeSize(this);
|
|
WaitForm.HideForm();
|
|
this.splitContainerControl.Visible = true;
|
|
}
|
|
|
|
}
|
|
|
|
#region 初始化设置
|
|
/// <summary>
|
|
/// <para>说明:初始化设置</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-23 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void InitializeSetting()
|
|
{
|
|
//开始日程
|
|
this.schedulerControl.Start = DateTime.Now;
|
|
this.SetMappings(this.schedulerControl);
|
|
this.SetLabelColor(this.schedulerStorage1);
|
|
////设置资源
|
|
schedulerControl.GroupType = SchedulerGroupType.Resource;
|
|
this.dtMenuList = BaseModuleImpl.GetBaseGridRightMenus(this.SysModel.ModuleCode);
|
|
GetMappingStr();
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region 拼接映射字段串
|
|
/// <summary>
|
|
/// <para>说明:拼接映射字段串</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-23 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void GetMappingStr()
|
|
{
|
|
for (int i = 1; i < _dtMapping.Count; i++)
|
|
{
|
|
_mappingStr += _dtMapping[i].ColumnName + ",";
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 设置资源树的映射关系
|
|
/// <summary>
|
|
/// <para>说明:设置资源树的映射关系</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-23 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void SetMappings(SchedulerControl schedulerControl)
|
|
{
|
|
//获取映射关系字段
|
|
_dtMapping = BaseImpl.GetTableColumns(this.ModuleObj.MenuTable).Columns;
|
|
if (_dtMapping.Count < 0)
|
|
{
|
|
MessageUtil.Show(ResourceKeys.ModuleConfigError);
|
|
return;
|
|
}
|
|
AppointmentMappingInfo appoint = schedulerControl.Storage.Appointments.Mappings;
|
|
appoint.AppointmentId = _dtMapping[0].ColumnName;
|
|
appoint.ResourceId = _dtMapping[1].ColumnName;
|
|
appoint.Subject = _dtMapping[2].ColumnName;
|
|
appoint.Description = _dtMapping[3].ColumnName;
|
|
appoint.Start = _dtMapping[4].ColumnName;
|
|
appoint.End = _dtMapping[5].ColumnName;
|
|
appoint.AllDay = _dtMapping[6].ColumnName;
|
|
appoint.Label = _dtMapping[7].ColumnName;
|
|
appoint.Location = _dtMapping[8].ColumnName;
|
|
appoint.PercentComplete = _dtMapping[9].ColumnName;
|
|
appoint.RecurrenceInfo = _dtMapping[10].ColumnName;
|
|
appoint.ReminderInfo = _dtMapping[11].ColumnName;
|
|
appoint.Type = _dtMapping[12].ColumnName;
|
|
}
|
|
#endregion
|
|
|
|
#region 初始化控件
|
|
/// <summary>
|
|
/// <para>说明:初始化控件</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-23 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void InitializeView()
|
|
{
|
|
try
|
|
{
|
|
this.SearchObj = new MyControl(this.ModuleObj.MenuSql, null);
|
|
this.SearchObj.InitSearchControl(BaseModuleImpl.GetCustomQueryFields(this.ModuleObj.CondKey), this.pl_top, null);
|
|
this.SearchObj.OnSearchBeforeCallBack += new SearchEventHandler(SearchObj_OnSearchBefore);
|
|
//绑定任务条和资源树数据
|
|
this.schedulerStorage1.Appointments.DataSource = BaseImpl.GetDataTableResult(this.ModuleObj.MenuSql);
|
|
this.schedulerStorage1.Resources.DataSource = BaseImpl.GetDataTableResult(BaseModuleImpl.GetBaseLeftTreeField(this.SysModel.ModuleCode)["fieldsql"] + "");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message,ex.Message);
|
|
}
|
|
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region 初始化自定义搜索
|
|
/// <summary>
|
|
/// <para>说明:初始化自定义搜索</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-02-27</para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void SearchObj_OnSearchBefore(object sender, SearchArgs e)
|
|
{
|
|
try
|
|
{
|
|
DataTable dt = this.schedulerStorage1.Appointments.DataSource as DataTable;
|
|
DataRow[] dr = dt.Select("1=1" + this.SearchObj.SetSearchSqlValue(""));
|
|
if (dr != null) this.schedulerControl1.Start = Convert.ToDateTime(dr[0][_dtMapping[4].ColumnName]);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message,ex.Message);
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region 刷新任务数据源
|
|
/// <summary>
|
|
/// <para>说明:刷新任务数据源</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-26 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void RefreshAppointments()
|
|
{
|
|
this.schedulerStorage1.Appointments.DataSource = ScheduderImpl.GetAppointments(this.ModuleObj.MenuTable);
|
|
this.schedulerControl.RefreshData();
|
|
}
|
|
#endregion
|
|
|
|
#region 设置任务时间阶段
|
|
/// <summary>
|
|
/// <para>说明:设置任务时间阶段</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-26 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void SetLabelColor(SchedulerStorage storage)
|
|
{
|
|
storage.Appointments.Labels.Clear();
|
|
storage.Appointments.Labels.Add(new AppointmentLabel(Color.Yellow, "生产中"));
|
|
storage.Appointments.Labels.Add(new AppointmentLabel(Color.LightBlue, "生产完成"));
|
|
storage.Appointments.Labels.Add(new AppointmentLabel(Color.Pink, "回炉"));
|
|
storage.Appointments.Labels.Add(new AppointmentLabel(Color.DarkSeaGreen, "其它"));
|
|
}
|
|
#endregion
|
|
|
|
#region 菜单配置
|
|
/// <summary>
|
|
/// <para>说明:设置任务菜单</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-26 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void schedulerControl_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
SchedulerControl control = this.schedulerControl;
|
|
Appointment appointment = control.SelectedAppointments.Cast<Appointment>().FirstOrDefault();
|
|
AppointmentMenuStrip appoint = new AppointmentMenuStrip();
|
|
if (e.Menu.Id == SchedulerMenuItemId.AppointmentMenu)
|
|
{
|
|
appoint.SetRightMenus(this.schedulerStorage1, appointment, dtMenuList, this.SysModel, null, null, e);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message,ex.Message);
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region 修改
|
|
/// <summary>
|
|
/// <para>说明:任务更改</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-26 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void schedulerStorage1_AppointmentsChanged(object sender, PersistentObjectsEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
Appointment appointment = (Appointment)e.Objects[0];
|
|
DataRowView rowView = appointment.GetRow(this.schedulerStorage1) as DataRowView;
|
|
|
|
if (appointment.Id != null)
|
|
{
|
|
string updateField = string.Empty;
|
|
foreach (DataColumn col in _dtMapping)
|
|
{
|
|
if (col.ColumnName == _dtMapping[0].ColumnName) continue;
|
|
updateField += string.Format("{0}='{1}',", col.ColumnName, rowView.Row[col.ColumnName]);
|
|
}
|
|
int result = ScheduderImpl.UpdateAppointment(this.ModuleObj.MenuTable, updateField, _dtMapping[0].ColumnName, appointment.Id + "");
|
|
MessageUtil.Show(result > 0 ? ResourceKeys.UpdateAppointmentSuccess : ResourceKeys.UpdateAppointmentFail);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message,ex.Message);
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region 删除
|
|
/// <summary>
|
|
/// <para>说明:任务删除</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-26 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void schedulerStorage1_AppointmentsDeleted(object sender, PersistentObjectsEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
Appointment appointment = (Appointment)e.Objects[0];
|
|
DataRowView rowView = appointment.GetRow(this.schedulerStorage1) as DataRowView;
|
|
if (appointment.Id != null)
|
|
{
|
|
int result = ScheduderImpl.DeleteAppointment(this.ModuleObj.MenuTable, appointment.Id + "", _dtMapping[0].ColumnName);
|
|
MessageUtil.Show(result > 0 ? ResourceKeys.DeleteSuccess : ResourceKeys.DeleteFault);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message,ex.Message);
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region 添加
|
|
/// <summary>
|
|
/// <para>说明:任务添加</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-26 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void schedulerStorage1_AppointmentsInserted(object sender, PersistentObjectsEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
//添加
|
|
Appointment appoint = (Appointment)e.Objects[0];
|
|
DataRowView rowView = appoint.GetRow(this.schedulerStorage1) as DataRowView;
|
|
object id = ScheduderImpl.InsertAppointment(this.ModuleObj.MenuTable, _mappingStr, rowView.Row);
|
|
this.schedulerStorage1.SetAppointmentId(appoint, id);
|
|
MessageUtil.Show(id != null ? ResourceKeys.InsertAppointmentSuccess : ResourceKeys.InsertAppointmentFail);
|
|
RefreshAppointments();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message,ex.Message);
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
}
|
|
}
|