笔记

private static HttpWebResponse Is_Exist_Path(string path)
        {
            HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(path);
            myReq.Method = "HEAD";
            HttpWebResponse myRes = (HttpWebResponse)myReq.GetResponse();
            return myRes;
        }
HttpWebResponse myRes = Is_Exist_Path(path);
                        if (myRes.StatusCode == HttpStatusCode.OK)   //判断如果文件存在,执行以下语句

-----------------

DialogResult result = MessageBox.Show("用户名:"+txtEntName.Text+",充值金额:"+txtMoney.Text+"元。确定要充值吗?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, MessageBoxOptions.DefaultDesktopOnly);
        if (result.ToString() == "OK")
        {
}

//用时

Stopwatch sw = new Stopwatch();
            sw.Start();

            sw.Stop();
           耗时:{0}毫秒", sw.ElapsedMilliseconds.ToString());

 

//定时器
<script language="javascript" type="text/javascript">
   var inforbox = document.getElementById("inforbox_10555");
   var timer = setTimeout(inforClose,20000);//设置定时器
   inforbox.onmouseover = function(){
    clearTimeout(timer);
    
   }
   inforbox.onmouseout = function(){
    timer = setTimeout(inforClose,20000);
   }
   
   function inforClose(){
   inforbox.style.display = "none";    
   }
  </script>

在项目中的CSS中添加下面的样式,就可以解决CalendarExtender被DropList遮挡的问题。
.ajax__calendar {
    position: relative;
    left: 0px !important;
    top: 0px !important;
    visibility: visible;
    display: block;
}
.ajax__calendar iframe
{
    left: 0px !important;
    top: 0px !important;
}

//手动指定ddl的Text和Value­

ddlArea.DataSource = areaBll.GetModelList(""); ­

        ddlArea.DataValueField = "AreaID"; ­

        ddlArea.DataTextField = "AreaName"; ­

        ddlArea.DataBind(); ­

­

绑定String时用<%# Container.DataItem%>

 

//格式化日期­

<%#Eval("OpeningTime", "{0:yyyy-MM-dd}")%>­

­

//查出指定时间的信息­

SELECT * FROM V_Product_Provide where Status=1 AND datediff(day,CreateTime,getdate()) <=7­

//插一行在第一列­

this.ddlTime.Items.Insert(0, "所有发布时间");­

 

//图片加边框
style="width: 55px; height: 69px; border: 1px #ccc solid"

 

 

// Search2 要加AND

DBUtility.Search3("T_Shop_Orders", "Id", "*", true, page, pageSize, "OrderDate", desc, sqlStr, false, ref pagesCount, ref rowsCount);

 

 

//只要没有CheckBox 被选种 则跳出提示

 function checkall(str) {
            var xi = 0;
            var tid = ";";
            var chk = $('input[type="checkbox"]');
            for ( var i = 0; i < chk.length; i++) {
                if ($(chk[i]).attr("Checked")) {
                    xi = xi + 1;
                    tid = tid + $(chk[i]).attr("title") + ";";
                }
            }           
            if (xi == 0) {
                alert("请选择要 "+ str +" 的邮件");
                return false;
            } else {               
                $("#TextBox1").val(tid);          
            }
        }

 OnClientClick="return checkall('str')"

(需要引入 jquery-1.3.2.min.js)

 

 //拆分字符为数组

 protected string[] GetProid(string proidString)
    {

        char[] s_line = {','};
        string[] proid = proidString.Split(s_line);
        return proid;
    }

调用  string[] temp = GetProid(Request.QueryString["proidString"]);
                for (int i = 0; i < temp.Length - 1; i++)(最后一个为 , 号所以减1)
                {
                    delOrderAndOrderDetail(temp[i]);
                }

//传参数

 Response.Redirect("/Member/Login.aspx?returnPage==" + Server.UrlDecode("/Web/CN/ShoppingCar/CheckCar.aspx" + Request.QueryString["MOrderId"] + Request.QueryString["OrderIdString"]));

 

 注册AJAX控件 <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

   

/// 订单编号 + 随即数   

 static string GetNo(int num)
    {
        string a = "0123456789";
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < num; i++)
        {
            sb.Append(a[new Random(Guid.NewGuid().GetHashCode()).Next(0, a.Length - 1)]);
        }

        return sb.ToString();
    }

 string number = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + GetNo(2);

 string number = DateTime.Now.ToString("yyyyMMddHHmmss") + GetNo(4);

 

    /// <summary>
    /// 计算两个日期的时间间隔
    /// </summary>
    /// <param name="DateTime1">第一个日期和时间</param>
    /// <param name="DateTime2">第二个日期和时间</param>
    /// <returns></returns>
    private int DateDiff(DateTime DateTime1, DateTime DateTime2)
    {
        TimeSpan ts1 = new TimeSpan(DateTime1.Ticks);
        TimeSpan ts2 = new TimeSpan(DateTime2.Ticks);
        TimeSpan ts = ts1.Subtract(ts2).Duration();
        return ts.Days;
    }

