protected void btnAdd_Click(object sender, EventArgs e)
    { /////Add Exception handilng try catch change by vishal 21-05-2012
        try
        {
            string vardate  = "";
            string vardate1 = "";
            string vardate2 = "";
            string vardate3 = "";

            DateTime dtendtime = new DateTime();
            if (txtatendtime.Text != "")
            {
                // string[] tempdate = txtatendtime.Text.ToString().Split(("/").ToCharArray());
                vardate   = txtatendtime.Text.ToString();
                dtendtime = Convert.ToDateTime(vardate);
                objChangetask.Actualendtime = dtendtime.ToString();
            }
            else
            {
                vardate = null;
                objChangetask.Actualendtime = vardate;
            }


            DateTime actstarttime = new DateTime();
            if (txtatsttime.Text != "")
            {
                //  string[] Actualstarttime = txtatsttime.Text.ToString().Split(("/").ToCharArray());
                vardate1     = txtatsttime.Text.ToString();
                actstarttime = Convert.ToDateTime(vardate1);
                objChangetask.Actualstarttime = actstarttime.ToString();
            }
            else
            {
                vardate1 = null;
                objChangetask.Actualstarttime = vardate1;
            }


            DateTime schdstime = new DateTime();
            if (txtschedlstarttime.Text != "")
            {
                //  string[] Scheduledstarttime = txtschedlstarttime.Text.ToString().Split(("/").ToCharArray());
                vardate2  = txtschedlstarttime.Text.ToString();
                schdstime = Convert.ToDateTime(vardate2);
                objChangetask.Scheduledstarttime = schdstime.ToString();
            }
            else
            {
                vardate2 = null;
                objChangetask.Scheduledstarttime = vardate2;
            }

            DateTime dt = new DateTime();
            if (txtschdlendtime.Text != "")
            {
                //string[] Scheduledendtime = txtschdlendtime.Text.ToString().Split(("/").ToCharArray());
                //vardate3 = Scheduledendtime[2] + "-" + Scheduledendtime[1] + "-" + Scheduledendtime[0];
                vardate3 = txtschdlendtime.Text.ToString();

                dt = Convert.ToDateTime(vardate3);
                objChangetask.Scheduledendtime = dt.ToString();
            }
            else
            {
                vardate3 = null;
                objChangetask.Scheduledendtime = vardate3;
            }

            objChangetask.Title        = txttitle.Text;
            objChangetask.Description  = txtdescription.Text;
            objChangetask.Ownerid      = Convert.ToInt32(drpTechnician1.SelectedValue);
            objChangetask.Taskstatusid = Convert.ToInt32(drptaskstatus.SelectedValue);
            objChangetask.Changeid     = Convert.ToInt32(Request.QueryString[0]);
            objChangetask.Comment      = "";
            objChangetask.Insert();
        }
        catch (Exception ex)
        {
            string myScript;
            myScript = "<script language=javascript>alert('Exception - '" + ex + "');</script>";
            Page.RegisterClientScriptBlock("MyScript", myScript);
            return;
        }
    }
コード例 #2
0
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        string vardate  = "";
        string vardate1 = "";
        string vardate2 = "";
        string vardate3 = "";

        DateTime dtendtime = new DateTime();

        if (txtatendtime.Text != "")
        {
            // string[] tempdate = txtatendtime.Text.ToString().Split(("/").ToCharArray());
            vardate   = txtatendtime.Text.ToString();
            dtendtime = Convert.ToDateTime(vardate);
            objChangetask.Actualendtime = dtendtime.ToString();
        }
        else
        {
            vardate = null;
            objChangetask.Actualendtime = vardate;
        }


        DateTime actstarttime = new DateTime();

        if (txtatsttime.Text != "")
        {
            //  string[] Actualstarttime = txtatsttime.Text.ToString().Split(("/").ToCharArray());
            vardate1     = txtatsttime.Text.ToString();
            actstarttime = Convert.ToDateTime(vardate1);
            objChangetask.Actualstarttime = actstarttime.ToString();
        }
        else
        {
            vardate1 = null;
            objChangetask.Actualstarttime = vardate1;
        }


        DateTime schdstime = new DateTime();

        if (txtschedlstarttime.Text != "")
        {
            //  string[] Scheduledstarttime = txtschedlstarttime.Text.ToString().Split(("/").ToCharArray());
            vardate2  = txtschedlstarttime.Text.ToString();
            schdstime = Convert.ToDateTime(vardate2);
            objChangetask.Scheduledstarttime = schdstime.ToString();
        }
        else
        {
            vardate2 = null;
            objChangetask.Scheduledstarttime = vardate2;
        }

        DateTime dt = new DateTime();

        if (txtschdlendtime.Text != "")
        {
            //string[] Scheduledendtime = txtschdlendtime.Text.ToString().Split(("/").ToCharArray());
            //vardate3 = Scheduledendtime[2] + "-" + Scheduledendtime[1] + "-" + Scheduledendtime[0];
            vardate3 = txtschdlendtime.Text.ToString();

            dt = Convert.ToDateTime(vardate3);
            objChangetask.Scheduledendtime = dt.ToString();
        }
        else
        {
            vardate3 = null;
            objChangetask.Scheduledendtime = vardate3;
        }

        objChangetask.Title        = txttitle.Text;
        objChangetask.Description  = txtdescription.Text;
        objChangetask.Ownerid      = Convert.ToInt16(drpTechnician1.SelectedValue);
        objChangetask.Taskstatusid = Convert.ToInt16(drptaskstatus.SelectedValue);
        objChangetask.Changeid     = Convert.ToInt16(Request.QueryString[0]);
        objChangetask.Comment      = "";
        objChangetask.Insert();
    }