Exemplo n.º 1
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            FileInfo fi       = null;
            string   fileName = null;

            if (fupPhoto.HasFile && !chkDeletePhoto.Checked)
            {
                fi       = new FileInfo(fupPhoto.FileName);
                fileName = chkDeletePhoto.Checked ? null : Guid.NewGuid().ToString().ToUpper() + fi.Extension;
                fupPhoto.SaveAs(Server.MapPath(ConfigurationManager.AppSettings[ApplicationSettingKeys.FolderPhotoPersons]) + @"\" + fileName);
            }
            else
            {
                fileName = Convert.ToString(ViewState["Photo"]);
            }

            switch (RowID)
            {
            case 0:
                if (personProvider.FatherIsExist(Request.QueryString["CustomerCode"]) && ddlConnection.SelectedValue == "F")
                {
                    WebFormHelper.SetLabelTextWithCssClass(
                        lblStatus,
                        "Information for father is already exist",
                        LabelStyleNames.ErrorMessage);
                    return;
                }

                if (personProvider.MotherIsExist(Request.QueryString["CustomerCode"]) && ddlConnection.SelectedValue == "M")
                {
                    WebFormHelper.SetLabelTextWithCssClass(
                        lblStatus,
                        "Information for mother is already exist",
                        LabelStyleNames.ErrorMessage);
                    return;
                }

                personProvider.Add(
                    Request.QueryString["CustomerCode"],
                    ddlConnection.SelectedValue,
                    txtName.Text,
                    chkUnknownBirthDate.Checked ? (DateTime?)null : calDateOfBirth.SelectedDate,
                    txtIDCardNo.Text,
                    txtEmail.Text,
                    txtPhone1.Text,
                    txtPhone2.Text,
                    fileName);
                break;

            default:
                personProvider.Update(
                    RowID,
                    Request.QueryString["CustomerCode"],
                    ddlConnection.SelectedValue,
                    txtName.Text,
                    chkUnknownBirthDate.Checked ? (DateTime?)null : calDateOfBirth.SelectedDate,
                    txtIDCardNo.Text,
                    txtEmail.Text,
                    txtPhone1.Text,
                    txtPhone2.Text,
                    fileName);

                break;
            }
            mvwParents.ActiveViewIndex = 0;
            gvwParent.DataBind();
        }
        catch (Exception ex)
        {
            WebFormHelper.SetLabelTextWithCssClass(
                lblStatus,
                ex.Message,
                LabelStyleNames.ErrorMessage);
        }
    }