using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.IO;
using System.Diagnostics;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CoreFS.CA06;
using Core.Mes.Client.Common;
namespace Core.LgMes.Client.LgIntegrationQuery
{
public partial class frmSchedulingShift : Core.Mes.Client.Common.frmStyleBase
{
bool blChange = false; //判断是否发生变化。
string ShiftCode = "";
public frmSchedulingShift()
{
InitializeComponent();
}
private void frmSchedulingShift_Load(object sender, EventArgs e)
{
//初始化时间和查询条件
this.uldtBeginTime.Value = DateTime.Today.AddDays(-7).ToString("yyyy-MM-dd") + " 00:00";
this.uldtEndTime.Value = DateTime.Today.ToString("yyyy-MM-dd") + " 23:59"; ;
this.cmbxShiftQuery.Enabled = false;
ckbTime.Checked = true;
this.uldtBeginTime.Enabled = true;
this.uldtEndTime.Enabled = true;
this.ultxtMan.Text =this.UserInfo.GetUserName();
string strErr = "";
ShiftCode = "";
ArrayList arry = new ArrayList();
arry.Add("GetCurrDuty.Select");
CommonClientToServer cctos = new CommonClientToServer();
cctos.ob = this.ob;
DataSet ds = cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBQuery",
"doSimpleQuery", arry, out strErr);
ShiftCode=ds.Tables[0].Rows[0][0].ToString();
if (!string.IsNullOrEmpty(ShiftCode))
{
cmbxShift.SelectedIndex = Convert.ToInt16(ShiftCode.Substring(1, 1)) - 1;
}
//获取原有调度信息
QueryShiftData();
//其他岗位只有查询功能的限制
if (this.Key.Contains("@Query") == true)
{
ultraExpandableGroupBox1.Visible = false;
}
}
private void ckbTime_CheckedChanged(object sender, EventArgs e)
{
uldtBeginTime.Enabled = ckbTime.Checked;
uldtEndTime.Enabled = ckbTime.Checked;
}
private void chkShift_CheckedChanged(object sender, EventArgs e)
{
cmbxShiftQuery.Enabled = chkShift.Checked;
if (chkShift.Checked == true)
{
string ShiftCode = "", strErr="";
ArrayList arry = new ArrayList();
arry.Add("GetCurrDuty.Select");
CommonClientToServer cctos = new CommonClientToServer();
cctos.ob = this.ob;
DataSet ds = cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBQuery",
"doSimpleQuery", arry, out strErr);
ShiftCode = ds.Tables[0].Rows[0][0].ToString();
if (!string.IsNullOrEmpty(ShiftCode))
{
cmbxShiftQuery.SelectedIndex = Convert.ToInt16(ShiftCode.Substring(1, 1)) - 1;
}
}
else
{
cmbxShiftQuery.Text = "";
}
}
public override void ToolBar_Click(object sender, string ToolbarKey)
{
switch (ToolbarKey)
{
case "Add":
if (MessageBox.Show("你确认要增加调度交接班信息?", "提示", System.Windows.Forms.MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
return;
if (string.IsNullOrEmpty(ultxtMan.Text))
{
MessageBox.Show("请输入交班人!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else if (string.IsNullOrEmpty(cmbxShift.Text))
{
MessageBox.Show("请选择班次!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else if (string.IsNullOrEmpty(txtContent.Text))
{
MessageBox.Show("请输入交班的内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else
{
AddShiftData();
}
break;
case "Delete":
if (ultraGrid.ActiveRow!=null)
{
System.Windows.Forms.DialogResult t = MessageBox.Show("你确认要删除所选择的行?", "提示", System.Windows.Forms.MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (t == System.Windows.Forms.DialogResult.Yes)
{
DeleteShiftData();
}
}
else
{
MessageBox.Show("请选择你要删除的行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
break;
case "Update":
if (MessageBox.Show("你确认要修改调度交接班信息?", "提示", System.Windows.Forms.MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
return;
if (ultraGrid.ActiveRow != null)
{
UpdateShiftData();
}
else
{
MessageBox.Show("请选择你要修改的行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
break;
case "Query":
QueryShiftData();
break;
case "Export":
if (ultraGrid.Rows.Count > 0)
{
ExportExcel();
}
else
MessageBox.Show("没有交班信息。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
break;
case "Exit":
this.Close();
break;
default:
break;
}
}
///
/// 获取调度交班信息
///
private void QueryShiftData()
{
string strShift = "";
string strStartTime = "";
string strEndTime = "";
string strErr = "";
if (ckbTime.Checked == true)
{
if (Convert.ToDateTime(uldtBeginTime.Value) > Convert.ToDateTime(uldtEndTime.Value))
{
MessageBox.Show("时间条件的开始时间不能大于结束时间!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
else
{
strStartTime = this.uldtBeginTime.DateTime.ToString("yyyy-MM-dd");
strEndTime = this.uldtEndTime.DateTime.ToString("yyyy-MM-dd");
}
}
if (chkShift.Checked == true)
{
strShift = Convert.ToString(cmbxShiftQuery.SelectedIndex+1);
}
ArrayList arry = new ArrayList();
arry.Add("QueryShiftData.select");
arry.Add(strStartTime);
arry.Add(strEndTime);
arry.Add(strShift);
arry.Add(strShift);
CommonClientToServer cctos = new CommonClientToServer();
cctos.ob = this.ob;
DataSet ds = cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBQuery",
"doSimpleQuery", arry, out strErr);
dataSet1.Clear(); //清空原有行
if (strErr =="" && ds != null)
{
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow Dr in ds.Tables[0].Rows)
{
DataRow dr1 = dataSet1.Tables[0].NewRow();
dr1["ID"] = Dr["ID"].ToString();
dr1["SHIFTNAME"] = Dr["SHIFTNAME"].ToString();
dr1["SHIFT"] = Dr["SHIFT"].ToString();
dr1["SHIFTCONTENT"] = Dr["SHIFTCONTENT"].ToString();
dr1["SHIFTDATE"] = Dr["SHIFTDATE"].ToString();
dataSet1.Tables[0].Rows.Add(dr1);
}
}
}
}
///
/// 增加调度交班信息
///
private void AddShiftData()
{
string strShift ="";
if (cmbxShift.SelectedIndex == 0)
strShift = "1";
else if (cmbxShift.SelectedIndex == 1)
strShift = "2";
else if (cmbxShift.SelectedIndex == 2)
strShift = "3";
else if (cmbxShift.SelectedIndex == 3)
strShift = "4";
string strShiftContent = txtContent.Text;
string strShiftTime = DateTime.Now.ToString();
string strShiftName = ultxtMan.Text;
string strErr = "";
ArrayList arry = new ArrayList();
arry.Add("AddShiftData.select");
arry.Add(strShiftName);
arry.Add(strShift);
arry.Add(strShiftContent);
arry.Add(strShiftTime);
CommonClientToServer cctos = new CommonClientToServer();
cctos.ob = this.ob;
DataSet ds = cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave",
"doSimpleSave", arry, out strErr);
if (strErr != "")
{
MessageBox.Show("保存失败!调度信息新增失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else
{
MessageBox.Show("调度信息新增成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
QueryShiftData();
}
}
///
/// 删除交班调度信息
///
private void DeleteShiftData()
{
if (ultraGrid.ActiveRow != null)
{
string strId = ultraGrid.ActiveRow.Cells["ID"].Value.ToString();
string strErr = "";
ArrayList arry = new ArrayList();
arry.Add("DeleteShiftData.select");
arry.Add(strId);
CommonClientToServer cctos = new CommonClientToServer();
cctos.ob = this.ob;
DataSet ds = cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave",
"doSimpleSave", arry, out strErr);
if (strErr != "")
{
MessageBox.Show("删除失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else
{
MessageBox.Show("交班调度信息删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
QueryShiftData();
ultxtMan.Text = "";
cmbxShift.Text = "";
ShiftTime.Text = "";
txtContent.Text = "";
}
}
}
///
/// 选择要编辑的信息
///
///
///
private void ultraGrid_Click(object sender, EventArgs e)
{
DialogResult dlgR = DialogResult.None;
if (ultraGrid.ActiveRow == null || ultraGrid.ActiveRow.Index < 0)
{
return;
}
else if (ultraGrid.ActiveRow.Index >= 0)
{
if (blChange == true && txtContent.Text.Trim().Length > 0)
dlgR = MessageBox.Show("调度交班信息已更新请先增加或修改操作!", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Asterisk);
if (dlgR == DialogResult.Yes || dlgR == DialogResult.Cancel) return;
blChange = false;
ultxtMan.Text = ultraGrid.ActiveRow.Cells["SHIFTNAME"].Value.ToString();
cmbxShift.Text = ultraGrid.ActiveRow.Cells["SHIFT"].Text;
ShiftTime.Text = ultraGrid.ActiveRow.Cells["SHIFTDATE"].Value.ToString();
txtContent.Text = ultraGrid.ActiveRow.Cells["SHIFTCONTENT"].Value.ToString();
}
}
///
/// 修改调度交班信息
///
private void UpdateShiftData()
{
if (ultraGrid.ActiveRow != null)
{
string strShift = "";
if (cmbxShift.SelectedIndex == 0)
strShift = "1";
else if (cmbxShift.SelectedIndex == 1)
strShift = "2";
else if (cmbxShift.SelectedIndex == 2)
strShift = "3";
else if (cmbxShift.SelectedIndex == 3)
strShift = "4";
string strId = ultraGrid.ActiveRow.Cells["ID"].Value.ToString();
string strShiftName = ultxtMan.Text;
string strShiftContent = txtContent.Text;
string strShiftTime = DateTime.Now.ToString();
string strErr = "";
ArrayList arry = new ArrayList();
arry.Add("UpdateShiftData.select");
arry.Add(strShiftName);
arry.Add(strShift);
arry.Add(strShiftContent);
arry.Add(strId);
CommonClientToServer cctos = new CommonClientToServer();
cctos.ob = this.ob;
DataSet ds = cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave",
"doSimpleSave", arry, out strErr);
if (strErr != "")
{
MessageBox.Show("调度交班信息修改失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else
{
MessageBox.Show("调度交班信息修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
QueryShiftData();
}
}
}
///
/// 导出Excel
///
private void ExportExcel()
{
try
{
string StrfileName = System.Windows.Forms.Application.StartupPath + "\\Report\\调度交班信息.xls";
this.ultraGridExcelExporter1.Export(this.ultraGrid, StrfileName);
ProcessStartInfo p = new ProcessStartInfo(StrfileName);
p.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
p.WorkingDirectory = Path.GetDirectoryName(StrfileName);
Process.Start(p);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void txtContent_TextChanged(object sender, EventArgs e)
{
//if (txtContent.Text.Trim().Length > 0)
// blChange = true;
}
private void butClear_Click(object sender, EventArgs e)
{
if (MessageBox.Show("是否要清空交接班信息?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
{
this.ultxtMan.Text = this.UserInfo.GetUserName();
if (!string.IsNullOrEmpty(ShiftCode))
{
cmbxShift.SelectedIndex = Convert.ToInt16(ShiftCode.Substring(1, 1)) - 1;
}
ShiftTime.Value = DateTime.Now;
txtContent.Clear();
}
}
private void txtContent_KeyPress(object sender, KeyPressEventArgs e)
{
if(txtContent.Text.Trim().Length>0)
blChange = true;
}
}
}