Ejemplo n.º 1
0
        public void lvwClasses_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            string commandName = e.CommandName.ToLower();

            if (!commandName.StartsWith("x"))
            {
                return;
            }

            ScheduleBLL scheduleDB = new ScheduleBLL();

            bool dbModified = false;

            string xPath = (string)e.CommandArgument;

            if (commandName.Equals("xdelete"))
            {
                if (scheduleDB.deleteItem(xPath))
                {
                    lvwClasses.DataBind();
                    dbModified = true;
                }
            }
            else
            {
                ClassInfo classInfo = new ClassInfo();

                TextBox     txtStartsDate         = (TextBox)e.Item.FindControl("txtStartsDate");
                HiddenField hidMandatoryDateArray = (HiddenField)e.Item.FindControl("hidMandatoryDateArray");
                TextBox     txtMandatoryDate      = (TextBox)e.Item.FindControl("txtMandatoryDate");
                HiddenField hidSkipDateArray      = (HiddenField)e.Item.FindControl("hidSkipDateArray");
                TextBox     txtSkipDate           = (TextBox)e.Item.FindControl("txtSkipDate");
                TextBox     txtEndsDate           = (TextBox)e.Item.FindControl("txtEndsDate");
                TextBox     txtDays      = (TextBox)e.Item.FindControl("txtDays");
                TextBox     txtTime      = (TextBox)e.Item.FindControl("txtTime");
                TextBox     txtArea      = (TextBox)e.Item.FindControl("txtArea");
                CheckBox    chkFilled    = (CheckBox)e.Item.FindControl("chkFilled");
                CheckBox    chkCancelled = (CheckBox)e.Item.FindControl("chkCancelled");

                classInfo.StartDate = DateTime.Parse(txtStartsDate.Text);
                classInfo.EndDate   = DateTime.Parse(txtEndsDate.Text);
                classInfo.Days      = txtDays.Text;
                classInfo.Time      = txtTime.Text;
                classInfo.Area      = txtArea.Text;
                classInfo.Filled    = chkFilled.Checked;
                classInfo.Cancelled = chkCancelled.Checked;

                // If hidMandatoryDateArray is blank, then only set the MandatoryDate,
                // otherwise set the MandatoryDateArray, which uses the first Date from the array as MandatoryDate
                if (string.IsNullOrEmpty(hidMandatoryDateArray.Value))
                {
                    classInfo.MandatoryDate = (string.IsNullOrEmpty(txtMandatoryDate.Text) ? DateTime.MinValue : DateTime.Parse(txtMandatoryDate.Text));
                }
                else
                {
                    classInfo.MandatoryDateArray = hidMandatoryDateArray.Value;
                }

                // If hidSkipDateArray is blank, then only set the SkipDate,
                // otherwise set the SkipDateArray, which uses the first Date from the array as SkipDate
                if (string.IsNullOrEmpty(hidSkipDateArray.Value))
                {
                    classInfo.SkipDate = (string.IsNullOrEmpty(txtSkipDate.Text) ? DateTime.MinValue : DateTime.Parse(txtSkipDate.Text));
                }
                else
                {
                    classInfo.SkipDateArray = hidSkipDateArray.Value;
                }

                // Update or save the series info based on the command name
                if (commandName.Equals("xupdate"))
                {
                    if (scheduleDB.saveChanges(xPath, classInfo))
                    {
                        lvwClasses.EditIndex = -1;
                        dbModified           = true;
                    }
                }
                else   // xinsert
                {
                    if (scheduleDB.saveNewItem(xPath, classInfo))
                    {
                        lvwClasses.DataBind();
                        dbModified = true;
                    }
                }

                if (dbModified)
                {
                    string strScript = "highLightClass('" + classInfo.ID.ToString() + "');";
                    ScriptManager.RegisterStartupScript(Page, this.GetType(), "hlClass", strScript, true);
                }
            }

            displayDbError(dbModified, scheduleDB.Error, commandName);
        }
Ejemplo n.º 2
0
        public void lvwSchedule_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            string commandName = e.CommandName.ToLower();

            if (!commandName.StartsWith("x"))
            {
                return;
            }

            ScheduleBLL scheduleDB = new ScheduleBLL();

            bool dbModified = false;

            string xPath = (string)e.CommandArgument;

            if (commandName.Equals("xdelete"))
            {
                if (scheduleDB.deleteItem(xPath))
                {
                    lvwSchedule.DataBind();
                    dbModified = true;
                }
            }
            else
            {
                SeriesInfo seriesInfo = new SeriesInfo();

                DropDownList ddlMonth       = (DropDownList)e.Item.FindControl("ddlMonth");
                DropDownList ddlYear        = (DropDownList)e.Item.FindControl("ddlYear");
                TextBox      txtTitle       = (TextBox)e.Item.FindControl("txtTitle");
                CheckBox     chkCustomTitle = (CheckBox)e.Item.FindControl("chkCustomTitle");
                CheckBox     chkVisible     = (CheckBox)e.Item.FindControl("chkVisible");

                // Set the new series information data
                seriesInfo.Date        = new DateTime(int.Parse(ddlYear.SelectedValue), int.Parse(ddlMonth.SelectedValue), 1);
                seriesInfo.Title       = txtTitle.Text;
                seriesInfo.CustomTitle = chkCustomTitle.Checked;
                seriesInfo.Visible     = chkVisible.Checked;

                // Update or save the series info based on the command name
                if (commandName.Equals("xupdate"))
                {
                    if (scheduleDB.saveChanges(xPath, seriesInfo))
                    {
                        lvwSchedule.EditIndex = -1;
                        dbModified            = true;
                    }
                }
                else   // xinsert
                {
                    if (scheduleDB.saveNewItem(seriesInfo))
                    {
                        lvwSchedule.DataBind();
                        dbModified = true;
                    }
                }

                if (dbModified)
                {
                    string strScript = "highLightSeries('" + seriesInfo.Date.ToShortDateString() + "');";
                    ScriptManager.RegisterStartupScript(Page, this.GetType(), "hlSeries", strScript, true);
                }
            }

            displayDbError(dbModified, scheduleDB.Error, commandName);
        }