很简单但老是忘的东东

代码

privatevoid lbl_min_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
privatevoid lbl_close_Click(object sender, EventArgs e)
{
Application.Exit();
}
privatevoid num_guess_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)13)//按下了回车键{this.doGuessNumber(this.btn_guess);
}
else{//nothing to do here!}
}
privatevoid GuessForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.ApplicationExitCall || e.CloseReason == CloseReason.UserClosing)
{
DialogResult dr;
dr
= MessageBox.Show("若现在退出,每个被邀请参加会议的人将断开连接。确实要退出吗?", "NetMeeting", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);if (dr == DialogResult.Yes)
{
//nothing to do here!}else{
e.Cancel
=true;//取消关闭,导致窗体继续保留}
}
else{//nothing to do here!}
}
privatevoid initData()
{
this.dlg_openfile.Filter ="所有文本文件(*.txt;*.cs)|*.txt;*.cs|所有文件(*。*)|*.*";
}
privatevoid menu_help_about_Click(object sender, EventArgs e)
{
AboutForm aboutform
=new AboutForm();
aboutform.ShowDialog();
}
privatevoid menu_file_open_Click(object sender, EventArgs e)
{
DialogResult dr;
dr
=this.dlg_openfile.ShowDialog();if (dr == DialogResult.OK)
{
string filename =this.dlg_openfile.FileName;this.fillText(filename); //填充文字框的方法this.fillByte(filename); //填充字节框的方法}else{//nothing to do here!}
}
privatevoid SingleWindow_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing )
{
e.Cancel
=true;this.Hide();
}
else{//nothing to do here!}
}
/*WinForm控件ListView始终定位在最后一行
this.lv_result.EnsureVisible(this.lv_result.Items.Count - 1);
*/

private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
{
if (!closecancel)

{
                if (MessageBox.Show("您真的要退出本系统吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                {
                    closecancel = true;
                    Application.Exit();
                }
                else
                    e.Cancel = true;
            }
}

        bool isQuit = false;private void FrmMain_FormClosing(objectsender, FormClosingEventArgs e){if (!isQuit){if (e.CloseReason == CloseReason.ApplicationExitCall || e.CloseReason ==CloseReason.UserClosing){DialogResult dr= MessageBox.Show("确定要关闭迁移工具吗?", "退出", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);if (dr ==DialogResult.No){e.Cancel= true;}else{isQuit= true;Application.Exit();}}}}

View Code

//使用weiluofeng.WinForm.UI.Docking, 当设置窗体为HideOnClose=true时, 如何显示已经隐藏的DockContent

        /// <summary>///显示DockPanel的窗体/// </summary>/// <param name="frm"></param>private voidShowFrm(DockContent frm){if(frm == null)return;foreach (IDockContent idc in this.dockPanelShow.Contents){if (idc.DockHandler.Form.Name ==frm.Name){idc.DockHandler.Show();return;}}frm.Show(this.dockPanelShow);}

View Code

//滚动条自适应内容宽度

this.lstBoxLog.HorizontalExtent = Math.Max(this.lstBoxLog.HorizontalExtent,(int)this.lstBoxLog.CreateGraphics().MeasureString(msg.Replace('\n','\r'),this.lstBoxLog.Font).Width+10);

View Code

补充个无关紧要的东东:  利用udl文件获取Access连接串

步骤: 新建1.udl文件后打开, 选择"Microsoft Jet 4.0 ODBC", 下一步选择access库的位置, 确定即可.

再补充个东东吧: Linq分组后取最大值的问题, 第二次写时居然完全忘记第一次咋搞的了

View Code

//Linq分组后取最大值的问题, 第二次写时居然完全忘记第一次咋写的了List<t_VersionsRequirement_Rel> reqLst = _db.t_VersionsRequirement_Rel.Where(vrr => (from v_VersionsRequirement_Rel in _db.t_VersionsRequirement_Rel group v_VersionsRequirement_Rel by v_VersionsRequirement_Rel.RequirementApplyID into g select new { CreateTime = g.Max(v_VersionsRequirement_Rel => v_VersionsRequirement_Rel.CreateTime) }.CreateTime).Contains(vrr.CreateTime) && vrr.OnlineTime >= DateTime.Parse(date.ToLongDateString() + "08:00") && vrr.OnlineTime <= DateTime.Parse(date.AddDays(1).ToLongDateString() + "08:00") && vrr.t_Versions.VersionType == "升级" && vrr.t_RequirementApply.Status != "上线成功" && vrr.t_RequirementApply.Status != "作废" && vrr.t_RequirementApply.Status != "驳回").Select(r => r.RequirementApplyID).Distinct().ToList();
 
//跟上边的一样:
List<string> rtLst = _db.t_RequirementDevelopment.Where(rd => rd.RequirementApplyID == requirementID && (_db.t_RequirementDevelopment.GroupBy(g => g.CreateTime).Select(g => g.Max(rd2 => rd2.CreateTime))).Contains(rd.CreateTime)).Select(rd => rd.ReferReview).Distinct().ToList();
List<string> rtLst = _db.t_RequirementDevelopment.Where(rd => (_db.t_RequirementDevelopment.Where(rd2 => rd2.RequirementApplyID == requirementID && rd2.CreateTime > requirementTime).GroupBy(g => g.Applyer).Select(g => g.Max(rd2 => rd2.CreateTime))).Contains(rd.CreateTime)).Select(rd => rd.ReferReview).Distinct().ToList();

//按需求编号、人名分组, 取每组的最大值

View Code

var dicReview = _db.t_RequirementDevelopment.Where(rd => (_db.t_RequirementDevelopment.GroupBy(g => new { g.RequirementApplyID, g.Applyer }).Select(g => g.Max(rd2 => rd2.CreateTime))).Contains(rd.CreateTime) && rd.t_RequirementApply.Status == "上线Review").OrderByDescending(rd => rd.RequirementApplyID).Select(dic => new { dic.RequirementApplyID,dic.Applyer, dic.ReferReview,dic.CreateTime });

//Linq联合查询, 老是忘掉做外连接, 标记下

View Code

内连接:

//(根据计量点和日期内连接) 取得最大日期的月累和年累                var total = (from a in all                             join g in group_M                                       on MetricPointID = a.MetricPointID      equals g.MetricPointIDselect new                             {                                 MetricPointID = a.MetricPointID,                                 TotalMonth = a.TotalMonth,                                 TotalYear = a.TotalYear,                                 AlertTotalMonth = a.AlertTotalMonth,                                 AlertTotalYear = a.AlertTotalYear,                             }).ToList();

多条件关联

//(根据计量点和日期内连接) 取得最大日期的月累和年累                var total = (from a in all                             join g in group_M                                       on new { MetricPointID = a.MetricPointID, UsageDate = a.UsageDate }                                       equals new { MetricPointID = g.MetricPointID, UsageDate = g.MaxUsageDate }select new                             {                                 MetricPointID = a.MetricPointID,                                 TotalMonth = a.TotalMonth,                                 TotalYear = a.TotalYear,                                 AlertTotalMonth = a.AlertTotalMonth,                                 AlertTotalYear = a.AlertTotalYear,                             }).ToList();

左外连接

//根据计量点左外关联all (主表)和 total//注:这里同一个计量点的TotalYear TotalMonth 都是相同的,所以下面关联的时候取max也就是同一个                var final = (from a in all                             join t in total                                       on a.MetricPointID equals t.MetricPointID                             into mfrom n in m.DefaultIfEmpty()select new                             {                                 CategoryName = a.CategoryName,                                 CategoryID = a.CategoryID,                                 CategorySort = a.CategorySort,                                 DepartmentID = a.DepartmentID,                                 DepartmentsSort = a.DepartmentsSort,                                 MediumSort = a.MediumSort,                                 MediumID = a.MediumID,                                 Usage = a.Usage,                                 MetricPointID = a.MetricPointID,                                 TotalMonth = n.TotalMonth,                                 TotalYear = n.TotalYear,                                 AlertUsage = a.AlertUsage,                                 AlertTotalMonth = n.AlertTotalMonth,                                 AlertTotalYear = n.AlertTotalYear                             }).ToList();

判断空值 

//最终分摊值 = 原始值 * 总表数据 / 总合计(普通分摊公式)//软化水分摊 = 原始值* (新水总表-新水合计) / (软化水总表-锅炉软化水) + 原始值 = 原始值* (合计(新水总表-新水合计) / 总表(软化水总表-锅炉软化水)+1)//这里用左外连接,如果为null 则返回1 (软化水因为没有总表所以不分摊)                var NewUsage = (from u in Usage                                join p in UnitUsage                                 on u.MediumID equals p.MediumID into gfrom m in g.DefaultIfEmpty()select new                                {                                    Usage = u.Usage * (m != null ? m.Usage : 1),                                    TotalYear = u.TotalYear * (m != null ? m.TotalYear : 1),                                    MetricPointID = u.MetricPointID,                                    CategoryID = u.CategoryID,                                    CategoryName = u.CategoryName,                                    CategorySort = u.CategorySort,                                    DepartmentID = u.DepartmentID,                                    DepartmentsSort = u.DepartmentsSort,                                    DepartmentName = u.DepartmentName,                                    MediumID = u.MediumID,                                    MediumSort = u.MediumSort                                }).ToList();

//参考的文章的写法, 地址是: http://hi.baidu.com/samdan/item/91c481c32576eb2d46d5c071

View Code

1、 查询Student表中的所有记录的Sname、Ssex和Class列。select sname,ssex,class fromstudent
Linq:from s inStudentsselect new{s.SNAME,s.SSEX,s.CLASS}Lambda: Students.Select( s=> new{SNAME= s.SNAME,SSEX = s.SSEX,CLASS =s.CLASS})2、 查询教师所有的单位即不重复的Depart列。select distinct depart fromteacher
Linq:from t inTeachers.Distinct()selectt.DEPARTLambda: Teachers.Distinct().Select( t=>t.DEPART)3、 查询Student表的所有记录。select * fromstudent
Linq:from s inStudentsselectsLambda: Students.Select( s=>s)4、 查询Score表中成绩在60到80之间的所有记录。select * from score where degree between 60 and 80Linq:from s inScoreswhere s.DEGREE >= 60 && s.DEGREE < 80selectsLambda: Scores.Where( s=>(s.DEGREE>= 60 && s.DEGREE < 80))5、 查询Score表中成绩为85,86或88的记录。select * from score where degree in (85,86,88)
Linq:
Infrom s inScoreswhere(new decimal[]{85,86,88}).Contains(s.DEGREE)selectsLambda: Scores.Where( s=> new Decimal[] {85,86,88}.Contains(s.DEGREE))Notin from s inScoreswhere !(new decimal[]{85,86,88}).Contains(s.DEGREE)selectsLambda: Scores.Where( s=> !(new Decimal[]{85,86,88}.Contains(s.DEGREE)))Any()应用:双表进行Any时,必须是主键为(String)CustomerDemographics CustomerTypeID(String)CustomerCustomerDemos (CustomerID CustomerTypeID) (String)一个主键与二个主建进行Any(或者是一对一关键进行Any)不可,以二个主键于与一个主键进行Anyfrom e inCustomerDemographicswhere !e.CustomerCustomerDemos.Any()selectefrom c inCategorieswhere !c.Products.Any()selectc6、 查询Student表中"95031"班或性别为""的同学记录。select * from student where class ='95031' or ssex= N''Linq:from s inStudentswhere s.CLASS == "95031" || s.CLASS == ""selectsLambda: Students.Where(s=> ( s.CLASS == "95031" || s.CLASS == ""))7、 以Class降序查询Student表的所有记录。select * fromstudent order by Class DESC
Linq:from s inStudentsorderbys.CLASS descendingselectsLambda: Students.OrderByDescending(s=>s.CLASS)8、 以Cno升序、Degree降序查询Score表的所有记录。select * fromscore order by Cno ASC,Degree DESC
Linq:(这里Cno ASC在linq中要写在最外面)from s inScoresorderbys.DEGREE descendingorderbys.CNO ascendingselectsLambda: Scores.OrderByDescending( s=>s.DEGREE).OrderBy( s=>s.CNO)9、 查询"95031"班的学生人数。select count(*) from student where class = '95031'Linq: (from s inStudentswhere s.CLASS == "95031"selects).Count()Lambda: Students.Where( s=> s.CLASS == "95031").Select( s=>s).Count()10、查询Score表中的最高分的学生学号和课程号。select distinct s.Sno,c.Cno from student as s,course as c ,score asscwhere s.sno=(select sno from score where degree = (select max(degree) fromscore))
and c.cno= (select cno from score where degree = (select max(degree) fromscore))
Linq: (from s inStudentsfrom c inCoursesfrom sc inScoreslet maxDegree= (from sss inScoresselectsss.DEGREE).Max()let sno= (from ss inScoreswhere ss.DEGREE ==maxDegreeselectss.SNO).Single().ToString()let cno= (from ssss inScoreswhere ssss.DEGREE ==maxDegreeselectssss.CNO).Single().ToString()where s.SNO == sno && c.CNO ==cnoselect new{s.SNO,c.CNO}).Distinct()操作时问题?执行时报错:where s.SNO == sno(这行报出来的) 运算符"=="无法应用于"string""System.Linq.IQueryable<string>"类型的操作数
解决:
原:let sno= (from ss inScoreswhere ss.DEGREE ==maxDegreeselectss.SNO).ToString()
Queryable().Single()
返回序列的唯一元素;如果该序列并非恰好包含一个元素,则会引发异常。
解:let sno= (from ss inScoreswhere ss.DEGREE ==maxDegreeselectss.SNO).Single().ToString()11、查询'3-105'号课程的平均分。select avg(degree) from score where cno = '3-105'Linq: (from s inScoreswhere s.CNO == "3-105"selects.DEGREE).Average()Lambda: Scores.Where( s=> s.CNO == "3-105").Select( s=>s.DEGREE).Average()12、查询Score表中至少有5名学生选修的并以3开头的课程的平均分数。select avg(degree) from score where cno like '3%' group by Cno having count(*)>=5Linq:from s inScoreswhere s.CNO.StartsWith("3")group s by s.CNOinto ccwhere cc.Count() >= 5select cc.Average( c =>c.DEGREE)Lambda: Scores.Where( s=> s.CNO.StartsWith("3") ).GroupBy( s=>s.CNO ).Where( cc=> ( cc.Count() >= 5) ).Select( cc=> cc.Average( c =>c.DEGREE) )Linq:
SqlMethod
like也可以这样写:s.CNO.StartsWith("3") or SqlMethods.Like(s.CNO,"%3")13、查询最低分大于70,最高分小于90的Sno列。select sno from score group by sno having min(degree) > 70 and max(degree) < 90Linq:from s inScoresgroup s by s.SNOinto sswhere ss.Min(cc => cc.DEGREE) > 70 && ss.Max( cc => cc.DEGREE) < 90select new{sno=ss.Key}Lambda: Scores.GroupBy (s=>s.SNO).Where (ss=> ((ss.Min (cc => cc.DEGREE) > 70) && (ss.Max (cc => cc.DEGREE) < 90))).Select ( ss=> new{sno=ss.Key})14、查询所有学生的Sname、Cno和Degree列。select s.sname,sc.cno,sc.degree from student as s,score as sc where s.sno =sc.sno
Linq:from s inStudentsjoin scinScoreson s.SNO equals sc.SNOselect new{s.SNAME,sc.CNO,sc.DEGREE}Lambda: Students.Join(Scores, s=>s.SNO,sc=>sc.SNO, (s,sc)=> new{SNAME=s.SNAME,CNO=sc.CNO,DEGREE=sc.DEGREE})15、查询所有学生的Sno、Cname和Degree列。select sc.sno,c.cname,sc.degree from course as c,score as sc where c.cno =sc.cno
Linq:from c inCoursesjoin scinScoreson c.CNO equals sc.CNOselect new{sc.SNO,c.CNAME,sc.DEGREE}Lambda: Courses.Join ( Scores, c=>c.CNO, sc=>sc.CNO, (c, sc)=> new{SNO=sc.SNO, CNAME=c.CNAME, DEGREE=sc.DEGREE})16、查询所有学生的Sname、Cname和Degree列。select s.sname,c.cname,sc.degree from student as s,course as c,score as sc where s.sno = sc.sno and c.cno =sc.cno
Linq:from s inStudentsfrom c inCoursesfrom sc inScoreswhere s.SNO == sc.SNO && c.CNO ==sc.CNOselect new { s.SNAME,c.CNAME,sc.DEGREE }

//多列分组后, 选最大值

View Code

  //分组以获取同一人同一类型时工作量的最大值(排重)List<t_WorkLoad> workLoadLst = (from wl inworkLoadLstgroup wl bynew{wl.RequirementApplyID,wl.Applyer,wl.PeriodType,wl.CreateTime} into gselect new t_WorkLoad{ RequirementApplyID = g.Key.RequirementApplyID, Applyer = g.Key.Applyer, PeriodType = g.Key.PeriodType, Period = g.Max(p => p.Period), CreateTime = info.CreateTime }).ToList();

mySql, 分组后取最大值

View Code

--MySql 分组排序取时间最大的一条记录
SELECT A.* FROMdigital_asset A,
(SELECT name, max(last_updated) max_day FROM digital_asset GROUP BYname) BWHERE A.name = B.name AND A.last_updated =B.max_daySelectA.IDFrom (select A.ID, max(A.ID) as Test from TbName group by A.Id order by max(a.Id) desc limit 1) xxwhere A.Id = xx.Id

//数据绑定

View Code

 <asp:HyperLinkID="HyperLink1"runat="server"Text='<%#DataBinder.Eval(Container.DataItem, "name") %>' NavigateUrl='<%#"aaa.aspx?id="+DataBinder.Eval(Container.DataItem,"ID")+ "&pwd=" +strPWD%>' /><asp:LinkButtonID="lbtnEditor"runat="server"PostBackUrl='<%#Eval("FID", "AdminInfo.aspx?flag=false&fid={0}")%>'CausesValidation="False" CommandName="Edit" Text="编辑"></asp:LinkButton> <asp:HyperLinkID="lnkRptAnalysisDocPath"runat="server"Target="_blank"NavigateUrl='<%#"~/Common/WebRequestTransferHandler.ashx?url=" + Server.UrlEncode(Eval("AnalysisDocPath").ToString().Trim())%>'><%#Eval("AnalysisDocPath")%></asp:HyperLink> <asp:repeaterid="Repeater1"runat="server">        <itemtemplate>            <li><%#((GeekStudio.ORM.Model.Blog)Container.DataItem).Title%></li>        </itemtemplate>    </asp:repeater>

//绑定表达式中的多个值

<a href='<%# string.Format("Default.aspx?id={0}&role={1}", Eval("userId"),Eval("userRole"))%>'><%# Eval("userName") %></a>

View Code

firefox,IE中默认span标记设置width值无效,显示只根据内容长短变化
解决办法如下:

span{}{   display:-moz-inline-box;/**//*firefox支持*/   display:inline-block;/**//*IE中*/   width:120px;   border:1px solid #ff0000;}
//DropdownList提示选择Value不再项目中, 原因是: 在绑定之前就选择了值, 造成绑定失败. 用下面可以替换ddlDevelopmentPrincipal.SelectedValue = "XX"即可
ddlDevelopmentPrincipal.SelectedIndex = ddlDevelopmentPrincipal.Items.IndexOf(ddlDevelopmentPrincipal.Items.FindByValue(info.DevelopmentPrincipal));
如果DropdownList第一次绑定后选择了一个值, 那么对改DropdownList重新绑定DataBind()方法会报错, 选择了不存在的项. 这个时候在DataBind()方法之前, 添加一行重置代码, 即ddlDevelopmentPrincipal.SelectedIndex = -1 ;
View Code

 //绑定的Combox列内容改变的问题
fileNames.Insert(0, new NameValuePair("请选择文件名称", ""));//this.cmbFileName.SelectedIndex = -1;
this.cmbFileName.DataSource =fileNames;this.cmbFileName.DisplayMember = "Name";this.cmbFileName.ValueMember = "Value";this.cmbFileName.SelectedValue = "";//使用
if (!(string.IsNullOrEmpty(this.txtDatFilePath.Text.Trim()) || string.IsNullOrEmpty(this.cmbFileName.SelectedValue.ToString()) || (this.cmbFileName.SelectedValue.GetType() == typeof(NameValuePair)))) 

//正则表达式

=========================================================

源:

<table>
    <tr>
     Tar_ServiceA
    </tr>
    <tr>
     Tar_TESTtest
    </tr>
    <tr>
     Tar_ServiceC
    </tr>
</table>

正则: <tr>[\n]?.*?Tar_TESTtest[\n]?.*?</tr>

结果:  第二个tr

======
假如: 上边的第二个Tr变成
<tr>
  <table>
    <tr>
      TESTtest
    </tr>
  </table>
</tr>
 
正则变为: <tr>((?!<tr>)[\s\S])*?Tar_TESTtest[\s\S]*?</tr>
结果为: 最里面的tr
 
类似还有: <td><form\s+action=.*?Tar_caddle.*?</form></td><td></td>

<a\s+href="job\/(.+?)\/">\1<\s*\/a\s*>
 
==================================================

匹配号段, 类似: 1352-1592,159-189,13458-13569
正则:
^[1-9][3458][\d]{1,9}-[1-9][3458][\d]{1,9}(,[1-9][3458][\d]{1,9}-[1-9][3458][\d]{1,9})*$
 
解: 基本单元 [1-9][3458][\d]{1,9}-[1-9][3458][\d]{1,9}
       (,[1-9][3458][\d]{1,9}-[1-9][3458][\d]{1,9})* 重复或没有
 
参照:
数字开头结尾, 中间逗号分隔, 且不想连. 逗号不能有相连的多个吧?
^\d(,\d*)*$|^\d+$
 
应该还要有只输入一个或多个数字的情况吧
^\d+$|^\d[\d,]*\d$|^\d+$
 
=====================================
源:
原文本:
-----新增-----
abc
efg
hig
空白行
-----更新-----
12344
23123
531231
空白行
-----卸载-----
!@#$$#@
!@@##$$
!@#@#$$$
@@!!!!!
ghhhhhhh -- 到这行末尾结束, 下边没有空白行

需要写正则表达式匹配内容:
匹配1:
-----新增-----
abc
efg
hig

匹配2:
-----更新-----
12344
23123
531231

匹配3:
-----卸载-----
!@#$$#@
!@@##$$
!@#@#$$$
@@!!!!!
ghhhhhhh

匹配结果忽略掉空白行

求助后, 给定正则的表达式:
(-+?)[^-]+?\1[^-]*(?=\s|$)

分析: 正则基础比较弱, 琢磨了2个小时, 看明白了
(-+?)[^-]+?\1[^-]*(?=\s|$)
(-+?) : 匹配'-', '-+'会匹配一溜'-', 加个'?'表示非贪婪匹配, 即(-+?)会匹配单个的'-'
[^-]+?: 匹配除'-'之外的任意字符, ? 表示非贪婪匹配, 即[^-]+?会匹配除'-'外的所有单个字符;  (-+?)[^-]+? 会匹配上例中的-----更  以及  ------换行符
\1: 就是指代第一个括号的内容, 如:  abxxxxx, 正则ab.*匹配整个字符串, 而(ab).*\1, 相当于(ab).*(ab)$, 即(ab).*\1会匹配abxxxxxab, 单不会匹配abxxxxx或abxxxxxabc
(-+?)[^-]+?\1: 指代  -----更新-----、-----新增-----、-----卸载-----内容
后面的[^-]*表示非-的人一个字符, 此时就基本可以基本匹配例子的情况. 最后的(?=\s|$), 表示正向预查, 即查到刚才的内容后, 紧着着查询是否以\s空白或本行结尾, 如 windows(?=2000|98|95), 只能匹配windows2000的windows而不能匹配windows3.1的windows;(?<!)是前向断言,声明后面的字符,之前的内容,不能是!后面的部分。

(?<=Expression)
 逆序肯定环视,表示所在位置左侧能够匹配Expression
 
(?<!Expression)
 逆序否定环视,表示所在位置左侧不能匹配Expression
 
(?=Expression)
 顺序肯定环视,表示所在位置右侧能够匹配Expression
 
(?!Expression)
 顺序否定环视,表示所在位置右侧不能匹配Expression

eg: <\s*a\s*href=["'](?!http://).*?<\s*/\s*a\s*>    匹配a标签, (!?....)表示不以http开头

引用 27 楼 mycwcgr 的回复:
谢谢!
我一直不明白为什么不能用 new Regex(@"(?<!;\s*)$");代替 new Regex("(?<!; *)$");

因为\s表示空白字符,如空格、\t、\n、\r 等,如果测试的环境中存在换行的话,那就不会成功
当然红空格的话不能匹配换行,看你的实际使用了

引用 29 楼 mycwcgr 的回复:
此外new Regex(@"^(?!.+?;\s*$).+$");中第一个问号表示子表达式不能匹配右侧的文本,请问第二个问号是什么意思,谢谢!

第二个?是尽可能少的匹配的意思 +? = {1} ?? = *? = {0}

=======================================

Javascript正则表达式,  ([\w]+)\((.+?)\)(.+?)

源数据:

Trer(aa)aajc@ff.com,TP(bb)bb@fa.com,TW(cc)ccao@fi.com,

匹配内容:

Trer(aa)aajc@ff.com  组: Trer,   aa,  aajc@ff.com

TP(bb)bb@fa.com      组: TP, bb ,bb@fa.com

TW(cc)ccao@fi.com    组:TW, cc , ccao@fi.com

(\.+?).*[^\"](?=\")
配置"......"中的.....的内容

//在后台程序的.cs文件中执行客户端Javascript代码块:

this.ClientScript.RegisterClientScriptBlock(this.GetType(), "提示信息", "alert('< " + str + " >没有Leader评估数据, 无法修改状态!');", true);

1. this.Page.ClientScript.RegisterStartupScript(this.GetType(),......)方法, 用于在页面上执行客户端脚本, 第一个参数为页面对象; 但当有用户控件等的时候, 就不好使了, 需要变通改一下ScriptManager.RegisterStartupScript(this.UpdatePanel1,....), 第一个参数控件ID;

2. 关闭IE窗口, 而不弹出提示:

<script>

  window.opener=null;window.open('','_self','');window.close();

</script>

关闭IE子窗口, 刷新父窗口:

<script>

    window.top.close();window.opener.refresh();window.opener=null;window.open('','_self','');window.close();

</script>

其中, 父窗口页面中需要有refresh方法, 如:

<script>

      function refresh() {
        window.location.href=window.location.href;
    }

</script>

<script>
 window.open('http://xxxx/AdminManagement/UserControls/Department/ChangeWorkGroup.aspx?did={1}','','toolbar=0,menubar=0,location=true,status=0,left='+(window.screen.width-800)/2+',top='+(window.screen.height-600)/2+',height=600px,width=800px');
</script>

4. JS跳转页面

相信很多人通过链接的onclick事件做跳转操作时,出现location.href不跳转的问题,下面对onclick事件中location.href的几种测试,来解决这个location.href不跳转的问题。

<script type="text/javascript">
function ToUrl(x)
{
      location.href=x;
}
</script>   <a href="javascript:;" οnclick="javascript:ToUrl('http://www.jingzhengli.cn');" location.href不跳转测试1</a>   <a href="javascript:void(0);" οnclick="javascript:ToUrl('http://www.jingzhengli.cn');">location.href不跳转测试2</a>   <a href="javascript:void(0);" οnclick="javascript:ToUrl('http://www.jingzhengli.cn');return false;">location.href不跳转测试3</a>   <a href="#" οnclick="javascript:ToUrl('http://www.jingzhengli.cn');">location.href不跳转测试4</a>  

<a href="###" οnclick="javascript:ToUrl('http://www.jingzhengli.cn');">location.href不跳转测试5</a>  

//超链接不跳转

让超链接点击后不跳转,可以用href = "#",但是这个#就会锚点到页面最上边 点击链接后不跳转可以设置成1.<a href="javascript:void(0);" >javascript:void(0);</a> 2.<a href="javascript:;" >javascript:;</a> 3.<a href="" οnclick="return false;">return false;</a>     4.<a href="#" οnclick="return false;">return false;</a> 5.<a href="##" >##</a> 6.<a href="####" >####</a>     7.<a href="#all" >#all</a>
如果想点击超链接调用js方法的话可以设置成1.<a href="javascript:void(0)" οnclick="jsFun()">jsFun</a> 2.<a href="#" οnclick="jsFun();return false;">jsFun();return false;</a>                3.<a href="#" οnclick="alert(1);event.returnValue=false;">alert(1);event.returnValue=false;</a> 1.javascript:void(0)不建议使用2.链接(href)直接使用javascript:void(0)在IE中可能会引起一些问题,比如:造成gif动画停止播放等,所以,最安全的办法还  是使用“####”。为防止点击链接后跳转到页首,onclick事件return false即可。3.如果仅仅是想鼠标移过,变成手形,可以使用<span style="cursor:pointer" οnclick="jsFun()">手型!</span> 

View Code


<asp:Button ID="btnAdd" runat="server" Text="Package管理" OnClientClick="location.href='ApplicationAdd.aspx';return false;" CssClass="btn_mouseout" οnmοuseοver="this.className='btn_mouseover'" οnmοuseοut="this.className='btn_mouseout'" οnmοusedοwn="this.className='btn_mousedown'" οnmοuseup="this.className='btn_mouseup'" Style="margin-left: 15px;" />

=====javascript中弹出选择框跳转到其他页面=====<script language="javascript">
<!--
functionlogout(){if (confirm("你确定要注销身份吗?\n是-选择确定,否-选择取消")){
window.location.href="logout.asp?act=logout"}
}-->
</script>
=====javascript中弹出提示框跳转到其他页面=====<script language="javascript">
<!--
functionlogout(){
alert("你确定要注销身份吗?");
window.location.href="logout.asp?act=logout"}-->
</script>
=====ASP中直接跳转到其他页面===========<%response.redirect"logont.asp"
%>=====Html中确认后弹出新页面===========functionDel(id){if (confirm("你确定要删除吗?")){window.open("otherfile.asp?ID="+id+"&act=del","top","width=640,height=400")}}=====Html中确认后跳转到其他页面=========functionDel(URL){if (confirm("你确定要删除吗?")){//URL="otherfile.htm"window.location.href=URL}}

View Code

测试之后相信大多数人出现location.href不跳转的问题都在测试1和测试2下,测试3,4,5三种方法均成功跳转!问题解决!

小提示:测试4点击后会回到页面顶部,所以请选择测试3,5两种方法!

//Button, 在新窗口打开超链接的问题

Button后便放一个隐藏的不可见的超链接, 超链接给上地址. 点击Button的时候, JS点击超链接
如:
<asp:Button ID="btnBranch" runat="server" Text="环境管理" OnClientClick="window.document.getElementById('aCatalogBranchList').click();return false;"
CssClass="btn_mouseout" οnmοuseοver="this.className='btn_mouseover'" οnmοuseοut="this.className='btn_mouseout'"
  οnmοusedοwn="this.className='btn_mousedown'" οnmοuseup="this.className='btn_mouseup'"
 Style="margin-left: 15px;" />

<a id="aCatalogBranchList" href="CatalogBranchList.aspx" target="_blank" CssClass="btn_mouseout" οnmοuseοver="this.className='btn_mouseover'" οnmοuseοut="this.className='btn_mouseout'" οnmοusedοwn="this.className='btn_mousedown'" οnmοuseup="this.className='btn_mouseup'"
 Style="margin-left: 15px; display:none;"></a>

//充值form的js脚本

<asp:ImageButton ID="imgCancle" runat="server" ImageUrl="imgs/cancle.gif" Style="z-index: 1; left: 718px; top: 622px; position: absolute; cursor: pointer;" OnClientClick="javascript:void(0);window.location.reload();return false();" />
或者 直接放一个服务端的按钮, 发个新请求即可.  在或者在客户端用js清楚文本框内容.

function ResetControl() {
            var v = document.forms[0].elements;
            for (var i = 0; i < v.length; i++) {
                if (v[i].type == "text") {
                    v[i].value = "";
                } else if (v[i].type == "select-one") {
                v[i].options[0].selected = true;
                }
            }

}

//页面验证fileupload

      <asp:TextBoxID="txtLicensePath"runat="server"ReadOnly="true"onchange="CheckFile(this);"Style="z-index: 1; left: 275px; top: 583px; position: absolute; width: 533px;font-size: 16px;"BorderStyle="None"Height="20px"ToolTip="请选择License文件"></asp:TextBox><asp:FileUploadID="fupLicense"runat="server"Style="display: none"onchange="document.getElementById('txtLicensePath').value = this.value;document.getElementById('txtLicensePath').onchange();return false;" />
<asp:ImageButtonID="imgBrower"runat="server"ImageUrl="imgs/browse.gif"Style="z-index: 1;left: 820px; top: 578px; position: absolute; cursor: pointer;"OnClientClick="javascript:void(0);document.getElementById('fupLicense').click();return false;" />

View Code

//fileupload的脚本内容

        functionCheckFile(obj) {var strRegex = "(.lic|.LIC)$"; //用于验证图片扩展名的正则表达式var re = newRegExp(strRegex);if(re.test(obj.value)) {return (true);}else{alert("禁止的文件扩展名,请选择*.lic文件!");obj.value= "";return (false);}}

View Code

//fileupload控件的值没有办法通过脚本,操作.. 这是个ie安全性的问题. 解决方式通过移动fileupload的位置, 让鼠标移到按钮上市时,点击的是fileupload的浏览

这是以前写的多附件添加,file透明度改成了50%,让咱们看得更明白。HTML code<HTML><BODY><divid="tt"style="position:relative;"><inputtype="button"value="添加附件"onmouseover="floatFile()"><br><divid="div1"><divid="file1text" ></div><inputid="file1"name="myfile"type="file"onchange="showText(this)"style="position:absolute;filter:alpha(opacity=50);width:30px;"hidefocus></div></div></p><inputtype="button"onclick="alert($('tt').innerHTML)"value="showHTML"></BODY>
</HTML>
<SCRIPTLANGUAGE="JavaScript">function$(id){returndocument.getElementById(id);}//全局变量,记录文件数;varfileNum=1;//mouseover时,把input file移到按扭上,保证点击的是file,functionfloatFile(){    $("file"+fileNum).style.posTop=event.srcElement.offsetTop;$("file"+fileNum).style.posLeft=event.x-$("file"+fileNum).offsetWidth/2;
}//选择完一个文件之后,自动创建一个新的div 和 file表单,用于下回使用,hidden刚用过的filefunctionshowText(obj){$(obj.id+"text").innerHTML=obj.value+"&nbsp;&nbsp;<a href='javascript:del("+fileNum+")'>删除</a>";$("file"+fileNum).style.display='none';fileNum=fileNum+1;//直接追加innerHTML(innerHTML+=)会清空原来file中的内容
$("div"+(fileNum-1)).insertAdjacentHTML('AfterEnd','<div id="div'+fileNum+'"><div id="file'+fileNum+'text" ></div><input id="file'+fileNum+'" name="myfile" type="file"  οnchange="showText(this)"  style="position:absolute;filter:alpha(opacity=0);width:30px;"hidefocus></div>');}functiondel(id){$("div"+id).innerHTML="";$("div"+id).style.display="none";}</SCRIPT>------回答---------------其他回答(5分)---------input file 文件上传控件隐藏后用button触发它的click事件为什么文件就上传不上去了
这个是ie居于安全性考虑的限制。
input file必须使用手动触发click事件,不然传个病毒到服务器上怎么办呢?

View Code

//上述实现的参考2

<formmethod="post"action="http://localhost/"enctype="multipart/form-data">
<inputtype="button"onmousemove="move(event)"value="请选择文件"size="30" />
<inputtype="file"id="f"onchange="this.form.submit()"name="f"style="position:absolute; filter:alpha(opacity=0); opacity:0; width:30px; "size="1" />
</form>
<scripttype="text/javascript">
functionmove(event){varevent=event||window.event;vara=document.getElementById('f');a.style.left=event.clientX-50+'px';a.style.top=event.clientY-10+'px';
}</script>跟上个例子相比,为按钮添加了 onmousemove 事件,主要目的是鼠标移动至按钮时,把上传文件字段置于鼠标下,这样点击按钮时实际上点击的是上传文件字段,而不是这个按钮。再次在 IE 下测试,可以上传文件了。一切看起来很正常,一个潜在的问题是若页面内容超出一屏范围,而很不幸的是按钮和上传字段不在同一屏,问题产生了,点击按钮无法出现选择文件的对话框。这是由于使用了 clientX 和 clientY 事件属性,而 clientY 的坐标不考虑文档的滚动。解决方案是用 jquery 的 pageX 事件属性。它实现了跨浏览器支持。

View Code

//自己的实现, 已成功

<!---HTML元素--> <asp:TextBoxID="txtLicensePath"runat="server"ReadOnly="true"onchange="CheckFile(this);"Style="z-index: 1; left: 275px; top: 583px; position: absolute; width: 533px;font-size: 16px;"BorderStyle="None"Height="20px"ToolTip="请选择License文件"></asp:TextBox><asp:FileUploadID="fupLicense"runat="server"Style="position: absolute;height:30px;filter:alpha(opacity=0);opacity:0;z-index:99;"size="1"onchange="CheckFile(this);document.getElementById('txtLicensePath').value = this.value;"hideFocus/><asp:ImageButtonID="imgBrower"runat="server"ImageUrl="imgs/browse.gif"Style="z-index: 1;left: 820px; top: 578px; position: absolute; cursor: pointer;"onmousemove="move(event);" /><asp:ImageButtonID="imgImport"runat="server"ImageUrl="imgs/import.gif"OnClick="imgImport_Click"Style="z-index: 1; left: 620px; top: 622px; position: absolute; cursor: pointer;right: 322px;" /><!--脚本块-->function CheckFile(obj) {var strRegex = "(.lic|.LIC)$"; //用于验证图片扩展名的正则表达式var re = new RegExp(strRegex);if (re.test(obj.value)) {return (true);}else {alert("禁止的文件扩展名,请选择*.lic文件!");obj.value = "";return (false);}}function move(event) {var event = event || window.event;var elem = document.getElementById('fupLicense');//elem.style.left = event.clientX - 50 + 'px';//elem.style.top = event.clientY - 10 + 'px';elem.style.top = event.srcElement.offsetTop + 'px';elem.style.left = event.srcElement.offsetLeft -60 + 'px';}

View Code

//清空upload

后台判断FileUpload是否为空 /JS判断FileUpload是否为空、上传类型(2011-06-08 19:56:17)
标签: 杂谈
if (FileUpload1.HasFile == false){Response.Write("<script>alert('请选择要上传的文件');history.go(-1)</script>");Response.End();}
、、、、、、、、、、、、、、、、、、、、
function Judge() {// 获取上传文件名var fileupload = document.getElementByIdx_x("<%=FileUpload1.ClientID%>");var filename = fileupload.value;if(filename == ""){alert('请输入上传图片!');return false;}           return true;}</script>、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、<headrunat="server"><scripttype="text/javascript">functionJudge() {//获取上传文件名varfileupload=document.getElementByIdx_xx_x("FileUpload1");varfilename=fileupload.value;//获取该文件名的后缀名varextend=filename.substring(filename.lastIndexOf(".")+ 1);//上传文件提示信息varhint=document.getElementByIdx_xx_x("hint");if(extend== "") {hint.innerHTML= "<span style='color:red'>上传文件不能为空</span>";}else if(extend!= "doc") {hint.innerHTML= "<span style='color:red'>必须上传word格式文件</span>";//清空上传文件控件的值
fileupload.outerHTML=fileupload.outerHTML}else if(extend== "doc") {hint.innerHTML= "";}}</script>
</head><body><formid="form1"runat="server"><div><asp:FileUploadID="FileUpload1"runat="server"/><inputid="btnUpload"type="button"value="上传"onclick="Judge()" /><divid="hint"></div></div></form>
</body>
</html>1.关于如何用脚本修改fileupload控件值的问题,开发环境vs2005,在上传文件时,需要一个取消的按钮来清空type=file的value,而且这个页面上有多个file控件这个比较麻烦因为file的值本身是不允许用脚本修改的(安全角度考虑)方法1.使用脚本把这个file的input移动到一个form中,然后调用reset,如果有多个这样的input当然还要再移出来.这个方法我不会采用,因为对.net开发者来讲习惯了一个页面就一个form所有控件都在其中.方法2.这个方法有点投机,就是在脚本中调用
var fileup = document.getElementByIdx_xx_x_x_x_x(fileid);
fileup.outerHTML = fileup.outerHTML; 这个ie对脚本处理以及展现机制有关方法3.这个主要是在解决ff上的问题时考虑到的,其实就是重新生成了一个id相同的file,这里要注意 name一定也要赋值,否则是很难提交给服务器接受的在平时项目开发中会有上传文件的功能,一般在前端会通过JS来判断上传文件是否属于指定的文件类型,如果不属于就将控件值清空! (当然你也可以不清空)有一种方法可以很简单的装文件上传组件的值清空,代码如下:
var file=document.getElementByIdx_xx_x_x_x_x("form1:fileupload");
file.outerHTML=file.outerHTML以上方法之能在IE中使用为了兼容FireFox我们使用下面的方式来清空fileupload控件的值:<spanid='uploadSpan'>
<inputtype="file">
</span>
<scriptlanguage="JavaScript">
varhtml=document.getElementByIdx_xx_x_x_x_x('uploadSpan').innerHTML;functionresetFile(){
document.getElementByIdx_xx_x_x_x_x('uploadSpan').innerHTML=html;
}</script>这样就行了,各浏览器都支持的

View Code

//js修改readonly=true的值, 即前台修改值, 后台也能获取. 原理是: server端会忽略enable = true的处理请求

当设置TextBox为ReadOnly时候,js改变了TextBox.Text值,但是在后台无法获取到改变的值,解决办法:
TextBox1.Attributes.Add("contentEidtable","false");
或者TextBox1.Attributes["contentEidtable"]=false;这样就可以达到客户端无法输入,只允许js改变TextBox值,且在后台页可以获取到改变的值。。。

View Code

//客户端值改变的问题

应将页面中的JavaScript函数改写如下:<script language="javascript" type="text/javascript">function whetherEmpty()
{//alert("KPI信息不能全为空!");emptflag = false;var jobgoal = document.getElementById("<%=txt_KPIName.ClientID%>").value;
}</script>

View Code

//js调RDP的问题

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html; charset=gb2312" />
<title>远程RDP连接</title> <script>
functionRdpConnect()
{varuserName, Pwd, server, pwd;userName= "administrator";//用户名
server= "10.99.238.180";//IP
pwd= "P@ssw0rd";if(!MsRdpClient.Connected) {MsRdpClient.Server=server;//设置远程桌面IP地址
MsRdpClient.AdvancedSettings2.RedirectDrives= false;MsRdpClient.AdvancedSettings2.RedirectPrinters= false;MsRdpClient.AdvancedSettings2.RedirectPrinters= false;MsRdpClient.AdvancedSettings2.RedirectClipboard= true;MsRdpClient.AdvancedSettings2.RedirectSmartCards= false;MsRdpClient.UserName=userName;MsRdpClient.AdvancedSettings2.ClearTextpassword=pwd;//密码
MsRdpClient.FullScreen= 0;MsRdpClient.Connect();}
}</script></head><bodyonload="RdpConnect();">
<OBJECTclassid="clsid:d2ea46a7-c2bf-426b-af24-e19c44456399"codebase="msrdp.cab#version=6,2,9200,16398"width="1024px"height="768px"align=centerhspace=0vspace=0id="MsRdpClient";></OBJECT>
</body>
</html> 

View Code

//Frame窗口跳转的问题

做WEB站点,表头是iframe有跳转功能
有Button按钮使结果转向Response.Redirect()
设定转向指定在父窗口打开需如下操作:------------------------------------------------------------------------------------------------------Response.Write("<script>window.top.location='xxx.aspx'</script>");
相当于改变地址栏里的路径
Response.Write("<script>window.parent.location='xxx.aspx'</script>")
相当于改变当前页面的父页面地址
两者均不会被拦截------------------------------------------------------------------------------------------------------如果有多层iframe,要控制中间层页面跳转
可以使用window.parent.parent.location='xxx.aspx'方式实现

View Code

//窗口跳转

1.控件再UpLoad中,弹出窗口ScriptManager.RegisterStartupScript(this, this.GetType(), "alert('!');", js, true);2.控件不再UpLoad中,弹出窗口Page.RegisterStartupScript("Messages", "<script>alert('OK'')</script>");3.弹出新的网页Response.Redirect("'Default.aspx");Response.Redirect("'Default.aspx?id=" + this.GridView1.SelectedDataKey.Value.ToString());4.利用前台注册脚本弹出固定大小的页面AutoId.Attributes.Add("onclick", "window.open('Default.aspx?AutoID=" +SetupList.DataKeys[e.Row.RowIndex][0].ToString() + "','','height=500,width=400px,top=100,left=200,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');");注:AutoId为服务器控件可以为LinkButton控件5.注册前台事件,关闭弹出窗体,并且刷新父窗体(结合4使用.)ClientScript.RegisterClientScriptBlock(this.GetType(), "closeWindow", "CloseWindowReflash()", true);前台js函数functionCloseWindowReflash(){window.opener.parent.document.frames.item('frame').location.reload();window.close();}

View Code

//window.opener返回值, ie&chrome

chrome的showModalDialog方法很像执行了window.open方法,那么我们可以利用window.opener来实现window.returnValue的功能。父窗体部分js代码:
returnValue= window.showModalDialog("son.html ", window);//for chrome  if (returnValue == undefined) {      returnValue = window.returnValue;  }
子窗体部分js代码:if (window.opener != undefined) {         //for chrome         window.opener.returnValue = "opener returnValue";  }  else {         window.returnValue = "window returnValue";  }  window.close();  这样也在IE,FireFox,Chrome,Safari等浏览器下都可以通用了。

View Code

//window.open和showModelDialog

首页 > 上网技巧 > 电脑小技巧 >正文搜索
IE的showModalDialog与FireFox的window.open父子窗口传值代码
时间:2014-07-18 09:51作者:QQ地带 我要评论
先简单介绍一下基本知识:
一、window.open()支持环境: JavaScript1.0+/JScript1.0+/Nav2+/IE3+/Opera3+二、基本语法:
window.open(pageURL,name,parameters)
其中:
pageURL 为子窗口路径
name 为子窗口句柄
parameters 为窗口参数(各参数用逗号分隔) 三、各项参数
其中yes/no也可使用1/0;pixel value为具体的数值,单位象素。参数| 取值范围 |说明
alwaysLowered| yes/no | 指定窗口隐藏在所有窗口之后
alwaysRaised | yes/no | 指定窗口悬浮在所有窗口之上
depended | yes/no | 是否和父窗口同时关闭
directories | yes/no | Nav2和3的目录栏是否可见
height | pixel value |窗口高度
hotkeys| yes/no | 在没菜单栏的窗口中设安全退出热键
innerHeight | pixel value |窗口中文档的像素高度
innerWidth| pixel value |窗口中文档的像素宽度
location| yes/no | 位置栏是否可见
menubar | yes/no | 菜单栏是否可见
outerHeight | pixel value |设定窗口(包括装饰边框)的像素高度
outerWidth| pixel value |设定窗口(包括装饰边框)的像素宽度
resizable| yes/no | 窗口大小是否可调整
screenX | pixel value |窗口距屏幕左边界的像素长度
screenY| pixel value |窗口距屏幕上边界的像素长度
scrollbars| yes/no | 窗口是否可有滚动栏
titlebar | yes/no | 窗口题目栏是否可见
toolbar | yes/no | 窗口工具栏是否可见
Width | pixel value |窗口的像素宽度
z-look | yes/no | 窗口被激活后是否浮在其它窗口之上
window.showModalDialog使用手册基本介绍:
showModalDialog() (IE4+支持)
showModelessDialog() (IE5+支持)
window.showModalDialog()方法用来创建一个显示HTML内容的模态对话框。
window.showModelessDialog()方法用来创建一个显示HTML内容的非模态对话框。使用方法:
vReturnValue=window.showModalDialog(sURL [, vArguments] [,sFeatures])
vReturnValue=window.showModelessDialog(sURL [, vArguments] [,sFeatures])参数说明:
sURL--必选参数,类型:字符串。用来指定对话框要显示的文档的URL。
vArguments--可选参数,类型:变体。用来向对话框传递参数。传递的参数类型不限,包括数组等。对话框通过window.dialogArguments来取得传递进来的参数。
sFeatures--可选参数,类型:字符串。用来描述对话框的外观等信息,可以使用以下的一个或几个,用分号“;”隔开。1.dialogHeight :对话框高度,不小于100px,IE4中dialogHeight 和 dialogWidth 默认的单位是em,而IE5中是px,为方便其见,在定义modal方式的对话框时,用px做单位。2.dialogWidth: 对话框宽度。3.dialogLeft: 离屏幕左的距离。4.dialogTop: 离屏幕上的距离。5.center: {yes | no | 1 | 0}:窗口是否居中,默认yes,但仍可以指定高度和宽度。6.help: {yes | no | 1 | 0}:是否显示帮助按钮,默认yes。7.resizable: {yes | no | 1 | 0} [IE5+]:是否可被改变大小。默认no。8.status: {yes | no | 1 | 0 } [IE5+]:是否显示状态栏。默认为yes[ Modeless]或no[Modal]。9.scroll:{ yes | no | 1 | 0 | on |off }:指明对话框是否显示滚动条。默认为yes。
下面几个属性是用在HTA中的,在一般的网页中一般不使用。10.dialogHide:{ yes | no | 1 | 0 | on |off }:在打印或者打印预览时对话框是否隐藏。默认为no。11.edge:{ sunken |raised }:指明对话框的边框样式。默认为raised。12.unadorned:{ yes | no | 1 | 0 | on |off }:默认为no。参数传递:1.要想对话框传递参数,是通过vArguments来进行传递的。类型不限制,对于字符串类型,最大为4096个字符。也可以传递对象,例如:-------------------------------parent.htm<script type="text/javascript">
var obj = newObject();
obj.name="oicqzone";
window.showModalDialog("modal.htm",obj,"dialogWidth=200px;dialogHeight=100px");</script>
modal.htm<script type="text/javascript">
var obj =window.dialogArguments
alert("您传递的参数为:" +obj.name)</script>
-------------------------------
2.可以通过window.returnValue向打开对话框的窗口返回信息,当然也可以是对象。例如:------------------------------parent.htm<script type="text/javascript">str=window.showModalDialog("modal.htm",,"dialogWidth=200px;dialogHeight=100px");
alert(str);</script>
modal.htm<script type="text/javascript">window.returnValue="http://www.oicqzone.com";</script>
在IE中,我们可以使用showModalDialog来传值。
语法如下:
vReturnValue=window.showModalDialog(sURL [, vArguments] [, sFeatures]) 但是.在Firefox中却沒有showModalDialog方法,不过我们可以用window.open()
语法如下:
oNewWindow=window.open( [sURL] [, sName] [, sFeatures] [, bReplace]) 只是,在Firefox下,window.open的参数中,sFeature多了一些功能设定,而在FireFox下要让开启的视窗跟IE的showModalDialog一样的话,只要在sFeatures中加個modal=yes就可以了。下面用一个示例来说明其用法。
功能说明:从子窗口中输入颜色种类提交到父窗口,并添加选项到下拉列表。
a.html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>a.html文档</title>
<script language="javascript">
functionopenstr()
{
ReturnValue=window.showModalDialog("b.html",window,"dialogWidth=510px;dialogHeight=150px;status=no");if(ReturnValue && ReturnValue!="")
{
oOption= document.createElement('OPTION');
oOption.text=ReturnValue;
oOption.value=ReturnValue;
document.all.txtselect.add(oOption);
}
}</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<label>
<select name="txtselect" id="txtselect">
</select>
</label>
<label>
<input type="button" name="Submit" value="打开子窗口" οnclick="openstr()" />
</label>
</form>
</body>
</html>
b.html<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>b.html文档</title>
<script language="javascript">
functionClickOk()
{var t=document.Edit;var url=t.color.value;if(url==null||url=="填写颜色") return(false); window.returnValue=url;
window.close();
}</script>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="2" align="center" width="300">
<form name="Edit" id="Edit">
<tr>
<td width="30" align="right" height="30">color:</td>
<td height="30"><input type="text" name="color" value="填写颜色" /></td>
<td width="56" align="center" height="30"><input " type="button" name="bntOk" value="确认" οnclick="ClickOk();"/> </td>
</tr>
</form>
</table>
</body>
</html>修改为兼容IE和FireFoxr的代码如下:
<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>a.html文档</title>
<script type="text/javascript">
functionopenstr()
{
window.open("b.html","","modal=yes,width=500,height=500,resizable=no,scrollbars=no");
}</script>
</head> <body>
<form id="form1" name="form1" method="post" action="">
<label>
<select name="txtselect" id="txtselect">
</select>
</label>
<label>
<input type="button" name="Submit" value="打开子窗口" οnclick="openstr()" />
</label>
</form>
</body>
</html>
b.html<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>b.html文档</title>
<script type="text/javascript">
functionClickOk()
{var t=document.Edit;var color=t.color.value;if(color==null||color=="填写颜色") return(false);var oOption = window.opener.document.createElement('OPTION');
oOption.text=url;
oOption.value=url;//检查浏览器类型
var bname =navigator.appName;if (bname.search(/netscape/i) == 0)
{
window.opener.document.getElementById("txtselect").appendChild(oOption);
}else if (bname.search(/microsoft/i) == 0)
{
window.opener.document.all.txtselect.add(oOption);
}else{
}
window.close();
}</script>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="2" align="center" width="300">
<form name="Edit" id="Edit">
<tr>
<td width="30" align="right" height="30">color:</td>
<td height="30"><input type="text" name="color" value="填写颜色" /></td>
<td width="56" align="center" height="30"><input " type="button" name="bntOk" value="确认" οnclick="ClickOk();"/> </td>
</tr>
</form>
</table>
</body>
</html>

View Code

FireFox中使用window.open打开模式窗口
已经加了modal=yes
还是没有效果functiontest(){if(document.all){var str = window.showModalDialog("usertree.aspx",null,"dialogWidth:400px; dialogHeight:500px; help:no; resizable:no; status:no");if (str != null)alert(str);   }else{this.returnAction=function(str){if (str != null)alert(str);} window.open("usertree.aspx",null,"width=400px,height=800px,help=no,resizable=no,status=no,modal=yes,location=no");}}
代码如上
大家帮帮忙
解决方案 »
火狐中不支持模式窗口
可以用div模拟<html>
<head>
<title>标题</title><script type="text/javascript">
function ShowWindow()
{document.getElementById("divDialog").style.display = "";
}
function CloseWindow()
{document.getElementById("divDialog").style.display = "none";//这里写你要的赋值操作,比如将textBox1值赋为"已设置"document.getElementById("textBox1").value = "已设置";
}
</script>
</head>
<body>
<!--
这个DIV就是弹出的窗口,按下面的参数设置修改一下就可以了
-->
<div id="divDialog" style="display:none;position:absolute;top:距窗口顶部的距离px;left:距窗口左边的距离px;background:url('图片地址');width:图片宽度px;height:图片高度px;">
<input type="button" value="单击我关闭对话框" οnclick="CloseWindow()"/>
</div><input type="button" value="单击我显对话框" οnclick="ShowWindow();" /> <input type="text" id="textBox1" value=""/></body>
</html>

View Code

//由于toFixed()方法默认是六舍五入, 这里扩展Math类的round2方法, 完成四舍五入的操作.

    //直接扩展Math类, (Math类不能像Data,string那样通过prototype来扩展)Math.round2 = function(num, precision) {var n =parseFloat(num);var p =parseInt(precision)if (isNaN(n) ||isNaN(p)) {return;}if (arguments.length == 1)returnMath.round(n);else{var bitNum = Math.pow(10,p);var r = Math.round(n * bitNum) /bitNum;var rs =r.toString();var dp = rs.indexOf('.');if (dp < 0) {dp=rs.length;rs+= '.';}while (rs.length <= dp +precision) {rs+= '0';}returnrs;}}

View Code

vs2008解决方案资源管理器不显示解决方案:

菜单栏》工具》选项》项目和解决方案》总是显示解决方案(打上勾)

======== bat读取xml信息

你附件收到了,你看以下代码能用吗? ~~~~~~~~~~~~~~~~~~~~~~~~~
@echo offfor /f "tokens=2 delims=>" %%i in ('type tool_config.xml') do ( for /f "delims=<" %%i in ("%%i")do echo %%i ) pause
~~~~~~~~~~~~~~~~~~~~~~~~~

//双重锁

//Port to C#
classSingleton {public staticSingleton Instance() {if (_instance == null)//提高效率
{lock (typeof(Singleton)) {if (_instance == null) //防止多次创建单例对象
{ _instance= newSingleton(); } } }return_instance;
}protectedSingleton() {
}private static volatile Singleton _instance = null;
}

View Code 

        private static volatile bool settingsInitalized = false;private static object appSettingsLock = new object();private static voidEnsureSettingsLoaded(){if (!settingsInitalized){lock(appSettingsLock){if (!settingsInitalized){NameValueCollection settings= null;try{settings=ConfigurationManager.AppSettings;}catch(ConfigurationErrorsException){}finally{if (settings == null || !Boolean.TryParse(settings["Transactions:IncludeDistributedTransactionIdInExceptionMessage"], out_includeDistributedTxIdInExceptionMessage)){_includeDistributedTxIdInExceptionMessage= false;}settingsInitalized= true;}}}}}

View Code

//char[]和string互转

字符串转换成Char数组string str="abcdefghijklmnopqretuvwxyz";char[] chars=str.ToCharArray();char数组转换成字符串char[] chars=new char[]{'a','b','c','d'};string str=new string(chars);

View Code

//Microsoft.Win32监控系统时间

在Microsoft.Win32命名空间中有一个SystemEvents类,我们只要定制它的一个静态事件TimeChanged就OK了!!
代码片断如下:private void Form1_Load(objectsender, System.EventArgs e)
{//定制事件SystemEvents.TimeChanged += newEventHandler(SystemEvents_TimeChanged);
}//事件处理函数
private void SystemEvents_TimeChanged(objectsender, EventArgs e)
{MessageBox.Show("系统时间被改变了,现在时间为:" +DateTime.Now.ToString());
}
注意,这个事件在Console程序中是无效的,可能是因为这个事件本身要依赖窗口和窗口消息吧。另外,建议大家仔细看看Microsoft.Win32命名空间中的所有内容,还有许多有用的东西呢!!

View Code

//lodop打印时, 依靠CSS来控制样式, 从页面传入的css地址应该是:

<inputid="hidCssRef"name="hidCssRef"type="hidden"value='<linkhref="http://<%= this.Request.Url.Authority %>//App_Themes//<%=Application["Theme"].ToString()%>//Css//PrintStyleSheet.css" rel="stylesheet" type="text/css" />' />

View Code

//弹出窗口样式失效的问题.

                        //(e.Row.FindControl("lbtnSelect") as LinkButton).Attributes.Add("onclick", string.Format("$(window.opener.document).find('#tmpEntityJson').val('{0}');refreshSupWin();window.opener=null;window.open('','_self','');window.close();",jsonStr));//(e.Row.FindControl("lbtnSelect") as LinkButton).Attributes.Add("onclick", string.Format("$(window.opener.document).find('#tmpEntityJson').val('{0}');window.opener=null;window.open('','_self','');window.close();", jsonStr));(e.Row.FindControl("lbtnSelect") as LinkButton).Attributes.Add("onclick", string.Format("window.opener.bindEntity2Tr('{0}','choosenTr');window.opener=null;window.open('','_self','');window.close();", jsonStr));

View Code

//jQuery的Ajax的写法, 经常忘记, 所以标记一下:

//默认是异步的var cssInfo = $.ajax({type: "GET",url: cssRef,async:false,}).responseText;//查询用户信息function searchUser() {$.ajax({type: "GET",url: "/SysAdmin/GroupMgrEdit.aspx",data: "keyWord=respon&depId=" + $("#<%=this.ddlDepartment.ClientID%>").val() + "&usrId=" + encodeURIComponent($("#<%=this.txtUserName.ClientID%>").val()),success: function (data) {clearForm();var jsonResult = eval("(" + data + ")");for (var i = 0; i<jsonResult.length; i++) {addOne(jsonResult[i].UserNo, jsonResult[i].UserName);}}});}//异步Post请求function test(){$.ajax({//提交数据的类型 POST GETtype:"POST",//提交的网址url:"testLogin.aspx",//提交的数据data:{Name:"sanmao",Password:"sanmaoword"},//返回数据的格式datatype: "html",//"xml", "html", "script", "json", "jsonp", "text".//在请求之前调用的函数beforeSend:function(){$("#msg").html("logining");},//成功返回之后调用的函数             success:function(data){$("#msg").html(decodeURI(data));            }   ,//调用执行后调用的函数complete: function(XMLHttpRequest, textStatus){alert(XMLHttpRequest.responseText);alert(textStatus);//HideLoading();},//调用出错执行的函数error: function(){//请求出错处理}         });}

View Code

//标记下Model和Table的解耦问题

2楼正解,例如在PDF.NET数据开发框架中,有一个实体类User:
C# code?
1
2
3
4
5
6
7
8
9
classUser:EntityBase
{publicUser(){...}publicSystem.String Name{//"Name" 是数据库的字段名称get{return getProperty<System.String>("Name");}set{setProperty("Name",value ,50);} }如果有一天数据库的字段“Name”修改成了 “UserName”,那么只需要这样修改:
C# code?
1
2
3
4
5
6
7
8
9
classUser:EntityBase
{publicUser(){...}publicSystem.String Name{//"Name" 是数据库的字段名称get{return getProperty<System.String>("UserName");}set{setProperty("UserName",value ,50);} }如果后来有一天,“UserName”字段从数据库删除了,没关系,继续下面这样修改:
C# code?
1
2
3
4
5
6
7
8
classUser:EntityBase
{publicUser(){...}publicSystem.String Name{get;set;}所以,数据怎么改,影响范围都在实体类内部,不会涉及到DAL,BLL和UI层,这就是引入实体类的强大和灵活之处。
另外,PDF.NET数据开发框架的实体类还可以从视图、存储过程或者任意复杂的自定义临时SQL映射。

View Code

我觉得可以这样做一下分解。我们把和数据库表对应的类叫做bean,和页面对应的类叫做model.
model和bean之间是包含和被包含的关系。model是绑定页面数据的类,而bean是绑定数据库表字段的类。
如果是修改的页面层的业务逻辑那么只需要在model里面添加逻辑。最后将model的数据复制给bean。所以
一般情况下bean是不需要随便改动的。只需要在model层做文章即可

View Code

//DIV中的Span或者P等块级元素, 完美垂直句中的问题

<!DOCTYPE html>
<htmllang="zh-cn">
<metacharset="GB2312" />
<head>
<style>#demo{overflow:hidden;resize:both;width:180px;height:100px;margin:10px auto;text-align:center;background:#eee;font-size:0;
}#demo:after,#demo span{display:inline-block;*display:inline;*zoom:1;width:0;height:100%;vertical-align:middle;
}#demo:after{content:'';
}#demo p{display:inline-block;*display:inline;*zoom:1;vertical-align:middle;font-size:16px;
}
</style>
</head>
<body>
<divid="demo"><p>这是一个终极实现的水平垂直居中实例</p><!--[if lt IE 8]><span></span><![endif]-->
</div>
</body>
</html>

View Code

//CSS文件

.detailContent span:after,.detailContent span{display:inline-block;height:40px;vertical-align:middle;overflow-y:hidden;
}.detailContent span span:after{content:'';
}

View Code

//通过表达式获取属性值

        //通过表达式取当前的属性值public static void GetValueByExpression<TModel, TProperty>(Expression<Func<TModel, TProperty>> expression, TModel model, out string propertyName, out objectvalue){MemberExpression body=(MemberExpression)expression.Body;var lamadaName = (body.Member is PropertyInfo) ? body.Member.Name : null;propertyName=lamadaName;value= null;System.Reflection.PropertyInfo[] lstPropertyInfo= typeof(TModel).GetProperties(BindingFlags.Public |BindingFlags.Instance);var oFind = lstPropertyInfo.FirstOrDefault(x => x.Name ==lamadaName);if (oFind != null){value= oFind.GetValue(model, null);}}

View Code

//Js防止事件冒泡

        $(function(){functioninitTableCheckbox() {var $thr = $('table thead tr');var $checkAllTh = $('<th><input type="checkbox" id="checkAll" name="checkAll" /></th>');/*将全选/反选复选框添加到表头最前,即增加一列*/$thr.prepend($checkAllTh);/*“全选/反选”复选框*/  var $checkAll = $thr.find('input');  $checkAll.click(function(event){/*将所有行的选中状态设成全选框的选中状态*/$tbr.find('input').prop('checked',$(this).prop('checked'));/*并调整所有选中行的CSS样式*/  if ($(this).prop('checked')) {  $tbr.find('input').parent().parent().addClass('warning');  }else{  $tbr.find('input').parent().parent().removeClass('warning');  }/*阻止向上冒泡,以防再次触发点击操作*/event.stopPropagation();  });/*点击全选框所在单元格时也触发全选框的点击操作*/$checkAllTh.click(function(){  $(this).find('input').click();  });var $tbr = $('table tbody tr');var $checkItemTd = $('<td><input type="checkbox" name="checkItem" /></td>');/*每一行都在最前面插入一个选中复选框的单元格*/$tbr.prepend($checkItemTd);/*点击每一行的选中复选框时*/$tbr.find('input').click(function(event){/*调整选中行的CSS样式*/$(this).parent().parent().toggleClass('warning');/*如果已经被选中行的行数等于表格的数据行数,将全选框设为选中状态,否则设为未选中状态*/$checkAll.prop('checked',$tbr.find('input:checked').length == $tbr.length ? true : false);/*阻止向上冒泡,以防再次触发点击操作*/event.stopPropagation();  });/*点击每一行时也触发该行的选中操作*/$tbr.click(function(){  $(this).find('input').click();  });  }  initTableCheckbox();  });</script> 

View Code

//定义jquery插件模板

//创建一个闭包
(function($) {//插件的定义$.fn.hilight = function(options) {    debug(this);//build main options before element iterationvar opts =$.extend({}, $.fn.hilight.defaults, options);//iterate and reformat each matched elementreturn this.each(function() {    $this = $(this);//build element specific optionsvar o = $.meta ? $.extend({}, opts, $this.data()) : opts;//update element styles$this.css({    backgroundColor: o.background,    color: o.foreground    });var markup = $this.html();//call our format functionmarkup =$.fn.hilight.format(markup);    $this.html(markup);    });    };//私有函数:debuggingfunctiondebug($obj) {if (window.console &&window.console.log)    window.console.log('hilight selection count: ' +$obj.size());    };//定义暴露format函数$.fn.hilight.format = function(txt) {return '<strong>' + txt + '</strong>';    };//插件的defaults$.fn.hilight.defaults ={    foreground:'red',    background:'yellow'};//闭包结束
})(jQuery);     

View Code

//Jquery插件模板2,  http://blog.jobbole.com/30550/

//Shawn Khameneh//ExtraordinaryThoughts.com
(function($) {var privateFunction = function() {//代码在这里运行
}var methods ={init:function(options) {return this.each(function() {var $this = $(this);var settings = $this.data('pluginName');if(typeof(settings) == 'undefined') {var defaults ={propertyName:'value',onSomeEvent:function() {}}settings=$.extend({}, defaults, options);$this.data('pluginName', settings);}else{settings=$.extend({}, settings, options);}//代码在这里运行
});},destroy:function(options) {return $(this).each(function() {var $this = $(this);$this.removeData('pluginName');});},val:function(options) {var someValue = this.eq(0).html();returnsomeValue;}};$.fn.pluginName= function() {var method = arguments[0];if(methods[method]) {method=methods[method];arguments= Array.prototype.slice.call(arguments, 1);}else if( typeof(method) == 'object' || !method ) {method=methods.init;}else{$.error('Method ' +  method + ' does not exist on jQuery.pluginName');return this;}return method.apply(this, arguments);}})(jQuery);

View Code

//将EF中, 使用DBFirst报错, :"XXXUnintentionalCodeFirstException",的解决办法:

将EF生成的连接串, 替换WebAPP中Web.Config的连接串即可.

//Nullable值的处理

在论坛里不止一次看到有网友提问关于LINQ NULL查询的问题了,现以微软NorthWind 数据库为例总结一下:如查询这样一句SQL ,用LINQ如何实现?view plain copy
SELECT*FROM [Orders] AS [t0]
WHERE ([t0].[ShippedDate]) IS NULL//v  方法一:
from o inOrderswhere o.ShippedDate==null
selecto  对应的Lamda表达式为:
Orders  .Where (o=> (o.ShippedDate == (DateTime?)null))  对应的SQL语句为:
SELECT [t0].[OrderID], [t0].[CustomerID], [t0].[EmployeeID], [t0].[OrderDate], [t0].[RequiredDate], [t0].[ShippedDate], [t0].[ShipVia], [t0].[Freight], [t0].[ShipName], [t0].[ShipAddress], [t0].[ShipCity], [t0].[ShipRegion], [t0].[ShipPostalCode], [t0].[ShipCountry]
FROM [Orders] AS [t0]
WHERE [t0].[ShippedDate] IS NULL//v  方法二:
from o inOrderswhere Nullable<DateTime>.Equals(o.ShippedDate,null)selecto
对应的Lamda表达式为:
Orders  .Where (o=> Object.Equals (o.ShippedDate, null))  对应的SQL语句为:
SELECT [t0].[OrderID], [t0].[CustomerID], [t0].[EmployeeID], [t0].[OrderDate], [t0].[RequiredDate], [t0].[ShippedDate], [t0].[ShipVia], [t0].[Freight], [t0].[ShipName], [t0].[ShipAddress], [t0].[ShipCity], [t0].[ShipRegion], [t0].[ShipPostalCode], [t0].[ShipCountry]
FROM [Orders] AS [t0]
WHERE [t0].[ShippedDate] IS NULL//v  方法三:
from o inOrderswhere !o.ShippedDate.HasValueselecto  对应的Lamda表达式为:
Orders  .Where (o=> !(o.ShippedDate.HasValue))  对应的SQL语句为:
SELECT [t0].[OrderID], [t0].[CustomerID], [t0].[EmployeeID], [t0].[OrderDate], [t0].[RequiredDate], [t0].[ShippedDate], [t0].[ShipVia], [t0].[Freight], [t0].[ShipName], [t0].[ShipAddress], [t0].[ShipCity], [t0].[ShipRegion], [t0].[ShipPostalCode], [t0].[ShipCountry]
FROM [Orders] AS [t0]
WHERE NOT ([t0].[ShippedDate] IS NOT NULL)//v  方法四:from o inOrderswhere o.ShippedDate.Value==(DateTime?)null
selecto  对应的Lamda表达式为:
Orders  .Where (o=> ((DateTime?)(o.ShippedDate.Value) == (DateTime?)null))  对应的SQL语句为:
SELECT [t0].[OrderID], [t0].[CustomerID], [t0].[EmployeeID], [t0].[OrderDate], [t0].[RequiredDate], [t0].[ShippedDate], [t0].[ShipVia], [t0].[Freight], [t0].[ShipName], [t0].[ShipAddress], [t0].[ShipCity], [t0].[ShipRegion], [t0].[ShipPostalCode], [t0].[ShipCountry]
FROM [Orders] AS [t0]
WHERE ([t0].[ShippedDate]) IS NULL//v  方法五:from o inOrderswhere  System.Data.Linq.SqlClient.SqlMethods.Equals(o.ShippedDate.Value,null)selecto  对应的Lamda表达式为:
Orders  .Where (o=> Object.Equals (o.ShippedDate.Value, null))  对应的SQL语句为:
SELECT [t0].[OrderID], [t0].[CustomerID], [t0].[EmployeeID], [t0].[OrderDate], [t0].[RequiredDate], [t0].[ShippedDate], [t0].[ShipVia], [t0].[Freight], [t0].[ShipName], [t0].[ShipAddress], [t0].[ShipCity], [t0].[ShipRegion], [t0].[ShipPostalCode], [t0].[ShipCountry]
FROM [Orders] AS [t0]
WHERE ([t0].[ShippedDate]) IS NULL  以上方法均只在LINQ TO SQL内验证实现,LINQ TO EF未验证。

View Code

//ajax请求时, 使用不同ContentType的时候的问题

HTTP/1.1 协议规定的 HTTP 请求方法有 OPTIONS、GET、HEAD、POST、PUT、DELETE、TRACE、CONNECT 这几种。其中 POST 一般用来向服务端提交数据,本文主要讨论 POST 提交数据的几种方式。我们知道,HTTP 协议是以 ASCII 码传输,建立在 TCP/IP 协议之上的应用层规范。规范把 HTTP 请求分为三个部分:状态行、请求头、消息主体。类似于下面这样:<method> <request-URL> <version>
<headers><entity-body>
协议规定 POST 提交的数据必须放在消息主体(entity-body)中,但协议并没有规定数据必须使用什么编码方式。实际上,开发者完全可以自己决定消息主体的格式,只要最后发送的 HTTP 请求满足上面的格式就可以。但是,数据发送出去,还要服务端解析成功才有意义。一般服务端语言如 php、python 等,以及它们的 framework,都内置了自动解析常见数据格式的功能。服务端通常是根据请求头(headers)中的 Content-Type 字段来获知请求中的消息主体是用何种方式编码,再对主体进行解析。所以说到 POST 提交数据方案,包含了 Content-Type 和消息主体编码方式两部分。下面就正式开始介绍它们。application/x-www-form-urlencoded这应该是最常见的 POST 提交数据的方式了。浏览器的原生 form 表单,如果不设置 enctype 属性,那么最终就会以 application/x-www-form-urlencoded 方式提交数据。请求类似于下面这样(无关的请求头在本文中都省略掉了):POST http://www.example.com HTTP/1.1
Content-Type: application/x-www-form-urlencoded;charset=utf-8title=test&sub%5B%5D=1&sub%5B%5D=2&sub%5B%5D=3
首先,Content-Type 被指定为 application/x-www-form-urlencoded;其次,提交的数据按照 key1=val1&key2=val2 的方式进行编码,key 和 val 都进行了 URL 转码。大部分服务端语言都对这种方式有很好的支持。例如 PHP 中,$_POST[‘title’] 可以获取到 title 的值,$_POST[‘sub’] 可以得到 sub 数组。很多时候,我们用 Ajax 提交数据时,也是使用这种方式。例如 JQuery 和 QWrap 的 Ajax,Content-Type 默认值都是「application/x-www-form-urlencoded;charset=utf-8」。multipart/form-data这又是一个常见的 POST 数据提交的方式。我们使用表单上传文件时,必须让 form 的 enctyped 等于这个值。直接来看一个请求示例:POST http://www.example.com HTTP/1.1
Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryrGKCBY7qhFd3TrwA------WebKitFormBoundaryrGKCBY7qhFd3TrwA
Content-Disposition: form-data; name="text"title
------WebKitFormBoundaryrGKCBY7qhFd3TrwA
Content-Disposition: form-data; name="file"; filename="chrome.png"
Content-Type: image/pngPNG ... content of chrome.png ...
------WebKitFormBoundaryrGKCBY7qhFd3TrwA--
这个例子稍微复杂点。首先生成了一个 boundary 用于分割不同的字段,为了避免与正文内容重复,boundary 很长很复杂。然后 Content-Type 里指明了数据是以 mutipart/form-data 来编码,本次请求的 boundary 是什么内容。消息主体里按照字段个数又分为多个结构类似的部分,每部分都是以 –boundary 开始,紧接着内容描述信息,然后是回车,最后是字段具体内容(文本或二进制)。如果传输的是文件,还要包含文件名和文件类型信息。消息主体最后以 –boundary– 标示结束。关于 mutipart/form-data 的详细定义,请前往 rfc1867 查看。这种方式一般用来上传文件,各大服务端语言对它也有着良好的支持。上面提到的这两种 POST 数据的方式,都是浏览器原生支持的,而且现阶段原生 form 表单也只支持这两种方式。但是随着越来越多的 Web 站点,尤其是 WebApp,全部使用 Ajax 进行数据交互之后,我们完全可以定义新的数据提交方式,给开发带来更多便利。application/jsonapplication/json 这个 Content-Type 作为响应头大家肯定不陌生。实际上,现在越来越多的人把它作为请求头,用来告诉服务端消息主体是序列化后的 JSON 字符串。由于 JSON 规范的流行,除了低版本 IE 之外的各大浏览器都原生支持 JSON.stringify,服务端语言也都有处理 JSON 的函数,使用 JSON 不会遇上什么麻烦。JSON 格式支持比键值对复杂得多的结构化数据,这一点也很有用。记得我几年前做一个项目时,需要提交的数据层次非常深,我就是把数据 JSON 序列化之后来提交的。不过当时我是把 JSON 字符串作为 val,仍然放在键值对里,以 x-www-form-urlencoded 方式提交。Google 的 AngularJS 中的 Ajax 功能,默认就是提交 JSON 字符串。例如下面这段代码:var data = {'title':'test', 'sub' : [1,2,3]};
$http.post(url, data).success(function(result) {...
});
最终发送的请求是:POST http://www.example.com HTTP/1.1
Content-Type: application/json;charset=utf-8{"title":"test","sub":[1,2,3]}
这种方案,可以方便的提交复杂的结构化数据,特别适合 RESTful 的接口。各大抓包工具如 Chrome 自带的开发者工具、Firebug、Fiddler,都会以树形结构展示 JSON 数据,非常友好。但也有些服务端语言还没有支持这种方式,例如 php 就无法通过 $_POST 对象从上面的请求中获得内容。这时候,需要自己动手处理下:在请求头中 Content-Type 为 application/json 时,从 php://input 里获得原始输入流,再 json_decode 成对象。一些 php 框架已经开始这么做了。当然 AngularJS 也可以配置为使用 x-www-form-urlencoded 方式提交数据。如有需要,可以参考这篇文章。text/xml我的博客之前提到过 XML-RPC(XML Remote Procedure Call)。它是一种使用 HTTP 作为传输协议,XML 作为编码方式的远程调用规范。典型的 XML-RPC 请求是这样的:POST http://www.example.com HTTP/1.1
Content-Type: text/xml<?xml version="1.0"?>
<methodCall><methodName>examples.getStateName</methodName><params><param><value><i4>41</i4></value></param></params>
</methodCall>
XML-RPC 协议简单、功能够用,各种语言的实现都有。它的使用也很广泛,如 WordPress 的 XML-RPC Api,搜索引擎的 ping 服务等等。JavaScript 中,也有现成的库支持以这种方式进行数据交互,能很好的支持已有的 XML-RPC 服务。不过,我个人觉得 XML 结构还是过于臃肿,一般场景用 JSON 会更灵活方便。转载请注明原处

View Code

在做Ajax请求时, POST方式发送时, Data数据被encode了. 原因是, content-type设置为application/json, 换为默认的content-type时, post中的data数据正常.

//翻页控件中的CurrentPageIndex并非改变不了,而是必须取得RecordCount值后才允许赋值,切记!切记

//如果将服务器控件的Enabled值设为false,在发布以后JS无法操作服务器控件的值。
//可以通过JS来通过设置disabled属性, 如:

document.getElementById("TextBox1").disabled = false;
document.getElementById("CheckBox1").disabled = false;
document.getElementById("CheckBox1").parentElement.disabled = false;//把他的父元素也disabled = false

View Code

Entity Framework Database First时报类似"XX UnintentionalCodeFirstException"的错误,

项目上单击右键,在弹出的菜单中可以看到增加了一个Entity Framework的菜单项,里面有一个Reverse Enginner Code First。单击它以后出现选择数据连接的窗口,建立好数据连接之后它会自动地生成所有数据表所映射的实体类和对应的映射类(放在Mapping文件夹中),并且还自动生成了DbContext类。用生成的这些类取代原来通过EF直接建立的实体类和Context,编译项目并运行测试,测试成功。

//CSS中, display设置为inline-block时, 默认会采用基线对齐的方式(vertical-align:baseline), 此时其中的块元素会出现各种对其问题, 需配合vertical-align:top来解决问题.

//Mysql 5.7.10密码过期重置

首先 跳过权限表模式启动mysql:mysqld --skip-grant-tables &
从现在开始,你将踏入第一个坑,如果你使用网上到处贴的 错误修改方法:mysql> UPDATE mysql.user SET authentication_string=PASSWORD('your_new_password') WHERE User='root';(注意,5.7之后password改成了authentication_string)那么恭喜你,你修改成功了,但是你会发现当你使用navicat这种GUI工具连接的时候会报如下错误:ERROR1820 (HY000): You must reset your password using ALTER USERstatement before executing this statement.同时你会发现命令行能使用mysql-u root -p 登录了,但是不能use mysql了,连库都用不了了,搞毛啊下面这个命令将会拯救你:mysql> SET PASSWORD = PASSWORD('your_new_password');
mysql> update user set password_expired='N' where user='root';执行完之后使用命令 mysqladmin-u root -p shutdown关闭mysqld再次 mysql.server start 启动mysql就全部ok了~

View Code

//js 显示页面宽度

        var s = "";s+= " 网页可见区域宽:"+document.body.clientWidth;s+= " 网页可见区域高:"+document.body.clientHeight;s+= " 网页可见区域宽:"+ document.body.offsetWidth+" (包括边线和滚动条的宽)";s+= " 网页可见区域高:"+ document.body.offsetHeight+" (包括边线的宽)";s+= " 网页正文全文宽:"+document.body.scrollWidth;s+= " 网页正文全文高:"+document.body.scrollHeight;s+= " 网页被卷去的高:"+document.body.scrollTop;s+= " 网页被卷去的左:"+document.body.scrollLeft;s+= " 网页正文部分上:"+window.screenTop;s+= " 网页正文部分左:"+window.screenLeft;s+= " 屏幕分辨率的高:"+window.screen.height;s+= " 屏幕分辨率的宽:"+window.screen.width;s+= " 屏幕可用工作区高度:"+window.screen.availHeight;s+= " 屏幕可用工作区宽度:"+window.screen.availWidth;s+= " 你的屏幕设置是 "+ window.screen.colorDepth +" 位彩色";s+= " 你的屏幕设置 "+ window.screen.deviceXDPI +" 像素/英寸";console.log(s)

View Code

//css 选择器

$(".class1 .class2") 选择class1元素下class2的元素(中间有空格)
$(".class1.class2") 选择同时含有class1和class2的元素(中间没有空格)
$(".class1,.class2") 选择class1或者class2的元素(中间有逗号)

View Code

转载于:https://www.cnblogs.com/cs_net/archive/2010/09/29/1838773.html

学习笔记---Winform的东东忘了好些。。。相关推荐

  1. C#学习笔记-Winform根据数据自动生成控件

    1.思路 (1)获取一个集合(数据) (2)遍历集合,设置统一的控件样式.设置控件坐标 (3)关联事件 2.实现 项目开发中,当需求发生改变时,UI界面需要简单更改,这时代码就需要去修改,这样子做比较 ...

  2. linux 串口信息记到日志,[linux学习笔记]之一:ubuntu ch340调试备忘

    [linux学习笔记]之一:ubuntu ch340调试备忘 已有 2183 次阅读2016-11-8 21:52 |个人分类:linux 最近迷上了Linux,入了一块板.电脑使用win7+ubun ...

  3. 刀片服务器改台式电脑_服务器到底是个什么东东?跟电脑有啥区别?电脑知识学习!...

    一位朋友留言点的内容,想了解服务器方面的知识,对于普通用户而言,确实对服务器感觉很神秘,不知道服务器到底是个什么东东,我保证看完这篇,你就会明白服务器到底是个啥了. 首先可以很明确的告诉你,服务器也是 ...

  4. BOLT.NET 学习笔记(一) 开篇 用.net winform 快速开发 炫酷的界面

    BOLT.NET 学习笔记(一) 开篇 用.net winform 快速开发 炫酷的界面 bolt 基本介绍 Bolt界面引擎是迅雷公司从2009年开始开发的第四代界面库.迅雷7是首个采用该引擎成功开 ...

  5. 【C#】 WinForm窗体应用程序学习笔记 (一)

    WinForm窗体应用程序学习笔记(一) 由于控制台应用程序的运行结果都是通过控制台输出的,不能提供良好的用户体验,为此,C#提供了WinForm窗体应用程序.WinForm具有一系列丰富的控件,用于 ...

  6. 不忘初心helloworld,IMX6入门学习笔记

    本文按照时间学习的先后顺序,入门体验了知名半导体厂商NXP的著名处理器--IMX6. 无论你是否有基础,都能按照流程学会软件使用和交叉编译方法,老规矩:看不懂算我的. 了解开发板 官方资料链接: ht ...

  7. 【TensorFlow-windows】学习笔记五——自编码器

    前言 上一篇博客介绍的是构建简单的CNN去识别手写数字,这一篇博客折腾一下自编码,理论很简单,就是实现对输入数据的重构,具体理论可以看我前面的[theano-windows]学习笔记十三--去噪自编码 ...

  8. java事件 socket_java中有关socket通信的学习笔记

    最近做的项目中使用到了一些基于java的socket长连接的一些功能,用来穿透有关行业的网闸.用到了也就学习了一下,下面是对学习内容的一个笔记,记录一下也希望有兴趣的同学可以参考一下,加深对javas ...

  9. 8. SpringBoot基础学习笔记

    SpringBoot基础学习笔记 课程前置知识说明 1 SpringBoot基础篇 1.1 快速上手SpringBoot SpringBoot入门程序制作 1.2 SpringBoot简介 1.2.1 ...

最新文章

  1. 远程主机访问mysql权限_如何给远程主机开启mysql远程登录权限
  2. 用python偷偷给班级群女同学的颜值进行排名,排最后的 说开学要打爆我
  3. AI(2)---高通人工智能
  4. 創世記(一): 一至三章
  5. 94% Asset Optimization
  6. ActiveX控件概述
  7. 【ESD专题】1.ESD基础及IEC61000-4-2标准
  8. 将一个数组中的值按逆序重新存放。例如,原来顺序为8,6,5,4,1。要求改为1,4,5,6,8
  9. Hibernate框架的入门级学习运用
  10. wps在Linux上使用命令打开文档的方法
  11. 如何建立一个属于自己的网站(小白教程)
  12. python ssl module_Python升级后ssl模块不可用问题解决和浅析
  13. 面向对象程序设计c++版董正言张聪课本课后习题答案第六章
  14. 第09课:生活中的工厂模式——你要拿铁还是摩卡
  15. “百度杯”CTF比赛 十月场 Login
  16. RoadFlow的表单设计中的数据表格
  17. STM32中U8, U16 ,U32啥意思
  18. 祈福、赏花、戏冰雪:春节北京公园将开展46项游园活动
  19. python迭代器什么时候用_python迭代器与生成器用途是什么
  20. Exp2 后门原理与实践 20204308李文艳

热门文章

  1. 计算机专业海报加文字,PS制作简洁漂亮的文字主题海报 -电脑资料
  2. 计算机任务无法结束,遇到Win7中任务管理器无法结束进程问题,如何解决
  3. css——指定某个区域可垂直或水平滑动
  4. 那些年,老师们说过的话!|中机智库教师节特辑
  5. 服务器自带的校时ip是多少钱,国内大概可用的NTP时间校准服务器IP地址
  6. 【商汤科技2019校招】计算机视觉研究员笔试
  7. Spring-Security 实现前后端分离登录
  8. 使用CityScapes数据集训练实例分割网络YOLACT
  9. java读取CAD(dxf)文件(获取layer,block,entity)
  10. 论坛议程|COSCon'22 女性论坛(L)