コード例 #1
0
 public void Transaction(Action handler) => Ado.Transaction(handler);
コード例 #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <returns></returns>
        public BaseTemplate_Update <T, V> Update()
        {
            try
            {
                // first of all, we check if user has the right to perform this operation!
                if (HasUserToBeAuthenticated())
                {
                    if (!IsUserAuthenticated() || !HasUserPrivilege())
                    {
                        OnAuthenticationFailed();
                        return(this);
                    }
                }
                //if we didn't attempt to authenticate and it's an external call then we still need to the the SamAccountName
                if (SamAccountName == null && Request.sessionCookie != null)
                {
                    //Does the cookie correspond with a live token for a user?
                    ADO_readerOutput user;
                    using (Login_BSO lBso = new Login_BSO())
                    {
                        user = lBso.ReadBySession(Request.sessionCookie.Value);
                        if (user.hasData)
                        {
                            SamAccountName = user.data[0].CcnUsername;
                        }
                    }
                }

                //Run the parameters through the cleanse process
                dynamic cleansedParams;

                //If the API has the IndividualCleanseNoHtml attribute then parameters are cleansed individually
                //Any of these parameters whose corresponding DTO property contains the NoHtmlStrip attribute will not be cleansed of HTML tags
                if (Resources.MethodReader.MethodHasAttribute(Request.method, "IndividualCleanseNoHtml"))
                {
                    dynamic dto = GetDTO(Request.parameters);
                    cleansedParams = Cleanser.Cleanse(Request.parameters, dto);
                }
                else
                {
                    cleansedParams = Cleanser.Cleanse(Request.parameters);
                }

                try
                {
                    DTO = GetDTO(cleansedParams);
                }
                catch
                {
                    throw new InputFormatException();
                }

                DTO = Sanitizer.Sanitize(DTO);

                DTOValidationResult = Validator.Validate(DTO);

                if (!DTOValidationResult.IsValid)
                {
                    OnDTOValidationError();
                    return(this);
                }

                Ado.StartTransaction();

                // The Actual Creation should happen here by the specific class!
                if (!Execute())
                {
                    Ado.RollbackTransaction();
                    OnExecutionError();
                }
                else
                {
                    Ado.CommitTransaction();
                    OnExecutionSuccess();
                }



                return(this);
            }
            catch (FormatException formatException)
            {
                //An error has been caught, rollback the transaction, log the error and return a message to the caller
                Ado.RollbackTransaction();
                Log.Instance.Error(formatException);
                Response.error = Label.Get("error.schema");
                return(this);
            }
            catch (InputFormatException inputError)
            {
                //An error has been caught, rollback the transaction, log the error and return a message to the caller
                Ado.RollbackTransaction();
                Log.Instance.Error(inputError);
                Response.error = Label.Get("error.schema");
                return(this);
            }
            catch (Exception ex)
            {
                Ado.RollbackTransaction();
                //An error has been caught, rollback the transaction, log the error and return a message to the caller
                Log.Instance.Error(ex);
                Response.error = Label.Get("error.exception");
                return(this);
            }
            finally
            {
                Dispose();
            }
        }
コード例 #3
0
 private int GetSeqValue(string seqName)
 {
     return(Ado.GetInt(" SELECT " + seqName + ".currval FROM DUAL"));
 }
コード例 #4
0
 public void Transaction(Action handler, TimeSpan timeout) => Ado.Transaction(handler, timeout);
