예제 #1
0
        /// <summary>
        /// 点击测试连接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnTestConn_Click(object sender, EventArgs e)
        {
            ISimpleFactory <string, IDbConnection> factory = AutofacTool.Resolve <ISimpleFactory <string, IDbConnection> >();
            IDbConnection dbConnection = factory.Create(cbxDataSourceType.SelectedItem.ToString());

            try
            {
                dbConnection.ConnectionString = GetDbConnectionString();
                dbConnection.Open();
                if (dbConnection.State == ConnectionState.Open)
                {
                    dbConnection.Close();
                    dbConnection.Dispose();

                    MessageBox.Show("连接成功");
                }
                else
                {
                    MessageBox.Show("连接失败");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #2
0
        /// <summary>
        /// 创建通用数据
        /// </summary>
        /// <param name="context">上下文</param>
        /// <param name="factory">通用数据工厂</param>
        /// <param name="key">键</param>
        /// <param name="menuCode">菜单编码</param>
        /// <param name="functionCodes">功能编码数组</param>
        /// <returns>通用数据</returns>
        public static CommonUseData CreateCommonUseData(this HttpContext context, ISimpleFactory <HttpContext, CommonUseData> factory, string key = null, string menuCode = null, params string[] functionCodes)
        {
            if (factory != null)
            {
                var result = factory.Create(context);
                if (result != null)
                {
                    result.Key           = key;
                    result.MenuCode      = menuCode;
                    result.FunctionCodes = functionCodes;

                    return(result);
                }
            }

            var comData = context.CreateBasicCommonUseData();

            if (string.IsNullOrWhiteSpace(comData.EventId))
            {
                comData.EventId = StringUtil.NewShortGuid();
            }

            return(comData);
        }