You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

130 lines
5.1 KiB

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Web;
using CK.SCP.Models;
using CK.SCP.Models.ScpEntity;
using CK.SCP.Common;
namespace SCP.Code
{
public class GetAsnBillNum : PageBase
{
/// <summary>
/// 获取单据编号
/// </summary>
/// <param name="Prefix">单据前缀</param>
/// <param name="LenSn">流水号长度</param>
/// <returns></returns>
public static string GetBillNo(string Prefix, int LenSn)
{
using (ScpEntities db = EntitiesFactory.CreateScpInstance())
{
int y = DateTime.Now.Year;
int m = DateTime.Now.Month;
//int d = DateTime.Now.Day;
string sYear;
string sMonth;
string sValue;
//string sWhere = "[Prefix]='{0}' and sYear={1} and sMonth={2} and sDay={3}";
//sWhere = string.Format(sWhere, Prefix, y, m, d);
string sWhere = "[Prefix]='{0}' and sYear={1} and sMonth={2}";
sWhere = string.Format(sWhere, Prefix, y, m);
TA_BillNoType NewmodelBillNoType = new TA_BillNoType();
TA_BillNoType modelBillNoType =
db.TA_BillNoType.SingleOrDefault(p => p.Prefix == Prefix && p.sYear == y && p.sMonth == m);
// DataTable dtBillNo = t_BillNo.GetData(sWhere);
// DataRow drBillNo = null;
if (modelBillNoType == null)
{
NewmodelBillNoType.Prefix = Prefix;
NewmodelBillNoType.sYear = y;
NewmodelBillNoType.sMonth = m;
//drBillNo["sDay"] = d;
NewmodelBillNoType.sValue = 1;
db.TA_BillNoType.Add(NewmodelBillNoType);
db.SaveChanges();
sYear = NewmodelBillNoType.ToString().Substring(2, 2);
sMonth = MyWebString.PadLeftString(NewmodelBillNoType.sMonth.ToString(), '0', 2);
//string sDay = drBillNo["sDay"].ToString(); sDay = MyWebString.PadLeftString(sDay, '0', 2);
// string sValue = drBillNo["sValue"].ToString();
sValue = "0";
sValue = MyWebString.PadLeftString(NewmodelBillNoType.sValue.ToString(), '0', LenSn);
}
else
{
modelBillNoType.Prefix = Prefix;
modelBillNoType.sYear = y;
modelBillNoType.sMonth = m;
modelBillNoType.sValue = Convert.ToInt32(modelBillNoType.sValue) + 1;
db.TA_BillNoType.AddOrUpdate(modelBillNoType);
db.SaveChanges();
// modelBillNoType = t_BillNo.Edit(dtBillNo.Rows[0]);
sYear = modelBillNoType.sYear.ToString().Substring(2, 2);
sMonth = MyWebString.PadLeftString(modelBillNoType.sMonth.ToString(), '0', 2);
//string sDay = drBillNo["sDay"].ToString(); sDay = MyWebString.PadLeftString(sDay, '0', 2);
// string sValue = drBillNo["sValue"].ToString();
sValue = "0";
sValue = MyWebString.PadLeftString(modelBillNoType.sValue.ToString(), '0', LenSn);
}
// string sYear = modelBillNoType.ToString().Substring(2, 2);
// string sMonth = MyWebString.PadLeftString(modelBillNoType.sMonth.ToString(), '0', 2);
// //string sDay = drBillNo["sDay"].ToString(); sDay = MyWebString.PadLeftString(sDay, '0', 2);
// // string sValue = drBillNo["sValue"].ToString();
// string sValue = "0";
//
// sValue = MyWebString.PadLeftString(modelBillNoType.sValue.ToString(), '0', LenSn);
//return Prefix + sYear + sMonth + sDay + sValue;
return Prefix + sYear + sMonth + sValue;
}
}
/// <summary>
/// 在指定字串右边填充指定的字串
/// </summary>
/// <param name="o_str">要填充的原字串</param>
/// <param name="p_str">填充的字符</param>
/// <param name="len">要填充的长度</param>
/// <returns></returns>
public static string PadLeftString(string o_str, char p_str, int len)
{
string result = "";
if (o_str.Length > len)
{
//result = o_str.Substring(0, len);
result = o_str;
}
else
{
int slen = len - o_str.Length;
result = o_str;
while (slen > 0)
{
result = p_str.ToString() + result;
slen--;
}
}
return result;
}
}
}