字串的宣告
string 變數 = string.Empty;
string 變數 = "abcdefg";

Session內容的取出
string 變數 = (string)Session["名稱"];

網頁元件內容的取出
string 變數 = ((TextBox)網頁元件的ID).Text;
string 變數 = ((DropDownList)網頁元件的ID).SelectedItem.Value;
string 變數 = ((DropDownList)網頁元件的ID).SelectedItem.Text;

日期時間格式的使用
DateTime DateTime1 = DateTime.Parse("2011-05-16 07:30:00");
DateTime DateTime2 = DateTime.Parse("2011-05-16 08:00:00");
TimeSpan t1 = new TimeSpan(DateTime1.Ticks);
TimeSpan t2 = new TimeSpan(DateTime2.Ticks);
double ts = t2.Subtract(t1).TotalHours; //ts=0.5(小時)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Form1 : System.Web.UI.Page
{
    DBmssql db1 = new DBmssql();
    string url = "Form1List.aspx";
    string op = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            txtAccount.Text = (string)Session["ec_userid"];
            initProjectList(drpProject);
            initTimeList();

            lblEditTag.Text = "";
            lblCount.Text = "";

            //增加opreation的tag,可以讓一個asp網頁處理兩種相似的功能,例如:新增and修改
            op = (string)Request["op"];
            if (op == "Edit")
            {
                initTable();
                lblEditTag.Text = (string)Request["op"];
                lblCount.Text = (string)Request["id"];
            }
        }
    }

    public void initProjectList(object sender)
    {
        System.Data.DataTable dt1 = new System.Data.DataTable();
        string drpValue = null;
        string drpText = null;

        ((DropDownList)sender).Items.Clear();
        ((DropDownList)sender).Items.Add(new ListItem("(請選擇工程專案)", ""));

        dt1 = db1.GetDataTable("SELECT id,cname FROM 專案列表 ORDER BY id DESC");
        for (int i = 0; i  3) {
            MsgStr = MsgStr + "超過網路申報時間,請改用紙本申報。";
            //lt.Text = tNow.ToString() + "-" + t2.ToString() + "=" + ta.ToString();
        }
        
        if (MsgStr != string.Empty)
        {
            string sScript = string.Empty;
            sScript = "alert('" + MsgStr + "')";
            this.ClientScript.RegisterStartupScript(this.GetType(), "error", sScript, true);
            return;
        }

        System.Data.DataTable dt1 = new System.Data.DataTable();
        string sqlstr = "";
        op = ((Label)lblEditTag).Text;
        string count = ((Label)lblCount).Text;
        try
        {
            //增加opreation的tag,可以讓一個asp網頁處理兩種相似的功能,例如:新增and修改
            if (op == "")
            {
                sqlstr = " INSERT INTO 每日工時表(account, pid, WorkDate, StartTime, EndTime) ";
                sqlstr += " VALUES('" + account + "','" + pid + "','" + strDate + "','" + strTimeStart + "','" + strTimeEnd + "')";
                db1.ExecuteCmd(sqlstr);
                lt.Text = "<script language=javascript>alert('新增成功。');location.href='" + url + "';</script>";
            }
            if (op == "Edit")
            {
                sqlstr = " INSERT INTO 每日工時表(account, pid, WorkDate, StartTime, EndTime) ";
                sqlstr += " VALUES('" + account + "','" + pid + "','" + strDate + "','" + strTimeStart + "','" + strTimeEnd + "')";
                sqlstr = " UPDATE 每日工時表 SET " ;
                sqlstr += " account='" + account + "'";
                sqlstr += ",pid='" + pid + "'";
                sqlstr += ",WorkDate='" + strDate + "'";
                sqlstr += ",StartTime='" + strTimeStart + "'";
                sqlstr += ",EndTime='" + strTimeEnd + "'";
                sqlstr += " WHERE count='" + count + "'";
                db1.ExecuteCmd(sqlstr);
                lt.Text = "<script language=javascript>alert('修改成功。');location.href='" + url + "';</script>";
            }
        }
        catch (Exception ex)
        {
            lt.Text = "操作失敗。<BR>" + ex.Message.ToString() + "<BR>" + sqlstr;
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Form1List : System.Web.UI.Page
{
    DBmssql db1 = new DBmssql();
    
    protected void Page_Load(object sender, EventArgs e)
    {
        //避免網頁有submit的動作時,重複執行init的function,造成使用者選取or填寫的資料被reset。
        if (!IsPostBack)
        {
            initList();
            initSerachItem();
        }
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("Form1.aspx"); //網頁重新導向
    }

    public void initList()
    {
        if (drpType.SelectedItem.Value == "人員")
        {
            initMemberList(drpKeyWord);
            ((CheckBox)ckbTag).Enabled = false;
        }
        else
        {
            initProjectList(drpKeyWord);
            ((CheckBox)ckbTag).Enabled = true;
        }
    }

    public void initProjectList(object sender)
    {
        System.Data.DataTable dt1 = new System.Data.DataTable();
        string drpValue = null;
        string drpText = null;

        ((DropDownList)sender).Items.Clear();
        ((DropDownList)sender).Items.Add(new ListItem("(請選擇工程專案)", ""));

        dt1 = db1.GetDataTable("SELECT id,cname FROM 專案列表 ORDER BY id DESC");
        for (int i = 0; i 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 伊 的頭像

    伊のspace~芳香精油*美容保養*程式設計

    伊 發表在 痞客邦 留言(0) 人氣()