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 公有字段 /// /// 系统模块模型 /// public DynamicGanttModel SysModel; /// /// 基础模型 /// public ModuleModel ModuleObj; /// /// 搜索框 /// public MyControl SearchObj; #endregion #region 私有字段 /// /// 映射字段 /// private DataColumnCollection _dtMapping; /// /// 当前任务Id /// private string _currentId; /// /// 映射字段串 /// private string _mappingStr; /// /// 菜单数据 /// private DataTable dtMenuList; #endregion public FrmMain() { InitializeComponent(); } /// /// 说明:窗体加载时 /// 创建人:龚宇超 /// 创建日期:2018-03-23 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// 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 初始化设置 /// /// 说明:初始化设置 /// 创建人:龚宇超 /// 创建日期:2018-03-23 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// 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 拼接映射字段串 /// /// 说明:拼接映射字段串 /// 创建人:龚宇超 /// 创建日期:2018-03-23 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void GetMappingStr() { for (int i = 1; i < _dtMapping.Count; i++) { _mappingStr += _dtMapping[i].ColumnName + ","; } } #endregion #region 设置资源树的映射关系 /// /// 说明:设置资源树的映射关系 /// 创建人:龚宇超 /// 创建日期:2018-03-23 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// 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 初始化控件 /// /// 说明:初始化控件 /// 创建人:龚宇超 /// 创建日期:2018-03-23 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// 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 初始化自定义搜索 /// /// 说明:初始化自定义搜索 /// 创建人:龚宇超 /// 创建日期:2018-02-27 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// 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 刷新任务数据源 /// /// 说明:刷新任务数据源 /// 创建人:龚宇超 /// 创建日期:2018-03-26 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void RefreshAppointments() { this.schedulerStorage1.Appointments.DataSource = ScheduderImpl.GetAppointments(this.ModuleObj.MenuTable); this.schedulerControl.RefreshData(); } #endregion #region 设置任务时间阶段 /// /// 说明:设置任务时间阶段 /// 创建人:龚宇超 /// 创建日期:2018-03-26 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// 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 菜单配置 /// /// 说明:设置任务菜单 /// 创建人:龚宇超 /// 创建日期:2018-03-26 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void schedulerControl_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e) { try { SchedulerControl control = this.schedulerControl; Appointment appointment = control.SelectedAppointments.Cast().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 修改 /// /// 说明:任务更改 /// 创建人:龚宇超 /// 创建日期:2018-03-26 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// 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 删除 /// /// 说明:任务删除 /// 创建人:龚宇超 /// 创建日期:2018-03-26 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// 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 添加 /// /// 说明:任务添加 /// 创建人:龚宇超 /// 创建日期:2018-03-26 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// 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 } }