zoukankan      html  css  js  c++  java
  • 关于 C#的一些记录

    1, 注意: 使用Linq to Sql 查询数据库的时候,进行where 判断需要注意。我使用的EF,以下为我的记录
    使用Contain 需要 使用 *.Contains("" + Ranking + "")。 其中Ranking是需要进行模糊匹配的内容。Level是数
    字类型的数字,可以直接进行比较

     1 from infos in dbContext.companyawards
     2 where infos.CompanyID == CId
     3 &&
     4 infos.AwardsRanking.Contains("" + Ranking + "")
     5 && 
     6 ( 
     7 Level == -1 || infos.AwardsLevel == Level
     8 )
     9 orderby infos.AwardID descending
    10 select new
    11 {
    12 infos.CompanyID
    13 ,
    14 infos.AwardID
    15 ,
    16 infos.HaveConstructedProject
    17 ,
    18 infos.AwardsName
    19 }
    View Code

    时间比较的方法

     1     var infoList = (
     2         from infos in dbContext.companycertificatemanagements
     3         where infos.EmployeeInfoID == EId
     4         && infos.IssuingCompany.Contains("" + Company + "")
     5         && (DateBegin == null || infos.IssuingTime.Value.CompareTo(DateBegin.Value) >= 0)
     6         && (DateEnd == null || infos.IssuingTime.Value.CompareTo(DateEnd.Value) <= 0)
     7         orderby infos.CertificateID descending
     8         select new
     9         {
    10             infos.EmployeeInfoID
    11             ,
    12             infos.CertificateID
    13             ,
    14             infos.Craft
    15             ,
    16             infos.QualificationCertificateCategory
    17             ,
    18             infos.IssuingCompany
    19             ,
    20             infos.IssuingTime
    21             ,
    22             infos.DurationOfCertificate
    23             ,
    24             WetherHaveDOTSEPSETC = infos.WetherHaveDOTSEPSETC == true ? "" : ""
    25         }
    26     );
    View Code

     

    2, 绑定泛类的一些记事

    使用方式:

    // 获得查询结果
    DataTable dt = DbHelper.ExecuteDataTable(...);
    // 把DataTable转换为IList<UserInfo>
    IList<UserInfo> users = ModelConvertHelper<UserInfo>.ConvertToModel(dt);

    Repeater绑定泛型List<T>比绑定DataTable效率更高,而且绑定List<T>可以实现智能感应提示:

    这里举例在Repeater中绑定泛型List<T>的用法:

    /*********************** 最重要的部分 *****************************/
    使用<%# ((Type)Container.DataItem).成员 %> 可以绑定数据,
    用<%#((Type)Container.DataItem).成员 %>可实现智能感应提示,而且比 <%# Eval("成员")%>效率更高!
    /****************************************************************************************/

      

    后台.cs代码:

    1 List<Model.OrderItems> orderItemList = new DAl.OrderItemsDAO().GetListArray( "OrderId = '" + orderId + "' order by Id desc" );
    2 repList.DataSource = orderItemList;
    3 repList.DataBind();
    View Code

    前台.aspx代码:

     1 <asp:Repeater ID= "repList" runat= "server" > 
     2 <ItemTemplate> 
     3 <tr> 
     4 <td class = "td02" ><a href= 'productcon.aspx?id=<%#Eval("ProductId") %>' target= "_blank" ><%#Eval( "ProductName" ) %></a></td> 
     5 <td align= "right" valign= "middle" class = "td02" >¥<%#((Model.OrderItems)Container.DataItem).UnitPrice %></td> 
     6 <td valign= "middle" class = "td02 colorgreg" ><%#((Model.OrderItems)Container.DataItem).Quantity%></td> 
     7 <td align= "right" class = "td02" >¥<%#((Model.OrderItems)Container.DataItem).TotalPrice %></td> 
     8 </tr> 
     9 </ItemTemplate> 
    10 </asp:Repeater>
    View Code

    3, 带有HTML标签的字符串直接输出只会显示字符串,不会按照指定的样式显示出来


    例如: <h1>aaaaaa</h1>

    直接输出的话 就会原样显示出来

    如果需要将样式也显示出来的话请使用 @(new HtmlString("<h1>aaaaaa</h1>"))

    MVC中以html形式输出文本编辑器的内容 : @Html.Raw(HttpUtility.HtmlDecode(Model.ContentCn))

    4, 路由使用的一些方法:

    System.Web.Routing.RouteValueDictionary route = new System.Web.Routing.RouteValueDictionary()
    {
    {"controller", "ServiceDetail"}
    , {"action", "Index"}
    , {"id", filterContext.HttpContext.Session["Model"].ToString()}
    };

    filterContext.Result = new RedirectToRouteResult("Default", route);

    5, 关于Net操作SqlParamer

    使用SqlParameter进行字符串传输时,需要注意添加类型,如果遇到的是浮点型float的数据,请使用SqlDBType.Decimal才不会出现数据精确度的问题

    string sql = "insert into 表合同发票申请(合同标识, 发票金额, 发票申请人, 申请时间, 删除, 备注) values(@contractId, @money, @applyId, @applyDate, 0, @comment); ";
                SqlParameter[] sqlp = new SqlParameter[] {
                    new SqlParameter("@contractId", SqlDbType.Int){Value = iContractId}
                    , new SqlParameter("@money", SqlDbType.Decimal){Value = money}
                    , new SqlParameter("@applyId", SqlDbType.Int){Value = applyId}
                    , new SqlParameter("@applyDate", SqlDbType.DateTime){Value = this.M_UCDatePicker_Time.SelectedDate.HasValue ? this.M_UCDatePicker_Time.SelectedDate.Value : System.Convert.DBNull} //  申请时间
                    , new SqlParameter("@comment", comment){Value = comment}
                };
    
    
    
    //  返回执行汇总第一条第一个记录的整数值
            private float ExecuteScalarToSum(string sql, SqlParameter[] sqlp)
            {
                using (SqlConnection sqlconn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
                {
                    sqlconn.Open();
                    SqlCommand sqlcomm = new SqlCommand(sql, sqlconn);
                    if (sqlp != null)
                    {
                        sqlcomm.Parameters.AddRange(sqlp);
                    }
                    float result = 0;
                    float.TryParse(sqlcomm.ExecuteScalar().ToString(), out result);
                    return result;
                }
            }
    View Code
  • 相关阅读:
    Python之迭代器,生成器
    Python函数--装饰器进阶
    Python之函数的本质、闭包、装饰器
    Python之函数--命名空间、作用域、global、nonlocal、函数的嵌套和作用域链
    Python函数的定义与调用、返回值、参数
    Python之文件操作
    Python之集合
    基本数据类型补充,深浅copy
    Python基础-元组、列表、字典
    Python常用模块(一)
  • 原文地址:https://www.cnblogs.com/xxjudfc/p/4633100.html
Copyright © 2011-2022 走看看