Ejemplo n.º 1
0
    protected void ButtonSalva_Click(object sender, EventArgs e)
    {
        SetValues();

        if (objUtente.existUser() != 0)
        {
            lblMessaggioError.InnerText = getDizionarioUI("ERR_UTE_VALORI_DUPLICATI");
            divRecordError.Visible      = true;
        }
        else
        {
            string PwdResetNotExist = getDizionarioUI("PWD_RESET_NOT_EXIST");

            switch (qMODALITA)
            {
            case "NEW":
                try
                {
                    //Ricavo dal cliente la password di default per settarla
                    objClienti.Read(Convert.ToInt32(DropDownListCliente.SelectedValue), qCultureInfoName);
                    if (objClienti.Cli_password_reset.ToString() != "" && !objClienti.Cli_password_reset.IsNull)
                    {
                        Database      db = DatabaseFactory.CreateDatabase("CONNECTION_STRING");
                        DbConnection  c  = db.CreateConnection();
                        DbTransaction t  = null;

                        try
                        {
                            c.Open();
                            t = c.BeginTransaction();

                            objUtente.Ute_password  = EncryptPwd(objClienti.Cli_password_reset.ToString());
                            objUtente.Ute_creato_da = base.idLoggedUser;
                            objUtente.Create(db, t);

                            RuoliUtente objRuoliUtente = new RuoliUtente();
                            objRuoliUtente.Ute_id_utente = objUtente.Ute_id_utente;
                            objRuoliUtente.CreateByDefaultCliente(Convert.ToInt32(DropDownListCliente.SelectedValue), db, t);

                            CrossUtenteWorkflow objCrossUtenteWorkflow = new CrossUtenteWorkflow();
                            objCrossUtenteWorkflow.Ute_id_utente = objUtente.Ute_id_utente;
                            objCrossUtenteWorkflow.CreateByDefaultCliente(Convert.ToInt32(DropDownListCliente.SelectedValue), db, t);

                            t.Commit();
                        }
                        catch (Exception ex)
                        {
                            try
                            {
                                t.Rollback();
                            }
                            catch (Exception ex2)
                            {
                                ex2.Data.Add("Class.Method", "frm_MSE_UTE.ButtonSalva.Rollback");
                                ex2.Data.Add("SQL", "Rollback error");
                            }

                            if (ex != null)
                            {
                                ex.Data["Class.Method"] += "frm_MSE_UTE.ButtonSalva";
                                ex.Data.Add("SQL", ex.Message);
                                throw ex;
                            }
                        }
                        finally
                        {
                            c.Close();
                        }

                        Response.Redirect("frm_MSE_UTE.aspx?MODALITA=EDIT&UTE_ID_UTENTE=" + objUtente.Ute_id_utente, false);
                    }
                    else
                    {
                        string strScript = @"<script type='text/javascript'>
                                alert('" + PwdResetNotExist + @"');                                
                                </script>";

                        if (!this.ClientScript.IsStartupScriptRegistered("Alert_JS"))
                        {
                            this.ClientScript.RegisterStartupScript(GetType(), "Alert_JS", strScript);
                        }
                    }
                }
                catch (Exception ex)
                {
                    // Gestione messaggistica all'utente e trace in DB dell'errore
                    ExceptionPolicy.HandleException(ex, "Propagate Policy");
                }
                break;

            case "EDIT":
                try
                {
                    //Update record relations
                    objUtente.Ute_aggiornato_da = base.idLoggedUser;
                    objUtente.Ute_id_utente     = qUTE_ID_UTENTE;
                    objUtente.Update();
                    Response.Redirect("frm_MSE_UTE.aspx?MODALITA=EDIT&UTE_ID_UTENTE=" + objUtente.Ute_id_utente, false);
                }
                catch (Exception ex)
                {
                    // Gestione messaggistica all'utente e trace in DB dell'errore
                    ExceptionPolicy.HandleException(ex, "Propagate Policy");
                }
                break;
            }

            GetValues();

            Page.ClientScript.RegisterStartupScript(this.GetType(), "varMODALITA", "$('#modalPage', parent.document).modal('hide');", true);
        }
    }