真爱无限的知识驿站

学习积累技术经验,提升自身能力

linq to Entities,将查询语句转换为普通的SQL语句

.Net Code:

            using (testEntities MyEntity = new testEntities())
            {
                #region linq to entities 内容练习3
                var result = from s in MyEntity.stuinfo
                             where s.username == "pkm"
                             select new
                             {
                                 username=s.username,
                                 age=s.age
                             };
                var psql = result.GetType().GetMethod("ToTraceString").Invoke(result, null);//得到原始sql语句
                
                Console.WriteLine(psql);
                #endregion
            }


pkm的linq to Entities学习2

.Net Code

            using (testEntities TestEntity = new testEntities())
            {
                #region linq to entities 内容练习2
                #region 父子关系表查询
                /*
                var maxScorePerClass = from s in TestEntity.stuinfo
                                       group s by s.classID into s1
                                       select new
                                       {
                                           classid = s1.Key,
                                           stuinfo = from s2 in s1
                                                     where s2.score == s1.Max(p => p.score)
                                                     select s2
                                       };


pkm的linq to Entities学习1

数据准备:

if exists (select * from sysobjects where id = OBJECT_ID('[classinfo]') and OBJECTPROPERTY(id, 'IsUserTable') = 1) 
DROP TABLE [classinfo]
CREATE TABLE [classinfo] (
[id] [bigint]  NOT NULL,
[classID] [bigint]  NOT NULL,
[className] [nvarchar]  (50) NOT NULL,
[stat] [varchar]  (2) NOT NULL DEFAULT (1),
[autoid] [bigint]  IDENTITY (1, 1)  NOT NULL)
ALTER TABLE [classinfo] WITH NOCHECK ADD  CONSTRAINT [PK_classinfo] PRIMARY KEY  NONCLUSTERED ( [id] )
SET IDENTITY_INSERT [classinfo] ON
INSERT [classinfo] ([id],[classID],[className],[stat],[autoid]) VALUES ( 1,1,N'计算机一班',N'1',1)
INSERT [classinfo] ([id],[classID],[className],[stat],[autoid]) VALUES ( 2,2,N'计算机二班',N'1',2)


今天在做textBox拖曳的功能,学到一点点


            textBoxCmdName.AllowDrop = true;
            textBoxCmdName.DragDrop += new DragEventHandler(txt_ObjDragDrop);
            textBoxCmdName.DragEnter += new DragEventHandler(txt_ObjDragEnter);


asp.net自定义控件中注册Javascript的问题

.Net 代码:

   

    protected override void OnPreRender(EventArgs e)
        {
           
            base.OnPreRender(e);
            RenderJS();
        }
        private void RenderJS()
        {
            if (!Page.ClientScript.IsClientScriptBlockRegistered(SCRIPT_ID))//如果还没有注册语句,则注册
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(),SCRIPT_ID,SCRIPT_CONTENT);
            }
            
        }
        private const string SCRIPT_ID = "5B7A061B93D546A7A2601D56A8738DB9";//自定义标识Guid
        private const string SCRIPT_CONTENT = "<script type="text/javascript">
var CB4949501DA_checkDouble = function (data) {
var key = event.keyCode;
if ((key < 48 || key > 57) && key != 46 && key != 45) {
return false;
}
else {
if (key == 46) {
if (data.indexOf(".") != -1 || data.length == 0)
return false;
}
else if (key == 45) {
if (data.indexOf("-") != -1 || data.length != 0) {
return false;
}
}
}
return true;
}
var CB4949501DA_checkInt = function (data) {
var key = event.keyCode;

if ((key < 48 || key > 57) && key != 45) {
return false;
}
else {
if (key == 45) {
if (data.indexOf("-") != -1 || data.length != 0) {
return false;
}
}
else {
var input = String.fromCharCode(key)
var intData = parseInt(data + input);
if (intData > 2147483647 || intData < -2147483648) {
return false;
}
}
return true;
}
return true;
}
var <span style="color:#ff0000;">CB4949501DA_checkLong </span>= function (data) {
var key = event.keyCode;

if ((key < 48 || key > 57) && key != 45) {
return false;
}
else {
if (key == 45) {
if (data.indexOf("-") != -1 || data.length != 0) {
return false;
}
}
else {
var input = String.fromCharCode(key)
var longstrData = data + input
if (longstrData.length > 19) {
return false;
}
}
}
return true;
}
</script>
";


c#页面验证类DataValidate代码



using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
namespace Tools.Common
{
    /// <summary>
    /// 页面验证类
    /// </summary>
    public class DataValidate
    {
        private static Regex RegPhone = new Regex(@"^(1d{10})|(d{3,4}[-]d{6,8})$");
        /// <summary>
        /// 纯数字,无正负号
        /// </summary>
        private static Regex RegNumber = new Regex("^[0-9]+$");
        /// <summary>
        /// 纯数字,可能有正负号
        /// </summary>
        private static Regex RegNumberSign = new Regex("^[+-]?[0-9]+$");
        /// <summary>
        /// 可能有有小数点的数字
        /// </summary>
        private static Regex RegDecimal = new Regex(@"^(d+[.]d+)|(d+)$");
        /// <summary>
        /// 可能有小数点,也有可能有正负号的数字
        /// </summary>
        private static Regex RegDecimalSign = new Regex(@"^[+-]?((d+[.]d+)|(d+))$"); //等价于^[+-]?d+[.]?d+$
        /// <summary>
        /// Email地址
        /// </summary>
        private static Regex RegEmail = new Regex("^[\w-]+@[\w-]+\.(com|net|org|edu|mil|tv|biz|info|com.cn)$");
        /// <summary>
        /// 是否有中文
        /// </summary>
        private static Regex RegCHZN = new Regex("[u4e00-u9fa5]");


winform将含有超过两列的DataTable绑定到combobox并有""请选择""或""全部""选择项


.Net winform:

        #region 显示多列DataTable到combobox
        /// <summary>
        /// 显示多列DataTable到combobox
        /// </summary>
        /// <param name="dataTable">含有超过两列的DataTable</param>
        /// <param name="comboBox">combobox控件名</param>
        /// <param name="TextColumn">显示的text对应的列</param>
        /// <param name="ValueColumn">value值对应的列</param>
        /// <param name="isNeedShowEmpty">是否显示‘请选择’</param>
        /// <param name="isNeedShowAll">是否显示‘全部’</param>
        public static void ToDataTableCombobox(DataTable dataTable, ComboBox comboBox, string TextColumn, string ValueColumn, bool isNeedShowEmpty, bool isNeedShowAll)
        {
            if (dataTable == null || comboBox == null || dataTable.Columns.Count == 0)
            {
                return;
            }
            DataTable dtnew = new DataTable();
            dtnew.Columns.Add("text");
            dtnew.Columns.Add("value");


winForm开发问题,vs的bug,Datagridview始终不能编辑!

如果更改Datagridview启用编辑为不选中

c#利用反射Assembly 对类和成员属性进行操作

        protected static void test()
        {
            //获取程序集
            Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();//Assembly.LoadFrom("test.dll"); 
            //获取模块
            Module[] modules = assembly.GetModules();
            foreach (Module module in modules)
            {
                Console.WriteLine("module name:" + module.Name);
            } 
            //获取类
            Type type = assembly.GetType("Reflect_test.PurchaseOrderHeadManageModel", true, true); //命名空间名称 + 类名
            //创建类的实例
            object obj = Activator.CreateInstance(type, true);


对Remoting进行封装,方便使用


using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Remoting.Channels;
using System.Xml;
using System.Runtime.Remoting;
using System.Collections;
namespace Tools
{
    /// <summary>
    /// Remote自定义操作类,更方便使用
    /// </summary>
    public class RemoteHelper
    {
        /// <summary>
        /// 服务端注册的端口信息
        /// </summary>
        public static IDictionary ServerHttpProp = new Hashtable();
        /// <summary>
        /// 客户端连接服务端的端口
        /// </summary>
        public static int ClientToServerPort = 8888;
        /// <summary>
        /// 服务端的http地址
        /// </summary>
        private string url = "";
        #region 单个实例  Instance
        private static readonly RemoteHelper instance = new RemoteHelper();
        /// <summary>
        /// 单个实例  Instance
        /// </summary>
        public static RemoteHelper Instance
        {
            get
            {
                return instance;
            }
        }
        #endregion


<< < 3 4 5 6 7 8 9 10 11 12 > >>

Powered By Z-BlogPHP 1.7.3

Copyright 2024-2027 pukuimin Rights Reserved.
粤ICP备17100155号