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.

100 lines
4.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mesnac.Action.Base;
using System.Windows.Forms;
using Mesnac.Codd.Session;
using System.Data;
using Mesnac.Action.Feeding.BasicInfo;
namespace Mesnac.Action.Feeding.SynchroData
{
/// <summary>
/// 从网络下载本机台的所有配方及相关物料数据
/// </summary>
public class RecipeDataSynchronous : FeedingAction, IAction
{
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime);
if (runtime.Sender is Control)
{
(runtime.Sender as Control).Enabled = false;
}
try
{
if (base.NetType == NetTypes.Local)
{
ICSharpCode.Core.LoggingService.Error("此系统版本为单机版,不能进行数据同步...");
base.ShowMsg(Language(32));
runtime.IsReturn = true;
return;
}
//if (!PlanCommon.PingIpOrDomainName(base.GetConfigValue("ServerIP", "127.0.0.1")))
if (!PlanCommon.IsCanConnectServer())
{
//网络不通
base.ShowMsg(Language(33), Language(1), MessageBoxButtons.OK, MessageBoxIcon.Information);
runtime.IsReturn = true;
return;
}
if (MessageBox.Show(Language(40), Language(1), MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
DbHelper serverHelper = base.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Server);
if (serverHelper == null)
{
//连接服务器数据库失败
MessageBox.Show(Language(33), Language(1), MessageBoxButtons.OK, MessageBoxIcon.Information);
runtime.IsReturn = true;
return;
}
//查询本机台的所有配方(正用、且审批通过的配方)
serverHelper.CommandType = System.Data.CommandType.Text;
serverHelper.CommandText = "select Mater_Code,Edt_Code from pmt_recipe where Equip_Code = @EquipCode and Recipe_State=1 and Audit_flag = 1";
serverHelper.AddParameter("@EquipCode", base.CurrEquipCode);
DataTable recipeServerTable = serverHelper.ToDataTable();
if (recipeServerTable != null && recipeServerTable.Rows.Count > 0)
{
NetRecipe netRecipe = new NetRecipe();
foreach (DataRow row in recipeServerTable.Rows)
{
string materCode = String.Empty;
string edtCode = String.Empty;
object objMaterCode = row["Mater_Code"];
object objEdtCode = row["Edt_Code"];
if (objMaterCode != null && objMaterCode != System.DBNull.Value)
{
materCode = objMaterCode.ToString();
}
if (objEdtCode != null && objEdtCode != System.DBNull.Value)
{
edtCode = objEdtCode.ToString();
}
netRecipe.DownloadRecipe(base.CurrEquipCode, materCode.Trim(), edtCode.Trim());
}
}
MessageBox.Show(Language(41), Language(1), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService.Error("从网络现在所有配方数据失败:" + ex.Message, ex);
MessageBox.Show(Language(295), Language(1), MessageBoxButtons.OK, MessageBoxIcon.Information);
runtime.IsReturn = true;
}
finally
{
if (runtime.Sender is Control)
{
(runtime.Sender as Control).Enabled = true;
}
}
}
}
}