/*
        Metodo que se utiliza para realizar inserciones
        */
        private void saveAuxiliar()
        {
            //Se verifica que se haya  el producto y el proceso no sean nulos
            if (ProductText.SelectedItem != null & ProcessText.SelectedItem != null)
            {
                //Se verifica que se haya completado el producto y el proceso, es decir que no esten en blanco
                if (ProductText.SelectedItem.Value != "" & ProcessText.SelectedItem.Value != "")
                {
                    //Se verifica que se haya añadido al menos un parametro
                    if (validateParameter())
                    {
                        int ProcessIdNew = Int32.Parse(HttpContext.Current.Session["ProcessId"].ToString());

                        if (verifyParameterTable())
                        {
                            //Se crea el servicio
                            ParameterService parameterService = new ParameterService();

                            //Insert Parameters
                            foreach (GridViewRow gvrow in GridView1.Rows)
                            {
                                ParameterInsertView parameter = new ParameterInsertView();

                                TextBox lblParameter = (TextBox)gvrow.FindControl("Parameter");
                                TextBox lblMinValue = (TextBox)gvrow.FindControl("MinValue");
                                DropDownList lblUnit = (DropDownList)gvrow.FindControl("Unit");
                                CheckBox lblxPlot = (CheckBox)gvrow.FindControl("xPlot");
                                CheckBox lblyPlot = (CheckBox)gvrow.FindControl("yPlot");
                                TextBox lblIncer = (TextBox)gvrow.FindControl("Incer");

                                if (lblParameter.Text != "")
                                {
                                    parameter.ParameterMinValue = Double.Parse(lblMinValue.Text);
                                    parameter.ParameterName = lblParameter.Text;
                                    parameter.ParameterXPlot = lblxPlot.Checked;
                                    parameter.ParameterYPlot = lblyPlot.Checked;
                                    parameter.ParameterYPlotRange = Int32.Parse(lblIncer.Text);
                                    parameter.ProcessId = ProcessIdNew;
                                    parameter.UnitId = Int32.Parse(lblUnit.SelectedItem.Value);
                                    //Se llenan los datos de la auditoria
                                    String user = Context.User.Identity.Name;
                                    AuditDataFromWeb audit = new AuditDataFromWeb();
                                    audit.Reason = "N/A";
                                    audit.StationIP = General.getIp(this.Page);
                                    audit.UserName = user;

                                    //Se realiza la insercion
                                    CUDView crud = parameterService.insertParameter(parameter, audit);
                                    if (crud.insert == false)
                                    {
                                        this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Could not insert the Parameters')", true);
                                    }
                                }
                            }
                            clearFields();
                            fillTable();
                        }
                        else
                        {
                            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Some parameters in Parameter Table has some incorrrect data format.')", true);
                        }
                    }
                    else
                    {
                        this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Add at least one parameter.')", true);

                    }
                }
            }
        }
        private void saveAuxiliar()
        {
            if (ProductText.SelectedItem != null & ProcessText.SelectedItem != null)
            {

                if (ProductText.SelectedItem.Value != "" & ProcessText.SelectedItem.Value != "")
                {

                    int ProcessIdNew = Int32.Parse(HttpContext.Current.Session["ProcessId"].ToString());

                    if (verifyParameterTable())
                    {
                        ParameterService parameterService = new ParameterService();

                        //Insert Parameters
                        foreach (GridViewRow gvrow in GridView1.Rows)
                        {
                            ParameterInsertView parameter = new ParameterInsertView();

                            TextBox lblParameter = (TextBox)gvrow.FindControl("Parameter");
                            TextBox lblMinValue = (TextBox)gvrow.FindControl("MinValue");
                            DropDownList lblUnit = (DropDownList)gvrow.FindControl("Unit");
                            CheckBox lblxPlot = (CheckBox)gvrow.FindControl("xPlot");
                            CheckBox lblyPlot = (CheckBox)gvrow.FindControl("yPlot");
                            TextBox lblIncer = (TextBox)gvrow.FindControl("Incer");

                            if (lblParameter.Text != "")
                            {
                                /*System.Diagnostics.Debug.WriteLine(lblParameter.Text);
                                System.Diagnostics.Debug.WriteLine(lblMinValue.Text);
                                System.Diagnostics.Debug.WriteLine(lblUnit.SelectedItem.Value);
                                System.Diagnostics.Debug.WriteLine(lblxPlot.Checked);
                                System.Diagnostics.Debug.WriteLine(lblyPlot.Checked);
                                System.Diagnostics.Debug.WriteLine(lblIncer.Text);*/

                                parameter.ParameterMinValue = Double.Parse(lblMinValue.Text);
                                parameter.ParameterName = lblParameter.Text;
                                parameter.ParameterXPlot = lblxPlot.Checked;
                                parameter.ParameterYPlot = lblyPlot.Checked;
                                parameter.ParameterYPlotRange = Int32.Parse(lblIncer.Text);
                                parameter.ProcessId = ProcessIdNew;
                                parameter.UnitId = Int32.Parse(lblUnit.SelectedItem.Value);

                                CUDView crud = parameterService.insertParameter(parameter);
                                if (crud.insert == false)
                                {
                                    this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Could not insert the Parameters')", true);
                                }
                            }
                        }
                        clearFields();
                        fillTable();
                    }
                    else
                    {
                        this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Some parameters in Parameter Table has some incorrrect data format.')", true);
                    }
                }
            }
        }