using HcUtility.Core;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
namespace JobPingTaiWork
{
///
/// 箱满仓查出的按提单号的费用
///
public class Local_Mblnomb
{
#region private Fields
private string _MBLNO = string.Empty;
private string _MFNO = string.Empty;
private string _ISMAIN = string.Empty;
private string _id = string.Empty;
#endregion
#region R&W
public string MBLNO
{
get { return _MBLNO; }
set { _MBLNO = value; }
}
public string MFNO
{
get { return _MFNO; }
set { _MFNO = value; }
}
public string ISMAIN
{
get { return _ISMAIN; }
set { _ISMAIN = value; }
}
public string id
{
get { return _id; }
set { _id = value; }
}
#endregion
public Local_Mblnomb(string str) {
MBLNO = str;
}
public static List getSaveSql(List MBLNOList) {
List result = new List();
foreach (var item in MBLNOList) {
//if (sqlstr != "") sqlstr += " go ";
//var sqlstr = " insert into WLXX_MBLNO values ('" + item.MBLNO + "','" + item.MFNO + "') ";
var sqlstr = $" insert into WLXX_MBLNO (MBLNO,MFNO) select '{item.MBLNO}','{item.MFNO}' where not exists(select 1 from WLXX_MBLNO where MBLNO = '{item.MBLNO}') ";
result.Add(sqlstr);
}
return result;
}
public static List getSaveSql_D6(List MBLNOList)
{
List result = new List();
foreach (var item in MBLNOList)
{
//insert into WLXX_MBLNO (MBLNO,MFNO,ISMAIN) select '1','1','1' where not exists(select 1 from WLXX_MBLNO where MBLNO = '1')
var sqlstr = $" insert into WLXX_MBLNO (MBLNO,MFNO,ISMAIN) select '{item.MBLNO}','{item.MFNO}',{item.ISMAIN } where not exists(select 1 from WLXX_MBLNO where MBLNO = '{item.MBLNO}') ";
result.Add(sqlstr);
}
return result;
}
}
public class RepWLXXModel
{
public string status { get; set; }
public List message { get; set; }
}
///
/// 舱单状态 物流信息网
///
public class WLXXModel
{
public string HuoWuZhuangTai { get; set; }
public string JianShu { get; set; }
public string ShenBaoXiangShu { get; set; }
public string ZhongLiang { get; set; }
public string YuPeiShiJian { get; set; } //预配时间
public string YuPeiJieGuo { get; set; }
public string YunDiShiJian { get; set; } //运抵时间
public string YunDiJieGuo { get; set; }
public string FangXingShiJian { get; set; } //放行时间
public string FangXingZhuangTai { get; set; }
public string ZhuangZaiShiJian { get; set; } //装载时间
public string ZhuangZaiJieGuo { get; set; }
public class cdstatus
{
public DateTime time { get; set; }
public string status { get; set; }
public bool insert { get; set; }
public bool havetime { get; set; }
public string timestr
{
get
{
if (time.ToString("yyyy-MM-dd") == "1900-01-01") return "";
return time.ToString("yyyy-MM-dd HH:mm:ss");
}
}
public cdstatus(string status, string date)
{
this.status = status;
if (string.IsNullOrWhiteSpace(date)) havetime = false;
else havetime = true;
settime(date);
}
public void settime(string date) {
time = gettime(date);
}
public bool needinsert() {
return insert;
}
}
public string getlaststatus_str_D6(string ISMAIN)
{
var last = getlaststatus_D6(ISMAIN);
return last.status;
}
public string getlaststatus_time(string ISMAIN)
{
var last = getlaststatus_D6(ISMAIN);
if (last.time.ToString("yyyy-MM-dd") == "1900-01-01") return "";
return last.time.ToString("yyyy-MM-dd HH:mm:ss");
}
public List getstatusList()
{
List cdlist = new List();
cdstatus yupei = new cdstatus(YuPeiJieGuo, YuPeiShiJian);
cdstatus yundi = new cdstatus(YunDiJieGuo, YunDiShiJian);
cdstatus zhuangzai = new cdstatus(ZhuangZaiJieGuo, ZhuangZaiShiJian);
cdstatus fangxing = new cdstatus(FangXingZhuangTai, FangXingShiJian);
if (yupei.status == "接受申报")
{
yupei.status = "接受申报";
yupei.insert = true;
}
else {
yupei.status = "接受申报";
yupei.insert = false;
}
cdlist.Add(yupei);
if (yundi.status == "接受申报_运抵正常")
{
yundi.status = "运抵正常";
yundi.insert = true;
}
else
{
yundi.status = "运抵正常";
yundi.insert = false;
}
cdlist.Add(yundi);
if (zhuangzai.status == "接受申报_同意装载" && zhuangzai.havetime)
{
zhuangzai.status = "装载放行";
zhuangzai.insert = true;
}
else
{
zhuangzai.status = "装载放行";
zhuangzai.insert = false;
}
cdlist.Add(zhuangzai);
if (fangxing.status == "已放行" && zhuangzai.havetime)
{
fangxing.status = "报关单放行";
fangxing.insert = true;
}
else
{
fangxing.status = "报关单放行";
fangxing.insert = false;
}
cdlist.Add(fangxing);
return cdlist;
}
public List getstatusList_D6()
{
List cdlist = new List();
cdstatus yupei = new cdstatus(YuPeiJieGuo, YuPeiShiJian);
cdstatus yundi = new cdstatus(YunDiJieGuo, YunDiShiJian);
cdstatus zhuangzai = new cdstatus(ZhuangZaiJieGuo, ZhuangZaiShiJian);
cdstatus fangxing = new cdstatus(FangXingZhuangTai, FangXingShiJian);
if (yupei.status == "接受申报")
{
yupei.status = "接受申报";
yupei.insert = true;
}
else
{
yupei.status = "接受申报";
yupei.insert = false;
}
cdlist.Add(yupei);
//if (yundi.status == "接受申报_运抵正常")
//{
// yundi.status = "运抵正常";
// yundi.insert = true;
//}
//else
//{
// yundi.status = "运抵正常";
// yundi.insert = false;
//}
//cdlist.Add(yundi);
//if (zhuangzai.status == "接受申报_同意装载" && zhuangzai.havetime)
//{
// zhuangzai.status = "装载放行";
// zhuangzai.insert = true;
//}
//else
//{
// zhuangzai.status = "装载放行";
// zhuangzai.insert = false;
//}
//cdlist.Add(zhuangzai);
//if (fangxing.status == "已放行" && zhuangzai.havetime)
//{
// fangxing.status = "报关单放行";
// fangxing.insert = true;
//}
//else
//{
// fangxing.status = "报关单放行";
// fangxing.insert = false;
//}
//cdlist.Add(fangxing);
return cdlist;
}
public cdstatus getlaststatus_D6(string ISMAIN)
{
//List cdlist = new List();
//cdstatus yupei = new cdstatus(YuPeiJieGuo, YuPeiShiJian);
//cdstatus yundi = new cdstatus(YunDiJieGuo, YunDiShiJian);
//cdstatus zhuangzai = new cdstatus(ZhuangZaiJieGuo, ZhuangZaiShiJian);
//cdstatus fangxing = new cdstatus(FangXingZhuangTai, FangXingShiJian);
List cdlist = getstatusList_D6();
//cdlist.Add(yupei);
//cdlist.Add(yundi);
//cdlist.Add(zhuangzai);
//cdlist.Add(fangxing);
//找到时间最晚的内容
//var last = cdlist.OrderByDescending(t => t.time).FirstOrDefault();
//return last;
var result = new cdstatus("","1900-01-01");
foreach (var item in cdlist) {
if (item.time > result.time && item.insert) {
if (ISMAIN == "0") {
if (item.status == "装载放行") continue;
}
result.status = item.status;
result.insert = item.insert;
result.settime(item.timestr);
}
}
return result;
}
private static DateTime gettime(string timestr)
{
if (string.IsNullOrWhiteSpace(timestr))
{
return Convert.ToDateTime("1900-01-01");
}
else
{
return Convert.ToDateTime(timestr);
}
}
///
/// 对于临时插队的主单信息
/// 如果状态文字包含 接受申报 放行
///
///
public bool 临时读取完成() {
var statuslist = getstatusList();
foreach (var item in statuslist) {
if (读取完成(item.status)) {
return true;
}
}
return false;
}
private bool 读取完成(string status) {
if(status.IndexOf("接受申报") >= 0 || status.IndexOf("放行") >= 0) return true;
return false;
}
}
public class DoWork
{
public static List GetMBLNOList(string connStr, string condition)
{
var result = new List();
var sqlQuery = condition;
DataTable tQuery = QuerySql(connStr, condition);
if (tQuery.Rows.Count > 0)
{
foreach (DataRow row in tQuery.Rows)
{
Local_Mblnomb item = new Local_Mblnomb(row["MBLNO"].ToString());
item.MFNO = row["MFNO"].ToString();
item.id = row["MFNO"].ToString();
result.Add(item);
}
}
return result;
}
public static List GetMBLNOList_D6(string connStr, string condition)
{
var result = new List();
var sqlQuery = condition;
DataTable tQuery = QuerySql(connStr, condition);
if (tQuery.Rows.Count > 0)
{
foreach (DataRow row in tQuery.Rows)
{
Local_Mblnomb item = new Local_Mblnomb(row["MBLNO"].ToString());
item.MFNO = row["MFNO"].ToString();
item.ISMAIN = row["ISMAIN"].ToString();
result.Add(item);
}
}
return result;
}
public static DataTable QuerySql(string connStr, string condition)
{
SqlConnection conn = new SqlConnection(connStr);
SqlDataAdapter dataAdapter = new SqlDataAdapter(condition, conn);
DataTable tQuery = new DataTable();
dataAdapter.Fill(tQuery);
return tQuery;
}
public static int ExecSql(string connStr, string SqlStr)
{
SqlConnection SCON = null;//连接对象
SqlCommand SCom = new SqlCommand();//命令对象
SCON = new SqlConnection(connStr);
SCON.Open();
SCom.CommandText = SqlStr;
SCom.Connection = SCON;
SCom.CommandType = CommandType.Text;
int num = SCom.ExecuteNonQuery();
SCON.Close();
return num;
}
}
[JsonObject]//头表
public class edistatusMb : ModelObjectBillHead
{
public override Dictionary GetPKey()
{//用于给扩展的动态数据提供主键字段名
var d = new Dictionary() { { "GID", ModelDBOprationType.All } };
return d;
}
public Dictionary SaveDic = new Dictionary();
public static string getSQL()
{
return " select * from op_seae_edi_status";
}
public edistatusMb()
{
TableName = "op_seae_edi_status";
}
public override string GetBillNoFieldName()
{
return "MFNO";
}
public override string GetTimeMarkFieldName()
{
return "";
}
}
public class EdiStatusDAL {
public static string connstr { get; set; }
public static List GetDataList(string connStr, string condition)
{
connstr = connStr;
var strcondition = edistatusMb.getSQL();
if (!string.IsNullOrWhiteSpace(condition))
{
strcondition += " where " + condition;
}
var result = new List();
var tQuery = DoWork.QuerySql(connStr, strcondition);
if (tQuery.Rows.Count > 0)
{
foreach (DataRow row in tQuery.Rows)
{
edistatusMb item = new edistatusMb();
item.SetExtendValue(tQuery, row);
result.Add(item);
}
}
return result;
}
public static bool Insert(edistatusMb edistatus)
{
edistatus.SetValue("gid", System.Guid.NewGuid().ToString());
var str = string.Format(" insert into op_seae_edi_status values(newid(),'{0}','{1}','{2}','{3}',getdate(),'{4}') ", edistatus.GetValue("mfno"), edistatus.GetValue("mblno"), edistatus.GetValue("statustext"), edistatus.GetValue("statustime"), edistatus.GetValue("ShenBaoXiangShu"));
var _r = DoWork.ExecSql(connstr,str);
if (_r > 0) return true;
else return false;
}
public static bool Update(edistatusMb edistatus)
{
var str = string.Format(" update op_seae_edi_status set statustime='{0}',ShenBaoXiangShu={1} where mfno='{2}' and statustext='{3}' ", edistatus.GetValue("statustime"), edistatus.GetValue("ShenBaoXiangShu"), edistatus.GetValue("mfno"), edistatus.GetValue("statustext"));
var _r = DoWork.ExecSql(connstr, str);
if (_r > 0) return true;
else return false;
}
public static bool Delete(edistatusMb edistatus)
{
var str = string.Format(" delete from op_seae_edi_status where mfno='{0}' and statustext='{1}' ",edistatus.GetValue("mfno"), edistatus.GetValue("statustext"));
var _r = DoWork.ExecSql(connstr, str);
if (_r > 0) return true;
else return false;
}
}
public class edistatusMb_D6 : edistatusMb
{
public override Dictionary GetPKey()
{//用于给扩展的动态数据提供主键字段名
var d = new Dictionary() { { "GID", ModelDBOprationType.All } };
return d;
}
public Dictionary SaveDic = new Dictionary();
public static string getSQL()
{
return " select * from t_op_seae_edi ";
}
public edistatusMb_D6()
{
TableName = "t_op_seae_edi";
}
public override string GetBillNoFieldName()
{
return "编号";
}
public override string GetTimeMarkFieldName()
{
return "";
}
}
public class EdiStatusDAL_D6
{
public static string connStr { get; set; }
public static List GetDataList(string connstr, string condition)
{
connStr = connstr;
var strcondition = edistatusMb_D6.getSQL();
if (!string.IsNullOrWhiteSpace(condition))
{
strcondition += " where " + condition;
}
var result = new List();
var tQuery = DoWork.QuerySql(connStr, strcondition);
if (tQuery.Rows.Count > 0)
{
foreach (DataRow row in tQuery.Rows)
{
edistatusMb_D6 item = new edistatusMb_D6();
item.SetExtendValue(tQuery, row);
result.Add(item);
}
}
return result;
}
public static bool Update(WLXXModel edistatus,string MFNO,string ISMAIN)
{
var str = string.Format($" update t_op_seae_edi set 申报状态='{edistatus.getlaststatus_str_D6(ISMAIN)}',状态日期='{edistatus.getlaststatus_time(ISMAIN)}' where 编号='{MFNO}' ");
var _r = DoWork.ExecSql(connStr, str);
if (_r > 0) return true;
else return false;
}
}
}