public void FillTableObj(LibTableObj tableObj) { SQLBuilder sQLBuilder = new SQLBuilder(tableObj.FromDSID); if (tableObj.WhereObject != null) { DataTable dt = this.GetDataTable(sQLBuilder.GetSQL(tableObj.TableName, null, tableObj.WhereObject, false, false)); tableObj.FillData(dt); } }
///// <summary> ///// 根据账户id 获取账户下的角色及权限对象。 ///// </summary> ///// <param name="userid"></param> ///// <returns></returns> //public DataTable GetAuthority(string userid) //{ // //SQLBuilder sQLBuilder = new SQLBuilder("Account"); // LibDSContext dSContext = new LibDSContext("Account"); // var userRole = dSContext["UserRole"]; // string sql = dSContext.GetSQL("UserRole", null, dSContext.Where(userRole.Columns.UserId + "={0}", userid)); // return this.DataAccess.GetDataTable(sql); //} /// <summary> /// 根据账户id 获取账户下的角色及权限对象。 /// </summary> /// <param name="userid"></param> /// <returns></returns> public LibTableObj GetAuthority(string userid) { //SQLBuilder sQLBuilder = new SQLBuilder("Account"); LibDSContext dSContext = new LibDSContext("Account"); LibTableObj userRole = dSContext["UserRole"]; //this.DataAccess.FillTableObj(userRole.Where(userRole.Columns.UserId + "={0}", userid)); string sql = dSContext.GetSQL("UserRole", null, dSContext.Where(userRole.Columns.UserId + "={0}", userid)); DataTable dt = this.DataAccess.GetDataTable(sql); userRole.DataTable.PrimaryKey = null; userRole.FillData(dt); return(userRole); }
private string DoGenerateNo(List <dynamic> rows) { if (rows != null && rows.Count > 0) { #region 判断是否有加锁 dynamic firstdr = rows[0]; DataRowObj rowobj = (DataRowObj)firstdr; if (this.ExistDataLock("CodeRuleConfig", rowobj.Row)) { //该功能和规则编号,正被锁着。 //throw new LibExceptionBase("该功能和规则编号,正被锁着。"); //msg000000011 该功能和规则编号,正被锁着。 this.AddMessage("msg000000011", null); } #endregion #region 加锁,防止生成重复序列号 this.AddDataLock("CodeRuleConfig", rowobj.Row, new DataColumn[] { rowobj.Row.Table.Columns[rowobj.TableObj.Columns.ProgId], rowobj.Row.Table.Columns[rowobj.TableObj.Columns.RuleId] } ); #endregion string currdate = firstdr.CurrDate; int currserial = firstdr.CurrSerial; string module = string.Empty; int serialen = -1; int index = 0; StringBuilder dateformat = new StringBuilder(); StringBuilder format = new StringBuilder(); foreach (var dr in rows) { module = dr.ModuleId; switch (module) { case "yy": case "yyyy": case "MM": case "dd": dateformat.Append(module); format.Append(module); break; case "prefix": case "suffix": format.Append(dr.FixValue); break; case "serial": format.Append("{" + index + "}"); index++; serialen = Convert.ToInt32(dr.SeriaLen); break; } } if (serialen != -1) { currserial = DateTime.Now.ToString(dateformat.ToString()) == currdate ? (currserial + 1) : 1; } #region 更新CodeRuleConfig表的当前日期和流水号 LibTableObj config = new LibTableObj("CodeRuleConfig", "CodeRuleConfig"); config.FillData(new DataRow[] { rowobj.Row }); dynamic rw = config.FindRow(0); rw.CurrDate = DateTime.Now.ToString(dateformat.ToString()); rw.CurrSerial = currserial; this.DataAccess.SaveChange(new LibTableObj[] { config }); #endregion #region 从容器中移除锁 RemoveDataLock("CodeRuleConfig", rowobj.Row); #endregion return(DateTime.Now.ToString(string.Format(format.ToString(), currserial.ToString().PadLeft(serialen, '0')))); } else { //msg000000012 找不到或未配置编码规则,请确认 this.AddMessage("msg000000012", null); } return(string.Empty); }
private string DoGenerateNo(DataRow[] rows) { //DataRow[] rows = dt.Select(string.Format("RuleId='{0}'", ruleid)); if (rows != null && rows.Length > 0) { LibTableObj config = new LibTableObj(rows[0].Table); config.FillData(rows); #region 判断是否有加锁 if (this.ExistDataLock("CodeRuleConfig", rows[0])) { //该功能和规则编号,正被锁着。 //throw new LibExceptionBase("该功能和规则编号,正被锁着。"); //this.AddMessage("该功能和规则编号,正被锁着。", LibMessageType.Error); //msg000000011 该功能和规则编号,正被锁着。 this.AddMessage("msg000000011", null); } #endregion #region 加锁,防止生成重复序列号 dynamic firstdr = config.FindRow(0); this.AddDataLock("CodeRuleConfig", rows[0], new DataColumn[] { rows[0].Table.Columns[config.Columns.ProgId], rows[0].Table.Columns[config.Columns.RuleId] }); #endregion //string currdate = rows[0][config.Columns .CurrDate].ToString(); //int currserial = Convert.ToInt32(rows[0][config.Columns .CurrSerial]); string currdate = firstdr.CurrDate; int currserial = firstdr.CurrSerial; string module = string.Empty; int serialen = -1; int index = 0; //string suffix = string.Empty; StringBuilder dateformat = new StringBuilder(); StringBuilder format = new StringBuilder(); foreach (DataRow dr in rows) { module = dr["ModuleId"].ToString(); switch (module) { case "yy": case "yyyy": case "MM": case "dd": dateformat.Append(module); format.Append(module); break; case "prefix": case "suffix": format.Append(dr["FixValue"].ToString()); break; case "serial": format.Append("{" + index + "}"); index++; serialen = Convert.ToInt32(dr["SeriaLen"]); break; } } if (serialen != -1) { currserial = DateTime.Now.ToString(dateformat.ToString()) == currdate ? (currserial + 1) : 1; //format.(format.ToString(), currserial.ToString().PadLeft(serialen, '0')); } #region 更新CodeRuleConfig表的当前日期和流水号 //SQLBuilder builder = new SQLBuilder("CodeRuleConfig"); //string sql= builder.GetUpdateSQL("CodeRuleConfig", builder.UpdateField("CurrDate={0},CurrSerial={1}", DateTime.Now.ToString(dateformat.ToString()), currserial), // builder.Where("ProgId={0} and RuleId={1}", rows[0]["ProgId"].ToString(), rows[0]["RuleId"].ToString())); //this.DataAccess.ExecuteNonQuery(sql); config = new LibTableObj("CodeRuleConfig", "CodeRuleConfig"); config.FillData(new DataRow[] { rows[0] }); dynamic rw = config.FindRow(0); rw.CurrDate = DateTime.Now.ToString(dateformat.ToString()); rw.CurrSerial = currserial; this.DataAccess.SaveChange(new LibTableObj[] { config }); #endregion #region 从容器中移除锁 RemoveDataLock("CodeRuleConfig", rows[0]); #endregion return(DateTime.Now.ToString(string.Format(format.ToString(), currserial.ToString().PadLeft(serialen, '0')))); } return(string.Empty); }