//日期大小 TimeSpan
    private void TimeSpan(DateTime start, DateTime end)
    {
        int time = 0;
        if (DateTime.Compare(start, end) < 0)
        {
            time = DateTime.Compare(start, end);
            TimeSpan ts = end - start;
            time = ts.Days;
        }
        else
        {
            time = DateTime.Compare(start, end);
            TimeSpan ts = start - end;
            time = ts.Days;
        }      

    }

 

获得HTTP请求的头
            for (int i = 0; i < HttpContext.Current.Request.ServerVariables.Count; i++)
            {
                HttpContext.Current.Response.Write(HttpContext.Current.Request.ServerVariables.GetKey(i) + "_________" + HttpContext.Current.Request.ServerVariables[i].ToString() + "  ");
            }

 

{

  1..Response.Redirect("/CN/Product/Supply/Bargain.aspx?pid=" + MyCategoryId + "&tpid=" + CategoryID);

  2..ScriptManager.RegisterClientScriptBlock(this, this.Page.GetType(), "open", "window.open(\"/CN/Product/Supply/Bargain.aspx?pid="+MyCategoryId+"&tpid="+CategoryID+"\");", true);

}

 


查找替换

using System.Text.RegularExpressions;
                                     它里面的  它     换 它        忽略大小写
1。tsql = Regex.Replace(tsql, "create", "alter", RegexOptions.IgnoreCase);   替换所有的
                      把它里面的       它    换成 它
2。tsql = tsql.Replace("CREATE", "ALTER"); 替换所有的

                                                                 在它里面   找它               忽略大小写
3。MatchCollection mc = Regex.Matches(tsql, @"create", RegexOptions.IgnoreCase);
if (mc.Count > 0)
{
 Match m = mc[0];//取得第一个           替换成它
 tsql = new Regex(m.Value).Replace(tsql, "alter ", 1, m.Index); 只替换第一个
}

 

确定窗口

DialogResult objDialogResult = MessageBox.Show("您确定要删除记录吗?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1,MessageBoxOptions.DefaultDesktopOnly);      
        if (objDialogResult == DialogResult.Yes)
        {
  }

调用前台JS

ScriptManager.RegisterClientScriptBlock(this, this.Page.GetType(), "clear", "getAllSelect(this)", true);

 

 <div style="padding-left: 21px; overflow: hidden; width: 230; white-space: nowrap; text-overflow: ellipsis;cursor:hand;" class="zhxx">  多出了自动用。。。表示</div>
       

DialogResult objDialogResult = MessageBox.Show("您确定要删除记录吗?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1,MessageBoxOptions.DefaultDesktopOnly);      
        if (objDialogResult == DialogResult.Yes)
        {
}

 public void Msg(string str) {
        Page.RegisterStartupScript("test", "<script>alert('" + str + "');window.location.href=window.location.href;</script>");
    }

初始化VS

devenv /resetsettings
devenv /resetskippkgs

 

12345.ToString("n"); //生成 12,345.00
12345.ToString("C"); //生成 ¥12,345.00
12345.ToString("e"); //生成 1.234500e+004
12345.ToString("f4"); //生成 12345.0000
12345.ToString("x"); //生成 3039 (16进制)
12345.ToString("p"); //生成 1,234,500.00%

//防止后退 重复提交

OnClientClick="javascript:location.replace(this.href); event.returnvalue=false; "

 

//web.config 乱码

 <system.web>
    <globalization requestEncoding="gb2312" responseEncoding="gb2312" />

 

//读取自定义节点

<SpringOverrideProperty>

    <add key="DbProvider.ConnectionString" value="Persist Security Info=False;User ID=sa;Initial Catalog=SFY;Data Source=172.16.73.69"/> 

    <add key="XX" value="XXX"/> 

  </SpringOverrideProperty> </configuration>
读取key为DbProvider.ConnectionString的value

XmlDocument DocXml = new XmlDocument();
DocXml.Load(Server.MapPath("web.config"));
XmlNode xmlNo = DocXml.SelectSingleNode("//SpringOverrideProperty/add[@key=\"DbProvider.ConnectionString\"]");
Num1.Text = xmlNo.Attributes["value"].Value.ToString();

 

//加载外部XML

 private static AppSettingsSection app;
        static AutomationEmail()
        {
            ExeConfigurationFileMap file = new ExeConfigurationFileMap();
            file.ExeConfigFilename = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + ConfigurationManager.AppSettings.Get("email");
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(file, ConfigurationUserLevel.None);
            app = config.AppSettings;
        }
        private static string GetValueByKey(string key)
        {
            return app.Settings[key].Value;
        }

 

//查找 重复项

select * from aspnet_Users where UserName in( select UserName from aspnet_Users group by UserName having count(*) > 3 )

你可能感兴趣的:(笔记)