Exemplo n.º 1
0
        public string GenerateSqlStatement(TableEntity tableEntity, bool generateDescription = true)
        {
            if (string.IsNullOrWhiteSpace(tableEntity?.TableName))
            {
                return("");
            }
            var sbSqlText = new StringBuilder();

            var sbSqlDescText = new StringBuilder();

            //create table
            sbSqlText.AppendLine($"---------- Create Table 【{tableEntity.TableName}】 Sql -----------");
            sbSqlText.Append($"CREATE TABLE [{(string.IsNullOrWhiteSpace(tableEntity.TableSchema) ? "dbo" : tableEntity.TableSchema)}].[{tableEntity.TableName.Trim()}](");
            //create description
            if (generateDescription && !string.IsNullOrEmpty(tableEntity.TableDescription))
            {
                sbSqlDescText.AppendFormat(CreateTableDescSqlFormat, tableEntity.TableName, tableEntity.TableDescription);
            }
            if (tableEntity.Columns.Count > 0)
            {
                foreach (var col in tableEntity.Columns)
                {
                    sbSqlText.AppendLine();
                    sbSqlText.AppendFormat("\t[{0}] {1}", col.ColumnName.Trim(), col.DataType);
                    if (col.DataType.ToUpperInvariant().Contains("CHAR"))
                    {
                        sbSqlText.Append($"({col.Size})");
                    }
                    if (col.IsPrimaryKey)
                    {
                        sbSqlText.Append(" PRIMARY KEY");
                        if (col.DataType.Contains("INT"))
                        {
                            sbSqlText.Append(" IDENTITY(1,1) ");
                        }
                    }
                    //Nullable
                    if (!col.IsNullable)
                    {
                        sbSqlText.Append(" NOT NULL");
                    }
                    //Default Value
                    if (!string.IsNullOrEmpty(col.DefaultValue?.ToString()))
                    {
                        if (!col.IsPrimaryKey)
                        {
                            if ((col.DataType.Contains("CHAR") || col.DataType.Contains("TEXT")) &&
                                !col.DefaultValue.ToString().StartsWith("N'") && !col.DefaultValue.ToString().StartsWith("'"))
                            {
                                sbSqlText.AppendFormat(" DEFAULT(N'{0}')", col.DefaultValue);
                            }
                            else
                            {
                                switch (col.DataType)
                                {
                                case "BIT":
                                    if (col.DefaultValue is bool bVal)
                                    {
                                        sbSqlText.AppendFormat(" DEFAULT({0}) ", bVal ? 1 : 0);
                                    }

                                    break;

                                default:
                                    sbSqlText.AppendFormat(" DEFAULT({0}) ", col.DefaultValue);
                                    break;
                                }
                            }
                        }
                    }
                    //
                    sbSqlText.Append(",");
                    //
                    if (generateDescription && !string.IsNullOrEmpty(col.ColumnDescription))
                    {
                        sbSqlDescText.AppendLine();
                        sbSqlDescText.AppendFormat(ConfigurationHelper.AppSetting(ConfigurationConstants.DbDescriptionGenType).EqualsIgnoreCase("AddOrUpdate") ? CreateOrUpdateColumnDescSqlFormat : CreateColumnDescSqlFormat, tableEntity.TableName, col.ColumnName, col.ColumnDescription);
                    }
                }
                sbSqlText.Remove(sbSqlText.Length - 1, 1);
                sbSqlText.AppendLine();
            }
            sbSqlText.AppendLine(");");
            if (generateDescription && sbSqlDescText.Length > 0)
            {
                sbSqlText.AppendLine();
                sbSqlText.AppendLine($"---------- Create Table 【{tableEntity.TableName}】 Description Sql -----------");
                sbSqlText.Append(sbSqlDescText);
            }
            sbSqlText.AppendLine();
            return(sbSqlText.ToString());
        }
