Exemplo n.º 1
0
        /// <summary>
        /// 添加一条数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool Add(Config model)
        {
            int maxID = DbHelperOleDb.GetMaxID("ID", "Config");

            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into Config(");
            strSql.Append("ConName,ConValue,ID,ConType)");
            strSql.Append(" values (");
            strSql.Append("@ConName,@ConValue,@ID,@ConType)");
            OleDbParameter[] parameters = {
                    new OleDbParameter("@ConName", OleDbType.VarChar,255),
                    new OleDbParameter("@ConValue", OleDbType.VarChar,255),
                    new OleDbParameter("@ID", OleDbType.Integer,4),
                    new OleDbParameter("@ConType",OleDbType.VarChar,255)};
            parameters[0].Value = model.ConName;
            parameters[1].Value = model.ConValue;
            parameters[2].Value = maxID;
            parameters[3].Value = model.ConType;

            int rows = DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Config model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Config set ");
            strSql.Append("ConName=@ConName,");
            strSql.Append("ConValue=@ConValue,");
            strSql.Append("ConType=@ConType");
            strSql.Append(" where ID=@ID");
            OleDbParameter[] parameters = {
                    new OleDbParameter("@ConName", OleDbType.VarChar,255),
                    new OleDbParameter("@ConValue", OleDbType.VarChar,255),
                    new OleDbParameter("@ConType",OleDbType.VarChar,255),
                    new OleDbParameter("@ID", OleDbType.Integer,4)};
            parameters[0].Value = model.ConName;
            parameters[1].Value = model.ConValue;
            parameters[2].Value = model.ConType;
            parameters[3].Value = model.ID;

            int rows = DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
Exemplo n.º 3
0
 private Config DataRowToModel(DataRow row)
 {
     Config model = new Config();
     if (row != null)
     {
         if (row["ID"] != null && row["ID"].ToString() != "")
         {
             model.ID = int.Parse(row["ID"].ToString());
         }
         if (row["ConName"] != null)
         {
             model.ConName = row["ConName"].ToString();
         }
         if (row["ConValue"] != null)
         {
             model.ConValue = row["ConValue"].ToString();
         }
         if (row["ConType"] != null)
         {
             model.ConType = row["ConType"].ToString();
         }
     }
     return model;
 }
Exemplo n.º 4
0
 /// <summary>
 /// 保存配置信息
 /// </summary>
 private void SaveConfig()
 {
     List<Config> list = new List<Config>();
     Config config;
     foreach (Control control in this.ControlList)
     {
         if (control.Tag != null)
         {
             if (control.Tag is Config)
             {
                 config = control.Tag as Config;
             }
             else
             {
                 config = new Config();
                 config.ConName = control.Tag.ToString();
                 config.ConType = control.GetType().Name;
             }
             config.ConValue = GetConValue(control);
             list.Add(config);
         }
     }
     dal.BatchUpdate(list);
 }