隨筆 - 30, 文章 - 0, 評(píng)論 - 9, 引用 - 0
          數(shù)據(jù)加載中……

          置頂隨筆

          [置頂]解決downlist 等優(yōu)先極高于其它控件,浮在其它控件上面

           <iframe style="position:absolute;z-index:9;width:expression(this.nextSibling.offsetWidth);height:expression(this.nextSibling.offsetHeight);top:expression(this.nextSibling.offsetTop);left:expression(this.nextSibling.offsetLeft);" frameborder="0" ></iframe>
            <div id="divTool" onmouseover="javascript:showdiv123()" onmouseout="javascript:HiddivTool()" class="class_title"  style="display:none">
          <table width="100" border="0"  align="center" cellpadding="0" cellspacing="0">
            <tr>
              <td height="20" colspan="2" bgcolor="ffffff" style="width: 100px" >&nbsp;&nbsp;<span class="t1" style="cursor:hand" name="layout/AddPage.aspx" onclick="javascript:openMyPage(this)">More tools</span></td>
            </tr>
            <tr>
              <td height="20" colspan="2"  bgcolor="ffffff"  style="width: 100px">&nbsp;&nbsp;<a href="#">About this tools</a></td>
            </tr><tr>
              <td height="8" colspan="2" bgcolor="ffffff" style="width: 100px"></td>
            </tr>
           
            </table>
          </div>

          posted @ 2007-12-26 14:35 風(fēng)雨兼程 閱讀(336) | 評(píng)論 (0)編輯 收藏

          [置頂]IList GetCategories();的問(wèn)題

          petshop4.0中的一段代碼  
             
            public   interface   ICategory   {  
             
            ///   <summary>  
            ///   Method   to   get   all   categories  
            ///   </summary>  
                            ///   <returns>Interface   to   Model   Collection   Generic   of   categories</returns>  
                       
                           
            IList<CategoryInfo>   GetCategories();  
                           
             
                            ///   <summary>  
                            ///   Get   information   on   a   specific   category  
                            ///   </summary>  
                            ///   <param   name="categoryId">Unique   identifier   for   a   category</param>  
                            ///   <returns>Business   Entity   representing   an   category</returns>  
                            CategoryInfo   GetCategory(string   categoryId);  
            }  
             
             
            我知道IList<CategoryInfo>是范型  
            表示list中的item是CategoryInfo對(duì)象  
             
             
            請(qǐng)問(wèn)為什么用IList<CategoryInfo>  
            用List<CategoryInfo>可以嗎?  
             
            兩者有什么區(qū)別?謝謝  

          沒(méi)有什么區(qū)別,這樣寫(xiě)靈活性大,實(shí)現(xiàn)ilist接口的類(lèi)很多,你寫(xiě)成list后,也許以后你要改成非list的,就會(huì)要改很多代碼
          舉個(gè)例子  
             
            RenderControlToString(DataList   L//Control   C)  
             
            你認(rèn)為是寫(xiě)control還是寫(xiě)datalist代碼的通用性高?

            OOP編碼原則:盡可能用接口編程

          posted @ 2007-12-26 11:44 風(fēng)雨兼程 閱讀(483) | 評(píng)論 (0)編輯 收藏

          [置頂]關(guān)于sqlhelper.cs

          public abstract class SqlHelper
                    {
                        public static readonly string connectionString = ConfigurationManager.ConnectionStrings["SqlConnString"].ConnectionString;
                  
                        SqlConnection conn;

                        #region open SqlConnection
                        public static void Open() {
                             conn = new SqlConnection(connectionString);
                             if (conn.State != ConnectionState.Open)
                                conn.Open();
                        }    
                        #endregion

                        #region close SqlConnection
                        public static void Close() {
                            if (conn != null)
                            {
                                conn.Close();
                                conn.Dispose();
                            }
                        }        
                        #endregion

                        #region prepare SqlCommand
                        private static void PrepareCommand(SqlCommand cmd, CommandType cmdType, string cmdText, SqlParameter[] cmdParms) {
                            Open();
                            cmd.Connection = conn;
                            cmd.CommandType = cmdType;
                            cmd.CommandText = cmdText;

                            if (cmdParms != null)
                            {
                                foreach (SqlParameter parm in cmdParms)
                                    cmd.Parameters.Add(parm);
                            }
                        }
                        #endregion

                        #region parm cache
                        /*
                         使用一個(gè)哈希表來(lái)保存緩存的參數(shù) 只緩存參數(shù)名
                         哈希表的特點(diǎn):一個(gè)鍵對(duì)應(yīng)一個(gè)值key對(duì)value(為object需要類(lèi)型轉(zhuǎn)化)        不能出現(xiàn)兩個(gè)相同的鍵 否則error
                   
                         下面的哈希表parmCache定義為static即一次定義全局使用
                         所以可能會(huì)出現(xiàn)有人在讀的時(shí)候,有人在寫(xiě),一般會(huì)用Lock就像Asp中用Application["count"]來(lái)統(tǒng)計(jì)點(diǎn)擊數(shù)一樣
                         要先鎖后解鎖
                         但.net框架提供了Synchroized          sync和syncroize中文意思 同步,同時(shí)發(fā)生
                         來(lái)提供這一操作
                        */
                        private static Hashtable parmCache = Hashtable.Synchronized(new Hashtable());

                        public static void CacheParameters(string cacheKey, params SqlParameter[] commandParameters) {
                            parmCache[cacheKey] = commandParameters;
                        }

                        /*
                        1、為何要克隆呢 為何不直接return cachedParms
                   
                        有一個(gè)參數(shù)數(shù)組
                        SqlParameter[] parms={
                        new SqlParameter("@num1",SqlDbType.Int,4),
                        new SqlParameter("@num2",SqlDbType.Int,4)
                        }
                        緩存該數(shù)組
                        用戶(hù)a和b都執(zhí)行插入操作
                        a用戶(hù)插入了1,1
                        b用戶(hù)插入了2,2
                        如果不用克隆的話,參數(shù)數(shù)組只有一份
                        而2個(gè)用戶(hù)需要根據(jù)不同的情況賦于不同的值
                        所以就用了克隆了
                  
                        2、(ICloneable)cachedParms[i]先將HashTable轉(zhuǎn)為ICloneable這樣HashTable就具有了Clone()克隆方法了
                        克隆一份后是什么類(lèi)型呢,,當(dāng)然要強(qiáng)制轉(zhuǎn)化為(SqlParameter)了
                        最后將它賦值給clonedParms[i]
                        */       
                        public static SqlParameter[] GetCachedParameters(string cacheKey) {
                            SqlParameter[] cachedParms = (SqlParameter[])parmCache[cacheKey];

                            if (cachedParms == null)
                                return null;
                            SqlParameter[] clonedParms = new SqlParameter[cachedParms.Length];

                            for (int i = 0; i < cachedParms.Length; i++)
                                clonedParms[i] = (SqlParameter)((ICloneable)cachedParms[i]).Clone();

                            return clonedParms;
                        }
                        #endregion        
                  
                        //below method support sqltext and procedure

                        #region ExecuteReader
                        /*
                         parms的作用,這也是一個(gè)知識(shí)點(diǎn)
                         舉例:
                         ExecuteReader(*,*,null)成功運(yùn)行
                         ExecuteReader(*,*,new SqlParameter(*))成功運(yùn)行
                         ExecuteReader(*,*,new SqlParameter(*),new SqlParameter(*))成功運(yùn)行
                         ExecuteReader(*,*,{new SqlParameter(*),new SqlParameter(*),})成功運(yùn)行
                         它讓參數(shù)類(lèi)型和參數(shù)個(gè)數(shù)任意
                         這可給了不是一般的好處,你不必為SqlParameter和SqlParameter[]進(jìn)行重載,寫(xiě)上兩個(gè)函數(shù)
                         又為null寫(xiě)上一個(gè)函數(shù),因?yàn)閚ull會(huì)不明確調(diào)用SqlParameter的函數(shù)還是SqlParameter[]的函數(shù)
                         啥你不知道我在說(shuō)什么,打屁屁,那回去看看c++的函數(shù)重載
                         */
                        public static SqlDataReader ExecuteReader(CommandType cmdType, string cmdText, params SqlParameter[] commandParameters) {
                      
                            SqlCommand cmd = new SqlCommand();

                            try {
                                PrepareCommand(cmd, null, cmdType, cmdText, commandParameters);
                                SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                                cmd.Parameters.Clear();
                                return rdr;
                            }
                            catch {
                                Close();
                                throw;
                            }
                        }
                        #endregion

                        #region ExecuteNonQuery
                        public static void ExecuteNonQuery(CommandType cmdType, string cmdText, params SqlParameter[] commandParameters) {

                            SqlCommand cmd = new SqlCommand();

                            PrepareCommand(cmd, cmdType, cmdText, commandParameters);
                            cmd.ExecuteNonQuery();
                            cmd.Parameters.Clear();

                            Close();
                        }
                        #endregion

                        #region ExecuteScalar
                        public static object ExecuteScalar(CommandType cmdType, string cmdText, params SqlParameter[] commandParameters) {

                            SqlCommand cmd = new SqlCommand();

                            PrepareCommand(cmd, cmdType, cmdText, commandParameters);
                            object val = cmd.ExecuteScalar();
                            cmd.Parameters.Clear();

                            Close();
                            return val;
                        }
                        #endregion


                    }
          }

          posted @ 2007-12-26 10:30 風(fēng)雨兼程 閱讀(922) | 評(píng)論 (0)編輯 收藏

          主站蜘蛛池模板: 安龙县| 九台市| 客服| 安顺市| 墨玉县| 特克斯县| 灵武市| 合川市| 贡山| 香河县| 阿巴嘎旗| 南昌市| 原阳县| 台江县| 论坛| 宁夏| 宜川县| 黎城县| 浙江省| 敖汉旗| 呼玛县| 平陆县| 密山市| 崇明县| 清河县| 溆浦县| 镇江市| 疏勒县| 淮北市| 黔江区| 屯留县| 衡东县| 长白| 文水县| 益阳市| 尼勒克县| 建昌县| 公安县| 清远市| 邻水| 铜梁县|