using Common.Model; using Common.Wechat; using CoreEntity.DAL; using CoreEntity.Entity; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Text; using ZcPeng.PublicLibrary; namespace CoreEntity.BAL { class IDHelper { /// /// 订单汇总里面关键的几个字段 ///一个是billno在智友的syscode表中prefix = 'F'的即为最大编号, ///一个是billcode在智友的billcode表中,需要对应的是采购订单的RULEID(固定5x80rrxrb24q2ktt), ///从billcode表中取到recnum,billcode的生成规则:PDD+机构标识+8位长度的流水码(recnum,不足补零)例如PDD+Y30+00000058 ///订单明细中没有BILLCODE,但是有billsn,即明细的序号 /// /// public static long GetRecNo() { long id = 0; #region 查id string commandTextUser = "Select RecNum From " + "SysCode Where Prefix=@Prefix"; string resultUser; DataTable dt = new DataTable(); List parametersUser = new List(); parametersUser.Add(new SqlParameter("Prefix", 'F')); //DataAccess.GetValues(commandTextUser, ref dt, parametersUser.ToArray(), out resultUser); //List users = new List(); //users = (List)ModelConvertHelper.ConvertToModel(dt); //SysCode user = users.ToArray()[0]; //id = user.RECNUM; SqlConnection conn = null; SqlTransaction tran = null; bool successUser = DataAccess.GetOneValue(commandTextUser, parametersUser.ToArray(), out var v, out resultUser, out conn, out tran, true); id = long.Parse(v.ToString()); string commandText = "Update " + "SysCode set RecNum = @id +1 " + " Where Prefix=@Prefix ;" + commandTextUser; string result; List parameters = new List(); parameters.Add(new SqlParameter( "id", id)); parameters.Add(new SqlParameter( "Prefix", 'F')); List list = new List(); list.Add(new DataAccessCommand(commandText, parameters, CommandType.Text, true)); bool success = DataAccess.ExecuteBatchCommands(list, out result,conn,tran); //bool success = DataAccess.GetOneValue(commandText,parameters, out var v, out result); //id = (long)v; #endregion if (success) return id + 1; return 0; } public static void Main(string[] args) { var id = IDHelper.GetRecNo(); string orderNo = id.ToString(); StringBuilder sb = new StringBuilder(""); if (orderNo.Length < 8) { for (int ik = 0; ik < (8 - orderNo.Length); ik++) { sb.Append('0'); } sb.Append(orderNo); } //string orgno = OrgDAL.GetOrgNo("","");//PurOrderDAL.ORGID //String OrderCode = "PJH" + orgno//机构标识 // + sb.ToString(); Console.Write("文本-:"+id); } } }