在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
委托编号大排行(自动生成): 效果: 描述:在本表中自动生成编号,自动生成的编号为所有表中的排序。例如:在添加页面中生成的委托编号未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
|
请发表评论