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.
DS7/DSWeb/Areas/MvcShipping/DAL/MsOpExpress/MsOpExpressDAL.cs

911 lines
42 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcShipping.Models.MsOpExpress;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.EntityDA;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
using System.Data.SqlClient;
using DSWeb.DataAccess;
using System.IO;
using HcUtility.Core;
using DSWeb.Areas.CommMng.DAL;
using DotNet4.Utilities;
using DSWeb.SoftMng.DBUtility;
namespace DSWeb.MvcShipping.DAL.MsOpExpressDAL
{
public class MsOpExpressDAL
{
#region 查询
static public List<MsOpExpress> GetDataList(string strCondition, string userid, string usercode, string companyid, string sort = null, string load = null)
{
var rangstr = GetRangDAStr("index", userid, usercode, companyid);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var strSql = new StringBuilder();
strSql.Append("SELECT GID,EXNO,BILLDATE,BILLSTATUS,BILLTYPE,EXPRESSCORP,SENDERCUST,SENDERATTN,SENDERCITY,");
strSql.Append("SENDER,SENDERADDR,SENDERPOST,SENDERTEL,RECEIVECUST,RECEIVEATTN,BILLFEE,SENDERPROVINCE,RECEIVEPROVINCE,");
strSql.Append("RECEIVECITY,[RECEIVE],RECEIVEADDR,RECEIVEPOST,RECEIVETEL,GOODSNAME,REMARKS,CREATEUSER,isnull(EXCOUNT,0)EXCOUNT");
strSql.Append(",(select top 1 showname from [user] where GID=OP_EXPRESS.CREATEUSER) as CREATEUSERREF,CREATETIME");
strSql.Append(" from OP_EXPRESS ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
//
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by CREATETIME desc");
}
return SetData(strSql);
}
static public MsOpExpress GetData(string condition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT GID,EXNO,BILLDATE,BILLSTATUS,BILLTYPE,EXPRESSCORP,SENDERCUST,SENDERATTN,SENDERCITY,");
strSql.Append("SENDER,SENDERADDR,SENDERPOST,SENDERTEL,RECEIVECUST,RECEIVEATTN,BILLFEE,isnull(EXCOUNT,0)EXCOUNT,");
strSql.Append("RECEIVECITY,[RECEIVE],RECEIVEADDR,RECEIVEPOST,RECEIVETEL,GOODSNAME,REMARKS,CREATEUSER,SENDERPROVINCE,RECEIVEPROVINCE");
strSql.Append(",(select top 1 showname from [user] where GID=OP_EXPRESS.CREATEUSER) as CREATEUSERREF,CREATETIME");
strSql.Append(" from OP_EXPRESS ");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" where " + condition);
}
var list=SetData(strSql);
if (list.Count > 0)
return list[0];
return new MsOpExpress();
}
private static List<MsOpExpress> SetData(StringBuilder strSql)
{
var headList = new List<MsOpExpress>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsOpExpress data = new MsOpExpress();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);//业务编号
data.EXNO = Convert.ToString(reader["EXNO"]);//委托方式
if (reader["BILLDATE"] != DBNull.Value)
data.BILLDATE = Convert.ToDateTime(reader["BILLDATE"]).ToString("yyyy-MM-dd");//到港日期
data.BILLSTATUS = Convert.ToString(reader["BILLSTATUS"]);//
data.BILLTYPE = Convert.ToString(reader["BILLTYPE"]);//
data.EXPRESSCORP = Convert.ToString(reader["EXPRESSCORP"]);//主编号
data.SENDERCUST = Convert.ToString(reader["SENDERCUST"]);//委托编号
data.SENDERATTN = Convert.ToString(reader["SENDERATTN"]);//主提单号
data.SENDERCITY = Convert.ToString(reader["SENDERCITY"]);//分提单号
data.SENDER = Convert.ToString(reader["SENDER"]);// 业务状态
data.SENDERADDR = Convert.ToString(reader["SENDERADDR"]);// 费用状态
data.SENDERPOST = Convert.ToString(reader["SENDERPOST"]);//会计期间
data.SENDERTEL = Convert.ToString(reader["SENDERTEL"]);//委托单位
data.RECEIVECUST = Convert.ToString(reader["RECEIVECUST"]);//业务来源
data.RECEIVEATTN = Convert.ToString(reader["RECEIVEATTN"]);//来源明细
data.RECEIVECITY = Convert.ToString(reader["RECEIVECITY"]);//录入人
data.RECEIVE = Convert.ToString(reader["RECEIVE"]);//操作员
data.RECEIVEADDR = Convert.ToString(reader["RECEIVEADDR"]);//客服员
data.RECEIVEPOST = Convert.ToString(reader["RECEIVEPOST"]);//揽货人
data.RECEIVETEL = Convert.ToString(reader["RECEIVETEL"]);//分公司代码
data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]);//所属部门
data.REMARKS = Convert.ToString(reader["REMARKS"]);//创建时间
data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]);//创建时间
data.CREATEUSERREF = Convert.ToString(reader["CREATEUSERREF"]);//创建时间
data.SENDERPROVINCE = Convert.ToString(reader["SENDERPROVINCE"]);//发件人省份
data.RECEIVEPROVINCE = Convert.ToString(reader["RECEIVEPROVINCE"]);//收件人省份
if (reader["CREATETIME"] != DBNull.Value)
data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]).ToString("yyyy-MM-dd HH:mm:ss");
data.BILLFEE = reader["BILLFEE"].ToString();//快递费
data.EXCOUNT = Convert.ToDecimal(reader["EXCOUNT"]);//寄托物数量
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static DBResult RefreshExpressSTATUSList(List<MsOpExpress> bodyList, string status)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"update OP_EXPRESS set BILLSTATUS=@BILLSTATUS WHERE GID=@GID ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@BILLSTATUS", DbType.String, status);
db.AddInParameter(cmdInsert, "@GID", DbType.String, enumValue.GID);
db.ExecuteNonQuery(cmdInsert, tran);
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
public static DBResult RefreshExpressSTATUS(string expid,string status)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"update OP_EXPRESS set BILLSTATUS=@BILLSTATUS WHERE GID=@GID ");
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@BILLSTATUS", DbType.String, status);
db.AddInParameter(cmdInsert, "@GID", DbType.String, expid);
db.ExecuteNonQuery(cmdInsert, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
public static DBResult UpdateSFExpress(string expid,string mailno, string status)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"update OP_EXPRESS set BILLSTATUS=@BILLSTATUS,EXNO =@EXNO WHERE GID=@GID ");
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@BILLSTATUS", DbType.String, status);
db.AddInParameter(cmdInsert, "@EXNO", DbType.String, mailno);
db.AddInParameter(cmdInsert, "@GID", DbType.String, expid);
db.ExecuteNonQuery(cmdInsert, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
#region 快递动态
static public DBResult GetExpressStatusList(string expno, string expcorpid,string expid)
{
var result = new DBResult();
result.Success = true;
try
{
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = "http://www.kuaidi100.com/autonumber/autoComNum?text="+expno,//URL这里都是测试 必需项
Referer = "http://www.kuaidi100.com/",
Encoding = null,//编码格式utf-8,gb2312,gbk 可选项 默认类会自动识别
Host = "www.kuaidi100.com",
UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",
Accept = "application/json, text/javascript, */*",// 可选项有默认值
ContentType = "text/html",
Method = "POST",//URL 可选项 默认为Get
};
HttpResult resulthtml = http.GetHtml(item);
var mycookie = resulthtml.Cookie;
item = new HttpItem()
{
URL = "http://www.kuaidi100.com/query?type="+expcorpid+"&postid="+expno+"&id=1&valicode=&temp=0.07429930970249981",//URL这里都是测试 必需项
Referer = "http://www.kuaidi100.com/",
Encoding = null,//编码格式utf-8,gb2312,gbk 可选项 默认类会自动识别
Cookie = mycookie,
Host = "www.kuaidi100.com",
UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",
Accept = "text/html, application/xhtml+xml, */*",// 可选项有默认值
ContentType = "application/x-www-form-urlencoded",
Method = "GET",//URL 可选项 默认为Get
};
resulthtml = http.GetHtml(item);
result.Message = resulthtml.Html;
var alltext = result.Message;
alltext = alltext.Replace(" ","");
if (alltext.IndexOf("已签收")>=0){
RefreshExpressSTATUS(expid,"已收件");
}
}
catch
{
result.Success = false;
result.Message = "提取数据过程中发生错误,请联系系统管理员!";
}
// bodyList=SumBodyList(bodyList);
return result;
}
#endregion
#endregion
#region 查询费用数据
static public List<MsOpReceiptEntity> GetExpressDocList(string strCondition, string userid, string username, string companyid,string sort=null)
{
//var rangstr = GetRangDAStr(userid, username, companyid);
//if (!string.IsNullOrEmpty(rangstr))
//{
// if (!string.IsNullOrEmpty(strCondition))
// {
// strCondition = strCondition + " and " + rangstr;
// }
// else
// {
// strCondition = rangstr;
// }
//}
StringBuilder strSql = new StringBuilder();
strSql.Append("select e.GID,d.GID DOCID,e.DOCTYPE, d.TRANCNO, d.ISREPEAT, d.REPEAT_MAN, convert(char(10),d.REPEAT_DATE,20) as REPEAT_DATE, d.ISRECEIVE,");
strSql.Append("d.RETURN_MAN, convert(char(10),d.RETURN_DATE,20) as RETURN_DATE, d.RETURN_TRANCER, d.RETURN_TRANCNO, d.REMARK, ");
strSql.Append("d.BSNO, d.CORPID, d.CREATEUSER, d.CREATETIME, d.MODIFIEDUSER, d.MODIFIEDTIME, d.RECEIPTNO, d.RECEIPTTYPE, d.RECEIVE_MAN,");
strSql.Append("convert(char(10),d.RECEIVE_DATE,20) as RECEIVE_DATE, d.SEND_MAN, convert(char(10),d.SEND_DATE,20) as SEND_DATE, d.TRANCER");
strSql.Append(",b.CUSTNO,b.MBLNO,b.CUSTOMERNAME,b.OPLBNAME,d.RECEIPTTYPE + '-' + d.RECEIPTNO AS RECEIPTTYPENO,b.OP,b.SALE");
strSql.Append(" from op_express_doc e left join op_receipt d on (d.GID=e.DOCID) ");
strSql.Append("left join v_op_bs b on (b.BSNO=d.BSNO) ");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}
if (!string.IsNullOrEmpty(sort))
{
strSql.Append(" order by " + sort);
}
else
{
strSql.Append(" order by CREATETIME desc");
}
return SetExpressDocData(strSql);
}
private static List<MsOpReceiptEntity> SetExpressDocData(StringBuilder strSql)
{
var bodyList = new List<MsOpReceiptEntity>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsOpReceiptEntity data = new MsOpReceiptEntity();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);//惟一编号
data.DOCID = Convert.ToString(reader["DOCID"]);//惟一编号
data.DOCTYPE = Convert.ToString(reader["DOCTYPE"]);//惟一编号
data.BSNO = Convert.ToString(reader["BSNO"]);//关联编号/业务编号BSNO
data.RECEIPTNO = Convert.ToString(reader["RECEIPTNO"]);//单据编号
data.RECEIPTTYPE = Convert.ToString(reader["RECEIPTTYPE"]);//单据类型
data.RECEIPTTYPENO = Convert.ToString(reader["RECEIPTTYPENO"]);//单据类型
data.RECEIVE_MAN = Convert.ToString(reader["RECEIVE_MAN"]);//接单人
data.RECEIVE_DATE = Convert.ToString(reader["RECEIVE_DATE"]);//接单日期
//if (reader["RECEIVE_DATE"] != DBNull.Value)
// data.RECEIVE_DATE = Convert.ToDateTime(reader["RECEIVE_DATE"]);//接单日期
data.SEND_MAN = Convert.ToString(reader["SEND_MAN"]);//送单人
data.SEND_DATE = Convert.ToString(reader["SEND_DATE"]);//接单日期
//if (reader["SEND_DATE"] != DBNull.Value)
// data.SEND_DATE = Convert.ToDateTime(reader["SEND_DATE"]);//送单日期
data.TRANCER = Convert.ToString(reader["TRANCER"]);//送单的快递公司
data.TRANCNO = Convert.ToString(reader["TRANCNO"]);//送单的快递单号
if (reader["ISREPEAT"] != DBNull.Value)
data.ISREPEAT = Convert.ToString(reader["ISREPEAT"]);//是否回单
if (data.ISREPEAT == "0")
data.ISREPEAT = "否";
else
data.ISREPEAT = "是";
data.REPEAT_MAN = Convert.ToString(reader["REPEAT_MAN"]);//回单人
data.REPEAT_DATE = Convert.ToString(reader["REPEAT_DATE"]);//回单日期
//if (reader["REPEAT_DATE"] != DBNull.Value)
// data.REPEAT_DATE = Convert.ToDateTime(reader["REPEAT_DATE"]);//回单日期
if (reader["ISRECEIVE"] != DBNull.Value)
data.ISRECEIVE = Convert.ToString(reader["ISRECEIVE"]);//是否还单
if (data.ISRECEIVE == "0")
data.ISRECEIVE = "否";
else
data.ISRECEIVE = "是";
data.RETURN_MAN = Convert.ToString(reader["RETURN_MAN"]);//还单人
data.RETURN_DATE = Convert.ToString(reader["RETURN_DATE"]);//还单日期
//if (reader["RETURN_DATE"] != DBNull.Value)
// data.RETURN_DATE = Convert.ToDateTime(reader["RETURN_DATE"]);//还单日期
data.RETURN_TRANCER = Convert.ToString(reader["RETURN_TRANCER"]);//还单的快递公司
data.RETURN_TRANCNO = Convert.ToString(reader["RETURN_TRANCNO"]);//还单的快递单号
data.REMARK = Convert.ToString(reader["REMARK"]);//备注
data.CORPID = Convert.ToString(reader["CORPID"]);//分公司代码
data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]);//创建人GID
data.CREATETIME = Convert.ToString(reader["CREATETIME"]);//创建时间
//if (reader["CREATETIME"] != DBNull.Value)
// data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]);//创建时间
data.MODIFIEDUSER = Convert.ToString(reader["MODIFIEDUSER"]);//更改操作人GID
data.MODIFIEDTIME = Convert.ToString(reader["MODIFIEDTIME"]);//更改操作时间
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);//更改操作时间
data.MBLNO = Convert.ToString(reader["MBLNO"]);//更改操作时间
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);//更改操作时间
data.OPLBNAME = Convert.ToString(reader["OPLBNAME"]);//更改操作时间
data.OP = Convert.ToString(reader["OP"]);//更改操作时间
data.SALE = Convert.ToString(reader["SALE"]);//更改操作时间
//if (reader["MODIFIEDTIME"] != DBNull.Value)
// data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]);//更改操作时间
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
private static List<MsOpAddress> SetAddressData(StringBuilder strSql)
{
var bodyList = new List<MsOpAddress>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsOpAddress data = new MsOpAddress();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);//惟一编号
data.NAME = Convert.ToString(reader["NAME"]);//收件人姓名
data.CORPNAME = Convert.ToString(reader["CORPNAME"]);//公司名称
data.ADDRESS = Convert.ToString(reader["ADDRESS"]);//收件地址
data.DESTI = Convert.ToString(reader["DESTI"]);//收件城市
data.TEL = Convert.ToString(reader["TEL"]);//电话
data.POSTCODE = Convert.ToString(reader["POSTCODE"]);//邮编
data.CORPNAMERV = Convert.ToString(reader["CORPNAMERV"]);//实际收件公司名称
data.PROVINCE = Convert.ToString(reader["PROVINCE"]);//收件省份
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
static public List<MsOpReceiptEntity> GetDocList(string strCondition, string userid, string username, string companyid,string doctype ,string sort=null)
{
StringBuilder strSql = new StringBuilder();
if (doctype == "发票")
{
strSql.Append("select top 10 NEWID() GID,'*' DOCID,'发票' DOCTYPE,'' TRANCNO, null ISREPEAT, '' REPEAT_MAN,null REPEAT_DATE, null ISRECEIVE,");
strSql.Append("'' RETURN_MAN, null RETURN_DATE, '' RETURN_TRANCER, '' RETURN_TRANCNO, '' REMARK, ");
strSql.Append("'' BSNO, '' CORPID, '' CREATEUSER,'' CREATETIME, '' MODIFIEDUSER, '' MODIFIEDTIME,INVOICENO RECEIPTNO,'' RECEIPTTYPE, '' RECEIVE_MAN,");
strSql.Append("null RECEIVE_DATE, '' SEND_MAN,null SEND_DATE, '' TRANCER");
strSql.Append(",'' CUSTNO,'' MBLNO,'' CUSTOMERNAME,'' OPLBNAME,'' AS RECEIPTTYPENO,'' SALE,'' OP");
strSql.Append(" from ch_fee_invoice ");
}
else
{
strSql.Append("select d.GID,d.GID DOCID,'1' DOCTYPE,d.TRANCNO, d.ISREPEAT, d.REPEAT_MAN, convert(char(10),d.REPEAT_DATE,20) as REPEAT_DATE, d.ISRECEIVE,");
strSql.Append("d.RETURN_MAN, convert(char(10),d.RETURN_DATE,20) as RETURN_DATE, d.RETURN_TRANCER, d.RETURN_TRANCNO, d.REMARK, ");
strSql.Append("d.BSNO, d.CORPID, d.CREATEUSER, d.CREATETIME, d.MODIFIEDUSER, d.MODIFIEDTIME, d.RECEIPTNO, d.RECEIPTTYPE, d.RECEIVE_MAN,");
strSql.Append("convert(char(10),d.RECEIVE_DATE,20) as RECEIVE_DATE, d.SEND_MAN, convert(char(10),d.SEND_DATE,20) as SEND_DATE, d.TRANCER");
strSql.Append(",b.CUSTNO,b.MBLNO,b.CUSTOMERNAME,b.OPLBNAME,d.RECEIPTTYPE + '-' + d.RECEIPTNO AS RECEIPTTYPENO,b.SALE,b.OP ");
strSql.Append(" from op_receipt d ");
strSql.Append("left join v_op_bs b on (b.BSNO=d.BSNO) ");
}
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}
if (!string.IsNullOrEmpty(sort))
{
strSql.Append(" order by " + sort);
}
else
{
strSql.Append(" order by CREATETIME desc");
}
return SetExpressDocData(strSql);
}
static public MsOpReceiptEntity GetDoc(string condition)
{
var strSql = new StringBuilder();
strSql.Append("select d.GID,d.GID DOCID,'1' DOCTYPE,d.TRANCNO, d.ISREPEAT, d.REPEAT_MAN, convert(char(10),d.REPEAT_DATE,20) as REPEAT_DATE, d.ISRECEIVE,");
strSql.Append("d.RETURN_MAN, convert(char(10),d.RETURN_DATE,20) as RETURN_DATE, d.RETURN_TRANCER, d.RETURN_TRANCNO, d.REMARK, ");
strSql.Append("d.BSNO, d.CORPID, d.CREATEUSER, d.CREATETIME, d.MODIFIEDUSER, d.MODIFIEDTIME, d.RECEIPTNO, d.RECEIPTTYPE, d.RECEIVE_MAN,");
strSql.Append("convert(char(10),d.RECEIVE_DATE,20) as RECEIVE_DATE, d.SEND_MAN, convert(char(10),d.SEND_DATE,20) as SEND_DATE, d.TRANCER");
strSql.Append(",b.CUSTNO,b.MBLNO,b.CUSTOMERNAME,b.OPLBNAME,d.RECEIPTTYPE + '-' + d.RECEIPTNO AS RECEIPTTYPENO,b.SALE,b.OP");
strSql.Append(" from op_receipt d ");
strSql.Append("left join v_op_bs b on (b.BSNO=d.BSNO) ");
var list = SetExpressDocData(strSql);
if (list.Count > 0)
return list[0];
return new MsOpReceiptEntity();
}
static public List<MsOpAddress> GetAddressList(string strCondition, string userid, string username, string companyid, string sort = null)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select GID,NAME,CORPNAME,ADDRESS,DESTI,PROVINCE,TEL,POSTCODE,CORPNAMERV ");
strSql.Append(" from op_express_address ");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}
if (!string.IsNullOrEmpty(sort))
{
strSql.Append(" order by " + sort);
}
else
{
strSql.Append(" order by NAME desc");
}
return SetAddressData(strSql);
}
public static DBResult SaveDetail(MsOpExpress bill, List<MsOpReceiptEntity> bodyList, string companyid, string username, string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"insert into op_express_doc (GID,EXPID,DOCID)
values (@GID,@EXPID,@DOCID) ");
var cmdInsertDoc =
db.GetSqlStringCommand(
@"insert into op_receipt (GID,BSNO,RECEIPTNO,RECEIPTTYPE,SEND_MAN,SEND_DATE,
TRANCER,TRANCNO,RETURN_MAN,RETURN_DATE,RETURN_TRANCER,RETURN_TRANCNO,CORPID,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,REMARK)
values (@GID,@BSNO,@RECEIPTNO,@RECEIPTTYPE,@SEND_MAN,@SEND_DATE,
@TRANCER,@TRANCNO,@RETURN_MAN,@RETURN_DATE,@RETURN_TRANCER,@RETURN_TRANCNO,@CORPID,@CREATEUSER,@CREATETIME,@MODIFIEDUSER,@MODIFIEDTIME,@REMARK) ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
var DOCID = "";
if (enumValue.DOCID == "*")
{
DOCID = Guid.NewGuid().ToString();
cmdInsertDoc.Parameters.Clear();
db.AddInParameter(cmdInsertDoc, "@GID", DbType.String, DOCID);
db.AddInParameter(cmdInsertDoc, "@BSNO", DbType.String, enumValue.BSNO);
db.AddInParameter(cmdInsertDoc, "@RECEIPTNO", DbType.String, enumValue.RECEIPTNO);
db.AddInParameter(cmdInsertDoc, "@RECEIPTTYPE", DbType.String, enumValue.RECEIPTTYPE);
db.AddInParameter(cmdInsertDoc, "@CORPID", DbType.String, companyid);
db.AddInParameter(cmdInsertDoc, "@CREATEUSER", DbType.String,userid);
db.AddInParameter(cmdInsertDoc, "@MODIFIEDUSER", DbType.String, userid);
db.AddInParameter(cmdInsertDoc, "@CREATETIME", DbType.String, DateTime.Now);
db.AddInParameter(cmdInsertDoc, "@MODIFIEDTIME", DbType.String, DateTime.Now);
if (bill.BILLTYPE == "送单")
{
db.AddInParameter(cmdInsertDoc, "@SEND_MAN", DbType.String,username);
db.AddInParameter(cmdInsertDoc, "@SEND_DATE", DbType.String, DateTime.Now.ToString("yyyy-MM-dd"));
db.AddInParameter(cmdInsertDoc, "@TRANCER", DbType.String,bill.EXPRESSCORP);
db.AddInParameter(cmdInsertDoc, "@TRANCNO", DbType.String,bill.EXNO);
db.AddInParameter(cmdInsertDoc, "@RETURN_MAN", DbType.String, "");
db.AddInParameter(cmdInsertDoc, "@RETURN_DATE", DbType.String,null);
db.AddInParameter(cmdInsertDoc, "@RETURN_TRANCER", DbType.String,"");
db.AddInParameter(cmdInsertDoc, "@RETURN_TRANCNO", DbType.String,"");
}
else if (bill.BILLTYPE == "还单")
{
db.AddInParameter(cmdInsertDoc, "@SEND_MAN", DbType.String,enumValue.SEND_MAN);
db.AddInParameter(cmdInsertDoc, "@SEND_DATE", DbType.String,enumValue.SEND_DATE);
db.AddInParameter(cmdInsertDoc, "@TRANCER", DbType.String,enumValue.TRANCER);
db.AddInParameter(cmdInsertDoc, "@TRANCNO", DbType.String,enumValue.TRANCNO);
db.AddInParameter(cmdInsertDoc, "@RETURN_MAN", DbType.String, username);
db.AddInParameter(cmdInsertDoc, "@RETURN_DATE", DbType.String, DateTime.Now.ToString("yyyy-MM-dd"));
db.AddInParameter(cmdInsertDoc, "@RETURN_TRANCER", DbType.String, bill.EXPRESSCORP);
db.AddInParameter(cmdInsertDoc, "@RETURN_TRANCNO", DbType.String, bill.EXNO);
}
else {
db.AddInParameter(cmdInsertDoc, "@SEND_MAN", DbType.String, enumValue.SEND_MAN);
db.AddInParameter(cmdInsertDoc, "@SEND_DATE", DbType.String, enumValue.SEND_DATE);
db.AddInParameter(cmdInsertDoc, "@TRANCER", DbType.String, enumValue.TRANCER);
db.AddInParameter(cmdInsertDoc, "@TRANCNO", DbType.String, enumValue.TRANCNO);
db.AddInParameter(cmdInsertDoc, "@RETURN_MAN", DbType.String,enumValue.RETURN_MAN);
db.AddInParameter(cmdInsertDoc, "@RETURN_DATE", DbType.String,enumValue.RETURN_DATE);
db.AddInParameter(cmdInsertDoc, "@RETURN_TRANCER", DbType.String,enumValue.RETURN_TRANCER);
db.AddInParameter(cmdInsertDoc, "@RETURN_TRANCNO", DbType.String,enumValue.RETURN_TRANCNO);
}
db.AddInParameter(cmdInsertDoc, "@REMARK", DbType.String, enumValue.REMARK);
db.ExecuteNonQuery(cmdInsertDoc, tran);
}
else {
DOCID = enumValue.DOCID;
if (bill.BILLTYPE == "送单")
{
var cmdUpdateDoc =
db.GetSqlStringCommand(
@"update op_receipt set SEND_MAN=@SEND_MAN,SEND_DATE=@SEND_DATE,TRANCER=@TRANCER,TRANCNO=@TRANCNO,REMARK=@REMARK where GID=@DOCID ");
db.AddInParameter(cmdUpdateDoc, "@SEND_MAN", DbType.String, username);
db.AddInParameter(cmdUpdateDoc, "@SEND_DATE", DbType.String, DateTime.Now.ToString("yyyy-MM-dd"));
db.AddInParameter(cmdUpdateDoc, "@TRANCER", DbType.String, bill.EXPRESSCORP);
db.AddInParameter(cmdUpdateDoc, "@TRANCNO", DbType.String, bill.EXNO);
db.AddInParameter(cmdUpdateDoc, "@REMARK", DbType.String, enumValue.REMARK);
db.AddInParameter(cmdUpdateDoc, "@DOCID", DbType.String, DOCID);
db.ExecuteNonQuery(cmdUpdateDoc, tran);
}
else
{
var cmdUpdateDoc =
db.GetSqlStringCommand(
@"update op_receipt set RETURN_MAN=@RETURN_MAN,RETURN_DATE=@RETURN_DATE,RETURN_TRANCER=@RETURN_TRANCER,RETURN_TRANCNO=@RETURN_TRANCNO,REMARK=@REMARK where GID=@DOCID ");
db.AddInParameter(cmdUpdateDoc, "@RETURN_MAN", DbType.String, username);
db.AddInParameter(cmdUpdateDoc, "@RETURN_DATE", DbType.String, DateTime.Now.ToString("yyyy-MM-dd"));
db.AddInParameter(cmdUpdateDoc, "@RETURN_TRANCER", DbType.String, bill.EXPRESSCORP);
db.AddInParameter(cmdUpdateDoc, "@RETURN_TRANCNO", DbType.String, bill.EXNO);
db.AddInParameter(cmdUpdateDoc, "@REMARK", DbType.String, enumValue.REMARK);
db.AddInParameter(cmdUpdateDoc, "@DOCID", DbType.String, DOCID);
db.ExecuteNonQuery(cmdUpdateDoc, tran);
}
}
if (enumValue.EXPID == "*")
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@EXPID", DbType.String, bill.GID);
db.AddInParameter(cmdInsert, "@DOCID", DbType.String, DOCID);
db.ExecuteNonQuery(cmdInsert, tran);
}
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
public static DBResult AddBill(string billno, List<MsOpReceiptEntity> bodyList)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"insert into op_express_doc (GID,EXPID,DOCID)
values (@GID,@EXPID,@DOCID) ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@EXPID", DbType.String, billno);
db.AddInParameter(cmdInsert, "@DOCID", DbType.String, enumValue.GID);
db.ExecuteNonQuery(cmdInsert, tran);
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
public static DBResult DelBill(List<MsOpReceiptEntity> boday)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (boday != null)
{
var cmddelete = db.GetSqlStringCommand("delete from op_express_doc where GID=@GID");
foreach (var enumValue in boday)
{
cmddelete.Parameters.Clear();
db.AddInParameter(cmddelete, "@GID", DbType.String, enumValue.GID);
db.ExecuteNonQuery(cmddelete, tran);
}
}
result = new DBResult();
result.Success = true;
result.Message = "成功";
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功";
return result;
}
#endregion
public static string GetRangDAStr(string tb, string userid, string username, string companyid)
{
string str = "";
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" VISIBLERANGE,OPERATERANGE ");
strSql.Append(" from VW_User_Authority ");
strSql.Append(" where [NAME]='modOpExpress' and USERID='" + userid + "' and ISDELETE=0");
string visiblerange = "4";
string operaterange = "4";
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
visiblerange = Convert.ToString(reader["VISIBLERANGE"]);
operaterange = Convert.ToString(reader["OPERATERANGE"]);
break;
}
reader.Close();
}
if (visiblerange == "4")
{
str = " CREATEUSER='" + userid + "' ";
}
else if (visiblerange == "3")
{
str = " CREATEUSER='" + userid + "' ";
}
else if (visiblerange == "2")
{
var rangeDa = new RangeDA();
var deptname = rangeDa.GetDEPTNAME(userid);
str = " CREATEUSER in (select USERID from user_company where COMPANYID='" + companyid + "') and CREATEUSER in (select userid from user_baseinfo where DEPTNAME='" + deptname + "') ";
}
else if (visiblerange == "1")
{
str = " CORPID='" + companyid + "' ";
}
else if (visiblerange == "0")
{
str = " 1=1 ";
}
return str;
}
#region 获取顺丰下单号
public static string GetSFOrderID()
{
SqlParameter[] parameters =
{
new SqlParameter("@BillType", SqlDbType.VarChar,4),
new SqlParameter("@BillDate", SqlDbType.VarChar, 8),
};
parameters[0].Value = "0501";
parameters[1].Value = DateTime.Now.ToString("yyyyMMdd");
int num = DbHelperSQL.ExcuteScalarProc("Proc_EIP_OrderNO", parameters);
StringBuilder strNo = new StringBuilder();
strNo.Append("QDLH");
strNo.Append(DateTime.Now.ToString("yyyyMMdd"));
strNo.Append(String.Format("{0:000}", num));
return strNo.ToString();
}
#endregion
}
}