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/SeaiInfoLCL/WmsOutLCLEdit.aspx.cs

4386 lines
260 KiB
C#

3 years ago
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Data.SqlClient;
using System.Text;
using System.Globalization;
using JsonHelper;
using DSWeb.Models;
using DSWeb.EntityDA;
using DSWeb.Log;
using DSWeb.Authority;
using DSWeb.DataAccess;
using System.IO;
using System.Xml;
namespace DSWeb.SeaiInfoLCL
{
public partial class WmsOutLCLEdit : System.Web.UI.Page
{
private string strUserID;
private string strCompanyID;//公司GID
private string strShowName;//用户显示名
private string strDeptName;//部门名称
private string strSearch;//仓储费率的客户、合同号、货物名称
private string WoJSON;//出库明细信息
private string WoDetailJSON;//出库明细信息
private string recvJSON;
private string payJSON;
private string strSeaBSNO;
private int iImportTemplateDetailType;
private string strCacheName;
private string strImportHistoryCacheName;
private int iHistoryType;//1-应收 2-应付
private string strHandle;
private bool isJsFee = false;
private int ischangecust = 0;
private IList<string> CustParent=new List<string>();
T_ALL_DA T_ALL_DA = new T_ALL_DA();
protected void Page_Load(object sender, EventArgs e)
{
this.h_oplb.Value = "op_Seai";
this.h_wmsoutbsno.Value = "";
this.h_IsFeeGain.Value = "0";
h_Mode.Value = "0";
this.txt_outdate.Value = DateTime.Today.ToString("yyyy-MM-dd");
this.txt_oldcustFeeDate.Value = this.txt_outdate.Value;
//addwmsout
if (Session["USERID"] != null)
{
strUserID = Session["USERID"].ToString();
}
if (Session["SHOWNAME"] != null)
{
strShowName = Session["SHOWNAME"].ToString();
}
if (Session["COMPANYID"] != null)
{
strCompanyID = Session["COMPANYID"].ToString();
}
if (Session["DEPTNAME"] != null)
{
strDeptName = Session["DEPTNAME"].ToString();
}
if (Request.QueryString["handle"] != null)
{
strHandle = Request.QueryString["handle"].ToString();
}
//
if (Request.QueryString["bsno"] != null)
{
this.h_opseaibsno.Value = Request.QueryString["bsno"].ToString();
}
else
{
this.h_opseaibsno.Value = "";
}
if (Request.QueryString["ischangecust"] != null)
{
ischangecust =int.Parse( Request.QueryString["ischangecust"].ToString());
if (ischangecust == 1)
{
this.h_Ischange.Value = "1";
this.btn_Out.InnerHtml = "货权转移";
this.Title = "货权转移";
this.h_IsSetRate.Value = "1";
this.txt_oldcustFeeDate.Disabled = false;
}
else if (ischangecust == 2)
{
this.h_Ischange.Value = "2";
this.btn_Out.InnerHtml = "盘亏处理";
this.Title = "盘亏处理";
this.h_IsSetRate.Value = "0";
this.txt_oldcustFeeDate.Disabled = true;
this.sel_outcustomer.Disabled = true;
}
else
{
this.h_Ischange.Value ="0";
this.h_IsSetRate.Value = "0";
this.btn_Out.InnerHtml = "生成出库单";
this.Title = "生成出库单";
this.txt_oldcustFeeDate.Disabled = true;
}
}
if (Request.QueryString["search"] != null)
{
UnicodeEncoding unicode = new UnicodeEncoding();
strSearch = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["search"].ToString())));
this.h_EditJson.Value = strSearch;
}
WoJSON = "";
WoDetailJSON = "";
WoJSON=this.WoContainer.Value;
WoDetailJSON = this.WoDetailContainer.Value;
recvJSON = "";
payJSON = "";
recvJSON = this.recvContainer.Value.Trim();
payJSON = this.payContainer.Value.Trim();
#region 获取引入费用模板缓存信息
if (recvJSON.Trim().Equals("") && payJSON.Trim().Equals("") && strCacheName != null && iImportTemplateDetailType > 0)
{
DataTable templateTable = (DataTable)Session[strCacheName];
StringBuilder templateBuilder = new StringBuilder();
if (templateTable != null)
{
if (templateTable.Rows.Count > 0)
{
templateBuilder.Append("{\"templates\":[");
for (int i = 0; i < templateTable.Rows.Count; i++)
{
templateTable.Rows[i]["GID"] = Guid.NewGuid().ToString();
if (i == templateTable.Rows.Count - 1)
{
templateBuilder.Append("{");
templateBuilder.Append("\"tid\":\"" + templateTable.Rows[i]["GID"].ToString() + "\",");
templateBuilder.Append("\"fname\":\"" + templateTable.Rows[i]["FEENAME"].ToString() + "\",");
templateBuilder.Append("\"client\":" + templateTable.Rows[i]["CLIENT"].ToString() + ",");
templateBuilder.Append("\"cust\":\"" + templateTable.Rows[i]["CUSTOMERNAME"].ToString() + "\",");
templateBuilder.Append("\"unit\":\"" + templateTable.Rows[i]["UNIT"].ToString() + "\",");
templateBuilder.Append("\"uprice\":" + templateTable.Rows[i]["UNITPRICE"].ToString() + ",");
templateBuilder.Append("\"cur\":\"" + templateTable.Rows[i]["CURRENCY"].ToString() + "\",");
templateBuilder.Append("\"exrate\":" + templateTable.Rows[i]["EXCHANGERATE"].ToString() + ",");
templateBuilder.Append("\"remark\":\"" + templateTable.Rows[i]["REMARK"].ToString() + "\",");
templateBuilder.Append("\"type\":" + templateTable.Rows[i]["FEETYPE"].ToString().ToString());
templateBuilder.Append("}");
}
else
{
templateBuilder.Append("{");
templateBuilder.Append("\"tid\":\"" + templateTable.Rows[i]["GID"].ToString() + "\",");
templateBuilder.Append("\"fname\":\"" + templateTable.Rows[i]["FEENAME"].ToString() + "\",");
templateBuilder.Append("\"client\":" + templateTable.Rows[i]["CLIENT"].ToString() + ",");
templateBuilder.Append("\"cust\":\"" + templateTable.Rows[i]["CUSTOMERNAME"].ToString() + "\",");
templateBuilder.Append("\"unit\":\"" + templateTable.Rows[i]["UNIT"].ToString() + "\",");
templateBuilder.Append("\"uprice\":" + templateTable.Rows[i]["UNITPRICE"].ToString() + ",");
templateBuilder.Append("\"cur\":\"" + templateTable.Rows[i]["CURRENCY"].ToString() + "\",");
templateBuilder.Append("\"exrate\":" + templateTable.Rows[i]["EXCHANGERATE"].ToString() + ",");
templateBuilder.Append("\"remark\":\"" + templateTable.Rows[i]["REMARK"].ToString() + "\",");
templateBuilder.Append("\"type\":" + templateTable.Rows[i]["FEETYPE"].ToString().ToString());
templateBuilder.Append("},");
}
}
templateBuilder.Append("]}");
this.h_importtype.Value = iImportTemplateDetailType.ToString();
this.h_cachename.Value = strCacheName;
this.h_cachetemplate.Value = templateBuilder.ToString();
}
else
{
this.h_importtype.Value = iImportTemplateDetailType.ToString();
this.h_cachename.Value = "";
this.h_cachetemplate.Value = "";
}
}
}
#endregion
#region 获取引入历史费用缓存信息
if (recvJSON.Trim().Equals("") && payJSON.Trim().Equals("") && strImportHistoryCacheName != null && iHistoryType > 0)
{
DataTable templateTable = (DataTable)Session[strImportHistoryCacheName];
StringBuilder templateBuilder = new StringBuilder();
if (templateTable != null)
{
if (templateTable.Rows.Count > 0)
{
templateBuilder.Append("{\"history\":[");
for (int i = 0; i < templateTable.Rows.Count; i++)
{
templateTable.Rows[i]["GID"] = Guid.NewGuid().ToString();
if (i == templateTable.Rows.Count - 1)
{
templateBuilder.Append("{");
templateBuilder.Append("\"tid\":\"" + templateTable.Rows[i]["GID"].ToString() + "\",");
templateBuilder.Append("\"fname\":\"" + templateTable.Rows[i]["FEENAME"].ToString() + "\",");
templateBuilder.Append("\"cust\":\"" + templateTable.Rows[i]["CUSTOMERNAME"].ToString() + "\",");
templateBuilder.Append("\"unit\":\"" + templateTable.Rows[i]["UNIT"].ToString() + "\",");
templateBuilder.Append("\"uprice\":" + templateTable.Rows[i]["UNITPRICE"].ToString() + ",");
templateBuilder.Append("\"quantity\":" + templateTable.Rows[i]["QUANTITY"].ToString() + ",");
templateBuilder.Append("\"comm\":" + templateTable.Rows[i]["COMMISSIONRATE"].ToString() + ",");
templateBuilder.Append("\"amount\":" + templateTable.Rows[i]["AMOUNT"].ToString() + ",");
templateBuilder.Append("\"cur\":\"" + templateTable.Rows[i]["CURRENCY"].ToString() + "\",");
templateBuilder.Append("\"exrate\":" + templateTable.Rows[i]["EXCHANGERATE"].ToString() + ",");
templateBuilder.Append("\"frt\":\"" + templateTable.Rows[i]["FEEFRT"].ToString() + "\",");
templateBuilder.Append("\"remark\":\"" + templateTable.Rows[i]["REMARK"].ToString() + "\",");
templateBuilder.Append("\"isadv\":" + (templateTable.Rows[i]["ISADVANCEDPAY"].ToString().ToLower().Equals("true") ? 1 : 0) + ",");
templateBuilder.Append("\"type\":" + templateTable.Rows[i]["FEETYPE"].ToString().ToString());
templateBuilder.Append("}");
}
else
{
templateBuilder.Append("{");
templateBuilder.Append("\"tid\":\"" + templateTable.Rows[i]["GID"].ToString() + "\",");
templateBuilder.Append("\"fname\":\"" + templateTable.Rows[i]["FEENAME"].ToString() + "\",");
templateBuilder.Append("\"cust\":\"" + templateTable.Rows[i]["CUSTOMERNAME"].ToString() + "\",");
templateBuilder.Append("\"unit\":\"" + templateTable.Rows[i]["UNIT"].ToString() + "\",");
templateBuilder.Append("\"uprice\":" + templateTable.Rows[i]["UNITPRICE"].ToString() + ",");
templateBuilder.Append("\"quantity\":" + templateTable.Rows[i]["QUANTITY"].ToString() + ",");
templateBuilder.Append("\"comm\":" + templateTable.Rows[i]["COMMISSIONRATE"].ToString() + ",");
templateBuilder.Append("\"amount\":" + templateTable.Rows[i]["AMOUNT"].ToString() + ",");
templateBuilder.Append("\"cur\":\"" + templateTable.Rows[i]["CURRENCY"].ToString() + "\",");
templateBuilder.Append("\"exrate\":" + templateTable.Rows[i]["EXCHANGERATE"].ToString() + ",");
templateBuilder.Append("\"frt\":\"" + templateTable.Rows[i]["FEEFRT"].ToString() + "\",");
templateBuilder.Append("\"remark\":\"" + templateTable.Rows[i]["REMARK"].ToString() + "\",");
templateBuilder.Append("\"isadv\":" + (templateTable.Rows[i]["ISADVANCEDPAY"].ToString().ToLower().Equals("true") ? 1 : 0) + ",");
templateBuilder.Append("\"type\":" + templateTable.Rows[i]["FEETYPE"].ToString().ToString());
templateBuilder.Append("},");
}
}
templateBuilder.Append("]}");
this.h_historytype.Value = iHistoryType.ToString();
this.h_historycachename.Value = strImportHistoryCacheName;
this.h_cachehistory.Value = templateBuilder.ToString();
}
else
{
this.h_historytype.Value = iHistoryType.ToString();
this.h_historycachename.Value = "";
this.h_cachehistory.Value = "";
}
}
}
#endregion
#region 保存操作
if (this.h_post.Value.Trim() != "")
{
//保存操作
if (this.h_post.Value.Trim() == "1")
{
if (!recvJSON.Trim().Equals("") || !payJSON.Trim().Equals(""))
{ // 将页面post获取的费用信息保存或更新“费用信息表”ch_fee,并保存或更新“利润信息”fee_gain并返回操作结果
SaveFeeAction();
}
}
else if (this.h_post.Value.Trim() == "2")
{
if (!WoJSON.Trim().Equals(""))
{
SaveWoOutAction();
//return;
}
}
else if (this.h_post.Value.Trim() == "3")
{
if (!WoJSON.Trim().Equals(""))
{
CargoRightTransfer();
//return;
}
}
else if (this.h_post.Value.Trim() == "4")
{
if (!WoJSON.Trim().Equals(""))
{
SetLosses();
//return;
}
}
}
if (strHandle == "edit")
{//获取出库单的信息
DoWmsOutEdit(strSearch);
h_Mode.Value = "1";
//
DataSet ds = T_ALL_DA.GetAllSQL("select GOODSPACKPFSL=isnull(sum(GOODSPACKPFSL),0),GOODSPFSL=isnull(sum(GOODSPFSL),0),ARFEE=isnull(sum(ARFEE),0),APFEE=isnull(sum(APFEE),0),GOODSOUTFEE=isnull(sum(GOODSOUTFEE),0),GOODSOUTFEEAP=isnull(sum(GOODSOUTFEEAP),0) from wms_out_detail where OUTBSNO='" + this.h_outbsno.Value.Trim() + "'");
if (ds != null)
{
//件数
this.dvGOODSPACKVal.InnerText = ds.Tables[0].Rows[0]["GOODSPACKPFSL"].ToString().Trim();
//计费数量
this.dvProfitTotalVal.InnerText = ds.Tables[0].Rows[0]["GOODSPFSL"].ToString().Trim();
//出库应收
this.dvRecvTotalVal.InnerText = ds.Tables[0].Rows[0]["ARFEE"].ToString().Trim();
//出库应付
this.dvPaySumVal.InnerText = ds.Tables[0].Rows[0]["APFEE"].ToString().Trim();
//仓储费应收
this.dvRVal.InnerText = ds.Tables[0].Rows[0]["GOODSOUTFEE"].ToString().Trim();
//仓储费应付
this.dvPVal.InnerText = ds.Tables[0].Rows[0]["GOODSOUTFEEAP"].ToString().Trim();
}
}
#endregion
//加载下拉框
Page.ClientScript.RegisterStartupScript(this.GetType(), "key0", "<script>initcomboOutCustomer();initComboTRUCKNAME();</script>");
}
#region 导出Excel
protected void btExcel1_Click(object sender, EventArgs e)
{
setExcelReport();
}
protected void setExcelReport()
{
StringWriter sw = new StringWriter();
string sSQL = "";
//sw.WriteLine("结算单位\t委托编号\t主提单号\t分提单号\t船名\t航次\tETD\t目的港\t揽货人\t应收RMB\t实收RMB\t应收USD\t实收USD\t余额");
sw.WriteLine(this.hdNAMES.Value.Trim());
T_ALL_DA T_ALL_DA = new T_ALL_DA();
DataSet DS = T_ALL_DA.GetAllSQL(this.hdSQL.Value.Trim());
if (DS != null)
{
foreach (DataTable myTable in DS.Tables)
{
foreach (DataRow myRow in myTable.Rows)//遍历表
{
sSQL = "";
for (int i = 0; i < myTable.Columns.Count; i++)
{
if (sSQL.Trim() != "")
{
sSQL += "\t";
}
if (myRow[i].ToString() == null || myRow[i].ToString() == "")
{
sSQL += "";
if (sSQL.Trim() == "")
{
sSQL += "\t";
}
}
else
{
string ls = myRow[i].ToString().Trim();
if (i == 17)
{
ls = ls.Replace(" ", "");
ls = ls.Replace("\r\n", "。");
}
sSQL += ls.Trim();
//sSQL += myRow[i].ToString();
}
}
sw.WriteLine(sSQL);
}
}
//
sw.Close();
switch ("MUEXCEL")
{
case "MUEXCEL":
Response.AddHeader("Content-Disposition", "attachment; filename=report.xls");
Response.ContentType = "application/ms-excel";
break;
case "MUTEXT":
Response.AddHeader("Content-Disposition", "attachment; filename=report.txt");
Response.ContentType = "application/txt";
break;
case "MUWORD":
Response.AddHeader("Content-Disposition", "attachment; filename=report.doc");
Response.ContentType = "application/ms-word";
break;
case "MUPDF":
Response.AddHeader("Content-Disposition", "attachment; filename=report.pdf");
Response.ContentType = "application/pdf";
break;
case "MUXML":
Response.AddHeader("Content-Disposition", "attachment; filename=report.xml");
Response.ContentType = "application/xml";
break;
}
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.Write(sw);
Response.End();
}
}
#endregion
#region 读取出库单的信息 WmsOutEdit
/// <summary>
///
/// </summary>
/// <param name="strSearch"></param>
private void DoWmsOutEdit(string strSearch)
{
if (strSearch != null)
{
if (!strSearch.Trim().Equals(""))
{
string tempSearch = strSearch;
tempSearch = tempSearch.Replace("{", "");
tempSearch = tempSearch.Replace("}", "");
tempSearch = tempSearch.Replace("[", "");
tempSearch = tempSearch.Replace("]", "");
string[] searchArg = tempSearch.Split(new char[] { ',' });
for (int i = 0; i < searchArg.Length; i++)
{
string[] strArg = searchArg[i].Split(new char[] { ':' });
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
switch (strArg[0].Replace("\"", ""))
{
case "id":
h_outgid.Value = strArg[1].ToString().Replace("\"", "");
break;
case "bsno":
this.h_outbsno.Value = strArg[1].ToString().Replace("\"", "");
txt_outbsno.Value = this.h_outbsno.Value;
this.h_wmsoutbsno.Value = this.h_outbsno.Value;
break;
case "cust":
h_customer.Value = strArg[1].ToString().Replace("\"", "");
h_outcustomer.Value = h_customer.Value;
break;
case "outdate":
string dt =strArg[1].ToString().Replace("\"", "");
//h_outdate.Value = dt.Substring(0,dt.IndexOf(" "));
h_outdate.Value = dt;
txt_outdate.Value = dt;
break;
case "storage":
h_storage.Value = strArg[1].ToString().Replace("\"", "");
break;
case "goodsname":
h_goods.Value = strArg[1].ToString().Replace("\"", "").Trim();
break;
case "goodsmodel":
h_goodsmodel.Value = strArg[1].ToString().Replace("\"", "").Trim();
txt_goodsmodel.Value = h_goodsmodel.Value;
break;
case "outnum":
h_outnum.Value = strArg[1].ToString().Replace("\"", "");
txt_goodspfsl.Value = h_outnum.Value;
break;
case "outfee":
h_outfee.Value =strArg[1].ToString().Replace("\"", "");
break;
case "truckno":
//
string ls = strArg[1].ToString().Replace("\"", "").Trim();
//ls = ls.Replace(" ", " ");
//ls = ls.Replace("\r\n", " ");
//
h_truckno.Value = ls;
break;
case "remark":
h_remark.Value = strArg[1].ToString().Replace("\"", "").Trim();
txt_remark.Value = h_remark.Value;
break;
case "opseaibsno":
h_bsno.Value = strArg[1].ToString().Replace("\"", "").Trim();
h_opseaibsno.Value = h_bsno.Value;
break;
case "packnum":
txt_packnum.Value = strArg[1].ToString().Replace("\"", "").Trim();
h_packnum.Value = txt_packnum.Value;
break;
case "newcust":
this.h_newcust.Value = strArg[1].ToString().Replace("\"", "").Trim();
break;
default:
break;
}
}
}
}
}
if (h_remark.Value.Equals("货权转移") && !h_newcust.Value.Equals(""))
{
this.h_IsSetRate.Value = "1";
}
else
{
this.h_IsSetRate.Value = "0";
}
}
#endregion
#region 将页面post获取的费用信息保存或更新“费用信息表”ch_fee,并保存或更新“利润信息”fee_gain并返回操作结果
/// <summary>
/// 将页面post获取的费用信息保存或更新“费用信息表”ch_fee,并保存或更新“利润信息”fee_gain并返回操作结果
/// </summary>
private void SaveFeeAction()
{
IList<FeeEntity> feeEntities = new List<FeeEntity>();
if (!recvJSON.Trim().Equals("") && !recvJSON.Trim().Equals("null") )
{ //将应收费用信息从前台页面写入费用实体类feeEntities
feeEntities = ResolveFeeJSON(recvJSON.Trim(), feeEntities);
recvContainer.Value = "";
}
if (!payJSON.Trim().Equals("") && !payJSON.Trim().Equals("null"))
{ //将应付费用信息从前台页面写入费用实体类feeEntities
feeEntities = ResolveFeeJSON(payJSON.Trim(), feeEntities);
payContainer.Value = "";
}
FeeDA feeDA = new FeeDA();
//如果是当前操作人权限范围只能查看应收或者应付时,单独更新费用利润
if (!ValidateUserFeeAuthority(1) || !ValidateUserFeeAuthority(2))
{ //将页面post获取的费用信息保存或更新“费用信息表”ch_fee,并保存或更新“利润信息”fee_gain并返回操作结果
int iRecvState = feeDA.DoFee(feeEntities, strSeaBSNO, strUserID);
if (iRecvState == 1)
{
gainContainer.Value = "";
if (Session[strCacheName] != null)
{
Session.Remove(strCacheName);
}
}
}
else
{
FeeProfitEntity feeProfitEntity = new FeeProfitEntity();
//将页面post获取的利润值读入到利润实体类中
feeProfitEntity = GetRequestProfit();
int iRecvState = feeDA.DoFee(feeEntities, feeProfitEntity, strSeaBSNO);
if (iRecvState == 1)
{
gainContainer.Value = "";
if (Session[strCacheName] != null)
{
Session.Remove(strCacheName);
}
}
}
h_post.Value = "";//请求状态清空
}
/// <summary>
/// 正数四舍五入,负数是五舍六入。(个人以为第一种方法合适处置货泉盘算)
/// </summary>
/// <param name="value">四舍五入的数</param>
/// <param name="decimals">表示要保存的小数点后为数</param>
/// <returns></returns>
private double Round(double value, int decimals,string money)
{
if (value < 0)
{
return Math.Round(value + 5 / Math.Pow(10, decimals + 1), decimals, MidpointRounding.AwayFromZero);
}
else
{
return Math.Round(value, decimals, MidpointRounding.AwayFromZero);
}
}
/// <summary>
/// 正负数都四舍五入(适合数据统计的显示)
/// </summary>
/// <param name="d">四舍五入的数</param>
/// <param name="i">表示要保存的小数点后为数</param>
/// <returns></returns>
private double Round(double d, int i)
{
if (d >= 0)
{
d += 5 * Math.Pow(10, -(i + 1));
}
else
{
d += -5 * Math.Pow(10, -(i + 1));
}
string str = d.ToString();
string[] strs = str.Split('.');
int idot = str.IndexOf('.');
string prestr = strs[0];
string poststr = strs[1];
if (poststr.Length > i)
{
poststr = str.Substring(idot + 1, i);
}
string strd = prestr + "." + poststr;
d = Double.Parse(strd);
return d;
}
#region 生成出库单 SaveWoOutAction
/// <summary>
/// 生成出库单
/// </summary>
private int SaveWoOutAction()
{
int iState = 0;
int result = 0;
string Sqlstr = "";
double totaloutfee = 0;//出库单的仓储费
int prescale = 0;
int nowscale = 0;
int nowgrade = 0;
double price = 0;
double gradefee = 0;
double sumfee = 0;
string newGID = "";
string bsno = "";
//出库单信息
WmsOutDA WmsOutDA = new WmsOutDA();
WmsOutEntity WmsOutEntity = new WmsOutEntity();
if (!WoJSON.Trim().Equals(""))
{ //将应收费用信息从前台页面写入费用实体类feeEntities
WmsOutEntity = ResolveWoJSON(WoJSON.Trim(), WmsOutEntity);
WoContainer.Value = "";
}
//出库单明细信息
WmsOutDetailDA WmsOutDetailDA = new WmsOutDetailDA();
IList<WmsOutDetailEntity> WmsOutDetailEntitys = new List<WmsOutDetailEntity>();
if (!WoDetailJSON.Trim().Equals(""))
{ //将应收费用信息从前台页面写入费用实体类feeEntities
WmsOutDetailEntitys = ResolveWoDetailJSON(WoDetailJSON.Trim(), WmsOutDetailEntitys);
this.WoDetailContainer.Value = "";
}
//IList<WmsOutDetailEntity> WmsOutDetailEntitysParents = new List<WmsOutDetailEntity>();
////原货主
//foreach (string custp in CustParent)
//{
// IList<WmsOutDetailEntity> ccs = new List<WmsOutDetailEntity>();
// Sqlstr = String.Format(" ASSOCIATEDNO='{0}' and CUSTOMERNAME like '%{1}%' ", WmsOutEntity.ASSOCIATEDNO, custp);
// ccs = WmsOutDetailDA.GetModels(Sqlstr);
// foreach (WmsOutDetailEntity cc in ccs)
// {
// WmsOutDetailEntitysParents.Add(cc);
// }
//}
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
#region 生成出库单并计算费用
#region 保存出库单wms_out 出库单明细wms_out_detail
//保存出库单wms_out
string ls = WmsOutEntity.TRUCKNO.ToString().Trim();
ls = ls.Replace(""," ");
ls = ls.Replace("","\r\n");
//
Sqlstr = String.Format("insert into wms_out(GID,BSNO,CUSTOMERNAME,DODATE,STORAGENAME,GOODSNAME,GOODSMODEL,GOODSPFSL,REMARK,CREATEUSER,CREATETIME,TRUCKNO,ASSOCIATEDNO,GOODSPACKPFSL,INSPECTIONNO,CUSTOMNO,CLIENTNAMEOLD,OLDCUSTFEEDATE,TRUCKNAME)"
+ " values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}',getdate(),'{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}' )"
, WmsOutEntity.GID, WmsOutEntity.BSNO, WmsOutEntity.CUSTOMERNAME, WmsOutEntity.DODATE, WmsOutEntity.STORAGENAME, WmsOutEntity.GOODSNAME, WmsOutEntity.GOODSMODEL, WmsOutEntity.GOODSPFSL, WmsOutEntity.REMARK, strUserID, ls, WmsOutEntity.ASSOCIATEDNO, WmsOutEntity.GOODSPACKPFSL, WmsOutEntity.INSPECTIONNO, WmsOutEntity.CUSTOMNO, WmsOutEntity.CLIENTNAMEOLD, WmsOutEntity.DODATE, WmsOutEntity.TRUCKNAME);
iState=SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, Sqlstr, null);
if (iState != 1)
{
sqlTran.Rollback();
result = -1;
Clearh();
return result;
}
//保存出库单明细wms_out_detail
foreach (WmsOutDetailEntity WmsOutDetailEntity in WmsOutDetailEntitys)
{
string dtime = "";//开始计费日期 STARTBILLINGDATE
int iFEEDAYS = 0;//计费天数 FEEDAYS
double outnums =double.Parse( WmsOutDetailEntity.GOODSPFSL.ToString());//出库量
int feedays = WmsOutDetailDA.GetDaysCount("day", WmsOutDetailEntity.DODATE.ToString(), WmsOutEntity.DODATE.ToString());
if (feedays > 0)
{
WmsOutDetailEntity.OUTBSNO = WmsOutEntity.BSNO;
SqlParameter parmrate = new SqlParameter("@BSNO", SqlDbType.VarChar, 100);
parmrate.Value = WmsOutDetailEntity.INBSNO;//WmsOutEntity.ASSOCIATEDNO;
Sqlstr = String.Format("SELECT FEEGRADE,FEESCALE,FEEPRICE,FEEUNIT FROM wms_rate where BSNO=@BSNO and CUSTOMERNAME like '%{0}%' order by BSNO,FEEGRADE ", WmsOutEntity.CUSTOMERNAME);
DataSet dsrate = SqlHelper.ExecuteQueryDataset(sqlTran, CommandType.Text, Sqlstr.ToString(), parmrate);
DataTable dtrate = new DataTable();
if (dsrate != null)
{
dtrate = dsrate.Tables[0];
if (dtrate.Rows.Count > 0)
{
prescale = 0;
nowscale = 0;
nowgrade = 0;
price = 0;
gradefee = 0;
sumfee = 0;
foreach (DataRow drow in dtrate.Rows)
{
nowgrade = int.Parse(drow["FEEGRADE"].ToString());//收费等级
nowscale = int.Parse(drow["FEESCALE"].ToString());//收费区间
price = double.Parse(drow["FEEPRICE"].ToString());//收费单价
if (nowgrade.Equals(1))//收费等级
{
if (feedays > nowscale)
{
gradefee = outnums * price * nowscale;//出库量*收费单价*收费区间
sumfee += gradefee;
//计算 开始计费日期和计费天数
if (price > 0)
{
dtime = WmsOutDetailEntity.DODATE.ToString();//开始计费日期 STARTBILLINGDATE
iFEEDAYS = nowscale;//计费天数 FEEDAYS
}
//
prescale = nowscale;//本次收费区间
}
else
{
gradefee = outnums * price * (feedays - prescale);//出库量*收费单价*(仓储天数-上一个收费区间(0)
sumfee += gradefee;
//计算 开始计费日期和计费天数
if (price > 0)
{
dtime = WmsOutDetailEntity.DODATE.ToString();//开始计费日期 STARTBILLINGDATE
iFEEDAYS = feedays - prescale;//计费天数 FEEDAYS
}
//
prescale = nowscale;//本次收费区间
break;
}
}
else if (nowgrade > 1)//收费等级
{
if (feedays > nowscale)
{
gradefee = outnums * price * (nowscale - prescale);//出库量*收费单价*(收费区间-上一个收费区间(0)
sumfee += gradefee;
//计算 开始计费日期和计费天数
if (price > 0)
{
if (dtime.Trim() == "")
{
dtime = (DateTime.Parse(WmsOutDetailEntity.DODATE.ToString()).AddDays(prescale)).ToString().Trim();//开始计费日期 STARTBILLINGDATE
}
iFEEDAYS += (nowscale - prescale);//计费天数 FEEDAYS
}
//
prescale = nowscale;//本次收费区间
}
else
{
gradefee = outnums * price * (feedays - prescale);//出库量*收费单价*(仓储天数-上一个收费区间(0)
sumfee += gradefee;
//计算 开始计费日期和计费天数
if (price > 0)
{
if (dtime.Trim() == "")
{
dtime = (DateTime.Parse(WmsOutDetailEntity.DODATE.ToString()).AddDays(prescale)).ToString().Trim();//开始计费日期 STARTBILLINGDATE
}
iFEEDAYS += (feedays - prescale);//计费天数 FEEDAYS
}
//
prescale = nowscale;//本次收费区间
break;
}
}
}
if (feedays > nowscale)
{
gradefee = outnums * price * (feedays - nowscale);//出库量*收费单价*(仓储天数-收费区间(0)
sumfee += gradefee;
//计算 开始计费日期和计费天数
if (price > 0)
{
if (dtime.Trim() == "")
{
dtime = (DateTime.Parse(WmsOutDetailEntity.DODATE.ToString()).AddDays(nowscale - 1)).ToString().Trim();//开始计费日期 STARTBILLINGDATE
}
iFEEDAYS += (feedays - nowscale);//计费天数 FEEDAYS
}
}
totaloutfee += sumfee;
//
WmsOutDetailEntity.DODATE = WmsOutEntity.DODATE;
WmsOutDetailEntity.GOODSOUTFEE = decimal.Parse(Round(sumfee, 2, "").ToString());
WmsOutDetailEntity.GOODSOUTFEEAP = 0;
WmsOutDetailEntity.STARTBILLINGDATE = dtime.ToString().Trim() == "" ? DateTime.Parse("0001-01-01 00:00:00") : DateTime.Parse(dtime);//开始计费日期
WmsOutDetailEntity.ENDBILLINGDATE = WmsOutEntity.DODATE;//结束计费日期
WmsOutDetailEntity.FEEDAYS = iFEEDAYS;//计费天数
}
else
{//仓储费率没有设定
sqlTran.Rollback();
result = -2;
Page.ClientScript.RegisterStartupScript(this.GetType(), "key0", "<script>alert('仓储费率没有设置');</script>");
Clearh();
return result;
}
}
else
{
sqlTran.Rollback();
result = -3;
Page.ClientScript.RegisterStartupScript(this.GetType(), "key0", "<script>alert('仓储费率没有设置');</script>");
Clearh();
return result;
}
//保存wms_out_detail
newGID = Guid.NewGuid().ToString();
//
//bsno = getCodeRuleWmsOutDetail("出库明细单号", "BSNO");
#region 提取规则编号 getCodeRuleWmsOutDetail
// <summary>
// 提取规则编号
// </summary>
// <param name="strRULENAME">规则项目名称</param>
// <param name="strfield">需要加规则的字段</param>
// <returns></returns>
//protected String getCodeRuleWmsOutDetail(string strRULENAME, string strfield)
//{
//调用编码规则
string strRULEYEAR = "";
string strRULECONTENT = "";
string strCODENAME = "";
string strDEPTNO = "";
string strRULENOLENGTH = "";
int iRULENOLENGTH = 0;
int inum = 0;
string strCONTENT = "";
DataSet ds = T_ALL_DA.GetAllSQL("select *,getdate() DODATE from code_rule where RULENAME='出库明细单号' and RULETYPE=3");
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0]["ISSTARTUSING"].ToString().Trim().Equals("True"))
{
getCodeRuleEnabled("出库明细单号", "BSNO");
//
if (ds.Tables[0].Rows[0]["RULEDATE"].ToString().Trim().Equals("业务日期"))
{
if (ds.Tables[0].Rows[0]["DODATE"].ToString().Trim() == "")
{
//return "";
bsno = "";
}
DateTime dETD = System.Convert.ToDateTime(ds.Tables[0].Rows[0]["DODATE"].ToString().Trim());
if (ds.Tables[0].Rows[0]["ISCLEAREDINEARLY"].ToString().Trim().Equals("True"))
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = dETD.ToString("yyyy") + dETD.ToString("MM");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = dETD.ToString("yy") + dETD.ToString("MM");
}
}
else
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = dETD.ToString("yyyy");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = dETD.ToString("yy");
}
}
}
else if (ds.Tables[0].Rows[0]["RULEDATE"].ToString().Trim().Equals("自然月份"))
{
DateTime fwqdate = System.Convert.ToDateTime(T_ALL_DA.GetStrSQL("fwqdate", "select fwqdate=getdate()"));
if (ds.Tables[0].Rows[0]["ISCLEAREDINEARLY"].ToString().Trim().Equals("True"))
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = fwqdate.ToString("yyyy") + fwqdate.ToString("MM");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = fwqdate.ToString("yy") + fwqdate.ToString("MM");
}
}
else
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = fwqdate.ToString("yyyy");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = fwqdate.ToString("yy");
}
}
}
//
if (ds.Tables[0].Rows[0]["ISCOMPANY"].ToString().Trim().Equals("True"))
{
strCODENAME = T_ALL_DA.GetStrSQL("CODENAME", "select CODENAME from [company] where GID=(select top 1 COMPANYID from user_company where USERID='" + strUserID + "')");
}
if (ds.Tables[0].Rows[0]["ISDEPT"].ToString().Trim().Equals("True"))
{
strDEPTNO = T_ALL_DA.GetStrSQL("DEPTNO", "select DEPTNO from [sys_dept] where LINKID=(select top 1 COMPANYID from user_company where USERID='" + strUserID + "')");
}
strRULECONTENT = ds.Tables[0].Rows[0]["RULECONTENT"].ToString().Trim();
strRULECONTENT = strRULECONTENT.Replace("《COMPANY》", strCODENAME);
strRULECONTENT = strRULECONTENT.Replace("《DEPT》", strDEPTNO);
//
if (ds.Tables[0].Rows[0]["RULENOLENGTH"].ToString().Trim() == "")
{
iRULENOLENGTH = 0;
}
else
{
iRULENOLENGTH = int.Parse(ds.Tables[0].Rows[0]["RULENOLENGTH"].ToString().Trim());
}
strCONTENT = strRULECONTENT + strRULEYEAR;
//获取分公司的票号头字符
string tempBANKSHEAD = T_ALL_DA.GetStrSQL("BANKSHEAD", "SELECT TOP 1 BANKSHEAD FROM company WHERE GID='" + strCompanyID.Trim() + "'");
strCONTENT = tempBANKSHEAD + strCONTENT;
//
string strSQL = "select top 1 BSNO from [wms_out_detail] where BSNO like '" + strCONTENT.Trim() + "%' order by BSNO DESC";
DataSet ds1 = SqlHelper.ExecuteQueryDataset(sqlTran, CommandType.Text, strSQL, null);
if (ds1 != null)
{
if (ds1.Tables[0].Rows.Count > 0)
{
strRULENOLENGTH = ds1.Tables[0].Rows[0]["BSNO"].ToString().Trim();
}
}
if (strRULENOLENGTH == "")
{
strRULENOLENGTH = "1";
}
else
{
strRULENOLENGTH = strRULENOLENGTH.Replace(strCONTENT.Trim(), "");
inum = int.Parse(strRULENOLENGTH.Trim());
inum = inum + 1;
strRULENOLENGTH = inum.ToString();
}
int j = iRULENOLENGTH - strRULENOLENGTH.Length;
for (int i = 1; i <= j; i++)
{
strRULENOLENGTH = "0" + strRULENOLENGTH;
}
//
strCONTENT = strCONTENT + strRULENOLENGTH;
bsno = strCONTENT;
//return strCONTENT;
}
}
}
// return "";
//}
#endregion
//
WmsOutDetailEntity.GID = newGID;
WmsOutDetailEntity.BSNO = bsno;
WmsOutDetailEntity.OUTBSNO = this.h_outbsno.Value;
//
ls = WmsOutDetailEntity.TRUCKNO.ToString().Trim();
ls = ls.Replace("", " ");
ls = ls.Replace("", "\r\n");
//
string strSTARTBILLINGDATE = WmsOutDetailEntity.STARTBILLINGDATE.ToString().IndexOf("0001") > -1 ? "" : "'" + WmsOutDetailEntity.STARTBILLINGDATE.ToString() + "',";
string strSTARTBILLINGDATE_name = strSTARTBILLINGDATE.Equals("") ? "" : "STARTBILLINGDATE,";
//
string strENDBILLINGDATE = WmsOutDetailEntity.STARTBILLINGDATE.ToString().IndexOf("0001") > -1 ? "" : "'" + WmsOutDetailEntity.DODATE.ToString() + "',";//如果开始计费日期为空,则结束计费日期也为空,否则为出库日期。
string strENDBILLINGDATE_name = strENDBILLINGDATE.Equals("") ? "" : "ENDBILLINGDATE,";
//
Sqlstr = String.Format("insert into wms_out_detail (GID,INBSNO,OUTBSNO,BSNO,CUSTOMERNAME,DODATE,STORAGENAME,GOODSNAME,GOODSMODEL,GOODSPFSL,GOODSOUTFEE,CREATEUSER,CREATETIME,REMARK,TRUCKNO,ASSOCIATEDNO,GOODSPACKPFSL,GOODSOUTFEEAP,ARFEE,APFEE,CLIENTNAMEOLD,OLDCUSTFEEDATE,{21}{23}FEEDAYS) "
+ " values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}',getdate(),'{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}',{22}{24}'{25}')"
, WmsOutDetailEntity.GID, WmsOutDetailEntity.INBSNO, WmsOutDetailEntity.OUTBSNO, WmsOutDetailEntity.BSNO, WmsOutDetailEntity.CUSTOMERNAME, WmsOutEntity.DODATE, WmsOutDetailEntity.STORAGENAME, WmsOutDetailEntity.GOODSNAME, WmsOutDetailEntity.GOODSMODEL, WmsOutDetailEntity.GOODSPFSL, WmsOutDetailEntity.GOODSOUTFEE, strUserID, WmsOutDetailEntity.REMARK, ls, WmsOutDetailEntity.ASSOCIATEDNO, WmsOutDetailEntity.GOODSPACKPFSL, WmsOutDetailEntity.GOODSOUTFEEAP, WmsOutDetailEntity.ARFEE, WmsOutDetailEntity.APFEE,
WmsOutDetailEntity.CLIENTNAMEOLD, WmsOutEntity.DODATE, strSTARTBILLINGDATE_name, strSTARTBILLINGDATE, strENDBILLINGDATE_name, strENDBILLINGDATE, WmsOutDetailEntity.FEEDAYS);
//
iState=SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, Sqlstr, null);
if (iState != 1)
{
sqlTran.Rollback();
result = -5;
Clearh();
return result;
}
//修改入库单wms_in
//Sqlstr = String.Format("update wms_in set GOODSSTOCK=GOODSSTOCK-{0},GOODSPACKSTOCK=GOODSPACKSTOCK-{1} where ISDELETE=0 and BSNO='{2}' ", WmsOutDetailEntity.GOODSPFSL, WmsOutDetailEntity.GOODSPACKPFSL, WmsOutDetailEntity.INBSNO);
Sqlstr = String.Format("update wms set GOODSSTOCK=GOODSSTOCK-{0},GOODSPACKSTOCK=GOODSPACKSTOCK-{1} where ISDELETE=0 and GID='{2}' ", WmsOutDetailEntity.GOODSPFSL, WmsOutDetailEntity.GOODSPACKPFSL, WmsOutDetailEntity.INBSNO);
iState=SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, Sqlstr, null);
if (iState != 1)
{
sqlTran.Rollback();
result = -6;
Clearh();
return result;
}
}
else if (feedays < 0 && !WmsOutDetailEntity.CUSTOMERNAMEPARENT.Equals(null) && !WmsOutDetailEntity.CUSTOMERNAMEPARENT.Equals("") && WmsOutDetailEntity.CUSTOMERNAMEPARENT != WmsOutDetailEntity.CUSTOMERNAME)
{
//重算原货主仓储费
SetOutPWmsFee(WmsOutEntity.DODATE.ToString(), WmsOutDetailEntity.CUSTOMERNAME, WmsOutDetailEntity.INBSNO, sqlTran);//.ASSOCIATEDNO
}
}// end 保存出库明细wms_out_detail
//修改wms_out的出库量、出库件数、应收应付装卸费
string lsSQL = "update wms_out set "
+ "GOODSPFSL=(select isnull(sum(GOODSPFSL),0) from wms_out_detail where OUTBSNO=wms_out.BSNO)"
+ ",GOODSPACKPFSL=(select isnull(sum(GOODSPACKPFSL),0) from wms_out_detail where OUTBSNO=wms_out.BSNO)"
+ ",ARFEE=(select isnull(sum(ARFEE),0) from wms_out_detail where OUTBSNO=wms_out.BSNO)"
+ ",APFEE=(select isnull(sum(APFEE),0) from wms_out_detail where OUTBSNO=wms_out.BSNO)"
+ " where ISLOCK=0 and GID='" + WmsOutEntity.GID.ToString().Trim() + "'";
iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, lsSQL, null);
if (iState != 1)
{
sqlTran.Rollback();
result = -7;
Clearh();
return result;
}
//修改wms_out的仓储费wmsOutEntity.GOODSOUTFEE
h_outfee.Value = totaloutfee.ToString();
WmsOutEntity.GOODSOUTFEE =decimal.Parse( Round(totaloutfee,2,"").ToString());
WmsOutEntity.GOODSOUTFEEAP = 0;
Sqlstr = String.Format("update wms_out set GOODSOUTFEE={0},GOODSOUTFEEAP={2} where GID='{1}'", WmsOutEntity.GOODSOUTFEE, WmsOutEntity.GID, WmsOutEntity.GOODSOUTFEEAP);
iState=SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, Sqlstr, null);
if (iState != 1)
{
sqlTran.Rollback();
result = -7;
Clearh();
return result;
}
#endregion
#region 将仓储费写入ch_fee
/*
if (isJsFee == true)
{
FeeDA feeDA = new FeeDA();
IList<FeeEntity> feeEntities = new List<FeeEntity>();
FeeEntity feeEntity = new FeeEntity();
double deprice = 0;
if (WmsOutEntity.GOODSPFSL != 0)
{
deprice = double.Parse((WmsOutEntity.GOODSOUTFEE / WmsOutEntity.GOODSPFSL).ToString());
}
else
{
deprice = 0;
}
deprice = Round(deprice, 2, "");
if (deprice != 0)
{
feeEntity.GID = Guid.NewGuid().ToString();
feeEntity.FeeType = 1;
feeEntity.BSNO = WmsOutEntity.ASSOCIATEDNO;
feeEntity.FeeName = "仓储费";
feeEntity.CustomerName = WmsOutEntity.CUSTOMERNAME;
feeEntity.Unit = "重量";
feeEntity.UnitPrice =decimal.Parse( deprice.ToString());
feeEntity.Quantity = WmsOutEntity.GOODSPFSL;
feeEntity.CommissionRate = 1;
feeEntity.Amount = WmsOutEntity.GOODSOUTFEE;
feeEntity.Currency = "RMB";
feeEntity.ExchangeRate = 1;
feeEntity.FeeFrt = "";
feeEntity.Remark = "";
feeEntity.IsAdvancePay = false;
feeEntity.EnterOperator = WmsOutEntity.CREATEUSER;
feeEntity.FeeStatus = 1;
feeEntity.WMSOUTBSNO = WmsOutEntity.BSNO;
feeEntities.Add(feeEntity);
iState = feeDA.DoFee(feeEntities, WmsOutEntity.BSNO, strUserID);
feeEntities.Remove(feeEntity);
if (iState != 1)
{
sqlTran.Rollback();
result = -8;
Clearh();
return result;
}
}
//出库费写入ch_fee
WmsFeeCodeDA WmsFeeCodeDA = new WmsFeeCodeDA();
string strSql11 = String.Format("SELECT GID,FEETYPE,FEECODE,FEENAME,BSNO,CLIENT,UNIT,CURRENCY,UNITPRICE,EXCHANGERATE,SORT,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,REMARK FROM wms_feeCode "
+ " where BSNO='{0}' ", WmsOutEntity.ASSOCIATEDNO);
DataSet ds = WmsFeeCodeDA.GetRateListByCondition(strSql11);
DataTable dt = ds.Tables[0];
if (dt.Rows.Count > 0)
{
foreach (DataRow r in dt.Rows)
{
if (r["FEENAME"].ToString() == "出库费")
{
feeEntity = new FeeEntity();
feeEntity.GID = Guid.NewGuid().ToString();
feeEntity.FeeType = 1;
feeEntity.BSNO = WmsOutEntity.ASSOCIATEDNO;
feeEntity.FeeName = "出库费";
feeEntity.CustomerName = WmsOutEntity.CUSTOMERNAME;
feeEntity.Unit = "重量";
feeEntity.UnitPrice = decimal.Parse(r["UNITPRICE"].ToString());
feeEntity.Quantity = WmsOutEntity.GOODSPFSL;
feeEntity.CommissionRate = 1;
double amount = double.Parse(WmsOutEntity.GOODSPFSL.ToString()) * double.Parse(r["UNITPRICE"].ToString());
feeEntity.Amount = decimal.Parse(Round(amount, 2, "").ToString());
feeEntity.Currency = "RMB";
feeEntity.ExchangeRate = 1;
feeEntity.FeeFrt = "";
feeEntity.Remark = "";
feeEntity.IsAdvancePay = false;
feeEntity.EnterOperator = WmsOutEntity.CREATEUSER;
feeEntity.FeeStatus = 1;
feeEntity.WMSOUTBSNO = WmsOutEntity.BSNO;
feeEntities.Add(feeEntity);
//保存如ch_fee
iState = feeDA.DoFee(feeEntities, WmsOutEntity.BSNO, strUserID);
if (iState != 1)
{
sqlTran.Rollback();
result = -9;
Clearh();
return result;
}
}
}
}
//else
//{//没有设置出库费
//}
}//end 将仓储费和出库费写入ch_fee
*/
#endregion
//页面赋值
this.h_wmsoutbsno.Value = WmsOutEntity.BSNO.ToString();
this.h_goodsmodel.Value = WmsOutEntity.GOODSMODEL.ToString();
this.h_goodspfsl.Value = WmsOutEntity.GOODSPFSL.ToString();
this.h_remark.Value = WmsOutEntity.REMARK.ToString();
txt_outbsno.Value = h_outbsno.Value;
txt_outdate.Value = h_outdate.Value;
string strcustomer = h_customer.Value;
string goods = h_goods.Value;
txt_goodsmodel.Value = h_goodsmodel.Value;
#endregion
this.h_newcust.Value = "";
this.h_IsSetRate.Value = "0";//正常出库,不需要设置费率
result = 1;//状态为1表示删除成功
sqlTran.Commit();
Page.ClientScript.RegisterStartupScript(this.GetType(), "key1", "<script>alert('出库单生成成功');window.parent.opener.location.href=window.parent.opener.location.href;</script>");
}
catch (Exception execError)
{
result = -10;//有异常,插入失败
sqlTran.Rollback();
result = -11;//插入异常,事务已回滚成功
Clearh();
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return result;
}
#endregion
private void SetOutPWmsFee(string OutDate, string CustName, string Associatedno, SqlTransaction sqlTran)
{
#region
int iState = 0;
string Sqlstr = "";
double totaloutfee = 0;//出库单的仓储费
int prescale = 0;
int nowscale = 0;
int nowgrade = 0;
double price = 0;
double gradefee = 0;
double sumfee = 0;
WmsOutDetailDA WmsOutDetailDA = new WmsOutDetailDA();
DataSet DsDetail;
DataTable TbDetail;
DataSet dsrate;
DataTable dtrate;
double outnums = 0;
int feedays = 0;
string OUTBSNO = "";//wms_out.BSNO
//查找对应的wms_out_detail记录
Sqlstr = String.Format("select a.GID,a.DODATE,a.GOODSPACKPFSL,a.GOODSPFSL,a.OUTBSNO,c.CLIENTNAMEOLD,c.CUSTOMERNAME as CLIENTNAME,a.ASSOCIATEDNO,a.INBSNO from wms_out_detail a inner join wms_out b on a.OUTBSNO=b.BSNO inner join wms c on c.GID=a.INBSNO and c.CLIENTNAMEOLD=b.CUSTOMERNAME and c.GOODSSTOCK=b.GOODSPFSL "
+ " where c.CUSTOMERNAME='{0}' and c.GID='{1}' and a.DODATE>'{2}' ", CustName, Associatedno, OutDate);
DsDetail = SqlHelper.ExecuteQueryDataset(sqlTran, CommandType.Text, Sqlstr.ToString(), null);
TbDetail = DsDetail.Tables[0];
foreach (DataRow r in TbDetail.Rows)
{
OUTBSNO = r["OUTBSNO"].ToString();
outnums = double.Parse(r["GOODSPFSL"].ToString());
feedays = WmsOutDetailDA.GetDaysCount("day", r["DODATE"].ToString(), OutDate);
if (feedays > 0)
{
Sqlstr = String.Format("SELECT FEEGRADE,FEESCALE,FEEPRICE,FEEUNIT FROM wms_rate where BSNO='{1}' and CUSTOMERNAME like '%{0}%' order by BSNO,FEEGRADE ", CustName, r["INBSNO"].ToString());//r["ASSOCIATEDNO"].ToString()
dsrate = SqlHelper.ExecuteQueryDataset(sqlTran, CommandType.Text, Sqlstr.ToString(), null);
dtrate = dsrate.Tables[0];
prescale = 0;
nowscale = 0;
nowgrade = 0;
price = 0;
gradefee = 0;
sumfee = 0;
foreach (DataRow drow in dtrate.Rows)
{
nowgrade = int.Parse(drow["FEEGRADE"].ToString());
nowscale = int.Parse(drow["FEESCALE"].ToString());
price = double.Parse(drow["FEEPRICE"].ToString());
if (nowgrade.Equals(1))
{
if (feedays > nowscale)
{
gradefee = outnums * price * nowscale;
sumfee += gradefee;
prescale = nowscale;
}
else
{
gradefee = outnums * price * (feedays - prescale);
sumfee += gradefee;
prescale = nowscale;
break;
}
}
else if (nowgrade > 1)
{
if (feedays > nowscale)
{
gradefee = outnums * price * (nowscale - prescale);
sumfee += gradefee;
prescale = nowscale;
}
else
{
gradefee = outnums * price * (feedays - prescale);
sumfee += gradefee;
prescale = nowscale;
break;
}
}
}
if (feedays > nowscale)
{
gradefee = outnums * price * (feedays - nowscale);
sumfee += gradefee;
}
totaloutfee += sumfee;
//更新wms_out_detail
Sqlstr = String.Format("update wms_out_detail set DODATE='{0}',GOODSOUTFEE={1},GOODSOUTFEEAP={3} where GID='{2}' "
, OutDate, decimal.Parse(Round(sumfee, 2, "").ToString()),r["GID"],0.00);
iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, Sqlstr.ToString(), null);
}
else if (feedays < 0 && r["CLIENTNAME"].ToString().Trim()!=r["CLIENTNAMEOLD"].ToString().Trim())
{
SetOutPWmsFee(OutDate, r["CLIENTNAMEOLD"].ToString(), r["INBSNO"].ToString(), sqlTran);
}
}
//查找到对应的wms_out记录,并更新wms_out OUTBSNO
Sqlstr = String.Format("update wms_out set DODATE='{0}',GOODSOUTFEE={1},GOODSOUTFEE={3} where BSNO='{2}' "
, OutDate, decimal.Parse(Round(totaloutfee, 2, "").ToString()), OUTBSNO,0.00);
iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, Sqlstr.ToString(), null);
#endregion
}
private void Clearh()
{
this.h_post.Value = "";
this.h_bsno.Value = "";
this.h_opseaibsno.Value = "";
this.h_wmsoutbsno.Value = "";
this.h_outgid.Value = "";
this.h_outbsno.Value = "";
txt_outbsno.Value = "";
txt_packnum.Value = "";
h_packnum.Value = "";
txt_goodspfsl.Value = "";
h_goodspfsl.Value = "";
}
#region 货权转移 CargoRightTransfer
/// <summary>
/// 货权转移
/// </summary>
private int CargoRightTransfer()
{
int iState = 0;
int result = 0;
string Sqlstr = "";
double totaloutfee = 0;//出库单的仓储费
int prescale = 0;
int nowscale = 0;
int nowgrade = 0;
double price = 0;
double gradefee = 0;
double sumfee = 0;
string newGID = "";
string bsno = "";
//出库单信息
WmsOutDA WmsOutDA = new WmsOutDA();
WmsOutEntity WmsOutEntity = new WmsOutEntity();
if (!WoJSON.Trim().Equals(""))
{ //将应收费用信息从前台页面写入费用实体类feeEntities
WmsOutEntity = ResolveWoJSON(WoJSON.Trim(), WmsOutEntity);
WoContainer.Value = "";
}
//出库单明细信息
WmsOutDetailDA WmsOutDetailDA = new WmsOutDetailDA();
IList<WmsOutDetailEntity> WmsOutDetailEntitys = new List<WmsOutDetailEntity>();
if (!WoDetailJSON.Trim().Equals(""))
{ //将应收费用信息从前台页面写入费用实体类feeEntities
WmsOutDetailEntitys = ResolveWoDetailJSON(WoDetailJSON.Trim(), WmsOutDetailEntitys);
this.WoDetailContainer.Value = "";
}
////原货主信息处理
//IList<WmsOutDetailEntity> WmsOutDetailEntitysParents = new List<WmsOutDetailEntity>();
//foreach (string custp in CustParent)
//{
// IList<WmsOutDetailEntity> ccs = new List<WmsOutDetailEntity>();
// Sqlstr = String.Format(" ASSOCIATEDNO='{0}' and CUSTOMERNAME like '%{1}%' ", WmsOutEntity.ASSOCIATEDNO, custp);
// ccs = WmsOutDetailDA.GetModels(Sqlstr);
// foreach (WmsOutDetailEntity cc in ccs)
// {
// WmsOutDetailEntitysParents.Add(cc);
// }
//}
double outnums = 0;
int feedays = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
#region 生成出库单并计算费用
#region 保存出库单wms_out 出库单明细wms_out_detail
//保存出库单wms_out
//
string ls = WmsOutEntity.TRUCKNO.ToString().Trim();
ls = ls.Replace("", " ");
ls = ls.Replace("", "\r\n");
//
Sqlstr = String.Format("insert into wms_out(GID,BSNO,CUSTOMERNAME,DODATE,STORAGENAME,GOODSNAME,GOODSMODEL,GOODSPFSL,REMARK,CREATEUSER,CREATETIME,TRUCKNO,ASSOCIATEDNO,GOODSPACKPFSL,INSPECTIONNO,CUSTOMNO,CLIENTNAMEOLD,OLDCUSTFEEDATE,TRUCKNAME)"
+ " values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}',getdate(),'{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}' )"
, WmsOutEntity.GID, WmsOutEntity.BSNO, WmsOutEntity.CUSTOMERNAME, WmsOutEntity.DODATE, WmsOutEntity.STORAGENAME, WmsOutEntity.GOODSNAME, WmsOutEntity.GOODSMODEL, WmsOutEntity.GOODSPFSL, "货权转移", strUserID, ls, WmsOutEntity.ASSOCIATEDNO, WmsOutEntity.GOODSPACKPFSL, WmsOutEntity.INSPECTIONNO, WmsOutEntity.CUSTOMNO, WmsOutEntity.CLIENTNAMEOLD, WmsOutEntity.OLDCUSTFEEDATE, WmsOutEntity.TRUCKNAME);
iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, Sqlstr, null);
if (iState != 1)
{
sqlTran.Rollback();
result = -1;
Clearh();
return result;
}
//保存出库单明细wms_out_detail
foreach (WmsOutDetailEntity WmsOutDetailEntity in WmsOutDetailEntitys)
{
string dtime = "";//开始计费日期 STARTBILLINGDATE
int iFEEDAYS = 0;//计费天数 FEEDAYS
outnums = double.Parse(WmsOutDetailEntity.GOODSPFSL.ToString());
feedays = WmsOutDetailDA.GetDaysCount("day", WmsOutDetailEntity.DODATE.ToString(), this.txt_oldcustFeeDate.Value.Trim());//WmsOutEntity.DODATE.ToString());
if (feedays > 0)
{
WmsOutDetailEntity.OUTBSNO = WmsOutEntity.BSNO;
SqlParameter parmrate = new SqlParameter("@BSNO", SqlDbType.VarChar, 100);
parmrate.Value = WmsOutDetailEntity.INBSNO;//WmsOutEntity.ASSOCIATEDNO;
Sqlstr = String.Format("SELECT FEEGRADE,FEESCALE,FEEPRICE,FEEUNIT FROM wms_rate where BSNO=@BSNO and CUSTOMERNAME like '%{0}%' order by BSNO,FEEGRADE ", WmsOutEntity.CUSTOMERNAME);
DataSet dsrate = SqlHelper.ExecuteQueryDataset(sqlTran, CommandType.Text, Sqlstr, parmrate);
DataTable dtrate = new DataTable();
if (dsrate != null)
{
dtrate = dsrate.Tables[0];
if (dtrate.Rows.Count > 0)
{
prescale = 0;
nowscale = 0;
nowgrade = 0;
price = 0;
gradefee = 0;
sumfee = 0;
foreach (DataRow drow in dtrate.Rows)
{
nowgrade = int.Parse(drow["FEEGRADE"].ToString());
nowscale = int.Parse(drow["FEESCALE"].ToString());
price = double.Parse(drow["FEEPRICE"].ToString());
if (nowgrade.Equals(1))
{
if (feedays > nowscale)
{
gradefee = outnums * price * nowscale;
sumfee += gradefee;
//计算 开始计费日期和计费天数
if (price > 0)
{
dtime = WmsOutDetailEntity.DODATE.ToString();//开始计费日期 STARTBILLINGDATE
iFEEDAYS = nowscale;//计费天数 FEEDAYS
}
//
prescale = nowscale;//本次收费区间
}
else
{
gradefee = outnums * price * (feedays - prescale);
sumfee += gradefee;
//计算 开始计费日期和计费天数
if (price > 0)
{
dtime = WmsOutDetailEntity.DODATE.ToString();//开始计费日期 STARTBILLINGDATE
iFEEDAYS = feedays - prescale;//计费天数 FEEDAYS
}
//
prescale = nowscale;//本次收费区间
break;
}
}
else if (nowgrade > 1)
{
if (feedays > nowscale)
{
gradefee = outnums * price * (nowscale - prescale);
sumfee += gradefee;
//计算 开始计费日期和计费天数
if (price > 0)
{
if (dtime.Trim() == "")
{
dtime = (DateTime.Parse(WmsOutDetailEntity.DODATE.ToString()).AddDays(prescale)).ToString().Trim();//开始计费日期 STARTBILLINGDATE
}
iFEEDAYS += (nowscale - prescale);//计费天数 FEEDAYS
}
//
prescale = nowscale;//本次收费区间
}
else
{
gradefee = outnums * price * (feedays - prescale);
sumfee += gradefee;
//计算 开始计费日期和计费天数
if (price > 0)
{
if (dtime.Trim() == "")
{
dtime = (DateTime.Parse(WmsOutDetailEntity.DODATE.ToString()).AddDays(prescale)).ToString().Trim();//开始计费日期 STARTBILLINGDATE
}
iFEEDAYS += (feedays - prescale);//计费天数 FEEDAYS
}
//
prescale = nowscale;//本次收费区间
break;
}
}
}
if (feedays > nowscale)
{
gradefee = outnums * price * (feedays - nowscale);
sumfee += gradefee;
//计算 开始计费日期和计费天数
if (price > 0)
{
if (dtime.Trim() == "")
{
dtime = (DateTime.Parse(WmsOutDetailEntity.DODATE.ToString()).AddDays(nowscale - 1)).ToString().Trim();//开始计费日期 STARTBILLINGDATE
}
iFEEDAYS += (feedays - nowscale);//计费天数 FEEDAYS
}
}
totaloutfee += sumfee;
//
WmsOutDetailEntity.GOODSOUTFEE = decimal.Parse(Round(sumfee, 2, "").ToString());
WmsOutDetailEntity.GOODSOUTFEEAP = 0;
WmsOutDetailEntity.DODATE = WmsOutEntity.DODATE;
WmsOutDetailEntity.STARTBILLINGDATE = dtime.ToString().Trim() == "" ? DateTime.Parse("0001-01-01 00:00:00") : DateTime.Parse(dtime);//开始计费日期
WmsOutDetailEntity.ENDBILLINGDATE = WmsOutEntity.OLDCUSTFEEDATE;//结束计费日期
WmsOutDetailEntity.FEEDAYS = iFEEDAYS;//计费天数
}
else
{//仓储费率没有设定
sqlTran.Rollback();
result = -2;
Page.ClientScript.RegisterStartupScript(this.GetType(), "key0", "<script>alert('仓储费率没有设置');</script>");
Clearh();
return result;
}
}
else
{
sqlTran.Rollback();
result = -3;
Page.ClientScript.RegisterStartupScript(this.GetType(), "key0", "<script>alert('仓储费率没有设置');</script>");
Clearh();
return result;
}
//保存wms_out_detail
newGID = Guid.NewGuid().ToString();
WmsOutDetailEntity.GID = newGID;
//WmsOutDetailEntity.DODATE = WmsOutEntity.DODATE;
//
//bsno = getCodeRuleWmsOutDetail("出库明细单号", "BSNO");
#region 提取规则编号 getCodeRuleWmsOutDetail
// <summary>
// 提取规则编号
// </summary>
// <param name="strRULENAME">规则项目名称</param>
// <param name="strfield">需要加规则的字段</param>
// <returns></returns>
//protected String getCodeRuleWmsOutDetail(string strRULENAME, string strfield)
//{
//调用编码规则
string strRULEYEAR = "";
string strRULECONTENT = "";
string strCODENAME = "";
string strDEPTNO = "";
string strRULENOLENGTH = "";
int iRULENOLENGTH = 0;
int inum = 0;
string strCONTENT = "";
DataSet ds = T_ALL_DA.GetAllSQL("select *,getdate() DODATE from code_rule where RULENAME='出库明细单号' and RULETYPE=3");
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0]["ISSTARTUSING"].ToString().Trim().Equals("True"))
{
getCodeRuleEnabled("出库明细单号", "BSNO");
//
if (ds.Tables[0].Rows[0]["RULEDATE"].ToString().Trim().Equals("业务日期"))
{
if (ds.Tables[0].Rows[0]["DODATE"].ToString().Trim() == "")
{
//return "";
bsno = "";
}
DateTime dETD = System.Convert.ToDateTime(ds.Tables[0].Rows[0]["DODATE"].ToString().Trim());
if (ds.Tables[0].Rows[0]["ISCLEAREDINEARLY"].ToString().Trim().Equals("True"))
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = dETD.ToString("yyyy") + dETD.ToString("MM");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = dETD.ToString("yy") + dETD.ToString("MM");
}
}
else
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = dETD.ToString("yyyy");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = dETD.ToString("yy");
}
}
}
else if (ds.Tables[0].Rows[0]["RULEDATE"].ToString().Trim().Equals("自然月份"))
{
DateTime fwqdate = System.Convert.ToDateTime(T_ALL_DA.GetStrSQL("fwqdate", "select fwqdate=getdate()"));
if (ds.Tables[0].Rows[0]["ISCLEAREDINEARLY"].ToString().Trim().Equals("True"))
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = fwqdate.ToString("yyyy") + fwqdate.ToString("MM");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = fwqdate.ToString("yy") + fwqdate.ToString("MM");
}
}
else
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = fwqdate.ToString("yyyy");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = fwqdate.ToString("yy");
}
}
}
//
if (ds.Tables[0].Rows[0]["ISCOMPANY"].ToString().Trim().Equals("True"))
{
strCODENAME = T_ALL_DA.GetStrSQL("CODENAME", "select CODENAME from [company] where GID=(select top 1 COMPANYID from user_company where USERID='" + strUserID + "')");
}
if (ds.Tables[0].Rows[0]["ISDEPT"].ToString().Trim().Equals("True"))
{
strDEPTNO = T_ALL_DA.GetStrSQL("DEPTNO", "select DEPTNO from [sys_dept] where LINKID=(select top 1 COMPANYID from user_company where USERID='" + strUserID + "')");
}
strRULECONTENT = ds.Tables[0].Rows[0]["RULECONTENT"].ToString().Trim();
strRULECONTENT = strRULECONTENT.Replace("《COMPANY》", strCODENAME);
strRULECONTENT = strRULECONTENT.Replace("《DEPT》", strDEPTNO);
//
if (ds.Tables[0].Rows[0]["RULENOLENGTH"].ToString().Trim() == "")
{
iRULENOLENGTH = 0;
}
else
{
iRULENOLENGTH = int.Parse(ds.Tables[0].Rows[0]["RULENOLENGTH"].ToString().Trim());
}
strCONTENT = strRULECONTENT + strRULEYEAR;
//获取分公司的票号头字符
string tempBANKSHEAD = T_ALL_DA.GetStrSQL("BANKSHEAD", "SELECT TOP 1 BANKSHEAD FROM company WHERE GID='" + strCompanyID.Trim() + "'");
strCONTENT = tempBANKSHEAD + strCONTENT;
//
string strSQL = "select top 1 BSNO from [wms_out_detail] where BSNO like '" + strCONTENT.Trim() + "%' order by BSNO DESC";
DataSet ds1 = SqlHelper.ExecuteQueryDataset(sqlTran, CommandType.Text, strSQL, null);
if (ds1 != null)
{
if (ds1.Tables[0].Rows.Count > 0)
{
strRULENOLENGTH = ds1.Tables[0].Rows[0]["BSNO"].ToString().Trim();
}
}
if (strRULENOLENGTH == "")
{
strRULENOLENGTH = "1";
}
else
{
strRULENOLENGTH = strRULENOLENGTH.Replace(strCONTENT.Trim(), "");
inum = int.Parse(strRULENOLENGTH.Trim());
inum = inum + 1;
strRULENOLENGTH = inum.ToString();
}
int j = iRULENOLENGTH - strRULENOLENGTH.Length;
for (int i = 1; i <= j; i++)
{
strRULENOLENGTH = "0" + strRULENOLENGTH;
}
//
strCONTENT = strCONTENT + strRULENOLENGTH;
bsno = strCONTENT;
//return strCONTENT;
}
}
}
// return "";
//}
#endregion
WmsOutDetailEntity.BSNO = bsno;
//
WmsOutDetailEntity.OUTBSNO = this.h_outbsno.Value;
//
ls = WmsOutDetailEntity.TRUCKNO.ToString().Trim();
ls = ls.Replace("", " ");
ls = ls.Replace("", "\r\n");
//
string strSTARTBILLINGDATE = WmsOutDetailEntity.STARTBILLINGDATE.ToString().IndexOf("0001") > -1 ? "" : "'" + WmsOutDetailEntity.STARTBILLINGDATE.ToString() + "',";
string strSTARTBILLINGDATE_name = strSTARTBILLINGDATE.Equals("") ? "" : "STARTBILLINGDATE,";
//
string strENDBILLINGDATE = WmsOutDetailEntity.STARTBILLINGDATE.ToString().IndexOf("0001") > -1 ? "" : "'" + WmsOutEntity.OLDCUSTFEEDATE.ToString() + "',";//如果开始计费日期为空,则结束计费日期也为空,否则为出库日期。
string strENDBILLINGDATE_name = strENDBILLINGDATE.Equals("") ? "" : "ENDBILLINGDATE,";
//
Sqlstr = String.Format("insert into wms_out_detail (GID,INBSNO,OUTBSNO,BSNO,CUSTOMERNAME,DODATE,STORAGENAME,GOODSNAME,GOODSMODEL,GOODSPFSL,GOODSOUTFEE,CREATEUSER,CREATETIME,REMARK,TRUCKNO,ASSOCIATEDNO,GOODSPACKPFSL,GOODSOUTFEEAP,ARFEE,APFEE,CLIENTNAMEOLD,OLDCUSTFEEDATE,{21}{23}FEEDAYS) "
+ " values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}',getdate(),'{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}',{22}{24}'{25}')"
, WmsOutDetailEntity.GID, WmsOutDetailEntity.INBSNO, WmsOutDetailEntity.OUTBSNO, WmsOutDetailEntity.BSNO, WmsOutDetailEntity.CUSTOMERNAME, WmsOutEntity.DODATE, WmsOutDetailEntity.STORAGENAME, WmsOutDetailEntity.GOODSNAME, WmsOutDetailEntity.GOODSMODEL, WmsOutDetailEntity.GOODSPFSL, WmsOutDetailEntity.GOODSOUTFEE, strUserID, "货权转移", ls, WmsOutDetailEntity.ASSOCIATEDNO, WmsOutDetailEntity.GOODSPACKPFSL, WmsOutDetailEntity.GOODSOUTFEEAP, WmsOutDetailEntity.ARFEE, WmsOutDetailEntity.APFEE,
WmsOutDetailEntity.CLIENTNAMEOLD, WmsOutEntity.OLDCUSTFEEDATE, strSTARTBILLINGDATE_name, strSTARTBILLINGDATE, strENDBILLINGDATE_name, strENDBILLINGDATE, WmsOutDetailEntity.FEEDAYS);
//
iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, Sqlstr, null);
if (iState != 1)
{
sqlTran.Rollback();
result = -5;
Clearh();
return result;
}
//修改入库单wms_in
//Sqlstr = String.Format("update wms_in set GOODSSTOCK=GOODSSTOCK-{0},GOODSPACKSTOCK=GOODSPACKSTOCK-{1} where ISDELETE=0 and BSNO='{2}' ", WmsOutDetailEntity.GOODSPFSL, WmsOutDetailEntity.GOODSPACKPFSL, WmsOutDetailEntity.INBSNO);
Sqlstr = String.Format("update wms set GOODSSTOCK=GOODSSTOCK-{0},GOODSPACKSTOCK=GOODSPACKSTOCK-{1} where ISDELETE=0 and GID='{2}' ", WmsOutDetailEntity.GOODSPFSL, WmsOutDetailEntity.GOODSPACKPFSL, WmsOutDetailEntity.INBSNO);
iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, Sqlstr, null);
if (iState != 1)
{
sqlTran.Rollback();
result = -6;
Clearh();
return result;
}
}
else if (feedays < 0 && !WmsOutDetailEntity.CUSTOMERNAMEPARENT.Equals(null) && !WmsOutDetailEntity.CUSTOMERNAMEPARENT.Equals("") && WmsOutDetailEntity.CUSTOMERNAMEPARENT != WmsOutDetailEntity.CUSTOMERNAME)
{
//重算原货主仓储费
SetOutPWmsFee(WmsOutEntity.DODATE.ToString(), WmsOutDetailEntity.CUSTOMERNAME, WmsOutDetailEntity.INBSNO, sqlTran);//.ASSOCIATEDNO
}
}// end 保存出库明细wms_out_detail
//修改wms_out的出库量、出库件数、应收应付装卸费
string lsSQL = "update wms_out set "
+ "GOODSPFSL=(select isnull(sum(GOODSPFSL),0) from wms_out_detail where OUTBSNO=wms_out.BSNO)"
+ ",GOODSPACKPFSL=(select isnull(sum(GOODSPACKPFSL),0) from wms_out_detail where OUTBSNO=wms_out.BSNO)"
+ ",ARFEE=(select isnull(sum(ARFEE),0) from wms_out_detail where OUTBSNO=wms_out.BSNO)"
+ ",APFEE=(select isnull(sum(APFEE),0) from wms_out_detail where OUTBSNO=wms_out.BSNO)"
+ " where ISLOCK=0 and GID='" + WmsOutEntity.GID.ToString().Trim() + "'";
iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, lsSQL, null);
if (iState != 1)
{
sqlTran.Rollback();
result = -7;
Clearh();
return result;
}
//修改wms_out的仓储费wmsOutEntity.GOODSOUTFEE
h_outfee.Value = totaloutfee.ToString();
WmsOutEntity.GOODSOUTFEE =decimal.Parse( Round(totaloutfee,2,"").ToString());
WmsOutEntity.GOODSOUTFEEAP = 0;
Sqlstr = String.Format("update wms_out set GOODSOUTFEE={0},GOODSOUTFEEAP={2} where GID='{1}'", WmsOutEntity.GOODSOUTFEE, WmsOutEntity.GID, WmsOutEntity.GOODSOUTFEEAP);
iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, Sqlstr, null);
if (iState != 1)
{
sqlTran.Rollback();
result = -7;
Clearh();
return result;
}
#endregion
#region 将仓储费写入ch_fee
/*
if (isJsFee == true)
{
FeeDA feeDA = new FeeDA();
IList<FeeEntity> feeEntities = new List<FeeEntity>();
FeeEntity feeEntity = new FeeEntity();
double deprice = 0;
if (WmsOutEntity.GOODSPFSL != 0)
{
deprice =double.Parse(( WmsOutEntity.GOODSOUTFEE / WmsOutEntity.GOODSPFSL).ToString());
}
else
{
deprice = 0;
}
if (deprice != 0)
{
feeEntity.GID = Guid.NewGuid().ToString();
feeEntity.FeeType = 1;
feeEntity.BSNO = WmsOutEntity.ASSOCIATEDNO;
feeEntity.FeeName = "仓储费";
feeEntity.CustomerName = WmsOutEntity.CUSTOMERNAME;
feeEntity.Unit = "重量";
feeEntity.UnitPrice =decimal.Parse( Round( deprice,2,"").ToString());
feeEntity.Quantity = WmsOutEntity.GOODSPFSL;
feeEntity.CommissionRate = 1;
feeEntity.Amount = WmsOutEntity.GOODSOUTFEE;
feeEntity.Currency = "RMB";
feeEntity.ExchangeRate = 1;
feeEntity.FeeFrt = "";
feeEntity.Remark = "";
feeEntity.IsAdvancePay = false;
feeEntity.EnterOperator = WmsOutEntity.CREATEUSER;
feeEntity.FeeStatus = 1;
feeEntity.WMSOUTBSNO = WmsOutEntity.BSNO;
feeEntities.Add(feeEntity);
iState = feeDA.DoFee(feeEntities, WmsOutEntity.BSNO, strUserID);
feeEntities.Remove(feeEntity);
feeEntity = new FeeEntity();
if (iState != 1)
{
sqlTran.Rollback();
result = -8;
Clearh();
return result;
}
}
}//end 将仓储费和出库费写入ch_fee
*/
#endregion
//页面赋值
this.h_wmsoutbsno.Value = WmsOutEntity.BSNO.ToString();
this.h_goodsmodel.Value = WmsOutEntity.GOODSMODEL.ToString();
this.h_goodspfsl.Value = WmsOutEntity.GOODSPFSL.ToString();
this.h_remark.Value = WmsOutEntity.REMARK.ToString();
txt_outbsno.Value = h_outbsno.Value;
txt_outdate.Value = h_outdate.Value;
string strcustomer = h_customer.Value;
string goods = h_goods.Value;
txt_goodsmodel.Value = h_goodsmodel.Value;
#endregion
#region 货权转移到 outcustomer.value
WmsInEntity WmsInEntity = new WmsInEntity();
WmsInDA wmsinDA = new WmsInDA();
WmsEntity WmsEntity = new WmsEntity();
WmsDA wmsDA = new WmsDA();
string Inbsno = "";
foreach (WmsOutDetailEntity WmsOutDetailEntity in WmsOutDetailEntitys)
{
Inbsno = WmsOutDetailEntity.INBSNO;
break;
}
//
#region 插入入库主表
#region 提取原入库wms数据
string SQL_SELECT_WMS_GID = "select GID, WMSNO, WMSDATE, CUSTOMERNAME, WMSOP, STOREMAN, MODIFIEDUSER, MODIFIEDTIME, ISDELETE, DELETEUSER, DELETETIME,TRUCKNAME, GOODSPACK, GOODSPACKSTOCK, GOODSRKSL, GOODSSTOCK, ARFEE, APFEE, ASSOCIATEDNO, BLNO, FREESTORAGEPERIOD, CONTRACTNO, GOODSNAME, GOODSMODEL, CLIENTCODEOLD, CLIENTNAMEOLD, STORAGENAME, CHARGEUNIT from wms where GID='" + Inbsno.Trim() + "' and ISDELETE=0";
SqlDataReader sqlRead = SqlHelper.ExecuteQueryReader(sqlTran, CommandType.Text, SQL_SELECT_WMS_GID, null);
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0)) { WmsEntity.GID = sqlRead.GetString(0); } // 唯一编码 newid()
if (!sqlRead.IsDBNull(1)) { WmsEntity.WMSNO = sqlRead.GetString(1); } //
if (!sqlRead.IsDBNull(2)) { WmsEntity.WMSDATE = sqlRead.GetDateTime(2); } //
if (!sqlRead.IsDBNull(3)) { WmsEntity.CUSTOMERNAME = sqlRead.GetString(3); } //
if (!sqlRead.IsDBNull(4)) { WmsEntity.WMSOP = sqlRead.GetString(4); } //
if (!sqlRead.IsDBNull(5)) { WmsEntity.STOREMAN = sqlRead.GetString(5); }
if (!sqlRead.IsDBNull(6)) { WmsEntity.MODIFIEDUSER = sqlRead.GetString(6); }
if (!sqlRead.IsDBNull(7)) { WmsEntity.MODIFIEDTIME = sqlRead.GetDateTime(7); }
if (!sqlRead.IsDBNull(8)) { WmsEntity.ISDELETE = sqlRead.GetBoolean(8); } // 是否废除
if (!sqlRead.IsDBNull(9)) { WmsEntity.DELETEUSER = sqlRead.GetString(9); } // 废除操作人
if (!sqlRead.IsDBNull(10)) { WmsEntity.DELETETIME = sqlRead.GetDateTime(10); } // 废除时间
if (!sqlRead.IsDBNull(11)) { WmsEntity.TRUCKNAME = sqlRead.GetString(11); } //
if (!sqlRead.IsDBNull(12)) { WmsEntity.GOODSPACK = sqlRead.GetDecimal(12); } //
if (!sqlRead.IsDBNull(13)) { WmsEntity.GOODSPACKSTOCK = sqlRead.GetDecimal(13); } //
if (!sqlRead.IsDBNull(14)) { WmsEntity.GOODSRKSL = sqlRead.GetDecimal(14); } //
if (!sqlRead.IsDBNull(15)) { WmsEntity.GOODSSTOCK = sqlRead.GetDecimal(15); } //
if (!sqlRead.IsDBNull(16)) { WmsEntity.ARFEE = sqlRead.GetDecimal(16); } //
if (!sqlRead.IsDBNull(17)) { WmsEntity.APFEE = sqlRead.GetDecimal(17); } //
if (!sqlRead.IsDBNull(18)) { WmsEntity.ASSOCIATEDNO = sqlRead.GetString(18); } //
if (!sqlRead.IsDBNull(19)) { WmsEntity.BLNO = sqlRead.GetString(19); } //
if (!sqlRead.IsDBNull(20)) { WmsEntity.FREESTORAGEPERIOD = sqlRead.GetInt32(20); } //
if (!sqlRead.IsDBNull(21)) { WmsEntity.CONTRACTNO = sqlRead.GetString(21); } //
if (!sqlRead.IsDBNull(22)) { WmsEntity.GOODSNAME = sqlRead.GetString(22); } //
if (!sqlRead.IsDBNull(23)) { WmsEntity.GOODSMODEL = sqlRead.GetString(23); } //
if (!sqlRead.IsDBNull(24)) { WmsEntity.CLIENTCODEOLD = sqlRead.GetString(24); } //
if (!sqlRead.IsDBNull(25)) { WmsEntity.CLIENTNAMEOLD = sqlRead.GetString(25); } //
if (!sqlRead.IsDBNull(26)) { WmsEntity.STORAGENAME = sqlRead.GetString(26); } //
if (!sqlRead.IsDBNull(27)) { WmsEntity.CHARGEUNIT = sqlRead.GetString(27); }//
}
sqlRead.Close();
sqlRead.Dispose();
#endregion
//
#region 提取货权转移的wms_out的数据
WmsOutEntity model = new WmsOutEntity();
StringBuilder strSql = new StringBuilder();
string SQL_SELECT_WMS_OUT_GID = "select top 1 GID,AssociatedNO,BSNO,CLIENTGID,CLIENTCODE,CUSTOMERNAME,DODATE,STORAGECODE,STORAGENAME,AREACODE,AREANAME,GOODSCODE,GOODSNAME,GOODSTYPE,GOODSMODEL,GOODSSTANDARD,GOODSPACK,GOODSPFSL,GOODSOUTFEE,REMARK,ISDELETE,DELETETIME,DELETEUSER,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,GOODSPACKPFSL,GOODSOUTFEEAP,TRUCKNAME from wms_out where GID='" + WmsOutEntity.GID.ToString().Trim() + "' ";
SqlDataReader sqlRead1 = SqlHelper.ExecuteQueryReader(sqlTran, CommandType.Text, SQL_SELECT_WMS_OUT_GID, null);
while (sqlRead1.Read())
{
if (sqlRead1["GID"] != null && sqlRead1["GID"].ToString() != "")
{
model.GID = sqlRead1["GID"].ToString();
}
if (sqlRead1["ASSOCIATEDNO"] != null && sqlRead1["ASSOCIATEDNO"].ToString() != "")
{
model.ASSOCIATEDNO = sqlRead1["ASSOCIATEDNO"].ToString();
}
if (sqlRead1["BSNO"] != null && sqlRead1["BSNO"].ToString() != "")
{
model.BSNO = sqlRead1["BSNO"].ToString();
}
if (sqlRead1["CLIENTGID"] != null && sqlRead1["CLIENTGID"].ToString() != "")
{
model.CLIENTGID = sqlRead1["CLIENTGID"].ToString();
}
if (sqlRead1["CLIENTCODE"] != null && sqlRead1["CLIENTCODE"].ToString() != "")
{
model.CLIENTCODE = sqlRead1["CLIENTCODE"].ToString();
}
if (sqlRead1["CUSTOMERNAME"] != null && sqlRead1["CUSTOMERNAME"].ToString() != "")
{
model.CUSTOMERNAME = sqlRead1["CUSTOMERNAME"].ToString();
}
if (sqlRead1["DODATE"] != null && sqlRead1["DODATE"].ToString() != "")
{
model.DODATE = DateTime.Parse(sqlRead1["DODATE"].ToString());
}
if (sqlRead1["STORAGECODE"] != null && sqlRead1["STORAGECODE"].ToString() != "")
{
model.STORAGECODE = sqlRead1["STORAGECODE"].ToString();
}
if (sqlRead1["STORAGENAME"] != null && sqlRead1["STORAGENAME"].ToString() != "")
{
model.STORAGENAME = sqlRead1["STORAGENAME"].ToString();
}
if (sqlRead1["AREACODE"] != null && sqlRead1["AREACODE"].ToString() != "")
{
model.AREACODE = sqlRead1["AREACODE"].ToString();
}
if (sqlRead1["AREANAME"] != null && sqlRead1["AREANAME"].ToString() != "")
{
model.AREANAME = sqlRead1["AREANAME"].ToString();
}
if (sqlRead1["GOODSCODE"] != null && sqlRead1["GOODSCODE"].ToString() != "")
{
model.GOODSCODE = sqlRead1["GOODSCODE"].ToString();
}
if (sqlRead1["GOODSNAME"] != null && sqlRead1["GOODSNAME"].ToString() != "")
{
model.GOODSNAME = sqlRead1["GOODSNAME"].ToString();
}
if (sqlRead1["GOODSTYPE"] != null && sqlRead1["GOODSTYPE"].ToString() != "")
{
model.GOODSTYPE = sqlRead1["GOODSTYPE"].ToString();
}
if (sqlRead1["GOODSMODEL"] != null && sqlRead1["GOODSMODEL"].ToString() != "")
{
model.GOODSMODEL = sqlRead1["GOODSMODEL"].ToString();
}
if (sqlRead1["GOODSSTANDARD"] != null && sqlRead1["GOODSSTANDARD"].ToString() != "")
{
model.GOODSSTANDARD = sqlRead1["GOODSSTANDARD"].ToString();
}
if (sqlRead1["GOODSPACK"] != null && sqlRead1["GOODSPACK"].ToString() != "")
{
model.GOODSPACK = sqlRead1["GOODSPACK"].ToString();
}
if (sqlRead1["GOODSPFSL"] != null && sqlRead1["GOODSPFSL"].ToString() != "")
{
model.GOODSPFSL = decimal.Parse(sqlRead1["GOODSPFSL"].ToString());
}
if (sqlRead1["GOODSOUTFEE"] != null && sqlRead1["GOODSOUTFEE"].ToString() != "")
{
model.GOODSOUTFEE = decimal.Parse(sqlRead1["GOODSOUTFEE"].ToString());
}
if (sqlRead1["REMARK"] != null && sqlRead1["REMARK"].ToString() != "")
{
model.REMARK = sqlRead1["REMARK"].ToString();
}
if (sqlRead1["ISDELETE"] != null && sqlRead1["ISDELETE"].ToString() != "")
{
if ((sqlRead1["ISDELETE"].ToString() == "1") || (sqlRead1["ISDELETE"].ToString().ToLower() == "true"))
{
model.ISDELETE = true;
}
else
{
model.ISDELETE = false;
}
}
if (sqlRead1["DELETETIME"] != null && sqlRead1["DELETETIME"].ToString() != "")
{
model.DELETETIME = DateTime.Parse(sqlRead1["DELETETIME"].ToString());
}
if (sqlRead1["DELETEUSER"] != null && sqlRead1["DELETEUSER"].ToString() != "")
{
model.DELETEUSER = sqlRead1["DELETEUSER"].ToString();
}
if (sqlRead1["CREATEUSER"] != null && sqlRead1["CREATEUSER"].ToString() != "")
{
model.CREATEUSER = sqlRead1["CREATEUSER"].ToString();
}
if (sqlRead1["CREATETIME"] != null && sqlRead1["CREATETIME"].ToString() != "")
{
model.CREATETIME = DateTime.Parse(sqlRead1["CREATETIME"].ToString());
}
if (sqlRead1["MODIFIEDUSER"] != null && sqlRead1["MODIFIEDUSER"].ToString() != "")
{
model.MODIFIEDUSER = sqlRead1["MODIFIEDUSER"].ToString();
}
if (sqlRead1["MODIFIEDTIME"] != null && sqlRead1["MODIFIEDTIME"].ToString() != "")
{
model.MODIFIEDTIME = DateTime.Parse(sqlRead1["MODIFIEDTIME"].ToString());
}
if (sqlRead1["GOODSPACKPFSL"] != null && sqlRead1["GOODSPACKPFSL"].ToString() != "")
{
model.GOODSPACKPFSL = decimal.Parse(sqlRead1["GOODSPACKPFSL"].ToString());
}
if (sqlRead1["GOODSOUTFEEAP"] != null && sqlRead1["GOODSOUTFEEAP"].ToString() != "")
{
model.GOODSOUTFEEAP = decimal.Parse(sqlRead1["GOODSOUTFEEAP"].ToString());
}
if (sqlRead1["TRUCKNAME"] != null && sqlRead1["TRUCKNAME"].ToString() != "")
{
model.TRUCKNAME = sqlRead1["TRUCKNAME"].ToString();
}
}
sqlRead1.Close();
sqlRead1.Dispose();
#endregion
//
WmsEntity.GID = getWMSNO();
//
#region 提取规则编号 getCodeRule("入库单号", "WMSNO")
// <summary>
// 提取规则编号
// </summary>
// <param name="strRULENAME">规则项目名称</param>
// <param name="strfield">需要加规则的字段</param>
// <returns></returns>
//protected String getCodeRule(string strRULENAME, string strfield)
//{
//调用编码规则
string tbWMSNO = "";
string strRULEYEAR1 = "";
string strRULECONTENT1 = "";
string strCODENAME1 = "";
string strDEPTNO1 = "";
string strRULENOLENGTH1 = "";
int iRULENOLENGTH1 = 0;
int inum1 = 0;
string strCONTENT1 = "";
DataSet ds2 = T_ALL_DA.GetAllSQL("select *,getdate() DODATE from code_rule where RULENAME='入库单号' and RULETYPE=3");
if (ds2 != null)
{
if (ds2.Tables[0].Rows.Count > 0)
{
if (ds2.Tables[0].Rows[0]["ISSTARTUSING"].ToString().Trim().Equals("True"))
{
getCodeRuleEnabled("入库单号", "WMSNO");
//
if (ds2.Tables[0].Rows[0]["RULEDATE"].ToString().Trim().Equals("业务日期"))
{
if (ds2.Tables[0].Rows[0]["DODATE"].ToString().Trim() == "")
{
//return "";
tbWMSNO = "";
}
DateTime dETD = System.Convert.ToDateTime(ds2.Tables[0].Rows[0]["DODATE"].ToString().Trim());
if (ds2.Tables[0].Rows[0]["ISCLEAREDINEARLY"].ToString().Trim().Equals("True"))
{
if (ds2.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR1 = dETD.ToString("yyyy") + dETD.ToString("MM");
}
else if (ds2.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR1 = dETD.ToString("yy") + dETD.ToString("MM");
}
}
else
{
if (ds2.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR1 = dETD.ToString("yyyy");
}
else if (ds2.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR1 = dETD.ToString("yy");
}
}
}
else if (ds2.Tables[0].Rows[0]["RULEDATE"].ToString().Trim().Equals("自然月份"))
{
DateTime fwqdate = System.Convert.ToDateTime(T_ALL_DA.GetStrSQL("fwqdate", "select fwqdate=getdate()"));
if (ds2.Tables[0].Rows[0]["ISCLEAREDINEARLY"].ToString().Trim().Equals("True"))
{
if (ds2.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR1 = fwqdate.ToString("yyyy") + fwqdate.ToString("MM");
}
else if (ds2.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR1 = fwqdate.ToString("yy") + fwqdate.ToString("MM");
}
}
else
{
if (ds2.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR1 = fwqdate.ToString("yyyy");
}
else if (ds2.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR1 = fwqdate.ToString("yy");
}
}
}
//
if (ds2.Tables[0].Rows[0]["ISCOMPANY"].ToString().Trim().Equals("True"))
{
strCODENAME1 = T_ALL_DA.GetStrSQL("CODENAME", "select CODENAME from [company] where GID=(select top 1 COMPANYID from user_company where USERID='" + strUserID + "')");
}
if (ds2.Tables[0].Rows[0]["ISDEPT"].ToString().Trim().Equals("True"))
{
strDEPTNO1 = T_ALL_DA.GetStrSQL("DEPTNO", "select DEPTNO from [sys_dept] where LINKID=(select top 1 COMPANYID from user_company where USERID='" + strUserID + "')");
}
strRULECONTENT1 = ds2.Tables[0].Rows[0]["RULECONTENT"].ToString().Trim();
strRULECONTENT1 = strRULECONTENT1.Replace("《COMPANY》", strCODENAME1);
strRULECONTENT1 = strRULECONTENT1.Replace("《DEPT》", strDEPTNO1);
//
if (ds2.Tables[0].Rows[0]["RULENOLENGTH"].ToString().Trim() == "")
{
iRULENOLENGTH1 = 0;
}
else
{
iRULENOLENGTH1 = int.Parse(ds2.Tables[0].Rows[0]["RULENOLENGTH"].ToString().Trim());
}
strCONTENT1 = strRULECONTENT1 + strRULEYEAR1;
//
//获取分公司的票号头字符
string tempBANKSHEAD = "";
string strSQL = "SELECT TOP 1 BANKSHEAD FROM company WHERE GID='" + strCompanyID.Trim() + "'";
DataSet ds21 = SqlHelper.ExecuteQueryDataset(sqlTran, CommandType.Text, strSQL, null);
if (ds21 != null)
{
if (ds21.Tables[0].Rows.Count > 0)
{
tempBANKSHEAD = ds21.Tables[0].Rows[0]["BANKSHEAD"].ToString().Trim();
}
}
strCONTENT1 = tempBANKSHEAD + strCONTENT1;
//
strSQL = "select top 1 WMSNO from [wms] where WMSNO like '" + strCONTENT1.Trim() + "%' order by WMSNO DESC";
ds21 = SqlHelper.ExecuteQueryDataset(sqlTran, CommandType.Text, strSQL, null);
if (ds21 != null)
{
if (ds21.Tables[0].Rows.Count > 0)
{
strRULENOLENGTH1 = ds21.Tables[0].Rows[0]["WMSNO"].ToString().Trim();
}
}
if (strRULENOLENGTH1 == "")
{
strRULENOLENGTH1 = "1";
}
else
{
strRULENOLENGTH1 = strRULENOLENGTH1.Replace(strCONTENT1.Trim(), "");
inum1 = int.Parse(strRULENOLENGTH1.Trim());
inum1 = inum1 + 1;
strRULENOLENGTH1 = inum1.ToString();
}
int j = iRULENOLENGTH1 - strRULENOLENGTH1.Length;
for (int i = 1; i <= j; i++)
{
strRULENOLENGTH1 = "0" + strRULENOLENGTH1;
}
//
strCONTENT1 = strCONTENT1 + strRULENOLENGTH1;
tbWMSNO = strCONTENT1;
//return strCONTENT1;
}
}
}
// return "";
//}
#endregion
WmsEntity.WMSNO = tbWMSNO;//调用编码规则
//
WmsEntity.CUSTOMERNAME = this.h_outcustomer.Value.ToString().Trim();
WmsEntity.WMSOP = strShowName.Trim();
WmsEntity.STOREMAN = strShowName.Trim();
WmsEntity.MODIFIEDUSER = strUserID;
//
WmsEntity.WMSDATE = model.DODATE;
WmsEntity.GOODSPACK = model.GOODSPACKPFSL;
WmsEntity.GOODSPACKSTOCK = model.GOODSPACKPFSL;
WmsEntity.GOODSRKSL = model.GOODSPFSL;
WmsEntity.GOODSSTOCK = model.GOODSPFSL;
WmsEntity.ARFEE = 0;
WmsEntity.APFEE = 0;
WmsEntity.CLIENTNAMEOLD = model.CUSTOMERNAME;// 原客户名称
WmsEntity.ISLOCK = false;// true;
WmsEntity.LOCKUSER = strUserID;
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,36) ,
new SqlParameter("@WMSNO", SqlDbType.VarChar,100) ,
new SqlParameter("@WMSDATE", SqlDbType.DateTime) ,
new SqlParameter("@CUSTOMERNAME", SqlDbType.VarChar,20) ,
new SqlParameter("@WMSOP", SqlDbType.VarChar,10) ,
new SqlParameter("@STOREMAN", SqlDbType.VarChar,10) ,
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36) ,
new SqlParameter("@TRUCKNAME", SqlDbType.VarChar,20) ,
new SqlParameter("@GOODSPACK", SqlDbType.Decimal,9) ,
new SqlParameter("@GOODSPACKSTOCK", SqlDbType.Decimal,9) ,
new SqlParameter("@GOODSRKSL", SqlDbType.Decimal,9) ,
new SqlParameter("@GOODSSTOCK", SqlDbType.Decimal,9) ,
new SqlParameter("@ARFEE", SqlDbType.Decimal,9) ,
new SqlParameter("@APFEE", SqlDbType.Decimal,9) ,
new SqlParameter("@ASSOCIATEDNO", SqlDbType.VarChar,100),
new SqlParameter("@BLNO", SqlDbType.VarChar,100) ,
new SqlParameter("@FREESTORAGEPERIOD", SqlDbType.Int,4) ,
new SqlParameter("@CONTRACTNO", SqlDbType.VarChar,100),
new SqlParameter("@GOODSNAME", SqlDbType.VarChar,100) ,
new SqlParameter("@GOODSMODEL", SqlDbType.VarChar,100) ,
new SqlParameter("@CLIENTCODEOLD", SqlDbType.VarChar,20) ,
new SqlParameter("@CLIENTNAMEOLD", SqlDbType.VarChar,20) ,
new SqlParameter("@STORAGENAME", SqlDbType.VarChar,20) ,
new SqlParameter("@CHARGEUNIT", SqlDbType.VarChar,10) ,
new SqlParameter("@ISLOCK", SqlDbType.Bit) ,
new SqlParameter("@LOCKUSER", SqlDbType.VarChar,36)
};
parameters[0].Value = WmsEntity.GID;
parameters[1].Value = WmsEntity.WMSNO;
parameters[2].Value = WmsEntity.WMSDATE;
parameters[3].Value = WmsEntity.CUSTOMERNAME;
parameters[4].Value = WmsEntity.WMSOP;
parameters[5].Value = WmsEntity.STOREMAN;
parameters[6].Value = WmsEntity.MODIFIEDUSER;
parameters[7].Value = WmsEntity.TRUCKNAME;
parameters[8].Value = WmsEntity.GOODSPACK;
parameters[9].Value = WmsEntity.GOODSPACKSTOCK;
parameters[10].Value = WmsEntity.GOODSRKSL;
parameters[11].Value = WmsEntity.GOODSSTOCK;
parameters[12].Value = WmsEntity.ARFEE;
parameters[13].Value = WmsEntity.APFEE;
parameters[14].Value = WmsEntity.ASSOCIATEDNO;
parameters[15].Value = WmsEntity.BLNO;
parameters[16].Value = WmsEntity.FREESTORAGEPERIOD;
parameters[17].Value = WmsEntity.CONTRACTNO;
parameters[18].Value = WmsEntity.GOODSNAME;
parameters[19].Value = WmsEntity.GOODSMODEL;
parameters[20].Value = WmsEntity.CLIENTCODEOLD;
parameters[21].Value = WmsEntity.CLIENTNAMEOLD;
parameters[22].Value = WmsEntity.STORAGENAME;
parameters[23].Value = WmsEntity.CHARGEUNIT;
parameters[24].Value = WmsEntity.ISLOCK;
parameters[25].Value = WmsEntity.LOCKUSER;
string lsSql = "insert into wms(GID,WMSNO,WMSDATE,CUSTOMERNAME,WMSOP,STOREMAN,MODIFIEDUSER,MODIFIEDTIME,ISDELETE,DELETEUSER,DELETETIME,TRUCKNAME,GOODSPACK,GOODSPACKSTOCK,GOODSRKSL,GOODSSTOCK,ARFEE,APFEE,ASSOCIATEDNO,BLNO,FREESTORAGEPERIOD,CONTRACTNO,GOODSNAME,GOODSMODEL,CLIENTCODEOLD,CLIENTNAMEOLD,STORAGENAME,CHARGEUNIT,ISLOCK,LOCKUSER,LOCKTIME) values (@GID,@WMSNO,@WMSDATE,@CUSTOMERNAME,@WMSOP,@STOREMAN,@MODIFIEDUSER,getdate(),0,'',getdate(),@TRUCKNAME,@GOODSPACK,@GOODSPACKSTOCK,@GOODSRKSL,@GOODSSTOCK,@ARFEE,@APFEE,@ASSOCIATEDNO,@BLNO,@FREESTORAGEPERIOD,@CONTRACTNO,@GOODSNAME,@GOODSMODEL,@CLIENTCODEOLD,@CLIENTNAMEOLD,@STORAGENAME,@CHARGEUNIT,@ISLOCK,@LOCKUSER,getdate())";
iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, lsSql, parameters);
if (iState != 1)
{
sqlTran.Rollback();
result = -9;
Clearh();
return result;
}
#endregion
//
#region 插入入库明细表
//
//保存出库单明细wms_out_detail
foreach (WmsOutDetailEntity WmsOutDetailEntity in WmsOutDetailEntitys)
{
#region 提取出库相对应的原入库wms_in数据
string SQL_SELECT_WMS_IN_GID = "select top 1 GID,ASSOCIATEDNO,BLNO,CONTRACTNO,CNTRNO,SEALNO,BSNO,CLIENTCODE,CLIENTNAME,DODATE,STORAGECODE,STORAGENAME,AREACODE,AREANAME,GOODSCODE,GOODSNAME,GOODSTYPE,GOODSMODEL,GOODSSTANDARD,GOODSPACK,CHARGEUNIT,GOODSRKSL,GOODSSTOCK,ISLOCK,LOCKTIME,LOCKUSER,ISDELETE,DELETETIME,DELETEUSER,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,REMARK,FREESTORAGEPERIOD,GOODSPACKSTOCK,GOODSKGS,CLIENTCODEOLD,CLIENTNAMEOLD,KINDPKGS,ARFEE,APFEE from wms_in where ASSOCIATEDNO in (select gid from wms where gid='" + WmsOutDetailEntity.INBSNO.ToString().Trim() + "') and ISDELETE=0";
sqlRead = SqlHelper.ExecuteQueryReader(sqlTran, CommandType.Text, SQL_SELECT_WMS_IN_GID, null);
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0)) { WmsInEntity.GID = sqlRead.GetString(0); }// 惟一编号
if (!sqlRead.IsDBNull(1)) { WmsInEntity.ASSOCIATEDNO = sqlRead.GetString(1); }// 关联号
if (!sqlRead.IsDBNull(2)) { WmsInEntity.BLNO = sqlRead.GetString(2); }// 提单号
if (!sqlRead.IsDBNull(3)) { WmsInEntity.CONTRACTNO = sqlRead.GetString(3); }// 合同号
if (!sqlRead.IsDBNull(4)) { WmsInEntity.CNTRNO = sqlRead.GetString(4); }// 箱号
if (!sqlRead.IsDBNull(5)) { WmsInEntity.SEALNO = sqlRead.GetString(5); }// 封号
if (!sqlRead.IsDBNull(6)) { WmsInEntity.BSNO = sqlRead.GetString(6); }// 仓单明细号
if (!sqlRead.IsDBNull(7)) { WmsInEntity.CLIENTCODE = sqlRead.GetString(7); }// 客户编码
if (!sqlRead.IsDBNull(8)) { WmsInEntity.CLIENTNAME = sqlRead.GetString(8); }// 客户名称
if (!sqlRead.IsDBNull(9)) { WmsInEntity.DODATE = sqlRead.GetDateTime(9); }// 操作时间
if (!sqlRead.IsDBNull(10)) { WmsInEntity.STORAGECODE = sqlRead.GetString(10); }// 仓库编码
if (!sqlRead.IsDBNull(11)) { WmsInEntity.STORAGENAME = sqlRead.GetString(11); }// 仓库名称
if (!sqlRead.IsDBNull(12)) { WmsInEntity.AREACODE = sqlRead.GetString(12); }// 库位编码
if (!sqlRead.IsDBNull(13)) { WmsInEntity.AREANAME = sqlRead.GetString(13); }// 库位名称
if (!sqlRead.IsDBNull(14)) { WmsInEntity.GOODSCODE = sqlRead.GetString(14); }// 货物编号
if (!sqlRead.IsDBNull(15)) { WmsInEntity.GOODSNAME = sqlRead.GetString(15); }// 货物名称
if (!sqlRead.IsDBNull(16)) { WmsInEntity.GOODSTYPE = sqlRead.GetString(16); }// 货物类型
if (!sqlRead.IsDBNull(17)) { WmsInEntity.GOODSMODEL = sqlRead.GetString(17); }// 型号
if (!sqlRead.IsDBNull(18)) { WmsInEntity.GOODSSTANDARD = sqlRead.GetString(18); }// 规格
if (!sqlRead.IsDBNull(19)) { WmsInEntity.GOODSPACK = sqlRead.GetDecimal(19); }// 件数
if (!sqlRead.IsDBNull(20)) { WmsInEntity.CHARGEUNIT = sqlRead.GetString(20); }// 计费单位
if (!sqlRead.IsDBNull(21)) { WmsInEntity.GOODSRKSL = sqlRead.GetDecimal(21); }// 入库量
if (!sqlRead.IsDBNull(22)) { WmsInEntity.GOODSSTOCK = sqlRead.GetDecimal(22); }// 库存量
if (!sqlRead.IsDBNull(23)) { WmsInEntity.ISLOCK = sqlRead.GetBoolean(23); }// 是否锁定
if (!sqlRead.IsDBNull(24)) { WmsInEntity.LOCKTIME = sqlRead.GetDateTime(24); }// 锁定时间
if (!sqlRead.IsDBNull(25)) { WmsInEntity.LOCKUSER = sqlRead.GetString(25); }// 锁定操作人
if (!sqlRead.IsDBNull(26)) { WmsInEntity.ISDELETE = sqlRead.GetBoolean(26); }// 是否废除
if (!sqlRead.IsDBNull(27)) { WmsInEntity.DELETETIME = sqlRead.GetDateTime(27); }// 废除时间
if (!sqlRead.IsDBNull(28)) { WmsInEntity.DELETEUSER = sqlRead.GetString(28); }// 废除操作人
if (!sqlRead.IsDBNull(29)) { WmsInEntity.CREATEUSER = sqlRead.GetString(29); }// 创建人
if (!sqlRead.IsDBNull(30)) { WmsInEntity.CREATETIME = sqlRead.GetDateTime(30); }// 创建时间
if (!sqlRead.IsDBNull(31)) { WmsInEntity.MODIFIEDUSER = sqlRead.GetString(31); }// 最后一次更新操作人
if (!sqlRead.IsDBNull(32)) { WmsInEntity.MODIFIEDTIME = sqlRead.GetDateTime(32); }// 最后一次更新操作时间
if (!sqlRead.IsDBNull(33)) { WmsInEntity.REMARK = sqlRead.GetString(33); }// 备注
if (!sqlRead.IsDBNull(34)) { WmsInEntity.FREESTORAGEPERIOD = sqlRead.GetInt32(34); }// 免仓储期
if (!sqlRead.IsDBNull(35)) { WmsInEntity.GOODSPACKSTOCK = sqlRead.GetDecimal(35); }// 剩余件数
if (!sqlRead.IsDBNull(36)) { WmsInEntity.GOODSKGS = sqlRead.GetDecimal(36); }// 重量
if (!sqlRead.IsDBNull(37)) { WmsInEntity.CLIENTCODEOLD = sqlRead.GetString(37); }// 原客户编码
if (!sqlRead.IsDBNull(38)) { WmsInEntity.CLIENTNAMEOLD = sqlRead.GetString(38); }// 原客户名称
if (!sqlRead.IsDBNull(39)) { WmsInEntity.KINDPKGS = sqlRead.GetString(39); }//
if (!sqlRead.IsDBNull(40)) { WmsInEntity.ARFEE = sqlRead.GetDecimal(40); }//
if (!sqlRead.IsDBNull(41)) { WmsInEntity.APFEE = sqlRead.GetDecimal(41); }//
}
sqlRead.Close();
sqlRead.Dispose();
#endregion
WmsInEntity.GID = Guid.NewGuid().ToString();
WmsInEntity.ASSOCIATEDNO = WmsEntity.GID;
//
#region 提取规则编号 getCodeRule("入库明细单号", "BSNO", "wms_in")
// <summary>
// 提取规则编号
// </summary>
// <param name="strRULENAME">规则项目名称</param>
// <param name="strfield">需要加规则的字段</param>
// <returns></returns>
//protected String getCodeRule(string strRULENAME, string strfield)
//{
//调用编码规则
string tbBSNO = "";
strRULEYEAR1 = "";
strRULECONTENT1 = "";
strCODENAME1 = "";
strDEPTNO1 = "";
strRULENOLENGTH1 = "";
iRULENOLENGTH1 = 0;
inum1 = 0;
strCONTENT1 = "";
ds2 = T_ALL_DA.GetAllSQL("select *,getdate() DODATE from code_rule where RULENAME='入库明细单号' and RULETYPE=3");
if (ds2 != null)
{
if (ds2.Tables[0].Rows.Count > 0)
{
if (ds2.Tables[0].Rows[0]["ISSTARTUSING"].ToString().Trim().Equals("True"))
{
getCodeRuleEnabled("入库明细单号", "BSNO");
//
if (ds2.Tables[0].Rows[0]["RULEDATE"].ToString().Trim().Equals("业务日期"))
{
if (ds2.Tables[0].Rows[0]["DODATE"].ToString().Trim() == "")
{
//return "";
tbBSNO = "";
}
DateTime dETD = System.Convert.ToDateTime(ds2.Tables[0].Rows[0]["DODATE"].ToString().Trim());
if (ds2.Tables[0].Rows[0]["ISCLEAREDINEARLY"].ToString().Trim().Equals("True"))
{
if (ds2.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR1 = dETD.ToString("yyyy") + dETD.ToString("MM");
}
else if (ds2.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR1 = dETD.ToString("yy") + dETD.ToString("MM");
}
}
else
{
if (ds2.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR1 = dETD.ToString("yyyy");
}
else if (ds2.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR1 = dETD.ToString("yy");
}
}
}
else if (ds2.Tables[0].Rows[0]["RULEDATE"].ToString().Trim().Equals("自然月份"))
{
DateTime fwqdate = System.Convert.ToDateTime(T_ALL_DA.GetStrSQL("fwqdate", "select fwqdate=getdate()"));
if (ds2.Tables[0].Rows[0]["ISCLEAREDINEARLY"].ToString().Trim().Equals("True"))
{
if (ds2.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR1 = fwqdate.ToString("yyyy") + fwqdate.ToString("MM");
}
else if (ds2.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR1 = fwqdate.ToString("yy") + fwqdate.ToString("MM");
}
}
else
{
if (ds2.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR1 = fwqdate.ToString("yyyy");
}
else if (ds2.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR1 = fwqdate.ToString("yy");
}
}
}
//
if (ds2.Tables[0].Rows[0]["ISCOMPANY"].ToString().Trim().Equals("True"))
{
strCODENAME1 = T_ALL_DA.GetStrSQL("CODENAME", "select CODENAME from [company] where GID=(select top 1 COMPANYID from user_company where USERID='" + strUserID + "')");
}
if (ds2.Tables[0].Rows[0]["ISDEPT"].ToString().Trim().Equals("True"))
{
strDEPTNO1 = T_ALL_DA.GetStrSQL("DEPTNO", "select DEPTNO from [sys_dept] where LINKID=(select top 1 COMPANYID from user_company where USERID='" + strUserID + "')");
}
strRULECONTENT1 = ds2.Tables[0].Rows[0]["RULECONTENT"].ToString().Trim();
strRULECONTENT1 = strRULECONTENT1.Replace("《COMPANY》", strCODENAME1);
strRULECONTENT1 = strRULECONTENT1.Replace("《DEPT》", strDEPTNO1);
//
if (ds2.Tables[0].Rows[0]["RULENOLENGTH"].ToString().Trim() == "")
{
iRULENOLENGTH1 = 0;
}
else
{
iRULENOLENGTH1 = int.Parse(ds2.Tables[0].Rows[0]["RULENOLENGTH"].ToString().Trim());
}
strCONTENT1 = strRULECONTENT1 + strRULEYEAR1;
//
//获取分公司的票号头字符
string tempBANKSHEAD = "";
string strSQL = "SELECT TOP 1 BANKSHEAD FROM company WHERE GID='" + strCompanyID.Trim() + "'";
DataSet ds21 = SqlHelper.ExecuteQueryDataset(sqlTran, CommandType.Text, strSQL, null);
if (ds21 != null)
{
if (ds21.Tables[0].Rows.Count > 0)
{
tempBANKSHEAD = ds21.Tables[0].Rows[0]["BANKSHEAD"].ToString().Trim();
}
}
strCONTENT1 = tempBANKSHEAD + strCONTENT1;
//
strSQL = "select top 1 BSNO from [wms_in] where BSNO like '" + strCONTENT1.Trim() + "%' order by BSNO DESC";
ds21 = SqlHelper.ExecuteQueryDataset(sqlTran, CommandType.Text, strSQL, null);
if (ds21 != null)
{
if (ds21.Tables[0].Rows.Count > 0)
{
strRULENOLENGTH1 = ds21.Tables[0].Rows[0]["BSNO"].ToString().Trim();
}
}
if (strRULENOLENGTH1 == "")
{
strRULENOLENGTH1 = "1";
}
else
{
strRULENOLENGTH1 = strRULENOLENGTH1.Replace(strCONTENT1.Trim(), "");
inum1 = int.Parse(strRULENOLENGTH1.Trim());
inum1 = inum1 + 1;
strRULENOLENGTH1 = inum1.ToString();
}
int j = iRULENOLENGTH1 - strRULENOLENGTH1.Length;
for (int i = 1; i <= j; i++)
{
strRULENOLENGTH1 = "0" + strRULENOLENGTH1;
}
//
strCONTENT1 = strCONTENT1 + strRULENOLENGTH1;
tbBSNO = strCONTENT1;
//return strCONTENT1;
}
}
}
// return "";
//}
#endregion
WmsInEntity.BSNO = tbBSNO;//调用编码规则
//
WmsInEntity.DODATE = model.DODATE;
WmsInEntity.CLIENTNAME = this.h_outcustomer.Value.ToString().Trim();
WmsInEntity.GOODSRKSL = WmsOutDetailEntity.GOODSPFSL;//入库数量
WmsInEntity.GOODSSTOCK = WmsOutDetailEntity.GOODSPFSL;//入库数量
WmsInEntity.GOODSPACK = WmsOutDetailEntity.GOODSPACKPFSL;//件数
WmsInEntity.GOODSPACKSTOCK = WmsOutDetailEntity.GOODSPACKPFSL;//件数
WmsInEntity.REMARK = "货权转移";
WmsInEntity.CREATEUSER = strUserID;// 创建人
WmsInEntity.MODIFIEDUSER = strUserID;// 最后一次更新操作人
WmsInEntity.CLIENTNAMEOLD = WmsOutDetailEntity.CUSTOMERNAME;//货权转移前货主
WmsInEntity.ARFEE = 0;
WmsInEntity.APFEE = 0;
WmsInEntity.ISLOCK = false;// true;
WmsInEntity.LOCKUSER = strUserID;
SqlParameter[] parms = new SqlParameter[]{
new SqlParameter("@GID",SqlDbType.VarChar,100),//惟一编号
new SqlParameter("@ASSOCIATEDNO",SqlDbType.VarChar,100),//关联号
new SqlParameter("@BLNO",SqlDbType.VarChar,30),//提单号
new SqlParameter("@CONTRACTNO",SqlDbType.VarChar,100),//合同号
new SqlParameter("@CNTRNO",SqlDbType.VarChar,30),//箱号
new SqlParameter("@SEALNO",SqlDbType.VarChar,12),//封号
new SqlParameter("@BSNO",SqlDbType.VarChar,100),//仓单明细号
new SqlParameter("@CLIENTCODE",SqlDbType.VarChar,20),//客户编码
new SqlParameter("@CLIENTNAME",SqlDbType.VarChar,20),//客户名称
new SqlParameter("@STORAGECODE",SqlDbType.VarChar,50),//仓库编码
new SqlParameter("@STORAGENAME",SqlDbType.VarChar,100),//仓库名称
new SqlParameter("@AREACODE",SqlDbType.VarChar,50),//库位编码
new SqlParameter("@AREANAME",SqlDbType.VarChar,100),//库位名称
new SqlParameter("@GOODSCODE",SqlDbType.VarChar,50),//货物编号
new SqlParameter("@GOODSNAME",SqlDbType.VarChar,100),//货物名称/品名
new SqlParameter("@GOODSTYPE",SqlDbType.VarChar,50),//货物类型
new SqlParameter("@GOODSMODEL",SqlDbType.VarChar,100),//型号
new SqlParameter("@GOODSSTANDARD",SqlDbType.VarChar,100),//规格
new SqlParameter("@GOODSPACK",SqlDbType.Decimal),//件数
new SqlParameter("@CHARGEUNIT",SqlDbType.VarChar,10),//计费单位
new SqlParameter("@GOODSRKSL",SqlDbType.Decimal),//入库量
new SqlParameter("@GOODSSTOCK",SqlDbType.Decimal) ,//库存量
new SqlParameter("@ISLOCK",SqlDbType.Bit),//是否锁定
new SqlParameter("@LOCKUSER",SqlDbType.VarChar,36),//锁定操作人
new SqlParameter("@ISDELETE",SqlDbType.Bit),//是否废除
new SqlParameter("@DELETEUSER",SqlDbType.VarChar,36),//废除操作人
new SqlParameter("@CREATEUSER",SqlDbType.VarChar,36),//创建人
new SqlParameter("@MODIFIEDUSER",SqlDbType.VarChar,36),//最后一次更新操作人
new SqlParameter("@REMARK",SqlDbType.VarChar,1024),//备注
new SqlParameter("@FREESTORAGEPERIOD",SqlDbType.Int),//
new SqlParameter("@GOODSPACKSTOCK",SqlDbType.Decimal),//
new SqlParameter("@GOODSKGS",SqlDbType.Decimal),//重量
new SqlParameter("@CLIENTCODEOLD",SqlDbType.VarChar,20),//原客户编码
new SqlParameter("@CLIENTNAMEOLD",SqlDbType.VarChar,20),//原客户名称
new SqlParameter("@KINDPKGS",SqlDbType.VarChar,20),//
new SqlParameter("@ARFEE",SqlDbType.Decimal),//
new SqlParameter("@APFEE",SqlDbType.Decimal)
};
parms[0].Value = WmsInEntity.GID;// 惟一编号
parms[1].Value = WmsInEntity.ASSOCIATEDNO;// 关联号
parms[2].Value = WmsInEntity.BLNO;// 提单号
parms[3].Value = WmsInEntity.CONTRACTNO;// 合同号
parms[4].Value = WmsInEntity.CNTRNO;// 箱号
parms[5].Value = WmsInEntity.SEALNO;// 封号
parms[6].Value = WmsInEntity.BSNO;// 仓单明细号
parms[7].Value = WmsInEntity.CLIENTCODE;// 客户编码
parms[8].Value = WmsInEntity.CLIENTNAME;// 客户名称
parms[9].Value = WmsInEntity.STORAGECODE;// 仓库编码
parms[10].Value = WmsInEntity.STORAGENAME;// 仓库名称
parms[11].Value = WmsInEntity.AREACODE;// 库位编码
parms[12].Value = WmsInEntity.AREANAME;// 库位名称
parms[13].Value = WmsInEntity.GOODSCODE;// 货物编号
parms[14].Value = WmsInEntity.GOODSNAME;// 货物名称
parms[15].Value = WmsInEntity.GOODSTYPE;// 货物类型
parms[16].Value = WmsInEntity.GOODSMODEL;// 型号
parms[17].Value = WmsInEntity.GOODSSTANDARD;// 规格
parms[18].Value = WmsInEntity.GOODSPACK;// 件数
parms[19].Value = WmsInEntity.CHARGEUNIT;// 计费单位
parms[20].Value = WmsInEntity.GOODSRKSL;// 入库量
parms[21].Value = WmsInEntity.GOODSSTOCK;// 库存量
parms[22].Value = WmsInEntity.ISLOCK;// 是否锁定
parms[23].Value = WmsInEntity.LOCKUSER;// 锁定操作人
parms[24].Value = WmsInEntity.ISDELETE;// 是否废除
parms[25].Value = WmsInEntity.DELETEUSER;// 废除操作人
parms[26].Value = WmsInEntity.CREATEUSER;// 创建人
parms[27].Value = WmsInEntity.MODIFIEDUSER;// 最后一次更新操作人
parms[28].Value = WmsInEntity.REMARK;// 备注
parms[29].Value = WmsInEntity.FREESTORAGEPERIOD;//
parms[30].Value = WmsInEntity.GOODSPACKSTOCK;//
parms[31].Value = WmsInEntity.GOODSKGS;// 重量
parms[32].Value = WmsInEntity.CLIENTCODEOLD;// 客户编码
parms[33].Value = WmsInEntity.CLIENTNAMEOLD;// 客户名称
parms[34].Value = WmsInEntity.KINDPKGS;//
parms[35].Value = WmsInEntity.ARFEE;//
parms[36].Value = WmsInEntity.APFEE;//
//
lsSql = "insert into wms_in(GID,ASSOCIATEDNO,BLNO,CONTRACTNO,CNTRNO,SEALNO,BSNO,CLIENTCODE,CLIENTNAME,{0}STORAGECODE,STORAGENAME,AREACODE,AREANAME,GOODSCODE,GOODSNAME,GOODSTYPE,GOODSMODEL,GOODSSTANDARD,GOODSPACK,CHARGEUNIT,GOODSRKSL,GOODSSTOCK,ISLOCK,LOCKUSER,ISDELETE,DELETEUSER,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,REMARK,FREESTORAGEPERIOD,GOODSPACKSTOCK,GOODSKGS,CLIENTCODEOLD,CLIENTNAMEOLD,KINDPKGS,ARFEE,APFEE,LOCKTIME) "
+ " values(@GID,@ASSOCIATEDNO,@BLNO,@CONTRACTNO,@CNTRNO,@SEALNO,@BSNO,@CLIENTCODE,@CLIENTNAME,{1}@STORAGECODE,@STORAGENAME,@AREACODE,@AREANAME,@GOODSCODE,@GOODSNAME,@GOODSTYPE,@GOODSMODEL,@GOODSSTANDARD,@GOODSPACK,@CHARGEUNIT,@GOODSRKSL,@GOODSSTOCK,@ISLOCK,@LOCKUSER,@ISDELETE,@DELETEUSER,@CREATEUSER,getdate(),@MODIFIEDUSER,getdate(),@REMARK,@FREESTORAGEPERIOD,@GOODSPACKSTOCK,@GOODSKGS,@CLIENTCODEOLD,@CLIENTNAMEOLD,@KINDPKGS,@ARFEE,@APFEE,getdate())";
//
string strDODATE = model.DODATE.ToString().IndexOf("0001") > -1 ? "" : "'" + model.DODATE.ToString() + "',";
string strDODATE_name = strDODATE.Equals("") ? "" : "DODATE,";
lsSql = String.Format(lsSql, strDODATE_name, strDODATE);
//
iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, lsSql, parms);
if (iState != 1)
{
sqlTran.Rollback();
result = -9;
Clearh();
return result;
}
}
#endregion
//
#region 依据原货主承担的天数插入货权转移的费率设置wms_rate
feedays = WmsOutDetailDA.GetDaysCount("day", model.DODATE.ToString(), this.txt_oldcustFeeDate.Value.Trim());//WmsOutEntity.DODATE.ToString());
WmsRateEntity rateentity = new WmsRateEntity();
rateentity.GID = Guid.NewGuid().ToString();
rateentity.BSNO = WmsEntity.GID.ToString();
rateentity.FEEGRADE = 1;
rateentity.FEESCALE = feedays;
rateentity.FEEPRICE = 0;
rateentity.FEEUNIT = "吨天";
rateentity.CREATEUSER = strShowName.Trim();
//rateentity.CREATETIME =DateTime.Parse( rr["CREATETIME"].ToString());
rateentity.MODIFIEDUSER = strShowName.Trim();
//rateentity.MODIFIEDTIME =DateTime.Parse( rr["MODIFIEDTIME"].ToString());
rateentity.REMARK = "货权转移";
rateentity.CUSTOMERNAME = this.h_outcustomer.Value.ToString().Trim();
//
Sqlstr = String.Format("insert into wms_rate("
+ "GID,BSNO,FEEGRADE,FEESCALE,FEEPRICE,FEEUNIT,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,REMARK,CUSTOMERNAME) "
+ " values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}',getdate(),'{8}',getdate(),'{10}','{11}')"
, rateentity.GID, rateentity.BSNO, rateentity.FEEGRADE, rateentity.FEESCALE, rateentity.FEEPRICE, rateentity.FEEUNIT, rateentity.CREATEUSER, rateentity.CREATETIME, rateentity.MODIFIEDUSER, rateentity.MODIFIEDTIME, rateentity.REMARK, rateentity.CUSTOMERNAME);
iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, Sqlstr.ToString(), null);
if (iState != 1)
{
sqlTran.Rollback();
result = -10;
Clearh();
return result;
}
/*
//依据bsno customernameold复制wms_rate.bsno customername
Sqlstr = String.Format("select GID,BSNO,FEEGRADE,FEESCALE,FEEPRICE,FEEUNIT,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,REMARK,CUSTOMERNAME FROM wms_rate where BSNO='{0}' and CUSTOMERNAME like '%{1}%' order by BSNO,FEEGRADE ", WmsOutEntity.GID, WmsOutEntity.CUSTOMERNAME);//WmsOutEntity.ASSOCIATEDNO,
DataSet newwmsrateds = SqlHelper.ExecuteQueryDataset(sqlTran, CommandType.Text, Sqlstr, null);
DataTable newwmsratetb = newwmsrateds.Tables[0];
foreach (DataRow rr in newwmsratetb.Rows)
{
WmsRateEntity rateentity = new WmsRateEntity();
rateentity.GID = Guid.NewGuid().ToString();
rateentity.BSNO = rr["BSNO"].ToString();
rateentity.FEEGRADE =int.Parse( rr["FEEGRADE"].ToString());
rateentity.FEESCALE =int.Parse( rr["FEESCALE"].ToString());
rateentity.FEEPRICE =decimal.Parse( rr["FEEPRICE"].ToString());
rateentity.FEEUNIT = rr["FEEUNIT"].ToString();
rateentity.CREATEUSER = rr["CREATEUSER"].ToString();
//rateentity.CREATETIME =DateTime.Parse( rr["CREATETIME"].ToString());
rateentity.MODIFIEDUSER = rr["MODIFIEDUSER"].ToString();
//rateentity.MODIFIEDTIME =DateTime.Parse( rr["MODIFIEDTIME"].ToString());
rateentity.REMARK = rr["REMARK"].ToString();
rateentity.CUSTOMERNAME = WmsInEntity.CLIENTNAME;
Sqlstr = String.Format("insert into wms_rate("
+ "GID,BSNO,FEEGRADE,FEESCALE,FEEPRICE,FEEUNIT,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,REMARK,CUSTOMERNAME) "
+ " values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}',getdate(),'{8}',getdate(),'{10}','{11}')"
, rateentity.GID, rateentity.BSNO, rateentity.FEEGRADE, rateentity.FEESCALE, rateentity.FEEPRICE, rateentity.FEEUNIT, rateentity.CREATEUSER, rateentity.CREATETIME, rateentity.MODIFIEDUSER, rateentity.MODIFIEDTIME, "货权转移", rateentity.CUSTOMERNAME);
iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, Sqlstr.ToString(), null);
if (iState != 1)
{
sqlTran.Rollback();
result = -10;
Clearh();
return result;
}
}
*/
#endregion
//
#endregion
//
this.h_newcust.Value = WmsInEntity.CLIENTNAME;
this.h_IsSetRate.Value = "1"; //货权转移,可以设置费率
result = 1;//状态为1表示删除成功
sqlTran.Commit();
Page.ClientScript.RegisterStartupScript(this.GetType(), "key1", "<script>reloadParent('" + WmsEntity.GID.ToString().Trim() + "','" + WmsEntity.ASSOCIATEDNO.ToString().Trim() + "');</script>");
}
catch (Exception execError)
{
result = -1;//有异常,插入失败
sqlTran.Rollback();
result = -2;//插入异常,事务已回滚成功
Clearh();
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return result;
}
#endregion
#region 盘亏处理 SetLosses
/// <summary>
/// 盘亏处理
/// </summary>
private int SetLosses()
{
int iState = 0;
int result = 0;
string Sqlstr = "";
double totaloutfee = 0;//出库单的仓储费
double sumfee = 0;
string newGID = "";
string bsno = "";
//出库单信息
WmsOutDA WmsOutDA = new WmsOutDA();
WmsOutEntity WmsOutEntity = new WmsOutEntity();
if (!WoJSON.Trim().Equals(""))
{ //将应收费用信息从前台页面写入费用实体类feeEntities
WmsOutEntity = ResolveWoJSON(WoJSON.Trim(), WmsOutEntity);
WoContainer.Value = "";
}
//出库单明细信息
WmsOutDetailDA WmsOutDetailDA = new WmsOutDetailDA();
IList<WmsOutDetailEntity> WmsOutDetailEntitys = new List<WmsOutDetailEntity>();
if (!WoDetailJSON.Trim().Equals(""))
{ //将应收费用信息从前台页面写入费用实体类feeEntities
WmsOutDetailEntitys = ResolveWoDetailJSON(WoDetailJSON.Trim(), WmsOutDetailEntitys);
this.WoDetailContainer.Value = "";
}
//
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
#region 生成出库单并计算费用
#region 保存出库单wms_out 出库单明细wms_out_detail
//保存出库单wms_out
//
string ls = WmsOutEntity.TRUCKNO.ToString().Trim();
ls = ls.Replace("", " ");
ls = ls.Replace("", "\r\n");
string pkcl = WmsOutEntity.TRUCKNAME.ToString().Trim();
if (pkcl == "")
{
pkcl="盘亏处理";
}
//
Sqlstr = String.Format("insert into wms_out(GID,BSNO,CUSTOMERNAME,DODATE,STORAGENAME,GOODSNAME,GOODSMODEL,GOODSPFSL,REMARK,CREATEUSER,CREATETIME,TRUCKNO,ASSOCIATEDNO,GOODSPACKPFSL,INSPECTIONNO,CUSTOMNO,CLIENTNAMEOLD,OLDCUSTFEEDATE,TRUCKNAME)"
+ " values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}',getdate(),'{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}' )"
, WmsOutEntity.GID, WmsOutEntity.BSNO, WmsOutEntity.CUSTOMERNAME, WmsOutEntity.DODATE, WmsOutEntity.STORAGENAME, WmsOutEntity.GOODSNAME, WmsOutEntity.GOODSMODEL, WmsOutEntity.GOODSPFSL, "盘亏处理", strUserID, ls, WmsOutEntity.ASSOCIATEDNO, WmsOutEntity.GOODSPACKPFSL, WmsOutEntity.INSPECTIONNO, WmsOutEntity.CUSTOMNO, WmsOutEntity.CLIENTNAMEOLD, WmsOutEntity.DODATE, pkcl);
iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, Sqlstr, null);
if (iState != 1)
{
sqlTran.Rollback();
result = -1;
Clearh();
return result;
}
//保存出库单明细wms_out_detail
foreach (WmsOutDetailEntity WmsOutDetailEntity in WmsOutDetailEntitys)
{
WmsOutDetailEntity.OUTBSNO = WmsOutEntity.BSNO;
WmsOutDetailEntity.GOODSOUTFEE = decimal.Parse(Round(sumfee, 2, "").ToString());
WmsOutDetailEntity.GOODSOUTFEEAP = 0;
//保存wms_out_detail
newGID = Guid.NewGuid().ToString();
WmsOutDetailEntity.GID = newGID;
WmsOutDetailEntity.DODATE = WmsOutEntity.DODATE;
//
//bsno = getCodeRuleWmsOutDetail("出库明细单号", "BSNO");
#region 提取规则编号 getCodeRuleWmsOutDetail
// <summary>
// 提取规则编号
// </summary>
// <param name="strRULENAME">规则项目名称</param>
// <param name="strfield">需要加规则的字段</param>
// <returns></returns>
//protected String getCodeRuleWmsOutDetail(string strRULENAME, string strfield)
//{
//调用编码规则
string strRULEYEAR = "";
string strRULECONTENT = "";
string strCODENAME = "";
string strDEPTNO = "";
string strRULENOLENGTH = "";
int iRULENOLENGTH = 0;
int inum = 0;
string strCONTENT = "";
DataSet ds = T_ALL_DA.GetAllSQL("select *,getdate() DODATE from code_rule where RULENAME='出库明细单号' and RULETYPE=3");
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0]["ISSTARTUSING"].ToString().Trim().Equals("True"))
{
getCodeRuleEnabled("出库明细单号", "BSNO");
//
if (ds.Tables[0].Rows[0]["RULEDATE"].ToString().Trim().Equals("业务日期"))
{
if (ds.Tables[0].Rows[0]["DODATE"].ToString().Trim() == "")
{
//return "";
bsno = "";
}
DateTime dETD = System.Convert.ToDateTime(ds.Tables[0].Rows[0]["DODATE"].ToString().Trim());
if (ds.Tables[0].Rows[0]["ISCLEAREDINEARLY"].ToString().Trim().Equals("True"))
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = dETD.ToString("yyyy") + dETD.ToString("MM");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = dETD.ToString("yy") + dETD.ToString("MM");
}
}
else
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = dETD.ToString("yyyy");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = dETD.ToString("yy");
}
}
}
else if (ds.Tables[0].Rows[0]["RULEDATE"].ToString().Trim().Equals("自然月份"))
{
DateTime fwqdate = System.Convert.ToDateTime(T_ALL_DA.GetStrSQL("fwqdate", "select fwqdate=getdate()"));
if (ds.Tables[0].Rows[0]["ISCLEAREDINEARLY"].ToString().Trim().Equals("True"))
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = fwqdate.ToString("yyyy") + fwqdate.ToString("MM");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = fwqdate.ToString("yy") + fwqdate.ToString("MM");
}
}
else
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = fwqdate.ToString("yyyy");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = fwqdate.ToString("yy");
}
}
}
//
if (ds.Tables[0].Rows[0]["ISCOMPANY"].ToString().Trim().Equals("True"))
{
strCODENAME = T_ALL_DA.GetStrSQL("CODENAME", "select CODENAME from [company] where GID=(select top 1 COMPANYID from user_company where USERID='" + strUserID + "')");
}
if (ds.Tables[0].Rows[0]["ISDEPT"].ToString().Trim().Equals("True"))
{
strDEPTNO = T_ALL_DA.GetStrSQL("DEPTNO", "select DEPTNO from [sys_dept] where LINKID=(select top 1 COMPANYID from user_company where USERID='" + strUserID + "')");
}
strRULECONTENT = ds.Tables[0].Rows[0]["RULECONTENT"].ToString().Trim();
strRULECONTENT = strRULECONTENT.Replace("《COMPANY》", strCODENAME);
strRULECONTENT = strRULECONTENT.Replace("《DEPT》", strDEPTNO);
//
if (ds.Tables[0].Rows[0]["RULENOLENGTH"].ToString().Trim() == "")
{
iRULENOLENGTH = 0;
}
else
{
iRULENOLENGTH = int.Parse(ds.Tables[0].Rows[0]["RULENOLENGTH"].ToString().Trim());
}
strCONTENT = strRULECONTENT + strRULEYEAR;
//获取分公司的票号头字符
string tempBANKSHEAD = T_ALL_DA.GetStrSQL("BANKSHEAD", "SELECT TOP 1 BANKSHEAD FROM company WHERE GID='" + strCompanyID.Trim() + "'");
strCONTENT = tempBANKSHEAD + strCONTENT;
//
string strSQL = "select top 1 BSNO from [wms_out_detail] where BSNO like '" + strCONTENT.Trim() + "%' order by BSNO DESC";
DataSet ds1 = SqlHelper.ExecuteQueryDataset(sqlTran, CommandType.Text, strSQL, null);
if (ds1 != null)
{
if (ds1.Tables[0].Rows.Count > 0)
{
strRULENOLENGTH = ds1.Tables[0].Rows[0]["BSNO"].ToString().Trim();
}
}
if (strRULENOLENGTH == "")
{
strRULENOLENGTH = "1";
}
else
{
strRULENOLENGTH = strRULENOLENGTH.Replace(strCONTENT.Trim(), "");
inum = int.Parse(strRULENOLENGTH.Trim());
inum = inum + 1;
strRULENOLENGTH = inum.ToString();
}
int j = iRULENOLENGTH - strRULENOLENGTH.Length;
for (int i = 1; i <= j; i++)
{
strRULENOLENGTH = "0" + strRULENOLENGTH;
}
//
strCONTENT = strCONTENT + strRULENOLENGTH;
bsno = strCONTENT;
//return strCONTENT;
}
}
}
// return "";
//}
#endregion
WmsOutDetailEntity.BSNO = bsno;
//
WmsOutDetailEntity.OUTBSNO = this.h_outbsno.Value;
//
ls = WmsOutDetailEntity.TRUCKNO.ToString().Trim();
ls = ls.Replace("", " ");
ls = ls.Replace("", "\r\n");
//
Sqlstr = String.Format("insert into wms_out_detail(GID,INBSNO,OUTBSNO,BSNO,CUSTOMERNAME,DODATE,STORAGENAME,GOODSNAME,GOODSMODEL,GOODSPFSL,GOODSOUTFEE,CREATEUSER,CREATETIME,REMARK,TRUCKNO,ASSOCIATEDNO,GOODSPACKPFSL,GOODSOUTFEEAP,ARFEE,APFEE,CLIENTNAMEOLD) "
+ " values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}',getdate(),'{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}' )"
, WmsOutDetailEntity.GID, WmsOutDetailEntity.INBSNO, WmsOutDetailEntity.OUTBSNO, WmsOutDetailEntity.BSNO, WmsOutDetailEntity.CUSTOMERNAME, WmsOutEntity.DODATE, WmsOutDetailEntity.STORAGENAME, WmsOutDetailEntity.GOODSNAME, WmsOutDetailEntity.GOODSMODEL, WmsOutDetailEntity.GOODSPFSL, WmsOutDetailEntity.GOODSOUTFEE, strUserID, "盘亏处理", ls, WmsOutDetailEntity.ASSOCIATEDNO, WmsOutDetailEntity.GOODSPACKPFSL, WmsOutDetailEntity.GOODSOUTFEEAP, WmsOutDetailEntity.ARFEE, WmsOutDetailEntity.APFEE, WmsOutDetailEntity.CLIENTNAMEOLD);
iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, Sqlstr, null);
if (iState != 1)
{
sqlTran.Rollback();
result = -5;
Clearh();
return result;
}
//修改入库单wms_in
Sqlstr = String.Format("update wms set GOODSSTOCK=GOODSSTOCK-{0},GOODSPACKSTOCK=GOODSPACKSTOCK-{1} where ISDELETE=0 and GID='{2}' ", WmsOutDetailEntity.GOODSPFSL, WmsOutDetailEntity.GOODSPACKPFSL, WmsOutDetailEntity.INBSNO);
iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, Sqlstr, null);
if (iState != 1)
{
sqlTran.Rollback();
result = -6;
Clearh();
return result;
}
}// end 保存出库明细wms_out_detail
//修改wms_out的出库量、出库件数、应收应付装卸费
string lsSQL = "update wms_out set "
+ "GOODSPFSL=(select isnull(sum(GOODSPFSL),0) from wms_out_detail where OUTBSNO=wms_out.BSNO)"
+ ",GOODSPACKPFSL=(select isnull(sum(GOODSPACKPFSL),0) from wms_out_detail where OUTBSNO=wms_out.BSNO)"
+ ",ARFEE=(select isnull(sum(ARFEE),0) from wms_out_detail where OUTBSNO=wms_out.BSNO)"
+ ",APFEE=(select isnull(sum(APFEE),0) from wms_out_detail where OUTBSNO=wms_out.BSNO)"
+ " where ISLOCK=0 and GID='" + WmsOutEntity.GID.ToString().Trim() + "'";
iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, lsSQL, null);
if (iState != 1)
{
sqlTran.Rollback();
result = -7;
Clearh();
return result;
}
//修改wms_out的仓储费wmsOutEntity.GOODSOUTFEE
h_outfee.Value = totaloutfee.ToString();
WmsOutEntity.GOODSOUTFEE =decimal.Parse( Round(totaloutfee,2,"").ToString());
WmsOutEntity.GOODSOUTFEEAP = 0;
Sqlstr = String.Format("update wms_out set GOODSOUTFEE={0},GOODSOUTFEEAP={2} where GID='{1}'", WmsOutEntity.GOODSOUTFEE, WmsOutEntity.GID, WmsOutEntity.GOODSOUTFEEAP);
iState = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, Sqlstr, null);
if (iState != 1)
{
sqlTran.Rollback();
result = -7;
Clearh();
return result;
}
#endregion
//页面赋值
this.h_wmsoutbsno.Value = WmsOutEntity.BSNO.ToString();
this.h_goodsmodel.Value = WmsOutEntity.GOODSMODEL.ToString();
this.h_goodspfsl.Value = WmsOutEntity.GOODSPFSL.ToString();
this.h_remark.Value = WmsOutEntity.REMARK.ToString();
txt_outbsno.Value = h_outbsno.Value;
txt_outdate.Value = h_outdate.Value;
string strcustomer = h_customer.Value;
string goods = h_goods.Value;
txt_goodsmodel.Value = h_goodsmodel.Value;
#endregion
this.h_newcust.Value = "";
this.h_IsSetRate.Value = "0";//正常出库,不需要设置费率
result = 1;//状态为1表示删除成功
sqlTran.Commit();
Page.ClientScript.RegisterStartupScript(this.GetType(), "key1", "<script>alert('盘亏处理成功!');window.parent.opener.location.href=window.parent.opener.location.href;</script>");
}
catch (Exception execError)
{
result = -1;//有异常,插入失败
sqlTran.Rollback();
result = -2;//插入异常,事务已回滚成功
Clearh();
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return result;
}
#endregion
#region 生成插入语句参数
/// <summary>
/// 生成插入语句参数
/// </summary>
/// <returns>返回SqlParameter数组</returns>
private SqlParameter[] GetInsertParms()
{
SqlParameter[] parms = new SqlParameter[]{
new SqlParameter("@GID",SqlDbType.VarChar,100),//惟一编号
new SqlParameter("@ASSOCIATEDNO",SqlDbType.VarChar,100),//关联号
new SqlParameter("@BLNO",SqlDbType.VarChar,30),//提单号
new SqlParameter("@CONTRACTNO",SqlDbType.VarChar,100),//合同号
new SqlParameter("@CNTRNO",SqlDbType.VarChar,30),//箱号
new SqlParameter("@SEALNO",SqlDbType.VarChar,12),//封号
new SqlParameter("@BSNO",SqlDbType.VarChar,100),//仓单明细号
new SqlParameter("@CLIENTCODE",SqlDbType.VarChar,20),//客户编码
new SqlParameter("@CLIENTNAME",SqlDbType.VarChar,20),//客户名称
new SqlParameter("@STORAGECODE",SqlDbType.VarChar,50),//仓库编码
new SqlParameter("@STORAGENAME",SqlDbType.VarChar,100),//仓库名称
new SqlParameter("@AREACODE",SqlDbType.VarChar,50),//库位编码
new SqlParameter("@AREANAME",SqlDbType.VarChar,100),//库位名称
new SqlParameter("@GOODSCODE",SqlDbType.VarChar,50),//货物编号
new SqlParameter("@GOODSNAME",SqlDbType.VarChar,100),//货物名称/品名
new SqlParameter("@GOODSTYPE",SqlDbType.VarChar,50),//货物类型
new SqlParameter("@GOODSMODEL",SqlDbType.VarChar,100),//型号
new SqlParameter("@GOODSSTANDARD",SqlDbType.VarChar,100),//规格
new SqlParameter("@GOODSPACK",SqlDbType.Int),//件数
new SqlParameter("@CHARGEUNIT",SqlDbType.VarChar,10),//计费单位
//new SqlParameter("@CHARGEPRICE",SqlDbType.Decimal),//计费单价
new SqlParameter("@GOODSRKSL",SqlDbType.Decimal),//入库量
new SqlParameter("@GOODSSTOCK",SqlDbType.Decimal) ,//库存量
new SqlParameter("@ISLOCK",SqlDbType.Bit),//是否锁定
new SqlParameter("@LOCKUSER",SqlDbType.VarChar,36),//锁定操作人
new SqlParameter("@ISDELETE",SqlDbType.Bit),//是否废除
new SqlParameter("@DELETEUSER",SqlDbType.VarChar,36),//废除操作人
new SqlParameter("@CREATEUSER",SqlDbType.VarChar,36),//创建人
new SqlParameter("@MODIFIEDUSER",SqlDbType.VarChar,36),//最后一次更新操作人
new SqlParameter("@REMARK",SqlDbType.VarChar,1024),//备注
new SqlParameter("@FREESTORAGEPERIOD",SqlDbType.Int),//件数
new SqlParameter("@CLIENTNAMEOLD",SqlDbType.VarChar,20),//备注
//new SqlParameter("@GOODSKGS",SqlDbType.Decimal)//重量
//new SqlParameter("@DODATE",SqlDbType.Datetime),//操作时间
//new SqlParameter("@LOCKTIME",SqlDbType.Datetime),//锁定时间
//new SqlParameter("@DELETETIME",SqlDbType.Datetime),//废除时间
//new SqlParameter("@CREATETIME",SqlDbType.Datetime),//创建时间
//new SqlParameter("@MODIFIEDTIME",SqlDbType.Datetime),//最后一次更新操作时间
};
return parms;
}
#endregion
/// <summary>
/// 将页面post获取的出库保存或更新“出库信息表和出库明细表”wms_out,wms_out_detail,并返回操作结果
/// </summary>
private void SaveWoAction()
{
WmsOutEntity WmsOutEntity = new WmsOutEntity();
//IList<WmsOutDetailEntity> WmsOutDetailEntitys = new List<WmsOutDetailEntity>();
if (!WoJSON.Trim().Equals(""))
{ //将应收费用信息从前台页面写入费用实体类feeEntities
WmsOutEntity = ResolveWoJSON(WoJSON.Trim(), WmsOutEntity);
WoContainer.Value = "";
}
WmsOutDA WmsOutDA = new WmsOutDA();
bool State = false;
if (WmsOutEntity != null)
{
State = WmsOutDA.Add(WmsOutEntity, "");
if (State)
{
this.h_wmsoutbsno.Value = WmsOutEntity.BSNO.ToString();
this.h_goodsmodel.Value = WmsOutEntity.GOODSMODEL.ToString();
this.h_goodspfsl.Value = WmsOutEntity.GOODSPFSL.ToString();
this.h_remark.Value = WmsOutEntity.REMARK.ToString();
SaveWoDetailAction(WmsOutEntity);//保存出库明细
Page.ClientScript.RegisterStartupScript(this.GetType(), "key2", "<script>alert('信息保存成功');window.parent.opener.location.href=window.parent.opener.location.href;</script>");
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key3", "<script>alert('信息保存失败');</script>");
}
}
h_post.Value = "";//请求状态清空
}
#endregion
#region 将页面post获取的费用信息读入到费用实体类ch_fee中
/// <summary>
/// 将页面post获取的费用信息读入到费用实体类ch_fee中
/// </summary>
/// <param name="tempJSON"></param>
/// <param name="tempFeeEntities"></param>
/// <returns>将页面post获取的费用信息读入到费用实体类ch_fee中</returns>
private WmsOutEntity ResolveWoJSON(string tempJSON, WmsOutEntity tempWoEntity)
{
string OutGid = "";
string OutBsno = "";
DateTime OutDate = new DateTime();
string strFilter = "";
WmsOutEntity WmsOutEntity = new WmsOutEntity();
if (tempJSON.IndexOf("[") >= 0 && tempJSON.IndexOf("]") > 0)
{
strFilter = tempJSON.Substring(tempJSON.IndexOf("[") + 1, tempJSON.IndexOf("]") - tempJSON.IndexOf("[") - 1);
string[] strFees = strFilter.Split(new string[] { "},{" }, System.StringSplitOptions.RemoveEmptyEntries);
if (strFees.Length > 0)
{
for (int i = 0; i < strFees.Length; i++)
{
strFees[i] = strFees[i].ToString().Replace("{", "");
strFees[i] = strFees[i].ToString().Replace("}", "");
string[] strCell = strFees[i].Split(new char[] { ',' });
if (strCell.Length > 0)
{
for (int j = 0; j < strCell.Length; j++)
{
string[] strArg = strCell[j].Split(new char[] { ':' });
switch (strArg[0].Replace("\"", ""))
{
case "cust":
WmsOutEntity.CUSTOMERNAME = UnicodeToGB(strArg[1].ToString().Replace("\"", ""));
h_customer.Value = WmsOutEntity.CUSTOMERNAME;
break;
case "outcus":
WmsOutEntity.CLIENTNAMEOLD = UnicodeToGB(strArg[1].ToString().Replace("\"", ""));
h_outcustomer.Value = WmsOutEntity.CLIENTNAMEOLD;
break;
//case "cusold":
// cusold = UnicodeToGB(strArg[1].ToString().Replace("\"", ""));
// break;
case "outdate":
WmsOutEntity.DODATE =DateTime.Parse( strArg[1].ToString().Replace("\"", ""));
OutDate = WmsOutEntity.DODATE;
h_outdate.Value = WmsOutEntity.DODATE.ToString();
break;
case "goodsname":
WmsOutEntity.GOODSNAME = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
h_goods.Value = WmsOutEntity.GOODSNAME;
break;
case "goodsmodel":
WmsOutEntity.GOODSMODEL = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
this.h_goodsmodel.Value = WmsOutEntity.GOODSMODEL;
txt_goodsmodel.Value = h_goodsmodel.Value;
break;
case "outnum":
double tmpoutnum = double.Parse(strArg[1].ToString().Replace("\"", "").Trim());
WmsOutEntity.GOODSPFSL =decimal.Parse( Round(tmpoutnum, 4).ToString());
this.h_goodspfsl.Value = WmsOutEntity.GOODSPFSL.ToString();
this.txt_goodspfsl.Value = this.h_goodspfsl.Value;
break;
case "outpacknum":
decimal outpacknum= decimal.Parse(strArg[1].ToString().Replace("\"", ""));
WmsOutEntity.GOODSPACKPFSL =Convert.ToInt16( Math.Round(outpacknum,0));
this.h_packnum.Value = WmsOutEntity.GOODSPACKPFSL.ToString();
this.txt_packnum.Value = this.h_packnum.Value;
break;
case "remark":
WmsOutEntity.REMARK = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
this.h_remark.Value = WmsOutEntity.REMARK;
this.txt_remark.Value = WmsOutEntity.REMARK;
break;
case "inspectionno":
WmsOutEntity.INSPECTIONNO = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
this.txt_inspectionno.Value = WmsOutEntity.INSPECTIONNO;
break;
case "customno":
WmsOutEntity.CUSTOMNO = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
this.txt_customno.Value = WmsOutEntity.CUSTOMNO;
break;
case "truckno":
WmsOutEntity.TRUCKNO = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
this.h_truckno.Value = WmsOutEntity.TRUCKNO;
break;
case "storage":
WmsOutEntity.STORAGENAME = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
this.h_storage.Value = WmsOutEntity.STORAGENAME;
break;
case "truckname":
WmsOutEntity.TRUCKNAME = UnicodeToGB(strArg[1].ToString().Replace("\"", ""));
hd_comboTRUCKNAME.Value = WmsOutEntity.TRUCKNAME;
if (hd_comboTRUCKNAME.Value.Trim() == "" && this.h_storage.Value.Trim() != "")
{
WmsOutEntity.TRUCKNAME = this.h_storage.Value.Trim();
hd_comboTRUCKNAME.Value = this.h_storage.Value.Trim();
}
break;
case "opseaibsno":
WmsOutEntity.ASSOCIATEDNO = strArg[1].ToString().Replace("\"", "").Trim();
this.h_opseaibsno.Value = WmsOutEntity.ASSOCIATEDNO;
this.h_bsno.Value = WmsOutEntity.ASSOCIATEDNO;
break;
case "isJsFee":
isJsFee =bool.Parse( strArg[1].ToString().Replace("\"", ""));
break;
case "oldcustfeedate":
this.txt_oldcustFeeDate.Value = strArg[1].ToString().Replace("\"", "");
WmsOutEntity.OLDCUSTFEEDATE = this.txt_oldcustFeeDate.Value.Trim() == "0001-01-01 00:00:00" ? DateTime.Parse("") : DateTime.Parse(this.txt_oldcustFeeDate.Value.Trim());
break;
default:
break;
}
}
if (this.h_storage.Value.Equals(null) || this.h_storage.Value.Trim().Equals(""))
{
WmsOutEntity.STORAGENAME = "";
}
else
{
WmsOutEntity.STORAGENAME = this.h_storage.Value.Trim();
}
WmsOutEntity.CREATEUSER = strShowName;
if ((this.txt_outbsno.Value.Trim().Equals("") || this.txt_outbsno.Value.Equals(null)) || this.h_addmode.Value.Equals("1"))
{
OutGid= getBSNO();
OutBsno = getCodeRuleWmsOut("出库单号", "BSNO");
this.h_outgid.Value = OutGid;
this.h_outbsno.Value = OutBsno;
this.txt_outbsno.Value = OutBsno;
}
else
{
OutGid = this.h_outgid.Value.ToString();
OutBsno = this.txt_outbsno.Value.ToString().Trim();
this.h_outbsno.Value = OutBsno;
}
WmsOutEntity.GID = OutGid;
WmsOutEntity.BSNO = OutBsno;
//WmsOutEntity.STORAGENAME = h_storage.Value;
//WmsOutEntity.TRUCKNO = h_truckno.Value;
}
}
}
}
return WmsOutEntity;
}
#endregion
#region 将页面post获取的出库保存或更新“出库明细表”wms_out_detail,并返回操作结果
/// <summary>
/// 将页面post获取的出库保存或更新“出库明细表”wms_out_detail,并返回操作结果
/// </summary>
private bool SaveWoDetailAction(WmsOutEntity wmsOutEntity)
{
IList<WmsOutDetailEntity> WmsOutDetailEntitys = new List<WmsOutDetailEntity>();
if (!WoDetailJSON.Trim().Equals(""))
{ //将应收费用信息从前台页面写入费用实体类feeEntities
WmsOutDetailEntitys = ResolveWoDetailJSON(WoDetailJSON.Trim(), WmsOutDetailEntitys);
this.WoDetailContainer.Value = "";
}
decimal totaloutfee = 0;//出库单的仓储费
bool State = false;
int count = 0;
int success = 0;
int nonum = 0;
int prescale = 0;
int nowscale = 0;
int nowgrade = 0;
decimal price = 0;
decimal gradefee = 0;
decimal sumfee = 0;
string newGID = "";
string bsno = "";
var strSql = "";
WmsOutDetailDA WmsOutDetailDA = new WmsOutDetailDA();
if (isJsFee==true)
{
if (WmsOutDetailEntitys != null)
{
foreach (WmsOutDetailEntity WmsOutDetailEntity in WmsOutDetailEntitys)
{
decimal outnums = WmsOutDetailEntity.GOODSPFSL;
int feedays = WmsOutDetailDA.GetDaysCount("day", WmsOutDetailEntity.DODATE.ToString(), wmsOutEntity.DODATE.ToString());
if (feedays > 0)
{
WmsOutDetailEntity.OUTBSNO = wmsOutEntity.BSNO;
strSql = String.Format("SELECT FEEGRADE,FEESCALE,FEEPRICE,FEEUNIT "
+ " FROM wms_rate "
+ " where BSNO='{0}' "
+ " order by BSNO,FEEGRADE ",
WmsOutDetailEntity.INBSNO);//wmsOutEntity.ASSOCIATEDNO);
DataSet dsrate = WmsOutDetailDA.GetRateListByCondition(strSql);
DataTable dtrate = new DataTable();
if (dsrate != null)
{
dtrate = dsrate.Tables[0];
if (dtrate.Rows.Count > 0)
{
prescale = 0;
nowscale = 0;
nowgrade = 0;
price = 0;
gradefee = 0;
sumfee = 0;
foreach (DataRow drow in dtrate.Rows)
{
nowgrade = int.Parse(drow["FEEGRADE"].ToString());
nowscale = int.Parse(drow["FEESCALE"].ToString());
price = decimal.Parse(drow["FEEPRICE"].ToString());
if (nowgrade.Equals(1))
{
if (feedays > nowscale)
{
gradefee = outnums * price * nowscale;
sumfee += gradefee;
prescale = nowscale;
}
else
{
gradefee = outnums * price * (feedays - prescale);
sumfee += gradefee;
prescale = nowscale;
break;
}
}
else if (nowgrade > 1)
{
if (feedays > nowscale)
{
gradefee = outnums * price * (nowscale - prescale);
sumfee += gradefee;
prescale = nowscale;
}
else
{
gradefee = outnums * price * (feedays - prescale);
sumfee += gradefee;
prescale = nowscale;
break;
}
}
}
if (feedays > nowscale)
{
gradefee = outnums * price * (feedays - nowscale);
sumfee += gradefee;
}
totaloutfee += sumfee;
WmsOutDetailEntity.DODATE = wmsOutEntity.DODATE;
WmsOutDetailEntity.GOODSOUTFEE = sumfee;
WmsOutDetailEntity.GOODSOUTFEEAP = 0;
}
else
{//仓储费率没有设定
}
}
}
else
{//计费天数错误
}
//保存wms_out_detail
newGID = Guid.NewGuid().ToString();
bsno = getCodeRuleWmsOutDetail("出库明细单号", "BSNO");
WmsOutDetailEntity.GID = newGID;
WmsOutDetailEntity.BSNO = bsno;
WmsOutDetailEntity.OUTBSNO = this.h_outbsno.Value;
State = WmsOutDetailDA.Add(WmsOutDetailEntity, "");
count++;
if (State)
{
success++;
WmsInDA wmsinDA = new WmsInDA();
bool inState = wmsinDA.Update(WmsOutDetailEntity.GOODSPFSL,WmsOutDetailEntity.GOODSPACKPFSL, WmsOutDetailEntity.INBSNO);
}
else
{//保存失败
nonum++;
}
}
//修改wms_out的仓储费wmsOutEntity.GOODSOUTFEE
h_outfee.Value = totaloutfee.ToString();
wmsOutEntity.GOODSOUTFEE = totaloutfee;
wmsOutEntity.GOODSOUTFEEAP = 0;
WmsOutDA wmsoutDA = new WmsOutDA();
State = wmsoutDA.Update(wmsOutEntity, "");
//页面赋值
txt_outbsno.Value = h_outbsno.Value;
txt_outdate.Value = h_outdate.Value;
string strcustomer = h_customer.Value;
string goods = h_goods.Value;
txt_goodsmodel.Value = h_goodsmodel.Value;
txt_packnum.Value = wmsOutEntity.GOODSPACKPFSL.ToString();
h_packnum.Value = wmsOutEntity.GOODSPACKPFSL.ToString();
#region 将仓储费写入ch_fee
/*
//将仓储费和出库费写入ch_fee
FeeDA feeDA = new FeeDA();
IList<FeeEntity> feeEntities = new List<FeeEntity>();
FeeEntity feeEntity = new FeeEntity();
int iState = 0;
decimal deprice = 0;
deprice = wmsOutEntity.GOODSOUTFEE / wmsOutEntity.GOODSPFSL;
if (deprice != 0)
{
feeEntity.GID = Guid.NewGuid().ToString();
feeEntity.FeeType = 1;
feeEntity.BSNO = wmsOutEntity.ASSOCIATEDNO;
feeEntity.FeeName = "仓储费";
feeEntity.CustomerName = wmsOutEntity.CUSTOMERNAME;
feeEntity.Unit = "重量";
feeEntity.UnitPrice = deprice;
feeEntity.Quantity = wmsOutEntity.GOODSPFSL;
feeEntity.CommissionRate = 1;
feeEntity.Amount = wmsOutEntity.GOODSOUTFEE;
feeEntity.Currency = "RMB";
feeEntity.ExchangeRate = 1;
feeEntity.FeeFrt = "";
feeEntity.Remark = "";
feeEntity.IsAdvancePay = false;
feeEntity.EnterOperator = wmsOutEntity.CREATEUSER;
feeEntity.FeeStatus = 1;
feeEntity.WMSOUTBSNO = wmsOutEntity.BSNO;
feeEntities.Add(feeEntity);
iState = feeDA.DoFee(feeEntities, wmsOutEntity.BSNO, strUserID);
feeEntities.Remove(feeEntity);
feeEntity = new FeeEntity();
}
//出库费
WmsFeeCodeDA WmsFeeCodeDA = new WmsFeeCodeDA();
string strSql11 = String.Format("SELECT GID,FEETYPE,FEECODE,FEENAME,BSNO,CLIENT,UNIT,CURRENCY,UNITPRICE,EXCHANGERATE,SORT,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,REMARK FROM wms_feeCode "
+ " where BSNO='{0}' ",wmsOutEntity.ASSOCIATEDNO );
DataSet ds = WmsFeeCodeDA.GetRateListByCondition(strSql11);
DataTable dt = ds.Tables[0];
if (dt.Rows.Count > 0)
{
foreach (DataRow r in dt.Rows)
{
if (r["FEENAME"].ToString().Trim() == "出库费")
{
feeEntity.GID = Guid.NewGuid().ToString();
feeEntity.FeeType = 1;
feeEntity.BSNO = wmsOutEntity.ASSOCIATEDNO;
feeEntity.FeeName = "出库费";
feeEntity.CustomerName = wmsOutEntity.CUSTOMERNAME;
feeEntity.Unit = "重量";
feeEntity.UnitPrice = decimal.Parse(r["UNITPRICE"].ToString());
feeEntity.Quantity = wmsOutEntity.GOODSPFSL;
feeEntity.CommissionRate = 1;
feeEntity.Amount = wmsOutEntity.GOODSPFSL * decimal.Parse(r["UNITPRICE"].ToString());
feeEntity.Currency = "RMB";
feeEntity.ExchangeRate = 1;
feeEntity.FeeFrt = "";
feeEntity.Remark = "";
feeEntity.IsAdvancePay = false;
feeEntity.EnterOperator = wmsOutEntity.CREATEUSER;
feeEntity.FeeStatus = 1;
feeEntity.WMSOUTBSNO = wmsOutEntity.BSNO;
feeEntities.Add(feeEntity);
//保存如ch_fee
iState = feeDA.DoFee(feeEntities, wmsOutEntity.BSNO, strUserID);
}
}
}
else
{//提示出库费用没有维护
}
*/
#endregion
}
}
//Page.ClientScript.RegisterStartupScript(this.GetType(), "key3", "<script>alert('出库单生成成功');</script>");
h_post.Value = "";//请求状态清空
return true;
}
#endregion
#region 将页面post获取的费用信息读入到费用实体类ch_fee中
/// <summary>
/// 将页面post获取的费用信息读入到费用实体类ch_fee中
/// </summary>
/// <param name="tempJSON"></param>
/// <param name="tempFeeEntities"></param>
/// <returns>将页面post获取的费用信息读入到费用实体类ch_fee中</returns>
private IList<WmsOutDetailEntity> ResolveWoDetailJSON(string tempJSON, IList<WmsOutDetailEntity> tempWoDetailEntities)
{
string strFilter = "";
if (tempJSON.IndexOf("[") >= 0 && tempJSON.IndexOf("]") > 0)
{
strFilter = tempJSON.Substring(tempJSON.IndexOf("[") + 1, tempJSON.IndexOf("]") - tempJSON.IndexOf("[") - 1);
string[] strFees = strFilter.Split(new string[] { "},{" }, System.StringSplitOptions.RemoveEmptyEntries);
if (strFees.Length > 0)
{
for (int i = 0; i < strFees.Length; i++)
{
strFees[i] = strFees[i].ToString().Replace("{", "");
strFees[i] = strFees[i].ToString().Replace("}", "");
string[] strCell = strFees[i].Split(new char[] { ',' });
if (strCell.Length > 0)
{
WmsOutDetailEntity WmsOutDetailEntity = new WmsOutDetailEntity();
for (int j = 0; j < strCell.Length; j++)
{
string[] strArg = strCell[j].Split(new char[] { ':' });
switch (strArg[0].Replace("\"", ""))
{
case "cust":
WmsOutDetailEntity.CUSTOMERNAME = UnicodeToGB(strArg[1].ToString().Replace("\"", ""));
break;
case "outcus":
WmsOutDetailEntity.CLIENTNAMEOLD = UnicodeToGB(strArg[1].ToString().Replace("\"", ""));
break;
case "inbsno":
WmsOutDetailEntity.INBSNO =strArg[1].ToString().Replace("\"", "");
break;
case "indate":
WmsOutDetailEntity.DODATE =DateTime.Parse(strArg[1].ToString().Replace("\"", ""));
break;
case "goodsname":
WmsOutDetailEntity.GOODSNAME = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "goodsmodel":
WmsOutDetailEntity.GOODSMODEL = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "truckno":
WmsOutDetailEntity.TRUCKNO = UnicodeToGB(strArg[1].ToString().Replace("\"", ""));
break;
case "storage":
WmsOutDetailEntity.STORAGENAME = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "opseaibsno":
WmsOutDetailEntity.ASSOCIATEDNO = strArg[1].ToString().Replace("\"", "").Trim();
break;
case "outnum":
double tmpoutnum = strArg[1].ToString().Replace("\"", "").ToString().Trim() == "" ? 0 : double.Parse(strArg[1].ToString().Replace("\"", "").Trim());
WmsOutDetailEntity.GOODSPFSL = decimal.Parse( Round(tmpoutnum, 4).ToString());
break;
case "outpacknum":
WmsOutDetailEntity.GOODSPACKPFSL = strArg[1].ToString().Replace("\"", "").ToString().Trim() == "" ? 0 : decimal.Parse(strArg[1].ToString().Replace("\"", "").ToString());
break;
case "remark":
WmsOutDetailEntity.REMARK = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "custparent":
WmsOutDetailEntity.CUSTOMERNAMEPARENT=strArg[1].ToString().Replace("\"", "").Trim();
//CustParent.Add(WmsOutDetailEntity.CUSTOMERNAMEPARENT);
break;
case "arfee":
WmsOutDetailEntity.ARFEE = strArg[1].ToString().Replace("\"", "").ToString().Trim() == "" ? 0 : decimal.Parse(strArg[1].ToString().Replace("\"", "").ToString());
break;
case "apfee":
WmsOutDetailEntity.APFEE = strArg[1].ToString().Replace("\"", "").ToString().Trim() == "" ? 0 : decimal.Parse(strArg[1].ToString().Replace("\"", "").ToString());
break;
default:
break;
}
}
if (!this.h_storage.Value.ToString().Equals("") && !this.h_storage.Value.Equals(null))
{
WmsOutDetailEntity.STORAGENAME = this.h_storage.Value.ToString();
}
else
{
WmsOutDetailEntity.STORAGENAME = " ";
}
WmsOutDetailEntity.CREATEUSER =strShowName;
tempWoDetailEntities.Add(WmsOutDetailEntity);
}
}
}
}
return tempWoDetailEntities;
}
#endregion
#region 将页面post获取的费用信息读入到费用实体类ch_fee中
/// <summary>
/// 将页面post获取的费用信息读入到费用实体类ch_fee中
/// </summary>
/// <param name="tempJSON"></param>
/// <param name="tempFeeEntities"></param>
/// <returns>将页面post获取的费用信息读入到费用实体类ch_fee中</returns>
private IList<FeeEntity> ResolveFeeJSON(string tempJSON, IList<FeeEntity> tempFeeEntities)
{
string strFilter = "";
if (tempJSON.IndexOf("[") >= 0 && tempJSON.IndexOf("]") > 0)
{
strFilter = tempJSON.Substring(tempJSON.IndexOf("[") + 1, tempJSON.IndexOf("]") - tempJSON.IndexOf("[") - 1);
string[] strFees = strFilter.Split(new string[] { "},{" }, System.StringSplitOptions.RemoveEmptyEntries);
if (strFees.Length > 0)
{
for (int i = 0; i < strFees.Length; i++)
{
strFees[i] = strFees[i].ToString().Replace("{", "");
strFees[i] = strFees[i].ToString().Replace("}", "");
string[] strCell = strFees[i].Split(new char[] { ',' });
if (strCell.Length > 0)
{
FeeEntity feeEntity = new FeeEntity();
for (int j = 0; j < strCell.Length; j++)
{
string[] strArg = strCell[j].Split(new char[] { ':' });
switch (strArg[0].Replace("\"", ""))
{
case "id":
feeEntity.GID = strArg[1].ToString().Replace("\"", "").Trim();
break;
case "type":
feeEntity.FeeType = int.Parse(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "bsno":
feeEntity.BSNO = strArg[1].ToString().Replace("\"", "").Trim();
break;
case "outbsno":
feeEntity.WMSOUTBSNO = strArg[1].ToString().Replace("\"", "").Trim();
break;
case "status":
break;
case "fname":
feeEntity.FeeName = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "cust":
feeEntity.CustomerName = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "unit":
string tempUnit = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
if (tempUnit.Equals("null") || tempUnit.Equals(""))
{
feeEntity.Unit = "";
}
else
{
feeEntity.Unit = tempUnit;
}
break;
case "price":
feeEntity.UnitPrice = decimal.Parse(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "quant":
feeEntity.Quantity = decimal.Parse(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "com":
feeEntity.CommissionRate = decimal.Parse(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "amount":
feeEntity.Amount = decimal.Parse(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "cur":
feeEntity.Currency = strArg[1].ToString().Replace("\"", "").Trim();
break;
case "rate":
feeEntity.ExchangeRate = decimal.Parse(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "frt":
feeEntity.FeeFrt = strArg[1].ToString().Replace("\"", "").Trim();
break;
case "remark":
feeEntity.Remark = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "isadv":
feeEntity.IsAdvancePay = strArg[1].ToString().Replace("\"", "").Trim().Equals("1") ? true : false;
break;
default:
break;
}
}
strSeaBSNO = feeEntity.BSNO;
feeEntity.EnterOperator = this.strUserID;
feeEntity.FeeStatus = 1;
tempFeeEntities.Add(feeEntity);
}
}
}
}
return tempFeeEntities;
}
#endregion
#region Unicode-GB Code转换
/// <summary>
/// Unicode-GB Code转换
/// </summary>
/// <param name="text">将Unicode编码字符转换成GB编码字符</param>
/// <returns>GB Code字符串</returns>
public string UnicodeToGB(string text)
{
UnicodeEncoding unicode = new UnicodeEncoding();
text = unicode.GetString(unicode.GetBytes(Regex.Unescape(text.Trim())));
return text;
}
/// <summary>
/// Unicode-GB Code转换
/// </summary>
/// <param name="text">将Unicode编码字符转换成GB编码字符</param>
/// <returns>GB Code字符串</returns>
public string UnicodeToGB_Old(string text)
{
MatchCollection mc = Regex.Matches(text, "([\\w]+)|(\\\\u([\\w]{4}))");
if (mc != null && mc.Count > 0)
{
StringBuilder sb = new StringBuilder();
foreach (Match m2 in mc)
{
string v = m2.Value;
if (v.IndexOf("\\") >= 0)
{
string word = v.Substring(2);
byte[] codes = new byte[2];
int code = Convert.ToInt32(word.Substring(0, 2), 16);
int code2 = Convert.ToInt32(word.Substring(2), 16);
codes[0] = (byte)code2;
codes[1] = (byte)code;
sb.Append(Encoding.Unicode.GetString(codes));
}
else
{
sb.Append(v);
}
}
return sb.ToString();
}
else
{
return text;
}
}
#endregion
#region 将页面post获取的利润值读入到利润实体类中
/// <summary>
/// 将页面post获取的利润值读入到利润实体类中
/// </summary>
/// <returns>返回利润实体类 FeeProfitEntity</returns>
private FeeProfitEntity GetRequestProfit()
{
FeeProfitEntity tempFeeProfitEntity = new FeeProfitEntity();
#region 保留
//tempFeeProfitEntity.RMBDR = Decimal.Parse(dvRecvRMBVal.InnerText.Trim());
//tempFeeProfitEntity.USDDR = Decimal.Parse(dvUSRecvVal.InnerHtml.Trim());
//tempFeeProfitEntity.OTHERDR = Decimal.Parse(dvOtherCurrencyRecvVal.InnerHtml.Trim());
//tempFeeProfitEntity.RMBCR = Decimal.Parse(dvPayRMBVal.InnerHtml.Trim());
//tempFeeProfitEntity.USDCR = Decimal.Parse(dvUSPayVal.InnerHtml.Trim());
//tempFeeProfitEntity.OTHERCR = Decimal.Parse(dvOtherCurrencyPayVal.InnerHtml.Trim());
//tempFeeProfitEntity.DRTTL = Decimal.Parse(dvRecvTotalVal.InnerHtml.Trim());
//tempFeeProfitEntity.CRTTL = Decimal.Parse(dvPaySumVal.InnerHtml.Trim());
//tempFeeProfitEntity.RMBProfit = Decimal.Parse(dvRMBProfitVal.InnerHtml.Trim());
//tempFeeProfitEntity.USDProfit = Decimal.Parse(dvUSProfitVal.InnerHtml.Trim());
//tempFeeProfitEntity.OTHERProfit = Decimal.Parse(dvOtherCurrencyProfitVal.InnerHtml.Trim());
//tempFeeProfitEntity.TTLProfit = Decimal.Parse(dvProfitTotalVal.InnerHtml.Trim());
//tempFeeProfitEntity.ProfitRate = dvProfitRateVal.InnerHtml.Trim();
#endregion
if (!gainContainer.Value.Trim().Equals(""))
{
string[] gainList = gainContainer.Value.Trim().Split(new char[] { ',' });
if (!gainList[0].ToString().Trim().Equals(""))
{
tempFeeProfitEntity.RMBDR = Decimal.Parse(gainList[0].ToString().Trim());
tempFeeProfitEntity.USDDR = Decimal.Parse(gainList[1].ToString().Trim());
tempFeeProfitEntity.OTHERDR = Decimal.Parse(gainList[2].ToString().Trim());
tempFeeProfitEntity.RMBCR = Decimal.Parse(gainList[3].ToString().Trim());
tempFeeProfitEntity.USDCR = Decimal.Parse(gainList[4].ToString().Trim());
tempFeeProfitEntity.OTHERCR = Decimal.Parse(gainList[5].ToString().Trim());
tempFeeProfitEntity.DRTTL = Decimal.Parse(gainList[6].ToString().Trim());
tempFeeProfitEntity.CRTTL = Decimal.Parse(gainList[7].ToString().Trim());
tempFeeProfitEntity.RMBProfit = Decimal.Parse(gainList[8].ToString().Trim());
tempFeeProfitEntity.USDProfit = Decimal.Parse(gainList[9].ToString().Trim());
tempFeeProfitEntity.OTHERProfit = Decimal.Parse(gainList[10].ToString().Trim());
tempFeeProfitEntity.TTLProfit = Decimal.Parse(gainList[11].ToString().Trim());
tempFeeProfitEntity.ProfitRate = gainList[12].ToString().Trim();
tempFeeProfitEntity.CreateUser = strUserID;
tempFeeProfitEntity.ModifiedUser = strUserID;
}
else
{
tempFeeProfitEntity.RMBDR = 0;
tempFeeProfitEntity.USDDR = 0;
tempFeeProfitEntity.OTHERDR = 0;
tempFeeProfitEntity.RMBCR = 0;
tempFeeProfitEntity.USDCR = 0;
tempFeeProfitEntity.OTHERCR = 0;
tempFeeProfitEntity.DRTTL = 0;
tempFeeProfitEntity.CRTTL = 0;
tempFeeProfitEntity.RMBProfit = 0;
tempFeeProfitEntity.USDProfit = 0;
tempFeeProfitEntity.OTHERProfit = 0;
tempFeeProfitEntity.TTLProfit = 0;
tempFeeProfitEntity.ProfitRate = "0%";
tempFeeProfitEntity.CreateUser = this.strUserID;
tempFeeProfitEntity.ModifiedUser = this.strUserID;
}
}
return tempFeeProfitEntity;
}
#endregion
#region 获取用户应收、应付权限信息
/// <summary>
/// 获取用户应收、应付权限信息
/// </summary>
/// <param name="tempFeeType">费用类型</param>
/// <returns>返回 true 有权限操作数据 false 没有权限操作数据</returns>
private bool ValidateUserFeeAuthority(int tempFeeType)
{
int iResult = 0;
if (tempFeeType == 1)
{
UserAuthorityManage userAuthorityManageOrder = new UserAuthorityManage(strUserID, "modSeaImportLCLList");
UserAuthorityManage userRecvAuthorityManage = new UserAuthorityManage(strUserID, "modSeaiLCLRecvFeeManagement");
if (userRecvAuthorityManage.OperateType != AuthorityType.NULL)
{
iResult = userAuthorityManageOrder.CheckOperateRange(ModuleType.OPSEAILIST, userRecvAuthorityManage.OperateType, strShowName, strCompanyID, strDeptName, strSeaBSNO, "", strUserID);
}
}
else
{
UserAuthorityManage userAuthorityManageOrder = new UserAuthorityManage(strUserID, "modSeaImportLCLList");
UserAuthorityManage userPayAuthorityManage = new UserAuthorityManage(strUserID, "modSeaiLCLPayFeeManagement");
if (userPayAuthorityManage.OperateType != AuthorityType.NULL)
{
iResult = userAuthorityManageOrder.CheckOperateRange(ModuleType.OPSEAILIST, userPayAuthorityManage.OperateType, strShowName, strCompanyID, strDeptName, strSeaBSNO, "", strUserID);
}
}
if (iResult > 0)
{
return true;
}
else
{
return false;
}
}
#endregion
#region getBSNO
protected String getBSNO()
{
string strBSNO = Guid.NewGuid().ToString();
strBSNO = strBSNO.Replace("-", "");
strBSNO = "WmsOut" + strBSNO;
return strBSNO;
}
#endregion
#region 提取规则编号 getCodeRuleWmsOutDetail
/// <summary>
/// 提取规则编号
/// </summary>
/// <param name="strRULENAME">规则项目名称</param>
/// <param name="strfield">需要加规则的字段</param>
/// <returns></returns>
protected String getCodeRuleWmsOutDetail(string strRULENAME, string strfield)
{
//调用编码规则
string strRULEYEAR = "";
string strRULECONTENT = "";
string strCODENAME = "";
string strDEPTNO = "";
string strRULENOLENGTH = "";
int iRULENOLENGTH = 0;
int inum = 0;
string strCONTENT = "";
DataSet ds = T_ALL_DA.GetAllSQL("select *,getdate() DODATE from code_rule where RULENAME='" + strRULENAME.Trim() + "' and RULETYPE=3");
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0]["ISSTARTUSING"].ToString().Trim().Equals("True"))
{
getCodeRuleEnabled(strRULENAME, strfield);
//
if (ds.Tables[0].Rows[0]["RULEDATE"].ToString().Trim().Equals("业务日期"))
{
if (ds.Tables[0].Rows[0]["DODATE"].ToString().Trim() == "")
{
return "";
}
DateTime dETD = System.Convert.ToDateTime(ds.Tables[0].Rows[0]["DODATE"].ToString().Trim());
if (ds.Tables[0].Rows[0]["ISCLEAREDINEARLY"].ToString().Trim().Equals("True"))
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = dETD.ToString("yyyy") + dETD.ToString("MM");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = dETD.ToString("yy") + dETD.ToString("MM");
}
}
else
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = dETD.ToString("yyyy");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = dETD.ToString("yy");
}
}
}
else if (ds.Tables[0].Rows[0]["RULEDATE"].ToString().Trim().Equals("自然月份"))
{
DateTime fwqdate = System.Convert.ToDateTime(T_ALL_DA.GetStrSQL("fwqdate", "select fwqdate=getdate()"));
if (ds.Tables[0].Rows[0]["ISCLEAREDINEARLY"].ToString().Trim().Equals("True"))
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = fwqdate.ToString("yyyy") + fwqdate.ToString("MM");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = fwqdate.ToString("yy") + fwqdate.ToString("MM");
}
}
else
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = fwqdate.ToString("yyyy");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = fwqdate.ToString("yy");
}
}
}
//
if (ds.Tables[0].Rows[0]["ISCOMPANY"].ToString().Trim().Equals("True"))
{
strCODENAME = T_ALL_DA.GetStrSQL("CODENAME", "select CODENAME from [company] where GID=(select top 1 COMPANYID from user_company where USERID='" + strUserID + "')");
}
if (ds.Tables[0].Rows[0]["ISDEPT"].ToString().Trim().Equals("True"))
{
strDEPTNO = T_ALL_DA.GetStrSQL("DEPTNO", "select DEPTNO from [sys_dept] where LINKID=(select top 1 COMPANYID from user_company where USERID='" + strUserID + "')");
}
strRULECONTENT = ds.Tables[0].Rows[0]["RULECONTENT"].ToString().Trim();
strRULECONTENT = strRULECONTENT.Replace("《COMPANY》", strCODENAME);
strRULECONTENT = strRULECONTENT.Replace("《DEPT》", strDEPTNO);
//
if (ds.Tables[0].Rows[0]["RULENOLENGTH"].ToString().Trim() == "")
{
iRULENOLENGTH = 0;
}
else
{
iRULENOLENGTH = int.Parse(ds.Tables[0].Rows[0]["RULENOLENGTH"].ToString().Trim());
}
strCONTENT = strRULECONTENT + strRULEYEAR;
//获取分公司的票号头字符
string tempBANKSHEAD = T_ALL_DA.GetStrSQL("BANKSHEAD", "SELECT TOP 1 BANKSHEAD FROM company WHERE GID='" + strCompanyID.Trim() + "'");
strCONTENT = tempBANKSHEAD + strCONTENT;
//
//DataSet ds1 = T_ALL_DA.GetAllSQL("select top 1 " + strfield + " from [wms_out_detail] where " + strfield + " like '" + strCONTENT.Trim() + "%' order by " + strfield + " DESC");
//if (ds1 != null)
//{
// if (ds.Tables[0].Rows.Count > 0)
// {
// strRULENOLENGTH = ds1.Tables[0].Rows[0][0].ToString().Trim();
// }
//}
T_ALL_DA.GetStrSQL(strfield, "select top 1 " + strfield + " from [wms_out_detail] where " + strfield + " like '" + strCONTENT.Trim() + "%' order by " + strfield + " DESC");// and isnull(ISDELETE,0)=0
if (strRULENOLENGTH == "")
{
strRULENOLENGTH = "1";
}
else
{
strRULENOLENGTH = strRULENOLENGTH.Replace(strCONTENT.Trim(), "");
inum = int.Parse(strRULENOLENGTH.Trim());
inum = inum + 1;
strRULENOLENGTH = inum.ToString();
}
int j = iRULENOLENGTH - strRULENOLENGTH.Length;
for (int i = 1; i <= j; i++)
{
strRULENOLENGTH = "0" + strRULENOLENGTH;
}
//
strCONTENT = strCONTENT + strRULENOLENGTH;
return strCONTENT;
}
}
}
return "";
}
#endregion
#region 提取规则编号 getCodeRuleWmsOut
/// <summary>
/// 提取规则编号
/// </summary>
/// <param name="strRULENAME">规则项目名称</param>
/// <param name="strfield">需要加规则的字段</param>
/// <returns></returns>
protected String getCodeRuleWmsOut(string strRULENAME, string strfield)
{
//调用编码规则
string strRULEYEAR = "";
string strRULECONTENT = "";
string strCODENAME = "";
string strDEPTNO = "";
string strRULENOLENGTH = "";
int iRULENOLENGTH = 0;
int inum = 0;
string strCONTENT = "";
DataSet ds = T_ALL_DA.GetAllSQL("select *,getdate() DODATE from code_rule where RULENAME='" + strRULENAME.Trim() + "' and RULETYPE=3");
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0]["ISSTARTUSING"].ToString().Trim().Equals("True"))
{
getCodeRuleEnabled(strRULENAME, strfield);
//
if (ds.Tables[0].Rows[0]["RULEDATE"].ToString().Trim().Equals("业务日期"))
{
if (ds.Tables[0].Rows[0]["DODATE"].ToString().Trim() == "")
{
return "";
}
DateTime dETD = System.Convert.ToDateTime(ds.Tables[0].Rows[0]["DODATE"].ToString().Trim());
if (ds.Tables[0].Rows[0]["ISCLEAREDINEARLY"].ToString().Trim().Equals("True"))
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = dETD.ToString("yyyy") + dETD.ToString("MM");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = dETD.ToString("yy") + dETD.ToString("MM");
}
}
else
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = dETD.ToString("yyyy");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = dETD.ToString("yy");
}
}
}
else if (ds.Tables[0].Rows[0]["RULEDATE"].ToString().Trim().Equals("自然月份"))
{
DateTime fwqdate = System.Convert.ToDateTime(T_ALL_DA.GetStrSQL("fwqdate", "select fwqdate=getdate()"));
if (ds.Tables[0].Rows[0]["ISCLEAREDINEARLY"].ToString().Trim().Equals("True"))
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = fwqdate.ToString("yyyy") + fwqdate.ToString("MM");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = fwqdate.ToString("yy") + fwqdate.ToString("MM");
}
}
else
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = fwqdate.ToString("yyyy");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = fwqdate.ToString("yy");
}
}
}
//
if (ds.Tables[0].Rows[0]["ISCOMPANY"].ToString().Trim().Equals("True"))
{
strCODENAME = T_ALL_DA.GetStrSQL("CODENAME", "select CODENAME from [company] where GID=(select top 1 COMPANYID from user_company where USERID='" + strUserID + "')");
}
if (ds.Tables[0].Rows[0]["ISDEPT"].ToString().Trim().Equals("True"))
{
strDEPTNO = T_ALL_DA.GetStrSQL("DEPTNO", "select DEPTNO from [sys_dept] where LINKID=(select top 1 COMPANYID from user_company where USERID='" + strUserID + "')");
}
strRULECONTENT = ds.Tables[0].Rows[0]["RULECONTENT"].ToString().Trim();
strRULECONTENT = strRULECONTENT.Replace("《COMPANY》", strCODENAME);
strRULECONTENT = strRULECONTENT.Replace("《DEPT》", strDEPTNO);
//
if (ds.Tables[0].Rows[0]["RULENOLENGTH"].ToString().Trim() == "")
{
iRULENOLENGTH = 0;
}
else
{
iRULENOLENGTH = int.Parse(ds.Tables[0].Rows[0]["RULENOLENGTH"].ToString().Trim());
}
strCONTENT = strRULECONTENT + strRULEYEAR;
//获取分公司的票号头字符
string tempBANKSHEAD = T_ALL_DA.GetStrSQL("BANKSHEAD", "SELECT TOP 1 BANKSHEAD FROM company WHERE GID='" + strCompanyID.Trim() + "'");
strCONTENT = tempBANKSHEAD + strCONTENT;
//
strRULENOLENGTH = T_ALL_DA.GetStrSQL(strfield, "select top 1 " + strfield + " from [wms_out] where " + strfield + " like '" + strCONTENT.Trim() + "%' and isnull(ISDELETE,0)=0 order by " + strfield + " DESC");
if (strRULENOLENGTH == "")
{
strRULENOLENGTH = "1";
}
else
{
strRULENOLENGTH = strRULENOLENGTH.Replace(strCONTENT.Trim(), "");
inum = int.Parse(strRULENOLENGTH.Trim());
inum = inum + 1;
strRULENOLENGTH = inum.ToString();
}
int j = iRULENOLENGTH - strRULENOLENGTH.Length;
for (int i = 1; i <= j; i++)
{
strRULENOLENGTH = "0" + strRULENOLENGTH;
}
//
strCONTENT = strCONTENT + strRULENOLENGTH;
return strCONTENT;
}
}
}
return "";
}
#endregion
#region 提取规则编号 getCodeRuleEnabled
/// <summary>
/// 提取规则编号
/// </summary>
/// <param name="strRULENAME">规则项目名称</param>
/// <param name="strfield">需要加规则的字段</param>
/// <returns></returns>
protected void getCodeRuleEnabled(string strRULENAME, string strfield)
{
//是否生成之后允许编辑
DataSet ds = T_ALL_DA.GetAllSQL("select * from code_rule where RULENAME='" + strRULENAME.Trim() + "' and RULETYPE=3");
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0]["ISSTARTUSING"].ToString().Trim().Equals("True"))
{
if (strfield == "BSNO")
{
if (ds.Tables[0].Rows[0]["ISALLOWEDITS"].ToString().Trim().Equals("True"))
{
txt_outbsno.Disabled=false;
}
else
{
txt_outbsno.Disabled=true;
}
}
}
}
}
}
#endregion
/// <summary>
/// 提取规则编号
/// </summary>
/// <param name="strRULENAME">规则项目名称</param>
/// <param name="strfield">需要加规则的字段</param>
/// <returns></returns>
protected String getCodeRuleWmsIn(string strRULENAME, string strfield, SqlTransaction trans)
{
//调用编码规则
string strRULEYEAR = "";
string strRULECONTENT = "";
string strCODENAME = "";
string strDEPTNO = "";
string strRULENOLENGTH = "";
int iRULENOLENGTH = 0;
int inum = 0;
string strCONTENT = "";
DataSet ds = new DataSet();
//DataSet ds = T_ALL_DA.GetAllSQL("select *,getdate() DODATE from code_rule where RULENAME='" + strRULENAME.Trim() + "' and RULETYPE=3");
SqlParameter parm = new SqlParameter("@RULENAME", SqlDbType.VarChar, 100);
parm.Value=strRULENAME.Trim();
string ststt="select *,getdate() DODATE from code_rule where RULENAME=@RULENAME and RULETYPE=3 ";
ds = SqlHelper.ExecuteQueryDataset(trans, CommandType.Text, ststt, parm);
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0]["ISSTARTUSING"].ToString().Trim().Equals("True"))
{
getCodeRuleEnabled(strRULENAME, strfield);
//
if (ds.Tables[0].Rows[0]["RULEDATE"].ToString().Trim().Equals("业务日期"))
{
//if (tbDODATE.Text.Trim() == "")
//{
// return "";
//}
if (ds.Tables[0].Rows[0]["DODATE"].ToString().Trim() == "")
{
return "";
}
DateTime dETD = System.Convert.ToDateTime(ds.Tables[0].Rows[0]["DODATE"].ToString().Trim());
if (ds.Tables[0].Rows[0]["ISCLEAREDINEARLY"].ToString().Trim().Equals("True"))
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = dETD.ToString("yyyy") + dETD.ToString("MM");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = dETD.ToString("yy") + dETD.ToString("MM");
}
}
else
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = dETD.ToString("yyyy");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = dETD.ToString("yy");
}
}
}
else if (ds.Tables[0].Rows[0]["RULEDATE"].ToString().Trim().Equals("自然月份"))
{
DateTime fwqdate = System.Convert.ToDateTime(T_ALL_DA.GetStrSQL("fwqdate", "select fwqdate=getdate()"));
if (ds.Tables[0].Rows[0]["ISCLEAREDINEARLY"].ToString().Trim().Equals("True"))
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = fwqdate.ToString("yyyy") + fwqdate.ToString("MM");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = fwqdate.ToString("yy") + fwqdate.ToString("MM");
}
}
else
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = fwqdate.ToString("yyyy");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = fwqdate.ToString("yy");
}
}
}
//
if (ds.Tables[0].Rows[0]["ISCOMPANY"].ToString().Trim().Equals("True"))
{
//strCODENAME = T_ALL_DA.GetStrSQL("CODENAME", "select CODENAME from [company] where GID=(select top 1 COMPANYID from user_company where USERID='" + strUserID + "')");
SqlParameter parm1 = new SqlParameter("@USERID", SqlDbType.VarChar, 100);
parm1.Value = strUserID;
ststt = "select CODENAME from [company] where GID=(select top 1 COMPANYID from user_company where USERID=@USERID)";
ds = SqlHelper.ExecuteQueryDataset(trans, CommandType.Text, ststt, parm1);
strCODENAME = ds.Tables[0].Rows[0]["CODENAME"].ToString().Equals(null) ? "" : ds.Tables[0].Rows[0]["CODENAME"].ToString();
}
if (ds.Tables[0].Rows[0]["ISDEPT"].ToString().Trim().Equals("True"))
{
//strDEPTNO = T_ALL_DA.GetStrSQL("DEPTNO", "select DEPTNO from [sys_dept] where LINKID=(select top 1 COMPANYID from user_company where USERID='" + strUserID + "')");
SqlParameter parm2 = new SqlParameter("@USERID", SqlDbType.VarChar, 100);
parm2.Value = strUserID;
ststt = "select DEPTNO from [sys_dept] where LINKID=(select top 1 COMPANYID from user_company where USERID=@USERID";
ds = SqlHelper.ExecuteQueryDataset(trans, CommandType.Text, ststt, parm2);
strDEPTNO = ds.Tables[0].Rows[0]["DEPTNO"].ToString().Equals(null) ? "" : ds.Tables[0].Rows[0]["DEPTNO"].ToString();
}
strRULECONTENT = ds.Tables[0].Rows[0]["RULECONTENT"].ToString().Trim();
strRULECONTENT = strRULECONTENT.Replace("《COMPANY》", strCODENAME);
strRULECONTENT = strRULECONTENT.Replace("《DEPT》", strDEPTNO);
//
if (ds.Tables[0].Rows[0]["RULENOLENGTH"].ToString().Trim() == "")
{
iRULENOLENGTH = 0;
}
else
{
iRULENOLENGTH = int.Parse(ds.Tables[0].Rows[0]["RULENOLENGTH"].ToString().Trim());
}
strCONTENT = strRULECONTENT + strRULEYEAR;
//获取分公司的票号头字符
string tempBANKSHEAD = T_ALL_DA.GetStrSQL("BANKSHEAD", "SELECT TOP 1 BANKSHEAD FROM company WHERE GID='" + strCompanyID.Trim() + "'");
strCONTENT = tempBANKSHEAD + strCONTENT;
//
//strRULENOLENGTH = T_ALL_DA.GetStrSQL(strfield, "select top 1 " + strfield + " from [wms_in] where " + strfield + " like '" + strCONTENT.Trim() + "%' and ISDELETE=0 order by " + strfield + " DESC");
SqlParameter parm3 = new SqlParameter("@BSNO", SqlDbType.VarChar, 100);
parm3.Value = strCONTENT.Trim();
ststt = "select top 1 BSNO from [wms_in] where BSNO like '"+strCONTENT.Trim()+ "%' and ISDELETE=0 order by BSNO DESC";
ds = SqlHelper.ExecuteQueryDataset(trans, CommandType.Text, ststt, parm3);
if (!ds.Equals(null) && !ds.Tables[0].Equals(null) && ds.Tables[0].Rows.Count>0 )
{
strRULENOLENGTH = ds.Tables[0].Rows[0]["BSNO"].ToString().Equals(null) ? "" : ds.Tables[0].Rows[0]["BSNO"].ToString();
}
else
{
strRULENOLENGTH = "";
}
if (strRULENOLENGTH == "")
{
strRULENOLENGTH = "1";
}
else
{
strRULENOLENGTH = strRULENOLENGTH.Replace(strCONTENT.Trim(), "");
inum = int.Parse(strRULENOLENGTH.Trim());
inum = inum + 1;
strRULENOLENGTH = inum.ToString();
}
int j = iRULENOLENGTH - strRULENOLENGTH.Length;
for (int i = 1; i <= j; i++)
{
strRULENOLENGTH = "0" + strRULENOLENGTH;
}
//
strCONTENT = strCONTENT + strRULENOLENGTH;
return strCONTENT;
}
}
}
return "";
}
protected String getBSNOWmsIn()
{
string strBSNO = Guid.NewGuid().ToString();
strBSNO = strBSNO.Replace("-", "");
strBSNO = "WmsIn" + strBSNO;
return strBSNO;
}
protected String getWMSNO()
{
string strWMSNO = Guid.NewGuid().ToString();
strWMSNO = strWMSNO.Replace("-", "");
strWMSNO = "Wms" + strWMSNO;
return strWMSNO;
}
}
}