コード例 #1
0
        /// <summary>
        /// 简单获取
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="con"></param>
        /// <param name="model"></param>
        /// <param name="sqlWhere"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        public static TModel SimpleGet <TModel>(this IDbConnection con, TModel model, string sqlWhere = null, IDbTransaction transaction = null)
        {
            DBInfo dbInfo = DBInfoHelper.GetDBInfo(con);
            string sql    = Model.GRUDHelper.GetSql <TModel>(sqlWhere, dbInfo.idName);

            return(con.QueryFirstOrDefault <TModel>(sql, model, transaction));
        }
コード例 #2
0
        /// <summary>
        /// 简单更新
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="con"></param>
        /// <param name="model"></param>
        /// <param name="sqlWhere"></param>
        /// <param name="transaction"></param>
        public static bool SimpleUpdate <TModel>(this IDbConnection con, TModel model, string sqlWhere = null, IDbTransaction transaction = null)
        {
            DBInfo dbInfo = DBInfoHelper.GetDBInfo(con);
            string sql    = Model.GRUDHelper.GetUpdateSql <TModel>(sqlWhere, dbInfo.idName);

            return(con.Execute(sql, model) > 0);
        }
コード例 #3
0
        //public static string selectIdSql = ";select @@IDENTITY";
        //public static string idName = "id";
        /// <summary>
        /// 简单插入
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="con"></param>
        /// <param name="model"></param>
        /// <param name="sqlWhere"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        public static TKey SimpleInsert <TKey, TModel>(this IDbConnection con, TModel model, string sqlWhere = null, IDbTransaction transaction = null)
        {
            DBInfo dbInfo = DBInfoHelper.GetDBInfo(con);
            string sql    = Model.GRUDHelper.GetInsertSql <TModel>(sqlWhere, dbInfo.selectIdSql);

            return(con.ExecuteScalar <TKey>(sql + dbInfo.selectIdSql));
        }
コード例 #4
0
        /// <summary>
        /// 获取前N行
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="con"></param>
        /// <param name="top"></param>
        /// <param name="sqlWhere"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        public static IEnumerable <TModel> SimpleGetTop <TModel>(this IDbConnection con, int top, string sqlWhere = null, IDbTransaction transaction = null)
        {
            DBInfo dbInfo = DBInfoHelper.GetDBInfo(con);
            string sql    = Model.GRUDHelper.GetTopSql <TModel>(top, dbInfo.dbType, sqlWhere);

            return(con.Query <TModel>(sql, transaction));
        }
コード例 #5
0
        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="con"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <param name="sqlWhere"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        public static IEnumerable <TModel> SimpleGetPage <TModel>(this IDbConnection con, int pageIndex, int pageSize, out int count, string sqlWhere = null, IDbTransaction transaction = null)
        {
            DBInfo dbInfo = DBInfoHelper.GetDBInfo(con);
            string countSql;
            string sql = Model.GRUDHelper.GetPageSql <TModel>(sqlWhere, dbInfo.idName, dbInfo.dbType, pageIndex, pageSize, out countSql);

            count = con.ExecuteScalar <int>(countSql);
            return(con.Query <TModel>(sql, transaction));
        }
コード例 #6
0
        private void btnConnectTest_Click(object sender, EventArgs e)
        {
            frm_DatabaseConfig frmdb = new frm_DatabaseConfig();

            if (frmdb.ShowDialog(this) == DialogResult.OK)
            {
                DBInfo Dbinfo = DBInfoHelper.GetDbInfoFromFile(Application.StartupPath + "\\dbinfo.kdc");
                MysqlEasy.ConnectionString = "server=" + Dbinfo.server + ";port=" + Dbinfo.port + ";database=" + Dbinfo.database
                                             + ";uid=" + Dbinfo.uid + ";pwd=" + Dbinfo.pwd + ";Allow User Variables = True";
            }
        }
コード例 #7
0
        public frm_DatabaseConfig()
        {
            InitializeComponent();

            DBInfo Dbinfo = DBInfoHelper.GetDbInfoFromFile(Application.StartupPath + "\\dbinfo.kdc");

            txtServerIP.Text = Dbinfo.server;
            txtPort.Text     = Dbinfo.port;
            txtDBName.Text   = Dbinfo.database;
            txtUID.Text      = Dbinfo.uid;
            txtPSW.Text      = Dbinfo.pwd;
        }
コード例 #8
0
        public frm_SplashAhead()
        {
            InitializeComponent();
            // MysqlEasy.ConnectionString = ConfigurationManager.ConnectionStrings["RemoteDbConnnect"].ConnectionString;
            backgroundWorker.WorkerReportsProgress      = true;
            backgroundWorker.WorkerSupportsCancellation = true;
            this.panel.BackColor = Color.FromArgb(50, Color.White);

            DBInfo Dbinfo = DBInfoHelper.GetDbInfoFromFile(Application.StartupPath + "\\dbinfo.kdc");

            MysqlEasy.ConnectionString = "server=" + Dbinfo.server + ";port=" + Dbinfo.port + ";database=" + Dbinfo.database
                                         + ";uid=" + Dbinfo.uid + ";pwd=" + Dbinfo.pwd + ";Allow User Variables = True";
        }
コード例 #9
0
        private void btnSaveConfigInfo_Click(object sender, EventArgs e)
        {
            DBInfo Dbinfo = new DBInfo();

            Dbinfo.server   = txtServerIP.Text;
            Dbinfo.port     = txtPort.Text;
            Dbinfo.database = txtDBName.Text;
            Dbinfo.uid      = txtUID.Text;
            Dbinfo.pwd      = txtPSW.Text;

            if (DBInfoHelper.SaveDbInfo(Dbinfo, Application.StartupPath + "\\dbinfo.kdc"))
            {
                XtraMessageBox.Show("数据库信息配置成功", "提示");
                this.DialogResult = DialogResult.OK;
                this.Dispose();
                this.Close();
            }
            else
            {
                XtraMessageBox.Show("数据库信息配置失败,请检查数据库配置文件是否有读写权限", "提示");
            }
        }