Files
lserp_cs_5.0/插件库/Lskj.IntervalView/Lskj.IntervalView/FrmMain.cs
T
2026-07-10 15:25:05 +08:00

1317 lines
60 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 Microsoft.Win32;
using System.Data.SqlClient;
using DevExpress.XtraScheduler;
using System.Collections;
using System.Threading;
using DevExpress.XtraScheduler.Services;
using DevExpress.XtraScheduler.Commands;
using DevExpress.Utils.Menu;
using CommonLib;
using DevExpress.Utils;
using DevExpress.XtraScheduler.Drawing;
using DevExpress.Utils.Controls;
using CommonLib.data;
using CommonLib.utils;
using DevExpress.XtraEditors;
using Lskj.Common;
using System.Diagnostics;
using Lskj.Common.ComfirmDialog;
namespace Lskj.IntervalView
{
public partial class FrmMain : FormBase
{
private string dirid;
private string addModel;
public string appointId;
public FrmMain()
{
InitializeComponent();
}
/// <summary>
/// 初始加载
/// </summary>
/// <param name="e"></param>
protected override void OnLoad(EventArgs e)
{
SetMappings(this.schedulerControl1);
SetLabeColor(this.schedulerStorage1);
initLoad();
base.OnLoad(e);
}
private DataTable Mapping = new DataTable();
private void SetMappings(SchedulerControl control)
{
var dt = getColumn();
Mapping = dt;
//string str = "";
//for (int a = 0; a < Mapping.Rows.Count; a++)
//{
// str = str + Mapping.Rows[a][Name] + ",";
//}
AppointmentMappingInfo appoint = control.Storage.Appointments.Mappings;
appoint.AppointmentId = dt.Rows[0]["name"] + "";
appoint.ResourceId = dt.Rows[1]["name"] + "";
appoint.Subject = dt.Rows[2]["name"] + "";
appoint.Description = dt.Rows[3]["name"] + "";
appoint.Start = dt.Rows[4]["name"] + "";
appoint.End = dt.Rows[5]["name"] + "";
appoint.AllDay = dt.Rows[6]["name"] + "";
appoint.Label = dt.Rows[7]["name"] + "";
appoint.Location = dt.Rows[8]["name"] + "";
appoint.PercentComplete = dt.Rows[9]["name"] + "";
appoint.RecurrenceInfo = dt.Rows[10]["name"] + "";
appoint.ReminderInfo = dt.Rows[11]["name"] + "";
appoint.Type = dt.Rows[12]["name"] + "";
//string s = string.Format("select column_prefix,* from p_systemtables where table_name='{0}'", tb);
//DataTable dts = SqlHelper.ExecuteDataTable(s);
//AppointmentMappingInfo appoint = control.Storage.Appointments.Mappings;
//appoint.AppointmentId = dts.Rows[0]["column_prefix"] + "";
//appoint.ResourceId = dts.Rows[0]["column_prefix"] + "";
//appoint.Subject = dts.Rows[0]["column_prefix"] + "";
//appoint.Description = dts.Rows[0]["column_prefix"] + "";
//appoint.Start = dts.Rows[0]["column_prefix"] + "";
//appoint.End = dts.Rows[0]["column_prefix"] + "";
//appoint.AllDay = dts.Rows[0]["column_prefix"] + "";
//appoint.Label = dts.Rows[0]["column_prefix"] + "";
//appoint.Location = dts.Rows[0]["column_prefix"] + "";
//appoint.PercentComplete = dts.Rows[0]["column_prefix"] + "";
//appoint.RecurrenceInfo = dts.Rows[0]["column_prefix"] + "";
//appoint.ReminderInfo = dts.Rows[0]["column_prefix"] + "";
//appoint.Type = dts.Rows[0]["column_prefix"] + "";
}
/// <summary>
/// 进度条编辑允许
/// </summary>
/// <param name="sc"></param>
//private void AppointmentBoolEdits(DevExpress.XtraScheduler.SchedulerControl sc)
//{
// sc.OptionsCustomization.AllowAppointmentCreate = DevExpress.XtraScheduler.UsedAppointmentType.All;
// sc.OptionsCustomization.AllowAppointmentDelete = DevExpress.XtraScheduler.UsedAppointmentType.All;
// sc.OptionsCustomization.AllowAppointmentEdit = DevExpress.XtraScheduler.UsedAppointmentType.All;
// sc.OptionsCustomization.AllowAppointmentDrag = DevExpress.XtraScheduler.UsedAppointmentType.All;
// sc.OptionsCustomization.AllowAppointmentMultiSelect = true;
// sc.OptionsRangeControl.AllowChangeActiveView = true;
// sc.Views.MonthView.CompressWeekend = true;
// sc.OptionsBehavior.ShowRemindersForm = true;
//}
private DataTable MenuList = new DataTable();
/// <summary>
/// 初步加载
/// </summary>
/// 创建人:姜棚
/// 创建日期:2017-09-13
/// 修改人:
/// 修改日期:
/// 修改备注:无
public void initLoad()
{
//string connectionStr = ReadConfig();
DataTable resouceTable = new DataTable();
DataTable dependenceTable = new DataTable();
DataTable taskTabel = new DataTable();
if (DBConfig.Instance.CreateConnection())
{
try
{
string sqls = string.Format("select top 1 fieldsql,* from P_systemwordbooktab where tab='{0}' and fieldsqltag=3", DLLCoid);
DataTable dt = SqlHelper.ExecuteDataTable(sqls);
if (dt.Rows.Count > 0)
{
resouceTable = SqlHelper.ExecuteDataTable(dt.Rows[0]["fieldsql"] + "");
}
//string sql = "select * from Resources";
//resouceTable = SqlHelper.ExecuteDataTable(sql);
//string sql = "select TM_tagID,* from p_systemwordbooktab where tab='WBS0002' and isnull(vislble,0)=0";
string sql2 = string.Format("select * from P_systemdlltab where dllcoid='{0}'", DLLCoid);
DataTable dts = SqlHelper.ExecuteDataTable(sql2);
if (dts.Rows.Count > 0)
{
taskTabel = SqlHelper.ExecuteDataTable(dts.Rows[0]["sql"] + ""); //加个AppointmentId作为查询条件
dirid = dts.Rows[0]["dirid"] + "";
addModel = dts.Rows[0]["AddDllName"] + "";
}
string str = "select * from P_systempopupmenu where visible=0 and tab='" + DLLCoid + "' and isnull(menutype,0)=0 and visible1=0 order by orderid";
MenuList = SqlHelper.ExecuteDataTable(str);
//string sql2 = "select * from Task";
//taskTabel = SqlHelper.ExecuteDataTable(sql2);
//string sql3 = "select * from TaskDependencies"; //依赖先不处理
//dependenceTable = SqlHelper.ExecuteDataTable(sql3);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
//绑定数据
this.schedulerStorage1.Appointments.DataSource = taskTabel;
//this.schedulerStorage1.AppointmentDependencies.DataSource = dependenceTable; 依赖先不处理
this.schedulerStorage1.Resources.DataSource = resouceTable;
}
private DataTable getColumn()
{
DataTable dts = new DataTable();
DataTable dtt = new DataTable();
if (DBConfig.Instance.CreateConnection())
{
string sql2 = string.Format("select SQLDT1,sql, * from P_systemdlltab where DLLCoid='{0}'", DLLCoid);
dts = SqlHelper.ExecuteDataTable(sql2);
if (dts.Rows.Count > 0)
{
tb = dts.Rows[0]["SQLDT1"] + "";
}
string sql = @"SELECT name FROM syscolumns WHERE (id =(SELECT id FROM sysobjects WHERE (id = OBJECT_ID('" + tb + "')))) ORDER BY colid";
dtt = SqlHelper.ExecuteDataTable(sql);
}
return dtt;
}
string tb = ""; //table表名
private object Id = 0;
/// <summary>
/// 添加任务
/// </summary>
/// 创建人:姜棚
/// 创建日期:2017-09-13
/// 修改人:
/// 修改日期:
/// 修改备注:无
/// <param name="sender"></param>
/// <param name="e"></param>
private void schedulerStorage1_AppointmentsInserted(object sender, PersistentObjectsEventArgs e)
{
DataTable dt = new DataTable();
string sql2 = string.Format("select SQLDT1,sql, * from P_systemdlltab where DLLCoid='{0}'", DLLCoid);
DataTable dts = SqlHelper.ExecuteDataTable(sql2);
if (dts.Rows.Count > 0)
{
tb = dts.Rows[0]["SQLDT1"] + "";
}
//粘贴
if (e == null)
{
string sqlt = string.Format(@"insert into {0} select " + Mapping.Rows[1]["name"] + "," + Mapping.Rows[2]["name"] + "," + Mapping.Rows[3]["name"] + "," + Mapping.Rows[4]["name"] + ","
+ Mapping.Rows[5]["name"] + "," + Mapping.Rows[6]["name"] + "," + Mapping.Rows[7]["name"] + "," + Mapping.Rows[8]["name"] + "," + Mapping.Rows[9]["name"] + "," + Mapping.Rows[10]["name"] + "," + Mapping.Rows[11]["name"] + "," + Mapping.Rows[12]["name"] + " from {0} where {1}='{2}'", tb, Mapping.Rows[0]["name"], CurrentId);
var d = SqlHelper.ExecuteNonQuery(sqlt);
//string sql = string.Format("Update {0} set " + Mapping.Rows[5]["name"] + "={1}" + Mapping.Rows[6]["name"] + "={2} where "+Mapping.Rows[6]["name"]+"={3}" , tab);
}
else
{
//触发事件流程条
Appointment apt = (Appointment)e.Objects[0];
DataRowView rowview = apt.GetRow(this.schedulerStorage1) as DataRowView;
DataRow row = rowview.Row;
var dtt = getColumn();
string str = String.Format(@"insert into {0}(" + dtt.Rows[1]["name"] + "," + dtt.Rows[2]["name"] + "," + dtt.Rows[3]["name"] + "," + dtt.Rows[4]["name"] + "," + dtt.Rows[5]["name"] + "," + dtt.Rows[6]["name"] + "," + dtt.Rows[7]["name"] + "," + dtt.Rows[8]["name"] + "," + dtt.Rows[9]["name"] + "," + dtt.Rows[10]["name"] + "," + dtt.Rows[11]["name"] + "," + dtt.Rows[12]["name"] + ")values('" + row.ItemArray[1] + "" + "','" + row.ItemArray[2] + "" + "','" + row.ItemArray[3] + "" + "','" +
row.ItemArray[4] + "" + "','" + row.ItemArray[5] + "" + "','" + row.ItemArray[6] + "" + "','" + row.ItemArray[7] + "" + "','" + row.ItemArray[8] + "" + "','" + row.ItemArray[9] + "" + "','" + row.ItemArray[10] + "" + "','" + row.ItemArray[11] + "" + "','" + row.ItemArray[12] + "" + "'" + ");Select @@identity", tb);
try
{
if (DBConfig.Instance.CreateConnection())
{
// 执行sql句等等
Id = SqlHelper.ExecuteScalar(CommandType.Text, str);
//返回添加数据自增Id
//Id = sqlcmd.ExecuteScalar();
if (Id != null)
{
//String sql = @"update Resources set Progress='" + row["PercentComplete"] + "%'" + " " + "where Id='" + row["ResourceId"] + "'";
//SqlHelper.ExecuteNonQuery(sql);
MessageBox.Show("添加成功");
}
else
{
MessageBox.Show("添加失败");
}
}
}
catch (Exception ex)
{
throw ex;
MessageBox.Show(ex.Message);
}
finally
{
//(网上也存在此问题)由于这里会存在刚添加的数据删除修改取不到Id,所以赋值一次ID
this.schedulerStorage1.SetAppointmentId((Appointment)e.Objects[0], Id);
}
}
RefreshMain();
}
/// <summary>
/// 删除任务
/// </summary>
/// 创建人:姜棚
/// 创建日期:2017-09-13
/// 修改人:
/// 修改日期:
/// 修改备注:无
/// <param name="sender"></param>
/// <param name="e"></param>
private void schedulerStorage1_AppointmentsDeleted(object sender, PersistentObjectsEventArgs e)
{
Appointment apt = (Appointment)e.Objects[0];
if (apt.Id != null)
{
if (DBConfig.Instance.CreateConnection())
{
string sql = string.Format("delete from {1} where {2}={0}", apt.Id, tb, Mapping.Rows[0]["name"]);
var a = SqlHelper.ExecuteNonQuery(sql);
try
{
if (a > 0)
{
MessageBox.Show("删除成功");
// string str = @"update Resources set Progress='" + 0 + "' " + "where Id=(select ResourceId from Task where Id=" + apt.Id + ")";
// SqlHelper.ExecuteNonQuery(str);
}
else
{
MessageBox.Show("删除失败");
}
}
catch (Exception ex)
{
throw ex;
}
}
}
}
/// <summary>
/// 更改任务
/// </summary>
/// 创建人:姜棚
/// 创建日期:2017-09-13
/// 修改人:
/// 修改日期:
/// 修改备注:无
/// <param name="sender"></param>
/// <param name="e"></param>
private void schedulerStorage1_AppointmentsChanged(object sender, PersistentObjectsEventArgs e)
{
Appointment apt = (Appointment)e.Objects[0];
DataRowView rowview = apt.GetRow(this.schedulerStorage1) as DataRowView;
DataRow row = rowview.Row;
if (apt.Id != null)
{
if (DBConfig.Instance.CreateConnection())
{
string sql = string.Format(@"update {0} set" + " " + Mapping.Rows[1]["name"] + "='" + row.ItemArray[1] + "'," + Mapping.Rows[2]["name"] + "='" + row.ItemArray[2] + "'," + Mapping.Rows[3]["name"] + "='" + row.ItemArray[3] + "'," + Mapping.Rows[4]["name"] + "='" + row.ItemArray[4] + "'," + Mapping.Rows[5]["name"] + "='" + row.ItemArray[5] + "'," + Mapping.Rows[6]["name"] + "='" + row.ItemArray[6] + "'," + Mapping.Rows[7]["name"] + "='" + row.ItemArray[7] + "'," + Mapping.Rows[8]["name"] + "='" + row.ItemArray[8]
+ "'," + Mapping.Rows[9]["name"] + "='" + row.ItemArray[9] + "'," + Mapping.Rows[10]["name"] + "='" + row.ItemArray[10] + "'," + Mapping.Rows[11]["name"] + "='" + row.ItemArray[11] + "' " + "where {1}=" + apt.Id, tb, Mapping.Rows[0]["name"]);
try
{
var a = SqlHelper.ExecuteNonQuery(sql);
if (a > 0)
{
//string sql2 = @"update Resources set Progress='" + row["PercentComplete"] + "%'" + " " + "where Id='" + row["ResourceId"] + "'";
//var z = SqlHelper.ExecuteNonQuery(sql2);
//if (z > 0)
MessageBox.Show("数据已经更新");
}
else
{
}
}
catch (Exception ex)
{
throw ex;
}
}
}
}
private object AppointmentDependenciesId = 0;
private void schedulerStorage1_AppointmentDependenciesInserted(object sender, PersistentObjectsEventArgs e)
{
//AppointmentDependency apt = (AppointmentDependency)e.Objects[0];
//if (DBConfig.Instance.CreateConnection())
//{
// string sql = @"insert into TaskDependencies(Parent,Dependent,Type)values(" + apt.ParentId + "," + apt.DependentId + ",'" + apt.Type + "'" + ")";
// AppointmentDependenciesId = SqlHelper.ExecuteScalar(CommandType.Text, sql);
// if (AppointmentDependenciesId != null)
// {
// //this.schedulerStorage1.SetAppointmentDependencyFactory ((AppointmentDependency)e.Objects[0], AppointmentDependenciesId);
// }
// else
// {
// MessageBox.Show("依赖不正确");
// }
//}
}
/// <summary>
/// 依赖更改
/// </summary>
/// 创建人:姜棚
/// 创建日期:2017-09-13
/// 修改人:
/// 修改日期:
/// 修改备注:无
/// <param name="sender"></param>
/// <param name="e"></param>
private void schedulerStorage1_AppointmentDependenciesChanged(object sender, PersistentObjectsEventArgs e)
{
//AppointmentDependency apt = (AppointmentDependency)e.Objects[0];
//if (DBConfig.Instance.CreateConnection())
//{
// string sql = @"update TaskDependencies set Type='" + apt.Type + "' " + "where Parent=" + apt.ParentId + "and Dependent=" + apt.DependentId;
// var a = SqlHelper.ExecuteNonQuery(sql);
// if (a > 0)
// {
// MessageBox.Show("依赖项更改成功");
// }
// else
// {
// }
//}
}
//private void Form1_FormClosing(object sender, FormClosingEventArgs e)
//{
// Settings.Default.year_scale = this.schedulerControl1.Views.GanttView.Scales[3].Enabled;
// Settings.Default.month_scale = this.schedulerControl1.Views.GanttView.Scales[1].Enabled;
// Settings.Default.date_scale = this.schedulerControl1.Views.GanttView.Scales[0].Enabled;
// Settings.Default.week_scale = this.schedulerControl1.Views.GanttView.Scales[4].Enabled;
// Settings.Default.Save();
//}
/// <summary>
/// 删除依赖
/// </summary>
/// 创建人:姜棚
/// 创建日期:2017-09-13
/// 修改人:
/// 修改日期:
/// 修改备注:无
/// <param name="sender"></param>
/// <param name="e"></param>
private void schedulerStorage1_AppointmentDependenciesDeleted(object sender, PersistentObjectsEventArgs e)
{
//if (DBConfig.Instance.CreateConnection())
//{
// AppointmentDependency apt = (AppointmentDependency)e.Objects[0];
// string CommandText = string.Format("delete from TaskDependencies where Parent={0} and Dependent={1}", apt.ParentId, apt.DependentId);
// var a = SqlHelper.ExecuteNonQuery(CommandText);
// if (a > 0)
// {
// MessageBox.Show("删除成功");
// }
// else
// {
// MessageBox.Show("删除失败");
// }
//}
}
/// <summary>
/// 图片处理
/// </summary>
/// 创建人:姜棚
/// 创建日期:2017-09-13
/// 修改人:
/// 修改日期:
/// 修改备注:无
/// <param name="sender"></param>
/// <param name="e"></param>
void menupicture_Click(object sender, EventArgs e)
{
// 主键值ObjectId
if (string.IsNullOrEmpty(CurrentId + ""))
{
MessageBox.Show("附件关联值丢失", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
string[] str = {
FormText,
OperatorId,
OperatorName,
Privilege,
DLLCoid,
CurrentId+"",
"0", //附件不受修改权限控制
dirid,
""
};
IForm form = PubUtil.LoadDllForm2("Lskj.PhotoView.dll", str);
form.SubForm.ShowDialog();
}
/// <summary>
/// 刷新函数
/// </summary>
/// 创建人:姜棚
/// 创建日期:2017-09-19
/// 修改人:
/// 修改日期:
/// 修改备注:无
private void RefreshMain()
{
string sql1 = "Select * from " + tb;
DataTable taskTabel = SqlHelper.ExecuteDataTable(sql1);
this.schedulerStorage1.Appointments.DataSource = taskTabel;
//this.schedulerStorage1.AppointmentDependencies.DataSource = dependenceTable; 依赖先不处理
//this.schedulerStorage1.Resources.DataSource = resouceTable;
this.schedulerControl1.RefreshData();
}
/// <summary>
/// 调用窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// 创建人:姜棚
/// 创建日期:2017-09-19
/// 修改人:
/// 修改日期:
/// 修改备注:无
void updateItem_Click(object sender, EventArgs e)
{
var appointId = CurrentId == null ? null : CurrentId + "";
string[] args = {
FormText,
OperatorId,
OperatorName,
Privilege,
DLLCoid,
"",
"0",
appointId,
"",
"",
"",
"",
"",
"",
""
};
IForm form = PubUtil.LoadDllForm(addModel, args);
DialogResult result = form.SubForm.ShowDialog();
if (result == DialogResult.OK)
{
// 修改成功后处理
RefreshMain();
}
}
private object CurrentId;
/// <summary>
/// 右键添加图片菜单
/// </summary>
/// 创建人:姜棚
/// 创建日期:2017-09-13
/// 修改人:
/// 修改日期:
/// 修改备注:无
/// <param name="sender"></param>
/// <param name="e"></param>
private void schedulerControl1_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
{
//对日程的右键菜单进行修改
SchedulerControl control = this.schedulerControl1;
CurrentId = control.SelectedAppointments.AsEnumerable().Select(o => o.Id).FirstOrDefault();
if (e.Menu.Id == DevExpress.XtraScheduler.SchedulerMenuItemId.AppointmentMenu)
{
//string str = "select * from P_systempopupmenu where visible=0 and tab='" + DLLCoid + "' and isnull(menutype,0)=0 and visible1=0 order by orderid";
//DataTable td = SqlHelper.ExecuteDataTable(str);
//创建一个新项,用内置的命令
ISchedulerCommandFactoryService service =
(ISchedulerCommandFactoryService)control.GetService(typeof(ISchedulerCommandFactoryService));
//SchedulerMenuItem copy = new SchedulerMenuItem("复制");
//copy.Click += schedulerControl1_AppointmentCopy;
//copy.BeginGroup = true;
//e.Menu.Items.Add(copy);
//创建一个新的自定义事件菜单
for (var i = 0; i < MenuList.Rows.Count; i++)
{
DXMenuItem updateItem = new SchedulerMenuItem(MenuList.Rows[i]["menuname"] + "");
updateItem.Click += MenuConfig;
updateItem.BeginGroup = true;
updateItem.Tag = MenuList.Rows[i];
e.Menu.Items.Add(updateItem);
}
//创建一个新的自定义事件菜单
//DXMenuItem menupicture = new SchedulerMenuItem("附件管理");
//menupicture.Click += menupicture_Click;
//menupicture.BeginGroup = true;
//e.Menu.Items.Add(menupicture);
}
else
{
e.Menu.RemoveMenuItem(SchedulerMenuItemId.TimeScaleVisible);
}
}
/// <summary>
/// 设置Appointment颜色
/// </summary>
/// 创建人:姜棚
/// 创建日期:2017-09-13
/// 修改人:
/// 修改日期:
/// 修改备注:无
private void SetLabeColor(DevExpress.XtraScheduler.SchedulerStorage SL)
{
///设置块的颜色
SL.Appointments.Labels.Clear();
//这个地方考虑取数据库Label字段进行动态生成颜色
SL.Appointments.Labels.Add(new DevExpress.XtraScheduler.AppointmentLabel(Color.Yellow, "生产中"));
SL.Appointments.Labels.Add(new DevExpress.XtraScheduler.AppointmentLabel(Color.LightBlue, "生产完成"));
SL.Appointments.Labels.Add(new DevExpress.XtraScheduler.AppointmentLabel(Color.Pink, "回炉"));
SL.Appointments.Labels.Add(new DevExpress.XtraScheduler.AppointmentLabel(Color.DarkSeaGreen, "其它"));
}
/// <summary>
/// 设置Appoint窗口
/// </summary>
/// 创建人:姜棚
/// 创建日期:2017-09-13
/// 修改人:
/// 修改日期:
/// 修改备注:无
private void schedulerControl1_EditAppointmentFormShowing(object sender, AppointmentFormEventArgs e)
{
if (e.Appointment.Id != null)
{
CurrentId = e.Appointment.Id;
}
else
{
CurrentId = null;
}
updateItem_Click(sender, e);
e.Handled = true;
//ComForm.Form1 form = new ComForm.Form1();
//ClearCntrValue(form);
//if (e.Appointment.Id != null)
//{
// DevExpress.XtraScheduler.SchedulerControl scheduler = ((DevExpress.XtraScheduler.SchedulerControl)(sender));
// string sql1 = "Select * from " + tb + " where " + Mapping.Rows[0]["name"] + "= '" + e.Appointment.Id + "'";
// DataTable taskTabel = SqlHelper.ExecuteDataTable(sql1);
// //读取可以通过这样读
// foreach (Control it in form.Controls)
// {
// for (int i = 0; i < Mapping.Rows.Count; i++)
// {
// if (it.Name == Mapping.Rows[i]["name"] + "")
// {
// if (it is TextBox) it.Text = taskTabel.Rows[0][Mapping.Rows[i]["name"] + ""] + "";
// if (it is DateTimePicker){
// var a= it as DateTimePicker;
// a.Value = Convert.ToDateTime(taskTabel.Rows[0][Mapping.Rows[i]["name"] + ""] + "");
// }
// if (it is Button)
// {
// switch (it.Text)
// {
// case "确认":
// var Yes_btn = it as Button;
// Yes_btn.Click += SaveControl;
// break;
// }
// }
// //这个地方判断控件类型,引入多种控件的判断
// }
// }
// }
//}
////foreach (Control item in form.Controls)
////{
//// foreach (var it in Mapping.Rows)
//// {
//// if()
//// }
////}
//// AppointmentCustomFieldMapping mapping = new AppointmentCustomFieldMapping();
////this.schedulerStorage1.Appointments.CustomFieldMappings.Add();
////SchedulerControl control = this.schedulerControl1;
////如果窗口自定义这里要考虑上面的事件函数失效。
//try
//{
// form.StartPosition = FormStartPosition.CenterParent;
// e.DialogResult = form.ShowDialog();
// e.Handled = true;
//}
//finally
//{
// form.Dispose();
//}
}
/// <summary>
/// 复制
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void schedulerControl1_AppointmentCopy(object sender, EventArgs e)
{
//复制判断
schedulerStorage1_AppointmentsInserted(this, null);
}
/// <summary>
/// 保存Control(预留)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
//private void SaveControl(object sender, EventArgs e)
//{
// MessageBox.Show("ok");
//}
/// 清除容器里面某些控件的值(预留)
/// </summary>
/// <param name="parContainer">容器类控件</param>
//public void ClearCntrValue(Control parContainer)
//{
// for (int index = 0; index < parContainer.Controls.Count; index++)
// {
// // 如果是容器类控件,递归调用自己
// if (parContainer.Controls[index].HasChildren)
// {
// ClearCntrValue(parContainer.Controls[index]);
// }
// else
// {
// switch (parContainer.Controls[index].GetType().Name)
// {
// case "TextBox":
// parContainer.Controls[index].Text = "";
// break;
// case "RadioButton":
// ((RadioButton)(parContainer.Controls[index])).Checked = false;
// break;
// case "CheckBox":
// ((CheckBox)(parContainer.Controls[index])).Checked = false;
// break;
// case "ComboBox":
// ((ComboBox)(parContainer.Controls[index])).Text = "";
// break;
// }
// }
// }
//}
//private void Form1_FormClosing(object sender, FormClosingEventArgs e)
//{
// //Settings.Default.year_scale = this.schedulerControl1.Views.GanttView.Scales[2].Enabled;
// //Settings.Default.month_scale = this.schedulerControl1.Views.GanttView.Scales[1].Enabled;
// //Settings.Default.date_scale = this.schedulerControl1.Views.GanttView.Scales[0].Enabled;
// //Settings.Default.week_scale = this.schedulerControl1.Views.GanttView.Scales[3].Enabled;
// //Settings.Default.Save();
//}
/// <summary>
/// 菜单配置
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MenuConfig(object sender, EventArgs e)
{
bool isContinue = true; // 是否继续执行
bool multiRow = false; //多行执行标记
bool msgHinted = true; //多行执行时如果定义有提示只提示一次
DXMenuItem t = sender as DXMenuItem;
DataRow dr_p = t.Tag as DataRow;
//DataRow d_Rows = this.schedulerControl1.SelectedAppointments..FirstOrDefault() as DataRow;
// this.schedulerControl1.SelectedAppointments.AsEnumerable()
string sqls = string.Format("Select * from {0} where {1}='{2}'", tb, Mapping.Rows[0]["name"], CurrentId);
DataTable dt = SqlHelper.ExecuteDataTable(sqls);
DataRow rowData = dt.Rows[0];
if (rowData == null)
{
XtraMessageBox.Show("请选择一行进行操作.");
return;
}
string beforeMsg = dr_p["beforeMsg"].ToString().Trim();
if ((beforeMsg != "") && (msgHinted == true))
{
msgHinted = false;
beforeMsg = PubClass.ReqSql(rowData, beforeMsg);
DialogResult dlgResult = XtraMessageBox.Show(beforeMsg, "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dlgResult != DialogResult.Yes)
return;
}
string action = dr_p["action"].ToString();
int actionType = Convert.ToInt32(dr_p["actiontype"]);
int ifRefresh = Convert.ToInt32(dr_p["ifRefresh"]);
string dllName = dr_p["dllname"].ToString();
string maxWindow = dr_p["maxWindow"] + "";
List<string> valueList = new List<string>();
valueList.Add(dr_p["dllpar1"].ToString() + "");
valueList.Add(dr_p["dllpar2"].ToString() + "");
valueList.Add(dr_p["dllpar3"].ToString() + "");
valueList.Add(dr_p["dllpar4"].ToString() + "");
valueList.Add(dr_p["dllpar5"].ToString() + "");
valueList.Add(dr_p["dllpar6"].ToString() + "");
valueList.Add(dr_p["dllpar7"].ToString() + "");
valueList.Add(dr_p["dllpar8"].ToString() + "");
valueList.Add(dr_p["dllpar9"].ToString() + "");
valueList.Add(dr_p["dllpar10"].ToString() + "");
string DJH = string.Empty;
dllName = dllName.Replace("{loginid}", ERPInfo.Instance.EmployeeId.ToString());
dllName = dllName.Replace("{loginname}", ERPInfo.Instance.EmployeeName.ToString());
//打开exe
if ((dllName.Trim() != "") && (dllName.ToLower().IndexOf(".exe", 1) != -1) && ((dllName.ToLower() != "iexplore.exe")) && ((dllName.ToLower() != "lstest.exe")))
{
string tmpDllName = dllName;
List<string> sqlpar = PubClass.GetParamValue(tmpDllName);
foreach (string s in sqlpar)
{
string filed = s.Replace("{", "").Replace("}", "");
tmpDllName = tmpDllName.Replace(s, rowData[filed] + "");
}
//MessageBox.Show(tmpDllName);
PubUtil.WinExec(tmpDllName, 1);
}
else if ((dllName.Trim() != "") && (dllName.ToLower().IndexOf("http:", StringComparison.OrdinalIgnoreCase) != -1) ||
(dllName.ToLower().IndexOf("www.", StringComparison.OrdinalIgnoreCase) != -1) ||
(dllName.ToLower().IndexOf("ftp:", StringComparison.OrdinalIgnoreCase) != -1))
{
Process.Start(dllName);
}
else
{
//打开dll
if (actionType == 2)
{
#region 打开DLL
List<string> paremList = new List<string>();
foreach (string item in valueList)
{
string action_type = string.Empty;
if (item.Length > 0)
{
action_type = item.Substring(0, 1);
}
// 解析sql
if (action_type == "@")
{
// 右键菜单假如是调用单据,则参数8和参数9为打开单据新增sql语句
if (dllName.ToLower() == "lskj.pubbill.dll" && (item == dr_p["dllpar8"] + "" || item == dr_p["dllpar9"] + ""))
{
isContinue = false;
string sql = item.Replace("@", "");
sql = PubClass.ReqSqlParam(sql, OperatorId, OperatorName);
List<string> sqlpar = PubClass.GetParamValue(sql);
foreach (string s in sqlpar)
{
string fieldValues = string.Empty;
string filed = s.Replace("{", "").Replace("}", "");
//fieldValues += "'" + rowItem[filed] + "',";
fieldValues += "" + rowData[filed] + ",";
sql = sql.Replace(s, (item == dr_p["dllpar8"] + "") ? rowData[filed] + "" : fieldValues.TrimEnd(','));
}
paremList.Add(sql);
}
else
{
string sql = item.Replace("@", "");
sql = PubClass.ReqSqlParam(sql, OperatorId, OperatorName);
List<string> sqlpar = PubClass.GetParamValue(sql);
foreach (string s in sqlpar)
{
string filed = s.Replace("{", "").Replace("}", "");
sql = sql.Replace(s, rowData[filed] + "");
}
string param = SqlHelper.ExecuteScalar(CommandType.Text, sql) + "";
paremList.Add(param);
}
}
else if (action_type == "{")
{
string p = item.Replace("{", "").Replace("}", "");
paremList.Add(rowData[p] + "");
}
else if (item.Contains("{") && item.Contains("}"))
{
string str = item;
List<String> listStr = PubClass.GetParamValue(item);
foreach (String s in listStr)
{
string fileName = s.Replace("{", "").Replace("}", "");
string v = rowData[fileName] + "";
str = str.Replace(s, v);
}
paremList.Add(str);
}
else if (item.Contains("[FormTitle_"))
{
String str = item.Replace("[", "{").Replace("]", "}");
List<String> listStr = PubClass.GetParamValue(str);
foreach (String s in listStr)
{
string fileName = s.Replace("FormTitle_", "").Replace("{", "").Replace("}", "");
string v = rowData[fileName] + "";
str = str.Replace(s, v);
}
paremList.Add(str);
}
else if (action_type == "#")
{
string sql = item.Replace("#", "");
List<string> sqlpar = PubClass.GetParamValue(sql);
foreach (string s in sqlpar)
{
string filed = s.Replace("{", "").Replace("}", "");
sql = sql.Replace(s, rowData[filed] + "");
}
paremList.Add(sql);
}
else
{
paremList.Add(item);
}
}
if (dllName.ToLower() == "iexplore.exe")
{
//MessageBox.Show(paremList[0] + Uri.EscapeUriString(paremList[1]));
string url = paremList[0] + Uri.EscapeUriString(paremList[1]);
url = url.Replace("#", "%23");
System.Diagnostics.Process.Start("iexplore.exe", url);
}
if (dllName.ToLower() == "lstest.exe")
{
StringBuilder dfile = new StringBuilder();
StringBuilder rfile = new StringBuilder();
int hwnd = 0;
dfile.Append(paremList[0] + paremList[1]);
rfile = PubUtil.DownloadAttach(dfile, hwnd);
rfile.Clear();
rfile.Append(Application.StartupPath + @"\tempfiles\" + System.IO.Path.GetFileName(dfile.ToString()));
if (System.IO.File.Exists(rfile.ToString()))
{
//MessageBox.Show(rfile.ToString());
System.Diagnostics.Process.Start(rfile.ToString(), "");
}
}
else if (dllName == "Lskj.PhotoView.dll")
{
string[] str = {
FormText,
OperatorId,
OperatorName,
Privilege,
DLLCoid,
paremList[0],
paremList[1],
paremList[2],
paremList[3],
paremList[4],
paremList[5],
paremList[6],
paremList[7],
paremList[8],
paremList[9]
};
IForm form = PubUtil.LoadDllForm2("Lskj.PhotoView.dll", str);
if (maxWindow == "1")
form.SubForm.WindowState = FormWindowState.Maximized;
form.SubForm.ShowDialog();
}
else
{
string[] str = {
FormText,
OperatorId,
OperatorName,
Privilege,
DLLCoid,
paremList[0],
paremList[1],
paremList[2],
paremList[3],
paremList[4],
paremList[5],
paremList[6],
paremList[7],
paremList[8],
paremList[9]
};
IForm form = PubUtil.LoadDllForm(dllName, str);
form.SubForm.WindowState = maxWindow == "1" ? FormWindowState.Maximized : FormWindowState.Normal;
form.SubForm.StartPosition = FormStartPosition.CenterParent;
form.SubForm.ShowDialog();
}
#endregion
}//执行存储过程
else if (actionType == 1)
{
#region 执行存储过程
try
{
List<string> paremList = new List<string>();
ArrayList sqlParamList = new ArrayList();
foreach (string item in valueList)
{
//解析sql
if (item.IndexOf('@') != -1)
{
string sql = item.Replace("@", "");
List<string> sqlpar = PubClass.GetParamValue(sql);
foreach (string s in sqlpar)
{
string filed = s.Replace("{", "").Replace("}", "");
sql = sql.Replace(s, rowData[filed] + "");
}
string param = SqlHelper.ExecuteScalar(CommandType.Text, sql) + "";
paremList.Add(param);
}
else if (item.IndexOf('{') != -1)
{
string p = item;
List<string> sqlpar = PubClass.GetParamValue(item);
foreach (string s in sqlpar)
{
string filedName = s.Replace("{", "").Replace("}", "");
if (filedName.Equals("loginname", StringComparison.OrdinalIgnoreCase))
{
p = p.Replace(s, OperatorName);
}
else if (filedName.Equals("loginid", StringComparison.OrdinalIgnoreCase))
{
p = p.Replace(s, OperatorId);
}
else
{
p = p.Replace(s, rowData[filedName] + "");
}
}
paremList.Add(p);
}
else
{
paremList.Add(item);
}
}
List<string> paramName = PubClass.GetParamValue(action);
string[] paramStr = paramName[0].Replace("{", "").Replace("}", "").Split(',');
SqlParameter pMsg = new SqlParameter("@msg", SqlDbType.VarChar, 2000);
//for (int i = 0; i < paremList.Count; i++)
//{
// string item = paremList[i];
// if (!string.IsNullOrEmpty(item))
// {
// if (paramStr[i].Equals("@msg", StringComparison.OrdinalIgnoreCase))
// {
// pMsg.Direction = ParameterDirection.Output;
// pMsg.Value = "";
// sqlParamList.Add(pMsg);
// }
// else
// {
// string paramStr1 = paramStr[i];
// SqlParameter param = new SqlParameter(string.Format("{0}", paramStr1),
// DbTypeConverter.ConvertToSql(FieldType.VarChar));
// param.Value = item;
// sqlParamList.Add(param);
// }
// }
//}
for (int i = 0; i < paramStr.Length; i++)
{
string item = paremList[i];
if (paramStr[i].Equals("@msg", StringComparison.OrdinalIgnoreCase))
{
pMsg.Direction = ParameterDirection.InputOutput;
pMsg.Value = "";
sqlParamList.Add(pMsg);
}
else
{
string paramStr1 = paramStr[i];
SqlParameter param = new SqlParameter(string.Format("{0}", paramStr1),
DbTypeConverter.ConvertToSql(FieldType.VarChar));
param.Value = item;
sqlParamList.Add(param);
}
}
SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int, 4);
returnValue.Direction = ParameterDirection.ReturnValue;
sqlParamList.Add(returnValue);
SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, action.Replace(paramName[0], "").Trim(), (SqlParameter[])sqlParamList.ToArray(typeof(SqlParameter)));
if (Convert.ToInt32(returnValue.Value) == -1)
{
XtraMessageBox.Show("操作失败\n" + pMsg.Value, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
else
{
if (Convert.ToInt32(returnValue.Value) == 9999)
{
XtraMessageBox.Show(pMsg.Value + "", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if (Convert.ToInt32(returnValue.Value) == 99)
{
//对话框输入
//ComfirmDialog.ComfirmDialog cfd = new ComfirmDialog.ComfirmDialog(pMsg.Value + "");
//DialogResult result = cfd.ShowDialog();
//if (result == DialogResult.Cancel)
// return;
//string hintMsg = cfd.ComfirmMsg;
//sqlParamList.Clear();
//for (int i = 0; i < paramStr.Length; i++)
//{
// string item = paremList[i];
// if (paramStr[i].Equals("@msg", StringComparison.OrdinalIgnoreCase))
// {
// pMsg.Direction = ParameterDirection.InputOutput;
// pMsg.Value = hintMsg;
// sqlParamList.Add(pMsg);
// }
// else
// {
// string paramStr1 = paramStr[i];
// SqlParameter param = new SqlParameter(string.Format("{0}", paramStr1),
// DbTypeConverter.ConvertToSql(FieldType.VarChar));
// param.Value = item;
// sqlParamList.Add(param);
// }
//}
//SqlParameter returnValue1 = new SqlParameter("@return", SqlDbType.Int, 4);
//returnValue1.Direction = ParameterDirection.ReturnValue;
//sqlParamList.Add(returnValue1);
//SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, action.Replace(paramName[0], "").Trim(), (SqlParameter[])sqlParamList.ToArray(typeof(SqlParameter)));
//if (Convert.ToInt32(returnValue1.Value) == -1)
//{
// XtraMessageBox.Show("操作失败\n" + pMsg.Value, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
// return;
//}
//else
//{
// if (!multiRow)
// XtraMessageBox.Show("操作成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
//}
}
else
{
if (!multiRow)
XtraMessageBox.Show("操作成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
try
{
if (action.Contains("p_baseApply"))
{
// 调用消息推送
PushHelper push = new PushHelper(paramStr[1], "0", paramStr[0], "", "", 0);
new Thread(new ThreadStart(push.push_base_oper_message));
}
else if (action.Contains("p_billApply"))
{
// 调用消息推送
PushHelper push = new PushHelper(paramStr[1], "0", paramStr[0], "", "", 0);
new Thread(new ThreadStart(push.push_bill_oper_message));
}
}
catch (Exception)
{
}
}
DJH = pMsg.Value.ToString().Trim();
}
}
catch (Exception ex)
{
XtraMessageBox.Show("操作失败\n" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
#endregion
}//调用delphi
else if (actionType == 3)
{
List<string> paremList = new List<string>();
foreach (string item in valueList)
{
string action_type = string.Empty;
if (item.Length > 0)
{
action_type = item.Substring(0, 1);
}
if (action_type == "@")
{
//解析sql
string sql = item.Replace("@", "");
List<string> sqlpar = PubClass.GetParamValue(sql);
foreach (string s in sqlpar)
{
string filed = s.Replace("{", "").Replace("}", "");
sql = sql.Replace(s, rowData[filed] + "");
}
string param = SqlHelper.ExecuteScalar(CommandType.Text, sql) + "";
paremList.Add(param);
}
else if (action_type == "{")
{
string p = item.Replace("{", "").Replace("}", "");
paremList.Add(rowData[p] + "");
}
else if (action_type == "#")
{
string sql = item.Replace("#", "");
List<string> sqlpar = PubClass.GetParamValue(sql);
foreach (string s in sqlpar)
{
string filed = s.Replace("{", "").Replace("}", "");
sql = sql.Replace(s, rowData[filed] + "");
}
paremList.Add(sql);
}
else
{
string sql = item;
List<string> sqlpar = PubClass.GetParamValue(sql);
foreach (string s in sqlpar)
{
string filed = s.Replace("{", "").Replace("}", "");
sql = sql.Replace(s, rowData[filed] + "");
}
paremList.Add(sql);
}
}
PubUtil.LoadDelphiDll(dllName, paremList[0], paremList[1], paremList[2], paremList[3], Convert.ToInt32(paremList[4]), paremList[5]);
}
else
{
//执行SQL
#region 执行SQL语句
try
{
List<string> pList = PubClass.GetParamValue(action);
string newSql = action;
for (int i = 0; i < pList.Count; i++)
{
newSql = newSql.Replace("'" + pList[i] + "'", "@" + pList[i].Replace("{#", "").Replace("{", "").Replace("}", ""));
newSql = newSql.Replace(pList[i], "@" + pList[i].Replace("{", "").Replace("}", ""));
}
//string newSql = action.Replace("{", "@").Replace("}", "").Replace("'", "");
ArrayList parameters = new ArrayList();
for (int i = 0; i < pList.Count; i++)
{
string filedName = pList[i].Replace("{", "").Replace("}", "");
if (filedName.Equals("loginname", StringComparison.OrdinalIgnoreCase))
{
SqlParameter param = new SqlParameter(string.Format("{0}", filedName),
DbTypeConverter.ConvertToSql(FieldType.VarChar));
param.IsNullable = true;
param.Value = OperatorName;
parameters.Add(param);
}
else if (filedName.Equals("loginid", StringComparison.OrdinalIgnoreCase))
{
SqlParameter param = new SqlParameter(string.Format("{0}", filedName),
DbTypeConverter.ConvertToSql(FieldType.VarChar));
param.IsNullable = true;
param.Value = OperatorId;
parameters.Add(param);
}
else
{
SqlParameter param = new SqlParameter(string.Format("{0}", filedName),
DbTypeConverter.ConvertToSql(FieldType.VarChar));
param.IsNullable = true;
param.Value = rowData[filedName];
parameters.Add(param);
}
}
int result = SqlHelper.ExecuteNonQuery(CommandType.Text, newSql, (SqlParameter[])parameters.ToArray(typeof(SqlParameter)));
}
catch (Exception ex)
{
XtraMessageBox.Show("操作失败!\n" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
#endregion
}
}
}
/// <summary>
/// 关闭后进行保存
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
{
Lskj.IntervalView.Properties.Settings.Default.Save();
}
}
}