using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
using System.Data;
using cuidian.Sql;
using WdtUtils.Proxy;
using WdtUtils.UpLoad;
using WdtUtils;
using cuidian.Common;
namespace TempDbToWang
{
///
/// 其他出库单从中间库上传到旺店通
///
///
public delegate void DelSql();
public class UploadRdrecord09 : BaseUpload
{
protected override void _PrepareData(Hashtable args)
{
string sql = "select sysid,id,ccode from wtu..rdrecord09 where processflag=0 and direction=0 ";
_data = DbUtils.Fill(sql, ConnectionUtils.Instance.GetConnection());
}
public List _results = new List();
private string _strSql="";
public string StrSql
{
get
{
return _strSql;
}
set
{
this._strSql = value;
}
}
protected override AddResult _Upload(DataRow dr)
{
Rdrecord09Upload upload = new Rdrecord09Upload();
string data = string.Empty;
AddResult result = upload.UploadToWang(_GetData(dr));
_results.Add(result);
return result;
}
protected override void _WriteLog(AddResult result, DataRow dr)
{
int id = Convert.ToInt32(dr["sysid"]);
string sql;
if (result.IsSucess)
{
//sql = "update wtu..rdrecord09 set processdate=getdate(),processflag=1 where sysid=" + id.ToString();
sql = "update wtu..rdrecord09 set processdate=getdate(),processflag=1,newcode='" + result.DocCode + "' where sysid=" + id.ToString();
OperationLog.Utils.UpdateTempRecord(sql);
}
else
{
OperationLog.Utils.WriteErrorLog("上传旺店通其他出库单", "其他出库单:" + dr["ccode"].ToString() + "\t\r" + result.Message);
}
}
protected override string _GetData(DataRow dr)
{
Dictionary args = new Dictionary();
string id = dr["id"].ToString();
args.Add("rdrecord09", "select * from wtu..rdrecord09 where id=" + id);
args.Add("rdrecords09", "select * from wtu..rdrecords09 where id=" + id);
DataSet ds = DbUtils.Fill(args, ConnectionUtils.Instance.GetConnection());
Stockin_List head = __GetHead(ds);
head.detail_list = __GetDetails(ds);
return JsonUtils.GetJsonString(head);
}
private Stockin_List __GetHead(DataSet ds)
{
Stockin_List rtn = new Stockin_List();
DataTable dt = ds.Tables["rdrecord09"];
rtn.outer_no = dt.Rows[0]["ccode"].ToString();
//rtn.warehouse_no = "yilv2test";
rtn.warehouse_no = dt.Rows[0]["cWhCode"].ToString();
rtn.remark = "来源U8";
return rtn;
}
private Detail_List[] __GetDetails(DataSet ds)
{
int cnt = ds.Tables["rdrecords09"].Rows.Count;
DataTable dt = ds.Tables["rdrecords09"];
Detail_List[] rtn = new Detail_List[cnt];
for (int i = 0; i < cnt; i++)
{
Detail_List item = new Detail_List();
item.spec_no = dt.Rows[i]["cInvCode"].ToString();
item.num = _ConvertNotStr(dt.Rows[i]["iQuantity"].ToString());
item.price = _ConvertNotStr(dt.Rows[i]["iUnitCost"].ToString());
//item.stockin_price = _ConvertNotStr(dt.Rows[i]["iUnitCost"].ToString());
rtn[i] = item;
}
return rtn;
}
private string _ConvertNotStr(string valueStr)
{
return string.IsNullOrWhiteSpace(valueStr) ? "0" : valueStr;
}
}
}