Exemple #1
0
        public T InsertT <T>(string tableName, BeeDataAdapter dataAdapter, bool removeIdentity)
        {
            ThrowExceptionUtil.ArgumentNotNullOrEmpty(tableName, "tableName");
            ThrowExceptionUtil.ArgumentNotNull(dataAdapter, "dataAdapter");

            if (removeIdentity)
            {
                TableSchema tableSchema = GetTableSchema(tableName);
                ThrowExceptionUtil.ArgumentConditionTrue(tableSchema != null, "tableName", "can not find table. Name:{0}".FormatWith(tableName));
                if (tableSchema.IdentityColumn != null)
                {
                    dataAdapter.RemoveKey(tableSchema.IdentityColumn.ColumnName);
                }
                else
                {
                    dataAdapter.RemoveKey(Constants.DefaultIdentityColumnName);
                }
            }

            T result = default(T);
            InsertBeeCommand insertBeeCommand =
                new InsertBeeCommand(this, tableName, dataAdapter, Constants.DefaultIdentityColumnName);

            result = insertBeeCommand.Excute <T>();

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// 保存数据。
        /// 默认的表名就是类名, 若T类型上有指定的表名,则以此为准
        /// 默认的自增列为Id,若T类型上有指定的自增列, 则以此为准。
        /// 若value中的标识列大于0, 则修改。 若小于等于0, 则新增。
        /// 注:主键为int
        /// </summary>
        /// <typeparam name="T">类型</typeparam>
        /// <param name="value">类型值</param>
        /// <returns>新增则返回自增列, 修改则返回本身标示列值。</returns>
        public int Save <T>(T value) where T : class
        {
            ThrowExceptionUtil.ArgumentNotNull(value, "value");

            string identityColumnName = OrmUtil.GetIdentityColumnName <T>();

            string tableName = OrmUtil.GetTableName <T>();

            EntityProxy <T> entityProxy = EntityProxyManager.Instance.GetEntityProxy <T>();

            object identity = entityProxy.GetPropertyValue(value, identityColumnName);

            ThrowExceptionUtil.ArgumentConditionTrue(identity != null, string.Empty, "未指定主键列");

            if ((int)identity <= 0)
            {
                return(Insert <T>(value));
            }
            else
            {
                BeeDataAdapter dataAdapter = BeeDataAdapter.From <T>(value);
                dataAdapter.RemoveKey(identityColumnName);

                Update(tableName, dataAdapter, SqlCriteria.New.Equal(identityColumnName, identity));

                return((int)identity);
            }
        }
Exemple #3
0
        private void Init(bool forceFlag)
        {
            if (string.IsNullOrEmpty(mpToken) || forceFlag)
            {
                string weiXinUserName = ConfigUtil.GetAppSettingValue <string>("WeiXinUserName");
                string weiXinPassword = ConfigUtil.GetAppSettingValue <string>("WeiXinPassword");

                string password = SecurityUtil.MD5EncryptS(weiXinPassword).ToUpper();

                Dictionary <string, string> postData = httpClient.PostingData;

                postData.Add("username", weiXinUserName);
                postData.Add("pwd", password);
                postData.Add("f", "json");

                httpClient.Url             = "https://mp.weixin.qq.com/cgi-bin/login?lang=zh_CN";
                httpClient.Context.Referer = "https://mp.weixin.qq.com/";

                string response = httpClient.GetString();

                Match match = mpTokenRegex.Match(response);

                ThrowExceptionUtil.ArgumentConditionTrue(match.Success, "", "模拟登入微信公众平台失败!");

                if (match.Success)
                {
                    mpToken = match.Groups["token"].Value;
                }
            }
        }
        protected override void BuildCommand()
        {
            base.dbCommand.CommandText = this.spName;
            base.dbCommand.CommandType = CommandType.StoredProcedure;

            SPSchema schema = CacheManager.Instance.GetEntity <SPSchema, string>(owner.ConnectionName,
                                                                                 spName, TimeSpan.MaxValue,
                                                                                 (name) =>
            {
                return(owner.DbDriver.GetSpSchema(name));
            });

            ThrowExceptionUtil.ArgumentConditionTrue(schema != null, "tableName", "Can not find sp. Name:{0}".FormatWith(spName));

            DataAdapterParser dataAdapterParser = new DataAdapterParser(owner, dataAdapter);

            if (dataAdapter != null)
            {
                foreach (SPParameter spParameter in schema.ParameterList)
                {
                    DbParameter parameter = owner.DbDriver.CreateParameter();
                    parameter.ParameterName = spParameter.Name;
                    parameter.Direction     = spParameter.Direction;
                    //parameter.DbType = spParameter.DbType;
                    if (spParameter.DbType == "REF CURSOR")
                    {
                        IEntityProxy parameterProxy = EntityProxyManager.Instance.GetEntityProxyFromType(parameter.GetType());
                        if (parameter.GetType().Namespace == "System.Data.OracleClient")
                        {
                            parameterProxy.SetPropertyValue(parameter, "OracleType", 5);
                            //parameter.DbType = (DbType)5;
                        }
                        else
                        {
                            parameterProxy.SetPropertyValue(parameter, "OracleDbType", 0x79);
                        }
                    }

                    if (dataAdapter[spParameter.Name] != null)
                    {
                        parameter.Value = dataAdapter[spParameter.Name];
                    }
                    else
                    {
                        if (owner.DbDriver.DbTypeMap.ContainsKey(spParameter.DbType))
                        {
                            Type type = owner.DbDriver.DbTypeMap[spParameter.DbType];
                            parameter.Value = GetDefaultValue(type);

                            if (spParameter.Direction == ParameterDirection.InputOutput && spParameter.MaxLength > 0)
                            {
                                parameter.Size = spParameter.MaxLength * 2;
                            }
                        }
                    }

                    base.dbCommand.Parameters.Add(parameter);
                }
            }
        }
Exemple #5
0
        public void SendMessage(string openId, string content)
        {
            content = HttpUtility.HtmlDecode(content);
            bool result = WeiXinManager.Instance.SendMessage(openId, content);

            ThrowExceptionUtil.ArgumentConditionTrue(result, "", "发送失败!");
        }
Exemple #6
0
        private DbDriver GetDbDriver(string connectionName,
                                     string providerName, string connectionString)
        {
            DbDriver driver     = null;
            string   driverName = string.Empty;

            DataRow[] rows = providerTable.Select(string.Format("invariantname='{0}'", providerName));

            DbProviderFactory dbProviderFactory = null;

            if (rows != null && rows.Length > 0)
            {
                dbProviderFactory = DbProviderFactories.GetFactory(rows[0]);
            }
            else
            {
                if (string.Compare(providerName, "System.Data.SQLite", true) == 0)
                {
                    dbProviderFactory = ReflectionUtil.CreateInstance("System.Data.SQLite.SQLiteFactory, System.Data.SQLite") as DbProviderFactory;
                }
                else if (string.Compare(providerName, "Npgsql", true) == 0)
                {
                    dbProviderFactory = ReflectionUtil.CreateInstance("Npgsql.NpgsqlFactory, Npgsql") as DbProviderFactory;
                }
            }

            ThrowExceptionUtil.ArgumentConditionTrue(dbProviderFactory != null, "connectionKey",
                                                     "the providerName of the connection setting '{0}' error, please check it.".FormatWith(connectionName));

            string[] keyArray = connectionName.Split("#".ToCharArray());
            if (keyArray.Length == 2)
            {
                string key = keyArray[0];
                driverName = keyArray[1];

                driver = ReflectionUtil.CreateInstance(driverNameDict[string.Format(DriverClassNameTemplate, driverName)],
                                                       dbProviderFactory, connectionString, connectionName) as DbDriver;
            }

            if (driver == null)
            {
                foreach (string key in ruleDict.Keys)
                {
                    if (providerName.IndexOf(key, StringComparison.CurrentCultureIgnoreCase) >= 0)
                    {
                        driverName = ruleDict[key];
                        break;
                    }
                }

                driver = ReflectionUtil.CreateInstance(driverNameDict[string.Format(DriverClassNameTemplate, driverName)],
                                                       dbProviderFactory, connectionString, connectionName) as DbDriver;
            }

            ThrowExceptionUtil.ArgumentConditionTrue(driver != null, "connectionName",
                                                     "the connection setting '{0}' error, please check it.".FormatWith(connectionName));

            return(driver);
        }
Exemple #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="dataTable"></param>
        /// <param name="mapping"></param>
        /// <param name="notifyHandler"></param>
        /// <param name="notifyAfter"></param>
        public void SqlBulkCopy(string tableName, DataTable dataTable, Dictionary <string, string> mapping, SqlRowsCopiedEventHandler notifyHandler, int notifyAfter)
        {
            ThrowExceptionUtil.ArgumentNotNullOrEmpty(tableName, "tableName");
            ThrowExceptionUtil.ArgumentConditionTrue(dataTable != null && dataTable.Rows.Count > 0, "dataTable", "data can not be null or empty");

            SqlServerBulkCopyCommand command = new SqlServerBulkCopyCommand(this, tableName, dataTable, mapping, notifyHandler, notifyAfter);

            command.Excute <int>();
        }
        // Methods
        public UpdateBeeCommand(DbSession owner, string tableName, BeeDataAdapter data, SqlCriteria sqlCriteria)
            : base(owner, BeeDbCommandBehavior.NoQuery)
        {
            ThrowExceptionUtil.ArgumentNotNullOrEmpty(tableName, "tableName");
            ThrowExceptionUtil.ArgumentConditionTrue(data != null && data.Count != 0, "data", "data should not be null or empty.");

            this.tableName   = tableName;
            this.dataAdapter = data;
            this.sqlCriteria = sqlCriteria;
        }
        protected override void BuildCommand()
        {
            string whereClause        = string.Empty;
            string orderbyClauseValue = string.Empty;

            if (sqlCriteria != null)
            {
                this.sqlCriteria.Owner = owner;
                whereClause            = string.Format("{0}", sqlCriteria.WhereClause);

                base.dbCommand.Parameters.AddRange(sqlCriteria.DbParameters.ToArray());


                TableSchema tableSchema = owner.GetTableSchema(tableName);
            }
            else
            {
                whereClause = "1=1";
            }

            if (!string.IsNullOrEmpty(orderbyClause))
            {
                ThrowExceptionUtil.ArgumentConditionTrue(
                    !Regex.IsMatch(orderbyClause, @"[-|;|,|\/|\(|\)|\[|\]|\}|\{|%|\*|!|\']")
                    , string.Empty, "orderbyClause contains invalid code");

                orderbyClauseValue = string.Format("order by {0}", orderbyClause);
            }

            // 分页的三个条件, 起始页, 页大小, 排序规则
            if (pageSize > 0 && pageIndex >= 0)
            {
                if (string.IsNullOrEmpty(orderbyClause))
                {
                    orderbyClauseValue = string.Format("order by {0}", Constants.DefaultIdentityColumnName);
                }

                if (tableName.IndexOf(" join ") < 0)
                {
                    tableName = owner.DbDriver.FormatField(tableName);
                }

                base.dbCommand.CommandText = owner.DbDriver.GetPagedSelectCmdText(selectClause, tableName,
                                                                                  whereClause, orderbyClauseValue, pageIndex, pageSize);
            }
            else
            {
                base.dbCommand.CommandText = string.Format(
                    @"select {0} 
from {1} 
where {2}
{3}", selectClause, owner.DbDriver.FormatField(tableName), whereClause, orderbyClauseValue);
            }
        }
Exemple #10
0
        protected override DbDriver CreateInstance(string connectionName)
        {
            DbDriver driver     = null;
            string   driverName = string.Empty;

            ConnectionStringSettings setting = ConfigUtil.InnerGetConnectionString(connectionName);

            ThrowExceptionUtil.ArgumentConditionTrue(setting != null, "connectionKey",
                                                     "there is no connectionKey named '{0}'".FormatWith(connectionName));

            driver = GetDbDriver(connectionName, setting.ProviderName, setting.ConnectionString);

            return(driver);
        }
        public T Take()
        {
            lock (lockObject)
            {
                T result = default(T);

                ThrowExceptionUtil.ArgumentConditionTrue(innerQueue.Count > 0, string.Empty, "there is no item in queue");

                queueSizeLatch.CountDown();

                result = innerQueue.Dequeue();

                return(result);
            }
        }
Exemple #12
0
        public bool SendMessage(string openId, string content)
        {
            bool result = false;

            Init(false);

            Dictionary <string, string> postData = httpClient.PostingData;

            postData.Add("tofakeid", openId);
            postData.Add("token", MPToken);
            postData.Add("type", "1");
            postData.Add("content", content);
            postData.Add("ajax", "1");


            httpClient.Url             = " https://mp.weixin.qq.com/cgi-bin/singlesend?t=ajax-response&lang=zh_CN ";
            httpClient.Context.Referer =
                "https://mp.weixin.qq.com/cgi-bin/singlesendpage?t=message/send&action=index&tofakeid={0}&token={1}&lang=zh_CN".FormatWith(openId, MPToken);


            string response = httpClient.GetString();

            Match match = wxGeneralResultRegext.Match(response);

            if (match.Success)
            {
                string ret = match.Groups["ret"].Value;
                string msg = match.Groups["msg"].Value;

                if (ret == "0")
                {
                    result = true;
                }
                else
                {
                    Init(true);
                }
            }

            ThrowExceptionUtil.ArgumentConditionTrue(result, "", "发送失败!");

            return(result);
        }
        private static void SearchControllers(Assembly assembly)
        {
            foreach (var type in assembly.GetTypes())
            {
                if (!type.IsInterface && !type.IsAbstract && type.IsSubclassOf(CbType) &&
                    !type.IsGenericType &&
                    type.Name.EndsWith("Controller"))
                {
                    var ci = new ControllerInfo(type);

                    if (ci.DefaultFlag)
                    {
                        ControllerManager.DefaultControllerName = ci.LowerName;
                    }

                    ThrowExceptionUtil.ArgumentConditionTrue(!ControllerDict.ContainsKey(ci.LowerName),
                                                             string.Empty, "ControllerName: {0} has existed".FormatWith(ci.LowerName));

                    ControllerDict[ci.LowerName] = ci;
                }
            }
        }
        private SqlCriteria VisitExpression(Expression expr)
        {
            SqlCriteria sqlCriteria = new SqlCriteria();

            if (expr.NodeType == ExpressionType.Equal) // ==
            {
                var bin = expr as BinaryExpression;

                ThrowExceptionUtil.ArgumentConditionTrue(bin.Left is MemberExpression, "expr", "left expression should be MemberExpression");

                if (bin.Right is MemberExpression)
                {
                    return(sqlCriteria.CEqual(this.VisitMember(bin.Left), this.VisitMember(bin.Right)));
                }
                else
                {
                    return(sqlCriteria.Equal(this.VisitMember(bin.Left), this.VisitValue(bin.Right)));
                }
            }
            else if (expr is MemberExpression && expr.Type == typeof(bool)) // x.Active
            {
                return(sqlCriteria.Equal(this.VisitMember(expr), true));
            }
            else if (expr.NodeType == ExpressionType.Not) // !x.Active
            {
                return(sqlCriteria.Equal(this.VisitMember(expr), false));
            }
            else if (expr.NodeType == ExpressionType.NotEqual) // !=
            {
                var bin = expr as BinaryExpression;

                ThrowExceptionUtil.ArgumentConditionTrue(bin.Left is MemberExpression, "expr", "left expression should be MemberExpression");

                if (bin.Right is MemberExpression)
                {
                    return(sqlCriteria.CNotEqual(this.VisitMember(bin.Left), this.VisitMember(bin.Right)));
                }
                else
                {
                    return(sqlCriteria.NotEqual(this.VisitMember(bin.Left), this.VisitValue(bin.Right)));
                }
            }
            else if (expr.NodeType == ExpressionType.LessThan) // <
            {
                var bin = expr as BinaryExpression;
                ThrowExceptionUtil.ArgumentConditionTrue(bin.Left is MemberExpression, "expr", "left expression should be MemberExpression");

                if (bin.Right is MemberExpression)
                {
                    return(sqlCriteria.CLessThan(this.VisitMember(bin.Left), this.VisitMember(bin.Right)));
                }
                else
                {
                    return(sqlCriteria.LessThan(this.VisitMember(bin.Left), this.VisitValue(bin.Right)));
                }
            }
            else if (expr.NodeType == ExpressionType.LessThanOrEqual) // <=
            {
                var bin = expr as BinaryExpression;
                ThrowExceptionUtil.ArgumentConditionTrue(bin.Left is MemberExpression, "expr", "left expression should be MemberExpression");

                if (bin.Right is MemberExpression)
                {
                    return(sqlCriteria.CLessThanOrEqual(this.VisitMember(bin.Left), this.VisitMember(bin.Right)));
                }
                else
                {
                    return(sqlCriteria.LessThanOrEqual(this.VisitMember(bin.Left), this.VisitValue(bin.Right)));
                }
            }
            else if (expr.NodeType == ExpressionType.GreaterThan) // >
            {
                var bin = expr as BinaryExpression;
                ThrowExceptionUtil.ArgumentConditionTrue(bin.Left is MemberExpression, "expr", "left expression should be MemberExpression");

                if (bin.Right is MemberExpression)
                {
                    return(sqlCriteria.CGreaterThan(this.VisitMember(bin.Left), this.VisitMember(bin.Right)));
                }
                else
                {
                    return(sqlCriteria.GreaterThan(this.VisitMember(bin.Left), this.VisitValue(bin.Right)));
                }
            }
            else if (expr.NodeType == ExpressionType.GreaterThanOrEqual) // >=
            {
                var bin = expr as BinaryExpression;

                ThrowExceptionUtil.ArgumentConditionTrue(bin.Left is MemberExpression, "expr", "left expression should be MemberExpression");

                if (bin.Right is MemberExpression)
                {
                    return(sqlCriteria.CGreaterThanOrEqual(this.VisitMember(bin.Left), this.VisitMember(bin.Right)));
                }
                else
                {
                    return(sqlCriteria.GreaterThanOrEqual(this.VisitMember(bin.Left), this.VisitValue(bin.Right)));
                }
            }
            else if (expr is MethodCallExpression)
            {
                var met    = expr as MethodCallExpression;
                var method = met.Method.Name;

                // StartsWith
                if (method == "StartsWith")
                {
                    var value = this.VisitValue(met.Arguments[0]).ToString();

                    return(sqlCriteria.StartWith(this.VisitMember(met.Object), value));
                }
                // Contains
                else if (method == "Contains")
                {
                    var value = this.VisitValue(met.Arguments[0]).ToString();

                    return(sqlCriteria.Contains(this.VisitMember(met.Object), value));
                }
                // Equals
                else if (method == "Equals")
                {
                    if (met.Arguments[0] is MemberExpression)
                    {
                        return(sqlCriteria.CEqual(this.VisitMember(met.Object), this.VisitMember(met.Arguments[0])));
                    }
                    else
                    {
                        var value = this.VisitValue(met.Arguments[0]);
                        return(sqlCriteria.Equal(this.VisitMember(met.Object), value));
                    }
                }
                // System.Linq.Enumerable methods
                else if (met.Method.DeclaringType.FullName == "System.Linq.Enumerable")
                {
                    //return ParseEnumerableExpression(met);
                }
            }
            else if (expr is BinaryExpression && expr.NodeType == ExpressionType.AndAlso)
            {
                // AND
                var bin   = expr as BinaryExpression;
                var left  = this.VisitExpression(bin.Left);
                var right = this.VisitExpression(bin.Right);

                return(left.And(right));
            }
            else if (expr is BinaryExpression && expr.NodeType == ExpressionType.OrElse)
            {
                // OR
                var bin   = expr as BinaryExpression;
                var left  = this.VisitExpression(bin.Left);
                var right = this.VisitExpression(bin.Right);

                return(left.Or(right));
            }

            throw new NotImplementedException("Not implemented Linq expression");
        }
Exemple #15
0
        public string Upload()
        {
            string inputname = "filedata";
            string attachdir = "/Resources/upimages";     // 上传文件保存路径,结尾不要带/

            System.Web.HttpRequest request = HttpContextUtil.CurrentHttpContext.Request;


            string disposition = request.ServerVariables["HTTP_CONTENT_DISPOSITION"];
            Stream fileData;
            string localname;

            if (disposition != null)
            {
                // HTML5上传
                byte[] file = request.BinaryRead(request.TotalBytes);
                fileData  = new MemoryStream(file);
                localname = HttpUtility.UrlDecode(Regex.Match(disposition, "filename=\"(.+?)\"").Groups[1].Value);// 读取原始文件名
            }
            else
            {
                HttpFileCollection filecollection = request.Files;
                HttpPostedFile     postedfile     = filecollection.Get(inputname);

                // 读取原始文件名
                localname = postedfile.FileName;

                fileData = postedfile.InputStream;

                filecollection = null;
            }

            string extension = localname.Substring(localname.LastIndexOf('.') + 1);
            bool   extFlag   = ExtArrayString.IndexOf(extension) >= 0;

            ThrowExceptionUtil.ArgumentConditionTrue(extFlag, "fileName", "不能上传该文件。");

            ThrowExceptionUtil.ArgumentConditionTrue(fileData.Length > 0 && fileData.Length < MaxFileLength, "filedata", "文件大小超过{0}字节".FormatWith(MaxFileLength));

            string attach_dir, attach_subdir, err;

            attach_subdir = "day_" + DateTime.Now.ToString("yyMMdd");

            attach_dir = attachdir + "/" + attach_subdir + "/";

            Random random   = new Random(DateTime.Now.Millisecond);
            string filename = DateTime.Now.ToString("yyyyMMddhhmmss") + random.Next(10000) + "." + extension;

            try
            {
                string dir = HttpContextUtil.CurrentHttpContext.Server.MapPath(attach_dir);
                IOUtil.SafeCreateDirectory(dir);

                System.IO.FileStream fs = new System.IO.FileStream(IOUtil.CombinePath(dir, filename)
                                                                   , System.IO.FileMode.Create, System.IO.FileAccess.Write);

                int    buffSize = (int)fileData.Length;
                byte[] buff     = new Byte[buffSize];
                fileData.Read(buff, 0, buffSize);
                fileData.Close();

                fs.Write(buff, 0, buffSize);

                fs.Flush();
                fs.Close();
            }
            catch (Exception ex)
            {
                err = ex.Message.ToString();
            }


            return(attach_dir + filename);
        }
Exemple #16
0
        protected override void BuildCommand()
        {
            BeeDataAdapter columnDataAdapter = new BeeDataAdapter();

            columnDataAdapter.Merge(this.dataAdapter, true);

            // 移除不存在的列名 及 计算列
            TableSchema tableSchema = owner.GetTableSchema(tableName);

            ThrowExceptionUtil.ArgumentConditionTrue(tableSchema != null, "tableName", "can not find table. Name:{0}".FormatWith(tableName));

            List <string> needToRemovedList = new List <string>();

            foreach (string key in columnDataAdapter.Keys)
            {
                ColumnSchema columnSchema = tableSchema.GetColumn(key);

                if (columnSchema == null)
                {
                    needToRemovedList.Add(key);
                }
                else if (columnSchema.IsComputeField)
                {
                    needToRemovedList.Add(key);
                }
                else
                {
                    // do nothing here.
                }
            }

            if (tableSchema.IdentityColumn != null)
            {
                needToRemovedList.Add(tableSchema.IdentityColumn.ColumnName);
            }

            foreach (string key in needToRemovedList)
            {
                columnDataAdapter.RemoveKey(key);
            }

            DataAdapterParser dataAdapterParser = new DataAdapterParser(owner, columnDataAdapter);

            base.dbCommand.Parameters.AddRange(dataAdapterParser.DbParameterList.ToArray());

            string whereClause = string.Empty;

            if (sqlCriteria != null)
            {
                this.sqlCriteria.Owner = owner;
                whereClause            = string.Format("where {0}", sqlCriteria.WhereClause);

                base.dbCommand.Parameters.AddRange(sqlCriteria.DbParameters.ToArray());
            }

            if (owner.DbDriver.GetType() == typeof(OracleDriver))
            {
                string sqlText = string.Format("update {0} set {1} {2}",
                                               owner.DbDriver.FormatField(this.tableName), dataAdapterParser.UpdateClause, whereClause);

                sqlText = sqlText.Replace(Environment.NewLine, " ");
                base.dbCommand.CommandText = sqlText;
            }
            else
            {
                base.dbCommand.CommandText = string.Format("update {0} \r\nset {1} \r\n{2}",
                                                           owner.DbDriver.FormatField(this.tableName), dataAdapterParser.UpdateClause, whereClause);
            }
        }
Exemple #17
0
        protected override void BuildCommand()
        {
            base.dbCommand.CommandType = CommandType.Text;

            BeeDataAdapter columnDataAdapter = new BeeDataAdapter();

            columnDataAdapter.Merge(this.dataAdapter, true);

            // 移除不存在的列名
            TableSchema tableSchema = owner.GetTableSchema(tableName);

            ThrowExceptionUtil.ArgumentConditionTrue(tableSchema != null, "tableName", "can not find table. Name:{0}".FormatWith(tableName));

            List <string> needToRemovedList = new List <string>();

            foreach (string key in columnDataAdapter.Keys)
            {
                ColumnSchema columnSchema = tableSchema.GetColumn(key);

                if (columnSchema == null)
                {
                    needToRemovedList.Add(key);
                }
                else if (columnSchema.IsComputeField)
                {
                    needToRemovedList.Add(key);
                }
                else
                {
                    // do nothing here.
                }
            }

            foreach (string key in needToRemovedList)
            {
                columnDataAdapter.RemoveKey(key);
            }

            DataAdapterParser dataAdapterParser = new DataAdapterParser(owner, columnDataAdapter);

            base.dbCommand.CommandText = string.Format(@" 
insert into {0} 
({1})
values
({2});"
                                                       , owner.DbDriver.FormatField(this.tableName)
                                                       , dataAdapterParser.ColumnClause, dataAdapterParser.ParameterClause);

            if (owner.DbServerType == DBServerType.Oracle)
            {
                string sqlText = string.Format(@"begin
    {0}
                    end;", base.dbCommand.CommandText);

                sqlText = sqlText.Replace(Environment.NewLine, " ");
                base.dbCommand.CommandText = sqlText;
            }
            else if (owner.DbServerType == DBServerType.Pgsql)
            {
                if (!string.IsNullOrEmpty(identityColumnName))
                {
                    string identitySelectString = string.Format(@"; SELECT {0} ", owner.DbDriver.IdentitySelectString);
                    identitySelectString = string.Format(identitySelectString, tableName).ToLower();

                    base.dbCommand.CommandText = base.dbCommand.CommandText + identitySelectString;
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(identityColumnName))
                {
                    string identitySelectString = string.Format(@" SELECT {0}", owner.DbDriver.IdentitySelectString);

                    base.dbCommand.CommandText = base.dbCommand.CommandText + identitySelectString;
                }
            }

            base.dbCommand.Parameters.AddRange(dataAdapterParser.DbParameterList.ToArray());
        }
Exemple #18
0
        public void Link(string openId)
        {
            bool result = WeiXinManager.Instance.SendMessage(openId, "邀请您体验推送功能, 请复制该消息并回复。$校验码${0}".FormatWith(SecurityUtil.EncryptS(openId, ConfigUtil.GetAppSettingValue <string>("WeiXinToken").Substring(0, 8))));

            ThrowExceptionUtil.ArgumentConditionTrue(result, "", "发送失败!");
        }
Exemple #19
0
 public void Create2(BeeDataAdapter dataAdapter)
 {
     ThrowExceptionUtil.ArgumentConditionTrue(dataAdapter.TryGetValue <string>("name", string.Empty) == "admin", string.Empty, "not null");
 }
Exemple #20
0
 public void Create(Person person)
 {
     ThrowExceptionUtil.ArgumentConditionTrue(person.Name == "admin", string.Empty, "not null");
 }