点滴积累【C#】---委托编号大排行(自动生成)

 

委托编号大排行(自动生成):

效果:

描述:在本表中自动生成编号,自动生成的编号为所有表中的排序。例如:在添加页面中生成的委托编号未00048,那么在别的表中生成的编号为00049。

调用:

 1 protected void Page_Load(object sender, EventArgs e)
 2         {
 3             Response.Expires = -1;
 4             if (!IsPostBack)
 5             {
 6              
 7                 if (ActionType == CommonEnum.ActionLevel.Write)
 8                 {
 9                     
10                     tbwtbh.Text = Getwtbh();
11                     
12                 }
13             }
14         }
15 
16 protected string Getwtbh()
17         {
18             string Getwtbh = CommonFunction.GetByMenuCode(ThisPositionID, ApplicationInfo.SerialNumWt, "qjlzhuan_lydj", "wtbh");
19             return Getwtbh;
20         }

函数:

 1 #region 委托编号大排行
 2 
 3         public static string GetByMenuCode(string ThisPositionID, int Digit, string TableName, string RowName)
 4         {
 5             string GetCode = string.Empty;
 6             string Title = string.Empty;
 7             string sql = string.Format(@"SELECT Max(RIGHT({0}," + Digit + ")) as RowName FROM {1}; " +
 8                                         "SELECT LEFT(Max({2}),LEN(Max({2}))-" + Digit + ") as RowTitle FROM {3}", "wtbhCode", "wtbh", RowName, TableName);
 9             DbCommand sqlCommand = ERPDataBase.ERPDB.GetSqlStringCommand(sql);
10             DataSet dsData = new DataSet();
11             ERPDataBase.ERPDB.LoadDataSet(sqlCommand, dsData, new string[] { "data", "Title" });
12             if (dsData.Tables["data"].Rows.Count > 0)
13             {
14                 DataRow row = dsData.Tables["data"].Rows[0];
15                 if (row["RowName"] == DBNull.Value)
16                 {
17                     GetCode = "1";
18                     GetCode = GetCode.PadLeft(Digit, '0');
19                 }
20                 else
21                 {
22                     string second = row["RowName"].ToString();
23                     GetCode = second.PadLeft(Digit, '0');
24                 }
25             }
26             if (dsData.Tables["Title"].Rows.Count > 0)
27             {
28                 DataRow row = dsData.Tables["Title"].Rows[0];
29                 if (row["RowTitle"] != DBNull.Value)
30                 {
31                     Title = row["RowTitle"].ToString();
32                 }
33             }
34             return Title + GetCode;
35         }
36 
37         public static bool RepeatExperimnetID(string wtbh, int Digit)
38         {
39             bool ISRepeat = false;
40             StringBuilder strSql = new StringBuilder();
41             strSql.Append(string.Format("SELECT RIGHT(wtbhCode," + Digit + ") AS wtbhCode FROM wtbh WHERE RIGHT(wtbhCode," + Digit + ")='{0}'", wtbh.Substring(wtbh.Length - Digit, Digit)));
42             DbCommand sqlStringCommand = ERPDataBase.ERPDB.GetSqlStringCommand(strSql.ToString());
43             DataSet dsData = new DataSet();
44             ERPDataBase.ERPDB.LoadDataSet(sqlStringCommand, dsData, "data");
45             if (dsData.Tables["data"].Rows.Count > 0)
46             {
47                 ISRepeat = true;
48             }
49             return ISRepeat;
50         }
51 
52         public static void UpdateWtCode(string wtbh, int Digit)
53         {
54             wtbh = (Convert.ToInt32(wtbh.Substring(wtbh.Length - Digit, Digit)) + 1).ToString().PadLeft(Digit, '0');
55             string sql = "UPDATE wtbh SET wtbhCode=@wtbhCode";
56             DbCommand sqlCommand = ERPDataBase.ERPDB.GetSqlStringCommand(sql);
57             ERPDataBase.ERPDB.AddInParameter(sqlCommand, "@wtbhCode", DbType.String, wtbh.Substring(wtbh.Length - Digit, Digit));
58             ERPDataBase.ERPDB.ExecuteNonQuery(sqlCommand);
59         }
60 
61         #endregion

 

转载于:https://www.cnblogs.com/xinchun/archive/2013/01/11/2856928.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值