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.
277 lines
12 KiB
C#
277 lines
12 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Mesnac.Action.Base;
|
|
using Mesnac.Codd.Session;
|
|
using Mesnac.Basic;
|
|
using System.Data;
|
|
|
|
namespace Mesnac.Action.Intake.Qingquan.SynchroData
|
|
{
|
|
#region 网络同步大罐设置、日罐设置、物料信息
|
|
/// <summary>
|
|
/// 网络同步大罐设置、日罐设置、物料信息
|
|
/// </summary>
|
|
public class WareMaterSynchronous : IntakeAction, IAction
|
|
{
|
|
public string GetBigbino(string materid)
|
|
{
|
|
string bin_num = "";
|
|
DbHelper dbHelperLocal = NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
if (dbHelperLocal == null)
|
|
{
|
|
return "";
|
|
}
|
|
dbHelperLocal.ClearParameter();
|
|
dbHelperLocal.CommandType = CommandType.Text;
|
|
string loacdsqlstr = "select * from pst_daybin ";
|
|
loacdsqlstr += " where bin_type=2 and mater_id= @materid ";
|
|
dbHelperLocal.CommandText = loacdsqlstr;
|
|
dbHelperLocal.AddParameter("@materide", materid);
|
|
|
|
IDataReader readerLocal = dbHelperLocal.ToDbDataReader();
|
|
if (readerLocal == null)
|
|
{
|
|
return "";
|
|
}
|
|
if (readerLocal.Read())
|
|
{
|
|
bin_num = readerLocal["bin_num"] as string;
|
|
return bin_num;
|
|
|
|
}
|
|
else
|
|
return bin_num;
|
|
|
|
}
|
|
// 根据物料代码从网络同步物料信息
|
|
public void downLoadMater(string MaterCode)
|
|
{
|
|
string matername = String.Empty;
|
|
string materbyname = String.Empty;
|
|
DbHelper dbHelperLocal = NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
if (dbHelperLocal == null)
|
|
{
|
|
return;
|
|
}
|
|
DbHelper dbHelperServer = NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Server);
|
|
if (dbHelperServer == null)
|
|
{
|
|
return;
|
|
}
|
|
//1、从网络库获取物料信息
|
|
dbHelperServer.ClearParameter();
|
|
dbHelperServer.CommandType = CommandType.Text;
|
|
string serversqlstr = "select * from pmt_material ";
|
|
serversqlstr += " where mater_Code = @materCode";
|
|
dbHelperServer.CommandText = serversqlstr;
|
|
dbHelperServer.AddParameter("@materCode", MaterCode);
|
|
|
|
IDataReader readerServer = dbHelperServer.ToDbDataReader();
|
|
if (readerServer == null)
|
|
{
|
|
return;
|
|
}
|
|
if (readerServer.Read())
|
|
{
|
|
matername = readerServer["Mater_Name"] as string;
|
|
materbyname = readerServer["Mater_byName"] as string;
|
|
}
|
|
readerServer.Close();
|
|
|
|
//2、从本地表查询物料信息,若已经存在该物料则更新,不存在则插入
|
|
dbHelperLocal.ClearParameter();
|
|
dbHelperLocal.CommandType = CommandType.Text;
|
|
string loacdsqlstr = "select * from pmt_material ";
|
|
loacdsqlstr += " where mater_Code = @MaterCode or mater_name=@MaterName ";
|
|
dbHelperLocal.CommandText = loacdsqlstr;
|
|
dbHelperLocal.AddParameter("@MaterCode", MaterCode);
|
|
dbHelperLocal.AddParameter("@MaterName", matername);
|
|
|
|
IDataReader readerLocal = dbHelperLocal.ToDbDataReader();
|
|
if (readerLocal == null)
|
|
{
|
|
return;
|
|
}
|
|
if (readerLocal.Read())
|
|
{
|
|
readerLocal.Close();
|
|
dbHelperLocal.ClearParameter();
|
|
dbHelperLocal.CommandType = CommandType.Text;
|
|
loacdsqlstr = " update pmt_material ";
|
|
loacdsqlstr += " set mater_Code=@MaterCode,Mater_name=@MaterName,Mater_ByCode=@MaterName ";
|
|
loacdsqlstr += " where mater_Code = @MaterCode or mater_name=@MaterName ";
|
|
dbHelperLocal.CommandText = loacdsqlstr;
|
|
dbHelperLocal.AddParameter("@MaterCode", MaterCode);
|
|
dbHelperLocal.AddParameter("@MaterName", matername);
|
|
dbHelperLocal.ExecuteNonQuery();
|
|
}
|
|
else
|
|
{
|
|
readerLocal.Close();
|
|
dbHelperLocal.ClearParameter();
|
|
dbHelperLocal.CommandType = CommandType.Text;
|
|
loacdsqlstr = " insert into pmt_material(mater_id,mater_Code,mater_name,mater_Bycode) ";
|
|
loacdsqlstr += " values ((select isnull(max(Mater_ID),0)+1 as id from pmt_material) ,@MaterCode,@MaterName,@MaterName )";
|
|
dbHelperLocal.CommandText = loacdsqlstr;
|
|
dbHelperLocal.AddParameter("@MaterCode", MaterCode);
|
|
dbHelperLocal.AddParameter("@MaterName", matername);
|
|
dbHelperLocal.ExecuteNonQuery();
|
|
}
|
|
|
|
|
|
}
|
|
public void Run(RuntimeParameter runtime)
|
|
{
|
|
base.RunIni(runtime);
|
|
if (base.NetType == NetTypes.Local)
|
|
{
|
|
base.LogError("{从网络同步大罐设置、日罐设置、物料信息} 此系统版本为单机版,不能进行数据同步...");
|
|
ShowMsg(base.Language(32));
|
|
|
|
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 G_EquipCode = "";
|
|
dbHelperServer.ClearParameter();
|
|
dbHelperServer.CommandType = CommandType.Text;
|
|
string serversqlstr = "select * from pmt_wm where equip_Code= ";
|
|
serversqlstr += " where jar_type='炭黑' and equip_Code = @G_EquipCode ";
|
|
dbHelperServer.CommandText = serversqlstr;
|
|
dbHelperServer.AddParameter("@G_EquipCode", G_EquipCode);
|
|
IDataReader readerServer = dbHelperServer.ToDbDataReader();
|
|
if (readerServer == null)
|
|
{
|
|
return;
|
|
}
|
|
string matercode = "";
|
|
string matername = "";
|
|
string warenum = "";
|
|
string materid = "";
|
|
while (readerServer.Read())
|
|
{
|
|
matercode = readerServer["Mater_Code"] as string;
|
|
warenum = readerServer["ware_num"] as string;
|
|
downLoadMater(matercode);
|
|
|
|
dbHelperLocal.ClearParameter();
|
|
dbHelperLocal.CommandType = CommandType.Text;
|
|
string loacdsqlstr = "select * from pmt_material ";
|
|
loacdsqlstr += " where mater_Code = @MaterCode ";
|
|
dbHelperLocal.CommandText = loacdsqlstr;
|
|
dbHelperLocal.AddParameter("@MaterCode", matercode);
|
|
|
|
IDataReader readerLocal = dbHelperLocal.ToDbDataReader();
|
|
if (readerLocal.Read())
|
|
{
|
|
matername = readerLocal["Mater_Name"] as string;
|
|
materid = readerLocal["Mater_id"] as string;
|
|
}
|
|
readerLocal.Close();
|
|
|
|
dbHelperLocal.ClearParameter();
|
|
dbHelperLocal.CommandType = CommandType.Text;
|
|
loacdsqlstr = " update pst_daybin ";
|
|
loacdsqlstr += " set mater_id =@materid,mater_name=@matername ";
|
|
loacdsqlstr += " where bin_type=2 and equip_Code=0 and bin_num= @warenum ";
|
|
dbHelperLocal.CommandText = loacdsqlstr;
|
|
dbHelperLocal.AddParameter("@materid", materid);
|
|
dbHelperLocal.AddParameter("@matername", matername);
|
|
dbHelperLocal.AddParameter("@warenum", warenum);
|
|
dbHelperLocal.ExecuteNonQuery();
|
|
}
|
|
readerServer.Close();
|
|
|
|
//同步日罐设置
|
|
string equipcode = "";
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
equipcode = ""; //应从配置文件获取
|
|
if (equipcode != "")
|
|
{
|
|
dbHelperServer.ClearParameter();
|
|
dbHelperServer.CommandType = CommandType.Text;
|
|
serversqlstr = "select * from pmt_wm where equip_Code= ";
|
|
serversqlstr += " where jar_type='炭黑' and equip_Code = @equipcode ";
|
|
dbHelperServer.CommandText = serversqlstr;
|
|
dbHelperServer.AddParameter("@G_EquipCode", equipcode);
|
|
readerServer = dbHelperServer.ToDbDataReader();
|
|
if (readerServer == null)
|
|
{
|
|
return;
|
|
}
|
|
string bigno = "";
|
|
while (readerServer.Read())
|
|
{
|
|
matercode = readerServer["Mater_Code"] as string;
|
|
warenum = readerServer["ware_num"] as string;
|
|
downLoadMater(matercode);
|
|
|
|
dbHelperLocal.ClearParameter();
|
|
dbHelperLocal.CommandType = CommandType.Text;
|
|
string loacdsqlstr = "select * from pmt_material ";
|
|
loacdsqlstr += " where mater_Code = @MaterCode ";
|
|
dbHelperLocal.CommandText = loacdsqlstr;
|
|
dbHelperLocal.AddParameter("@MaterCode", matercode);
|
|
|
|
IDataReader readerLocal = dbHelperLocal.ToDbDataReader();
|
|
if (readerLocal.Read())
|
|
{
|
|
matername = readerLocal["Mater_Name"] as string;
|
|
materid = readerLocal["Mater_id"] as string;
|
|
}
|
|
readerLocal.Close();
|
|
|
|
bigno = GetBigbino(materid);
|
|
|
|
|
|
dbHelperLocal.ClearParameter();
|
|
dbHelperLocal.CommandType = CommandType.Text;
|
|
loacdsqlstr = " update pst_daybin ";
|
|
loacdsqlstr += " set mater_id =@materid,mater_name=@matername ,silo_num=@silo_num ";
|
|
loacdsqlstr += " bin_type=1 and equip_Code=@equipcode and bin_num= @bigno ";
|
|
dbHelperLocal.CommandText = loacdsqlstr;
|
|
dbHelperLocal.AddParameter("@materid", materid);
|
|
dbHelperLocal.AddParameter("@matername", matername);
|
|
dbHelperLocal.AddParameter("@bigno", bigno);
|
|
dbHelperLocal.AddParameter("@warenum", warenum);
|
|
dbHelperLocal.ExecuteNonQuery();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
}
|