You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
4.1 KiB
C#

1 year ago
using ICSharpCode.Core;
using Mesnac.Action.Base;
using Mesnac.Codd.Session;
using Mesnac.Controls.Base;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Mesnac.Action.ChemicalWeighing.ShiftManage
{
/// <summary>
/// 修改班次时间Action
/// </summary>
class ModifyShiftTimeAction : ChemicalWeighingAction, IAction
{
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须要调用的
ICSharpCode.Core.LoggingService<ModifyShiftTimeAction>.Debug("班次管理-修改班次时间...");
List<DbMCControl> mcControllist = GetAllDbMCControlsByOption(DbOptionTypes.Query);//获取所有待初始化控件
IBaseControl morningstart = mcControllist.Where(t => t.BaseControl.MCKey != null && t.BaseControl.MCKey.ToLower() == "morningstart").FirstOrDefault().BaseControl;
IBaseControl morningend = mcControllist.Where(t => t.BaseControl.MCKey != null && t.BaseControl.MCKey.ToLower() == "morningend").FirstOrDefault().BaseControl;
IBaseControl noonstart = mcControllist.Where(t => t.BaseControl.MCKey != null && t.BaseControl.MCKey.ToLower() == "noonstart").FirstOrDefault().BaseControl;
IBaseControl noonend = mcControllist.Where(t => t.BaseControl.MCKey != null && t.BaseControl.MCKey.ToLower() == "noonend").FirstOrDefault().BaseControl;
IBaseControl nightstart = mcControllist.Where(t => t.BaseControl.MCKey != null && t.BaseControl.MCKey.ToLower() == "nightstart").FirstOrDefault().BaseControl;
IBaseControl nightend = mcControllist.Where(t => t.BaseControl.MCKey != null && t.BaseControl.MCKey.ToLower() == "nightend").FirstOrDefault().BaseControl;
string str1 = morningstart.MCValue.ToString();
string str2 = morningend.MCValue.ToString();
string str3 = noonstart.MCValue.ToString();
string str4 = noonend.MCValue.ToString();
string str5 = nightstart.MCValue.ToString();
string str6 = nightend.MCValue.ToString();
string mornStart = str1.Substring(str1.Length - 8);
string mornEnd = str2.Substring(str1.Length - 8);
string noonStart = str3.Substring(str1.Length - 8);
string noonEnd = str4.Substring(str1.Length - 8);
string nighStart = str5.Substring(str1.Length - 8);
string nighEnd = str6.Substring(str1.Length - 8);
string msg1 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_ShiftManage_ModifyShiftTimeAction_msg1")); //确认保存修改的班次时间???
if (MessageBox.Show(msg1, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
StringBuilder strSql = new StringBuilder(@"UPDATE Pmt_Shiftime SET Shift_st = CASE Shift_id WHEN 1 THEN @mornStart WHEN 2 THEN @noonStart WHEN 3 THEN @nighStart END,
Shift_et = CASE Shift_id WHEN 1 THEN @mornEnd WHEN 2 THEN @noonEnd WHEN 3 THEN @nighEnd END WHERE Shift_id IN (1,2,3)");
dbHelper.CommandText = strSql.ToString();
dbHelper.AddParameter("@mornStart", mornStart);
dbHelper.AddParameter("@mornEnd", mornEnd);
dbHelper.AddParameter("@noonStart", noonStart);
dbHelper.AddParameter("@noonEnd", noonEnd);
dbHelper.AddParameter("@nighStart", nighStart);
dbHelper.AddParameter("@nighEnd", nighEnd);
dbHelper.ExecuteNonQuery();
}
}
}
}