コード例 #5
0
        /// <summary>
        /// SqlSugar的功能介绍
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //设置执行的DEMO
            string switchOn = "update";
            IDemos demo     = null;

            switch (switchOn)
            {
            /****************************基本功能**************************************/
            //查询
            case "select": demo = new Select(); break;

            //删除
            case "delete": demo = new Delete(); break;

            //插入
            case "insert": demo = new Insert(); break;

            //更新
            case "update": demo = new Update(); break;

            //基层函数的用法
            case "ado": demo = new Ado(); break;

            //事务
            case "tran": demo = new Tran(); break;

            //创建实体函数
            case "createclass": demo = new CreateClass(); break;
            //T4生成 http://www.cnblogs.com/sunkaixuan/p/5751503.html

            //日志记录
            case "log": demo = new Log(); break;

            //枚举支持
            case "enum": demo = new EnumDemo(); break;



            /****************************实体映射**************************************/
            //自动排除非数据库列
            case "ignoreerrorcolumns": demo = new IgnoreErrorColumns(); break;

            //别名表
            case "mappingtable": demo = new MappingTable(); break;

            //别名列
            case "mappingcolumns": demo = new MappingColumns(); break;

            //通过属性的方法设置别名表和别名字段
            case "attributesmapping": demo = new AttributesMapping(); break;



            /****************************业务应用**************************************/
            //过滤器
            case "filter": demo = new Filter(); break;

            //过滤器2
            case "filter2": demo = new Filter2(); break;

            //流水号功能
            case "serialnumber": demo = new SerialNumber(); break;

            //配置与实例的用法
            case "initconfig": demo = new InitConfig(); break;



            /****************************支持**************************************/
            //公开函数数
            case "pubmethod": demo = new PubMethod(); break;

            //设置ToJson的日期格式
            case "serializerdateformat": demo = new SerializerDateFormat(); break;



            /****************************测试用例**************************************/
            case "test": demo = new Test(); break;

            default: Console.WriteLine("switchOn的值错误,请输入正确的 case"); break;
            }
            //执行DEMO
            demo.Init();

            //更多例子请查看API
            //http://www.cnblogs.com/sunkaixuan/p/5654695.html
            Console.WriteLine("执行成功请关闭窗口");
            Console.ReadKey();
        }
コード例 #6
0
 public void Transaction(TimeSpan timeout, Action handler) => Ado.Transaction(timeout, handler);
コード例 #7
0
 public void Transaction(IsolationLevel isolationLevel, TimeSpan timeout, Action handler) => Ado.Transaction(isolationLevel, timeout, handler);
コード例 #8
0
ファイル: SSDBContext.cs プロジェクト: chn-gd-st-zp/Spear
        public List <TEntity> SelectFromStoredProcedure <TEntity>(string sql, params DBParameter[] paramArray) where TEntity : DBEntity_Basic, new()
        {
            DataTable dt = Ado.UseStoredProcedure().GetDataTable(sql, paramArray.Parse());

            return(dt.ToDataList <TEntity>());
        }
コード例 #9
0
ファイル: KingbaseESProvider.cs プロジェクト: zzl1010/FreeSql
 public void Transaction(IsolationLevel isolationLevel, Action handler) => Ado.Transaction(isolationLevel, handler);
コード例 #10
0
ファイル: SSDBContext.cs プロジェクト: chn-gd-st-zp/Spear
 public List <TEntity> SelectFromSql <TEntity>(string sql, params DBParameter[] paramArray) where TEntity : DBEntity_Basic, new()
 {
     return(Ado.SqlQuery <TEntity>(sql, paramArray.Parse()));
 }
コード例 #11
0
ファイル: SSDBContext.cs プロジェクト: chn-gd-st-zp/Spear
 public int ExecuteStoredProcedure(string sql, params DBParameter[] paramArray)
 {
     return(Ado.UseStoredProcedure().ExecuteCommand(sql, paramArray.Parse()));
 }
コード例 #12
0
ファイル: SSDBContext.cs プロジェクト: chn-gd-st-zp/Spear
 public int ExecuteSql(string sql, params DBParameter[] paramArray)
 {
     return(Ado.ExecuteCommand(sql, paramArray.Parse()));
 }
コード例 #13
0
 private object GetSeqValue(string seqName)
 {
     return(Ado.GetScalar(" SELECT " + seqName + ".currval FROM DUAL"));
 }
コード例 #14
0
ファイル: Analysis.cs プロジェクト: yujunlee2017/HzyAdminSpa
 /// <summary>
 /// Min
 /// </summary>
 /// <param name="_LambdaExpression"></param>
 /// <param name="Ado"></param>
 /// <param name="_Sql"></param>
 /// <returns></returns>
 public T Min <T>(LambdaExpression _LambdaExpression, SQL _Sql)
 {
     new Max_Min_Sum_Analysis(_Sql, "MIN").Visit(_LambdaExpression);
     Analysis.ToSql(_Sql, Ado.CommitState);
     return(Ado.ExecuteScalar <T>(_Sql.Code.ToString(), _Sql.GetDynamicParameters()));
 }