Exemplo n.º 2
0
        /// <summary>
        /// 微信登录
        /// add by fruitchan
        /// 2017-1-4 20:33:56
        /// </summary>
        /// <param name="code">code</param>
        /// <param name="code">state</param>
        /// <returns>Redirect</returns>
        public ActionResult DoWeixinLogin(string code, string state)
        {
            string appId = ConfigurationHelper.AppSetting("WeixinAppID");

            if (!String.IsNullOrEmpty(code) && !String.IsNullOrEmpty(state))
            {
                // 校验state
                if (Session["State"] == null || Session["State"].ToString() != state)
                {
                    return(Content("登录失败!"));
                }

                Session["State"] = null;

                // 通过code获取access_token
                string appSecret = ConfigurationHelper.AppSetting("WeixinAppSecret");

                StringBuilder strUrl = new StringBuilder();
                strUrl.Append("https://api.weixin.qq.com/sns/oauth2/access_token?appid=");
                strUrl.Append(appId);
                strUrl.Append("&secret=");
                strUrl.Append(appSecret);
                strUrl.Append("&code=");
                strUrl.Append(code);
                strUrl.Append("&grant_type=authorization_code");

                string jsonAccessToken = HttpHelper.RequestURL(strUrl.ToString(), null, "GET");

                if (!String.IsNullOrEmpty(jsonAccessToken))
                {
                    AccessToken token = JsonConvert.DeserializeObject <AccessToken>(jsonAccessToken);

                    if (token != null && !String.IsNullOrEmpty(token.access_token) && !String.IsNullOrEmpty(token.openid))
                    {
                        // 通过Token获取用户信息
                        string url = "https://api.weixin.qq.com/sns/userinfo?access_token=" + token.access_token + "&openid=" + token.openid;

                        string jsonUserInfo = HttpHelper.RequestURL(url, null, "GET");

                        if (!String.IsNullOrEmpty(jsonUserInfo))
                        {
                            WeixinUserInfo weixinUserInfo = JsonConvert.DeserializeObject <WeixinUserInfo>(jsonUserInfo);

                            if (weixinUserInfo != null && !String.IsNullOrEmpty(weixinUserInfo.unionid))
                            {
                                OperateContext.Current.UserLogin(new UserInfoView()
                                {
                                    Gender        = weixinUserInfo.sex,
                                    Img           = weixinUserInfo.headimgurl,
                                    Nikename      = weixinUserInfo.nickname,
                                    Username      = weixinUserInfo.nickname,
                                    WeixinUnionid = weixinUserInfo.unionid
                                }, 2, true);
                            }
                            else
                            {
                                return(Content("登录失败:解析微信用户信息失败!" + jsonUserInfo));
                            }
                        }
                        else
                        {
                            return(Content("登录失败:获取微信用户信息失败!"));
                        }
                    }
                    else
                    {
                        return(Content("登录失败:解析Token失败!" + jsonAccessToken));
                    }
                }
                else
                {
                    return(Content("登录失败:获取微信Token失败!"));
                }

                return(Redirect("/Home/Index"));
            }
            else
            {
                // https://open.weixin.qq.com/connect/qrconnect?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect

                string redirectUri = HttpUtility.UrlEncode(ConfigurationHelper.AppSetting("RedirectUri"));
                string strState    = Guid.NewGuid().ToString().Replace("-", "");
                Session["State"] = strState;

                StringBuilder sbUrl = new StringBuilder();
                sbUrl.Append("https://open.weixin.qq.com/connect/qrconnect?appid=");
                sbUrl.Append(appId);
                sbUrl.Append("&redirect_uri=");
                sbUrl.Append(redirectUri);
                sbUrl.Append("&response_type=code&scope=snsapi_login");
                sbUrl.Append("&state=");
                sbUrl.Append(strState);
                sbUrl.Append("#wechat_redirect");

                return(Redirect(sbUrl.ToString()));
            }
        }
Exemplo n.º 3
0
 static SentryLogHelperLogger()
 {
     SentryClient =
         new RavenClient(ConfigurationHelper.AppSetting("SentryClientKey"));
 }
Exemplo n.º 4
0
        // 获取公众号全局token
        public static string GetAccessToken()
        {
            if (String.IsNullOrEmpty(access_token) || expires_time == null || expires_time <= DateTime.Now)
            {
                //string url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + WxPayAPI.WxPayConfig.APPID + "&secret=" + WxPayAPI.WxPayConfig.APPSECRET;
                string url       = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + ConfigurationHelper.AppSetting("WeixinAppID") + "&secret=" + ConfigurationHelper.AppSetting("WeixinAppSecret");
                string jsonToken = HttpHelper.RequestURL(url, null, "GET");

                if (!String.IsNullOrEmpty(jsonToken))
                {
                    AccessToken accessToken = JsonConvert.DeserializeObject <AccessToken>(jsonToken);

                    if (accessToken != null && !String.IsNullOrEmpty(accessToken.access_token))
                    {
                        access_token = accessToken.access_token;
                        expires_time = DateTime.Now.AddSeconds(accessToken.expires_in - 60);
                    }
                }
            }

            return(access_token);
        }