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.
183 lines
9.3 KiB
C#
183 lines
9.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.Basic;
|
|
using Mesnac.Codd.Session;
|
|
using System.Data;
|
|
|
|
namespace Mesnac.Action.Feeding.Qingquan.SynchroData
|
|
{
|
|
#region 从网络更新日罐物料参数
|
|
|
|
/// <summary>
|
|
/// 从网络更新日罐物料参数
|
|
/// </summary>
|
|
public class UpdateJarMaterNameFromNet : FeedingAction, IAction
|
|
{
|
|
public void Run(RuntimeParameter runtime)
|
|
{
|
|
base.RunIni(runtime);
|
|
if (base.NetType == NetTypes.Local)
|
|
{
|
|
base.LogError("{从网络更新日罐物料参数} 此系统版本为单机版,不能进行数据更新...");
|
|
ShowMsg(base.Language(39));
|
|
runtime.IsReturn = true;
|
|
return;
|
|
}
|
|
if (!PlanCommon.IsCanConnectServer())
|
|
{
|
|
//连接网络数据库失败...
|
|
ShowMsg(base.Language(33));
|
|
runtime.IsReturn = true;
|
|
return;
|
|
}
|
|
//您确定要执行此操作吗?
|
|
if (MessageBox.Show(Language(40), Language(1), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
|
{
|
|
runtime.IsReturn = true; //终止执行
|
|
return;
|
|
}
|
|
|
|
DatabaseAction action = new DatabaseAction();
|
|
///////本地、服务器连接信息
|
|
DataSourceItem Sdsi = action.GetDataSourceItem(Mesnac.Basic.DataSourceFactory.MCDbType.Server);
|
|
DataSourceItem Ldsi = action.GetDataSourceItem(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
//////测试服务器数据库连接
|
|
DbHelper dbHelperServer;
|
|
dbHelperServer = action.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Server);
|
|
if (dbHelperServer == null)
|
|
{
|
|
action.LogError("连接服务器数据库失败...");
|
|
ShowMsg(base.Language(33));
|
|
return;
|
|
}
|
|
|
|
/////本地数据库
|
|
DbHelper dbHelperlocal;
|
|
dbHelperlocal = action.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
if (dbHelperlocal == null)
|
|
{
|
|
action.LogError("连接本地数据库失败...");
|
|
ShowMsg(base.Language(34));
|
|
return;
|
|
}
|
|
string ServerStr = string.Empty;
|
|
if (Sdsi.Server != Ldsi.Server)
|
|
{
|
|
ServerStr = "[" + Sdsi.Server + "].";
|
|
}
|
|
#region 清空本地日罐物料表中的物料名称
|
|
|
|
string strSql1 = "update [SytJar] set [MaterialName]=''";
|
|
dbHelperlocal.ClearParameter();
|
|
dbHelperlocal.CommandText = strSql1;
|
|
dbHelperlocal.ExecuteNonQuery();
|
|
|
|
#endregion
|
|
///////获取本地
|
|
StringBuilder loacdsqlstr = new StringBuilder("select ObjID,JarSerial,JarType,MaterialName from SytJar");
|
|
dbHelperlocal.ClearParameter();
|
|
dbHelperlocal.CommandType = CommandType.Text;
|
|
dbHelperlocal.CommandText = loacdsqlstr.ToString();
|
|
DataTable jarTable = dbHelperlocal.ToDataTable();
|
|
///////获取服务器信息
|
|
StringBuilder serversqlstr = new StringBuilder("");
|
|
serversqlstr.Append(@"select b.Jar_type as JarType, b.Ware_num as JarSerial, b.Mater_Code, a.Mater_Name, JarUsed = case Mater_Used when 1 then '使用' else '未用' end from Pmt_material a inner join pmt_wm b on a.Mater_code=b.Mater_code where Equip_code=@EquipCode");
|
|
dbHelperServer.CommandText = serversqlstr.ToString();
|
|
dbHelperServer.AddParameter("@EquipCode", base.CurrEquipCode);
|
|
DataTable materTable = dbHelperServer.ToDataTable();
|
|
|
|
if (materTable != null && materTable.Rows.Count > 0)
|
|
{
|
|
foreach (DataRow dr in materTable.Rows)
|
|
{
|
|
string strServerJarType = String.Empty;
|
|
int intServerJarSerial = -1;
|
|
string strMaterCode = String.Empty;
|
|
string strMaterName = String.Empty;
|
|
string strJarUsed = String.Empty;
|
|
strServerJarType = Mesnac.Basic.DataProcessor.RowValue(dr, "JarType", String.Empty);
|
|
intServerJarSerial = Mesnac.Basic.DataProcessor.RowValue(dr, "JarSerial", -1);
|
|
strMaterCode = Mesnac.Basic.DataProcessor.RowValue(dr, "Mater_Code", String.Empty);
|
|
strMaterName = Mesnac.Basic.DataProcessor.RowValue(dr, "Mater_Name", String.Empty);
|
|
strJarUsed = Mesnac.Basic.DataProcessor.RowValue(dr, "JarUsed", String.Empty);
|
|
|
|
bool isUpdate = false; //是否进行了本地更新
|
|
if (jarTable != null && jarTable.Rows.Count > 0)
|
|
{
|
|
foreach (DataRow row in jarTable.Rows)
|
|
{
|
|
#region 注释
|
|
///////获取服务器信息
|
|
//dbHelperServer.ClearParameter();
|
|
//StringBuilder serversqlstr = new StringBuilder("");
|
|
//serversqlstr.Append(@"select top 1 b.Mater_Code, a.Mater_Name from Pmt_material a inner join pmt_wm b on a.Mater_code=b.Mater_code where b.Jar_type=@JarType and b.Ware_num=@JarSerial and Equip_code=@EquipCode");
|
|
//dbHelperServer.CommandText = serversqlstr.ToString();
|
|
//dbHelperServer.AddParameter("@JarType", row["JarType"]);
|
|
//dbHelperServer.AddParameter("@JarSerial", row["JarSerial"]);
|
|
//dbHelperServer.AddParameter("@EquipCode", base.CurrEquipCode);
|
|
//DataTable materTable = dbHelperServer.ToDataTable();
|
|
//string strMaterCode = String.Empty;
|
|
//string strMaterName = String.Empty;
|
|
//if (materTable != null && materTable.Rows != null && materTable.Rows.Count > 0)
|
|
//{
|
|
// DataRow dr = materTable.Rows[0];
|
|
// strMaterCode = Mesnac.Basic.DataProcessor.RowValue(dr, "Mater_Code", String.Empty);
|
|
// strMaterName = Mesnac.Basic.DataProcessor.RowValue(dr, "Mater_Name", String.Empty);
|
|
//}
|
|
#endregion
|
|
|
|
#region 更新日罐物料名称
|
|
string strLocalJarType = Mesnac.Basic.DataProcessor.RowValue(row, "JarType", String.Empty);
|
|
int intLocalJarSerial = Mesnac.Basic.DataProcessor.RowValue(row, "JarSerial", -1);
|
|
if (!String.IsNullOrEmpty(strServerJarType) && strServerJarType.Trim() == strLocalJarType.Trim() && intServerJarSerial == intLocalJarSerial)
|
|
{
|
|
dbHelperlocal.ClearParameter();
|
|
string strSql = "update SytJar set MaterialName=@MaterialName where JarType=@JarType and JarSerial=@JarSerial";
|
|
dbHelperlocal.CommandText = strSql;
|
|
dbHelperlocal.AddParameter("@MaterialName", strMaterName.Trim());
|
|
dbHelperlocal.AddParameter("@JarType", row["JarType"]);
|
|
dbHelperlocal.AddParameter("@JarSerial", row["JarSerial"]);
|
|
dbHelperlocal.ExecuteNonQuery();
|
|
isUpdate = true;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 同步日罐中对应的物料
|
|
|
|
if (strLocalJarType == strServerJarType && intLocalJarSerial == intServerJarSerial)
|
|
{
|
|
if (!String.IsNullOrEmpty(strMaterCode))
|
|
{
|
|
string strMaterType = Mesnac.Basic.DataProcessor.RowValue(row, "JarType", String.Empty);
|
|
MaterialSynchronous.DownLoadMaterial(dbHelperlocal, strMaterCode, strMaterName, strMaterType);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
//如果本地没有此日罐参数,则追加
|
|
if (!isUpdate && !String.IsNullOrEmpty(strServerJarType))
|
|
{
|
|
string strSql3 = "insert into SytJar(JarSerial,JarType,MaterialName,JarUsed) values ({0},'{1}','{2}','{3}') ";
|
|
strSql3 = String.Format(strSql3, intServerJarSerial, strServerJarType, strMaterName, strJarUsed);
|
|
dbHelperlocal.ClearParameter();
|
|
dbHelperlocal.CommandText = strSql3;
|
|
dbHelperlocal.ExecuteNonQuery();
|
|
//同步日罐中对应的物料
|
|
MaterialSynchronous.DownLoadMaterial(dbHelperlocal, strMaterCode, strMaterName, strServerJarType);
|
|
}
|
|
}
|
|
}
|
|
ShowMsg(base.Language(20));
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|