コード例 #15
0
        /// <summary>
        /// Constructio
        /// </summary>
        /// <returns></returns>
        public BaseTemplate_Create <T, V> Create()
        {
            try
            {
                // first of all, we check if user has the right to perform this operation!
                if (HasUserToBeAuthenticated())
                {
                    if (!IsUserAuthenticated() || !HasUserPrivilege())
                    {
                        return(this);
                    }
                }

                //Run the parameters through the cleanse process
                dynamic cleansedParams = Cleanser.Cleanse(Request.parameters);
                try
                {
                    DTO = GetDTO(cleansedParams);
                }
                catch
                {
                    throw new InputFormatException();
                }

                DTO = Sanitizer.Sanitize(DTO);

                DTOValidationResult = Validator.Validate(DTO);

                if (!DTOValidationResult.IsValid)
                {
                    OnDTOValidationError();
                    return(this);
                }

                Ado.StartTransaction(IsolationLevel.Snapshot);

                // The Actual Creation should happen here by the specific class!
                if (!Execute())
                {
                    Ado.RollbackTransaction();
                    OnExecutionError();
                    return(this);
                }

                Ado.CommitTransaction();
                OnExecutionSuccess();

                return(this);
            }
            catch (FormatException formatException)
            {
                //A FormatException error has been caught, rollback the transaction, log the error and return a message to the caller
                Ado.RollbackTransaction();
                Log.Instance.Error(formatException);
                Response.error = Label.Get("error.schema");
                return(this);
            }
            catch (InputFormatException inputError)
            {
                //An error has been caught, rollback the transaction, log the error and return a message to the caller
                Ado.RollbackTransaction();
                Log.Instance.Error(inputError);
                Response.error = Label.Get("error.schema");
                return(this);
            }
            catch (Exception ex)
            {
                //An error has been caught, rollback the transaction, log the error and return a message to the caller
                Ado.RollbackTransaction();
                Log.Instance.Error(ex);
                Response.error = Label.Get("error.exception");
                return(this);
            }
            finally
            {
                Dispose();
            }
        }
コード例 #16
0
        public static void Main(string[] args)
        {
            //解决Core输出中文乱码
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);


            //设置执行的DEMO
            string switchOn = "select";
            IDemos demo     = null;

            switch (switchOn)
            {
            //查询
            case "select": demo = new Select(); break;

            //删除
            case "delete": demo = new Delete(); break;

            //插入
            case "insert": demo = new Insert(); break;

            //更新
            case "update": demo = new Update(); break;

            //基层函数的用法
            case "ado": demo = new Ado(); break;

            //事务
            case "tran": demo = new Tran(); break;

            //创建实体函数
            case "createclass": demo = new CreateClass(); break;

            //日志记录
            case "log": demo = new Log(); break;

            //枚举支持
            case "enum": demo = new EnumDemo(); break;

            //别名表
            case "mappingtable": demo = new MappingTable(); break;

            //过滤器
            case "filter": demo = new Filter(); break;

            //过滤器2
            case "filter2": demo = new Filter2(); break;

            //自动排除非数据库列
            case "ignoreerrorcolumns": demo = new IgnoreErrorColumns(); break;

            //流水号功能
            case "serialnumber": demo = new SerialNumber(); break;

            //公开含数
            case "pubmethod": demo = new PubMethod(); break;

            //Sql2012分页的支持
            case "sqlpagemodel": demo = new SqlPageModel(); break;

            //设置ToJson的日期格式
            case "serializerdateformat": demo = new SerializerDateFormat(); break;

            default: Console.WriteLine("switchOn的值错误,请输入正确的 case"); break;
            }
            //执行DEMO
            demo.Init();

            //更多例子请查看API
            //http://www.cnblogs.com/sunkaixuan/p/5654695.html
            Console.WriteLine("执行成功请关闭窗口");
            Console.ReadKey();
        }