添加领料单
This commit is contained in:
44
U8AppMain/Voucher/Vouch.cs
Normal file
44
U8AppMain/Voucher/Vouch.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace U8AppMain.Voucher
|
||||
{
|
||||
public class Vouch
|
||||
{
|
||||
//id,ddate,ccode,crdcode,cdepcode,cpersoncode,cmaker,vt_id,iswfcontrolled,
|
||||
//dnmaketime,dnmodifytime,dnverifytime
|
||||
public int ID { get; set; }
|
||||
|
||||
public DateTime DDate { get; set; }
|
||||
|
||||
public string CCode { get; set; }
|
||||
|
||||
public string CRdCode { get; set; }
|
||||
|
||||
public string CDepCode { get; set; }
|
||||
|
||||
public string CPersonCode { get; set; }
|
||||
|
||||
public string CMaker { get; set; }
|
||||
|
||||
public string Vt_id { get; set; }
|
||||
|
||||
public int IswfControlled { get; set; }
|
||||
|
||||
public DateTime dnmaketime { get; set; }
|
||||
|
||||
public DateTime dnmodifytime { get; set; }
|
||||
|
||||
public DateTime dnverifytime { get; set; }
|
||||
|
||||
public IEnumerable<Vouchs> Vouchs { get; set; } = new List<Vouchs>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
114
U8AppMain/Voucher/VoucherDAL.cs
Normal file
114
U8AppMain/Voucher/VoucherDAL.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Dapper;
|
||||
using System.Data.SqlClient;
|
||||
namespace U8AppMain.Voucher
|
||||
{
|
||||
|
||||
|
||||
public class IdEnity
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
public string cAcc_Id { get; set; }
|
||||
public string cVouchType { get; set; }
|
||||
|
||||
public int iAmount { get; set; }
|
||||
|
||||
//public int iFatherId { get; set; }
|
||||
|
||||
//public int iChildId { get; set; }
|
||||
|
||||
public bool bEnableNewRule { get; set; } = true;
|
||||
|
||||
}
|
||||
|
||||
public class VoucherDAL
|
||||
{
|
||||
private string _connStr;
|
||||
|
||||
public VoucherDAL(string connStr)
|
||||
{
|
||||
_connStr = connStr;
|
||||
}
|
||||
|
||||
public void Add(Vouch vouch)
|
||||
{
|
||||
|
||||
var conn = new SqlConnection(this._connStr);
|
||||
conn.Open();
|
||||
var trans = conn.BeginTransaction();
|
||||
try
|
||||
{
|
||||
//获取ID
|
||||
var idEnity = new IdEnity();
|
||||
idEnity.cAcc_Id = "003";
|
||||
idEnity.cVouchType = "mv";
|
||||
idEnity.iAmount = vouch.Vouchs.Count();
|
||||
DynamicParameters sp = new DynamicParameters(idEnity);
|
||||
sp.Add("@iFatherId", 0, System.Data.DbType.Int32, System.Data.ParameterDirection.Output);
|
||||
sp.Add("@iChildId", 0, System.Data.DbType.Int32, System.Data.ParameterDirection.Output);
|
||||
conn.Execute("sp_GetID", sp, trans, commandType: System.Data.CommandType.StoredProcedure);
|
||||
int iFatherId = sp.Get<int>("@iFatherId");
|
||||
int iChildId = sp.Get<int>("@iChildId");
|
||||
//获取最大值
|
||||
var cSeed = DateTime.Today.ToString("yyyyMM");
|
||||
var sqlMax = $@"select cNumber as Maxnumber From VoucherHistory with (ROWLOCK) Where CardNumber='0413' and cContent='日期' and cSeed=@cSeed";
|
||||
var maxCode = conn.ExecuteScalar<int>(sqlMax, new { cSeed }, trans);
|
||||
maxCode++;
|
||||
//更新最大之
|
||||
var sqlUpdate = "update VoucherHistory set cNumber=@cNumber Where CardNumber='0413' and cContent='日期' and cSeed=cSeed ";
|
||||
conn.Execute(sqlUpdate, new { cNumber = maxCode, cSeed }, trans);
|
||||
|
||||
//获取前缀
|
||||
var sqlPrefix = " Select Prefix1Rule From VoucherNumber Where CardNumber = '0413'";
|
||||
var prefix = conn.ExecuteScalar<string>(sqlPrefix, null, trans);
|
||||
//组装Code
|
||||
var cCode = prefix + cSeed.Substring(2,cSeed.Length-2) + maxCode.ToString().PadLeft(5, '0');
|
||||
//主表
|
||||
var sql = @"insert into MaterialAppVouch(id,ddate,ccode,crdcode,cdepcode,cpersoncode,cmaker,vt_id,iswfcontrolled,dnmaketime)
|
||||
values(@id,@ddate,@ccode,@crdcode,@cdepcode,@cpersoncode,@cmaker,@vt_id,@iswfcontrolled, getdate())";
|
||||
vouch.ID = iFatherId;
|
||||
vouch.CCode = cCode;
|
||||
conn.Execute(sql, vouch, trans);
|
||||
sql = @"INSERT INTO MaterialAppVouchs (autoid, id, cinvcode, inum, iquantity , cwhcode, iexpiratdatecalcu, irowno, iordertype, isotype , ipesotype)
|
||||
VALUES (@autoid, @id, @cinvcode, @inum, @iquantity , @cwhcode, @iexpiratdatecalcu, @irowno, @iordertype, @isotype , @ipesotype)";
|
||||
//明细
|
||||
var n = vouch.Vouchs.Count();
|
||||
foreach (var item in vouch.Vouchs)
|
||||
{
|
||||
item.autoid = iChildId - n;
|
||||
item.id =iFatherId ;
|
||||
n--;
|
||||
item.IRowNO = n;
|
||||
}
|
||||
conn.Execute(sql, vouch.Vouchs, trans);
|
||||
trans.Commit();
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
|
||||
trans.Rollback();
|
||||
throw err;
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
conn.Close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
38
U8AppMain/Voucher/Vouchs.cs
Normal file
38
U8AppMain/Voucher/Vouchs.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace U8AppMain.Voucher
|
||||
{
|
||||
|
||||
|
||||
|
||||
//autoid, id, cinvcode, inum, iquantity, cwhcode, iexpiratdatecalcu, irowno, iordertype, isotype, ipesotype
|
||||
public class Vouchs
|
||||
{
|
||||
public int autoid { get; set; }
|
||||
|
||||
public int id { get; set; }
|
||||
|
||||
public string CInvCode { get; set; }
|
||||
public int Inum { get; set; }
|
||||
|
||||
public int Iquantity { get; set; }
|
||||
|
||||
public string CwhCode { get; set; }
|
||||
|
||||
public int IExpiratdatecalcu { get; set; }
|
||||
|
||||
|
||||
public int IRowNO { get; set; }
|
||||
|
||||
public int IorderType { get; set; }
|
||||
|
||||
public int ISotype { get; set; }
|
||||
|
||||
public int IPesotype { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user