示例#1
0
    protected void btnHolidayadd_Click(object sender, EventArgs e)
    {
        string vardate;

        lblerrmsg.Text = "";
        int varholidaydate, varsiteid;

        varsiteid = Convert.ToInt16(drpsite.SelectedValue);
        string[] tempdate = txtHolidayDate.Text.ToString().Split(("/").ToCharArray());
        vardate        = tempdate[2] + "-" + tempdate[1] + "-" + tempdate[0];
        varholidaydate = ObjHoliday.Get_By_HolidayDate_Siteid(varsiteid, vardate);
        if ((varholidaydate == 0) && (varsiteid != 0) && (txtHolidaydesc.Text != ""))
        {
            ObjHoliday.Holidaydate = vardate;
            ObjHoliday.Siteid      = Convert.ToInt16(drpsite.SelectedValue);
            ObjHoliday.Description = txtHolidaydesc.Text.ToString();
            ObjHoliday.Insert();
            lblerrmsg.Text      = Resources.MessageResource.erradd.ToString();
            txtHolidaydesc.Text = "";
            txtHolidayDate.Text = "";
        }
        else if (varholidaydate >= 1)
        {
            lblerrmsg.Text = Resources.MessageResource.erralready.ToString();
        }
        //else if (varsiteid == 0)
        //{
        //    lblerrmsg.Text = "Select the site name";
        //}
    }
    protected void grdvwEdit_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        Holiday_mst obj = new Holiday_mst();
        Holiday_mst obj1 = new Holiday_mst();
        string      hdate, vardate;
        string      hdesc1, id;
        int         hid, sid, varholidaydate;

        hdate  = ((TextBox)grdvwEdit.Rows[e.RowIndex].Cells[1].Controls[1]).Text;
        hdesc1 = ((TextBox)grdvwEdit.Rows[e.RowIndex].Cells[2].Controls[1]).Text;
        id     = Convert.ToString(grdvwEdit.Rows[e.RowIndex].Cells[0].Text);
        hid    = Convert.ToInt32(id);
        sid    = Convert.ToInt32(drpsite.SelectedValue);
        string[] tempdate = ((TextBox)grdvwEdit.Rows[e.RowIndex].Cells[1].Controls[1]).Text.ToString().Split(("/").ToCharArray());
        vardate        = tempdate[0] + "/" + tempdate[1] + "/" + tempdate[2];
        varholidaydate = obj.Get_By_HolidayDate_Siteid(sid, vardate);
        objholiday     = objholiday.Get_Description_By_Holidayid(hid);

        if ((objholiday.Holidaydate == vardate) && (objholiday.Description != ""))
        {
            objholiday.Holidayid   = hid;
            objholiday.Holidaydate = hdate;
            objholiday.Description = hdesc1;
            objholiday.Siteid      = sid;
            objholiday.Update();
            grdvwEdit.EditIndex = -1;
            BindGrid();
            lblerrmsg.Text = Resources.MessageResource.errupdate.ToString();
        }
        else if ((varholidaydate == 0) && (hdate != "") && (hdesc1 != ""))
        {
            objholiday.Holidayid   = hid;
            objholiday.Holidaydate = hdate;
            objholiday.Description = hdesc1;
            objholiday.Siteid      = sid;
            objholiday.Update();
            grdvwEdit.EditIndex = -1;
            BindGrid();
            lblerrmsg.Text = Resources.MessageResource.errupdate.ToString();
        }
        else if ((hdate == "") || (hdesc1 == ""))
        {
            lblerrmsg.Text = "Holiday Date or Description should not be empty";
        }
        else
        {
            lblerrmsg.Text = Resources.MessageResource.erralready.ToString();
        }
    }
    protected void grdvwEdit_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        Holiday_mst obj = new Holiday_mst();
        Holiday_mst obj1 = new Holiday_mst();
        string hdate, vardate;
        string hdesc1,id;
        int hid, sid, varholidaydate;
        hdate = ((TextBox)grdvwEdit.Rows[e.RowIndex].Cells[1].Controls[1]).Text;
        hdesc1 = ((TextBox)grdvwEdit.Rows[e.RowIndex].Cells[2].Controls[1]).Text;
        id = Convert.ToString(grdvwEdit.Rows[e.RowIndex].Cells[0].Text);
        hid = Convert.ToInt16(id);
        sid = Convert.ToInt16(drpsite.SelectedValue);
        string[] tempdate =((TextBox)grdvwEdit.Rows[e.RowIndex].Cells[1].Controls[1]).Text.ToString().Split(("/").ToCharArray());
        vardate = tempdate[0] + "/" + tempdate[1] + "/" + tempdate[2];
        varholidaydate = obj.Get_By_HolidayDate_Siteid(sid, vardate);
        objholiday = objholiday.Get_Description_By_Holidayid(hid);

        if ((objholiday.Holidaydate == vardate)&&(objholiday.Description!=""))
        {
            objholiday.Holidayid = hid;
            objholiday.Holidaydate = hdate;
            objholiday.Description = hdesc1;
            objholiday.Siteid = sid;
            objholiday.Update();
            grdvwEdit.EditIndex = -1;
            BindGrid();
            lblerrmsg.Text = Resources.MessageResource.errupdate.ToString();
        }
        else if ((varholidaydate == 0) &&( hdate!="") && (hdesc1 != ""))
        {
                objholiday.Holidayid = hid;
                objholiday.Holidaydate = hdate;
                objholiday.Description = hdesc1;
                objholiday.Siteid = sid;
                objholiday.Update();
                grdvwEdit.EditIndex = -1;
                BindGrid();
                lblerrmsg.Text = Resources.MessageResource.errupdate.ToString();
        }
        else if ((hdate == "") ||(hdesc1 == "" ))
        {
            lblerrmsg.Text = "Holiday Date or Description should not be empty";
        }
        else
        {
            lblerrmsg.Text = Resources.MessageResource.erralready.ToString();
        }
    }