private void UpdateSupplements(int childId)
    {
        ChildSupplements su = ChildSupplements.GetChildSupplementsByChild(childId);

        if (su != null)
        {
            su.ChildId    = childId;
            su.Vita       = chkVitA.Checked;
            su.Mebendezol = chkMebendezol.Checked;
            su.Date       = DateTime.Now;
            // or
            // DateTime date = DateTime.ParseExact(lblVitADate.Text, ConfigurationDate.GetConfigurationDateById(int.Parse(Configuration.GetConfigurationByName("DateFormat").Value)).DateFormat.ToString(), CultureInfo.CurrentCulture);
            // su.Date = date;
            su.ModifiedOn = DateTime.Now;
            su.ModifiedBy = CurrentEnvironment.LoggedUser.Id;

            ChildSupplements.Update(su);
        }
        else
        {
            su            = new ChildSupplements();
            su.ChildId    = childId;
            su.Vita       = chkVitA.Checked;
            su.Mebendezol = chkMebendezol.Checked;
            su.Date       = DateTime.Now;

            // or
            // DateTime date = DateTime.ParseExact(lblVitADate.Text, ConfigurationDate.GetConfigurationDateById(int.Parse(Configuration.GetConfigurationByName("DateFormat").Value)).DateFormat.ToString(), CultureInfo.CurrentCulture);
            // su.Date = date;
            su.ModifiedOn = DateTime.Now;
            su.ModifiedBy = CurrentEnvironment.LoggedUser.Id;

            ChildSupplements.Insert(su);
        }
    }
Пример #2
0
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        try
        {
            if (Page.IsValid)
            {
                int userId = CurrentEnvironment.LoggedUser.Id;

                int    id  = -1;
                string _id = Request.QueryString["id"].ToString();
                int.TryParse(_id, out id);
                int i;

                ChildSupplements su = ChildSupplements.GetChildSupplementsByChild(id);
                if (su != null)
                {
                    su.Vita       = chkVitA.Checked;
                    su.Mebendezol = chkMebendezol.Checked;
                    su.Date       = DateTime.Now;
                    su.ModifiedOn = DateTime.Now;
                    su.ModifiedBy = userId;

                    i = ChildSupplements.Update(su);
                }
                else
                {
                    su            = new ChildSupplements();
                    su.ChildId    = id;
                    su.Vita       = chkVitA.Checked;
                    su.Mebendezol = chkMebendezol.Checked;
                    su.Date       = DateTime.Now;
                    su.ModifiedOn = DateTime.Now;
                    su.ModifiedBy = userId;

                    i = ChildSupplements.Insert(su);
                }

                if (i > 0)
                {
                    lblSuccess.Visible = true;
                    lblWarning.Visible = false;
                    lblError.Visible   = false;
                    gvChildSupplements.DataBind();
                    gvChildSupplements.Visible = true;
                    //ClearControls(this);
                }
                else
                {
                    lblSuccess.Visible = false;
                    lblWarning.Visible = false;
                    lblError.Visible   = true;
                }
            }
        }
        catch (Exception ex)
        {
            lblSuccess.Visible = false;
            lblWarning.Visible = false;
            lblError.Visible   = true;
        }
    }