/*
        Metodo utilizado para insertar recipes
        */
        private void saveAuxiliar()
        {
            if (Product2.SelectedItem != null & Process2.SelectedItem != null & Operation2.SelectedItem != null)
            {
                if (Process2.SelectedItem.Value != "" & Operation2.SelectedItem.Value != "")
                {
                    if (validateParameterOnRecipeInsert())
                    {
                        if (validatetableParameterOneForInt())
                        {
                            //Crea el servicio
                            RecipeService recipeService = new RecipeService();
                            RecipeInsertView recipe = new RecipeInsertView();
                            recipe.ProcessId = Int32.Parse(Process2.SelectedItem.Value);
                            recipe.OperationId = Int32.Parse(Operation2.SelectedItem.Value);
                            recipe.RecipeEnable = recipeEnable2.Items[0].Selected;
                            String user = Context.User.Identity.Name;
                            String reason = "N/A";
                            //AƱade los datos para la auditoria
                            AuditDataFromWeb audit = new AuditDataFromWeb();
                            audit.Reason = reason;
                            audit.StationIP = General.getIp(this.Page);
                            audit.UserName = user;
                            //Realiza la insercion
                            CUDView crud = recipeService.insertRecipe(recipe, audit);
                            string idRecipNew = crud.insertPK;

                            if (crud.insert == false)
                            {
                                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Could not insert the recipe')", true);
                            }
                            else
                            {

                                //Insert Parameters
                                foreach (GridViewRow gvrow in GridView4.Rows)
                                {
                                    Label lblParameterId = (Label)gvrow.FindControl("ParameterId");
                                    TextBox lblValue = (TextBox)gvrow.FindControl("Value");

                                    if (lblValue.Text != "")
                                    {
                                        RecipeParameterInsertView newParameter = new RecipeParameterInsertView();
                                        newParameter.ParameterId = Int32.Parse(lblParameterId.Text);
                                        newParameter.ParameterValue = Int32.Parse(lblValue.Text);
                                        newParameter.RecipeId = Int32.Parse(idRecipNew);

                                        crud = recipeService.InsertRecipeParameter(newParameter, audit);
                                    }
                                }

                                //Insert Equipments
                                foreach (GridViewRow gvrow in GridView5.Rows)
                                {
                                    CheckBox chk = (CheckBox)gvrow.FindControl("Link");
                                    Label lblID = (Label)gvrow.FindControl("ID");
                                    Label lblEquipment = (Label)gvrow.FindControl("EquipmentName");

                                    RecipeEquipmentInsertView newEquipment = new RecipeEquipmentInsertView();
                                    newEquipment.EquipmentId = lblID.Text;
                                    newEquipment.Link = chk.Checked;
                                    newEquipment.RecipeId = Int32.Parse(idRecipNew);
                                    newEquipment.OperationId = recipe.OperationId;
                                    crud = recipeService.insertRecipeEquipment(newEquipment, audit);
                                }

                                clearFields();
                            }

                        }
                        else
                        {
                            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('All parameter values must be numbers')", true);
                        }
                    }
                    else
                    {
                        this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Please add parameters for this process.')", true);

                    }

                }
                else
                {
                    this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Please complete all fields')", true);
                }
            }
            else
            {
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Please complete all fields.')", true);
            }
        }
        private void saveAuxiliar()
        {
            if (Product2.SelectedItem != null & Process2.SelectedItem != null & Operation2.SelectedItem != null)
            {
                if (Process2.SelectedItem.Value != "" & Operation2.SelectedItem.Value != "")
                {

                    if (validatetableParameterOneForInt())
                    {
                        string confirmValue = Request.Form["confirm_value"];
                        if (confirmValue == "Yes")
                        {
                            RecipeService recipeService = new RecipeService();
                            RecipeInsertView recipe = new RecipeInsertView();

                            recipe.ProcessId = Int32.Parse(Process2.SelectedItem.Value);
                            recipe.OperationId = Int32.Parse(Operation2.SelectedItem.Value);

                            string DOMAINUSER = User.Identity.Name;
                            string[] paramsLogin = DOMAINUSER.Split('\\');
                            recipe.FirstUserLoginPermision = paramsLogin[1].ToString();// login with actice directory

                            CUDView crud = recipeService.insertRecipe(recipe);
                            string idRecipNew = crud.insertPK;

                            if (crud.insert == false)
                            {
                                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Could not insert the recipe')", true);
                            }
                            else
                            {

                                //Insert Parameters
                                foreach (GridViewRow gvrow in GridView4.Rows)
                                {
                                    Label lblParameterId = (Label)gvrow.FindControl("ParameterId");
                                    TextBox lblValue = (TextBox)gvrow.FindControl("Value");

                                    if (lblValue.Text != "")
                                    {
                                        RecipeParameterInsertView newParameter = new RecipeParameterInsertView();
                                        newParameter.ParameterId = Int32.Parse(lblParameterId.Text);
                                        newParameter.ParameterValue = Int32.Parse(lblValue.Text);
                                        newParameter.RecipeId = Int32.Parse(idRecipNew);
                                        crud = recipeService.InsertRecipeParameter(newParameter);
                                    }
                                }

                                //Insert Equipments
                                foreach (GridViewRow gvrow in GridView5.Rows)
                                {
                                    CheckBox chk = (CheckBox)gvrow.FindControl("Link");
                                    Label lblID = (Label)gvrow.FindControl("ID");
                                    Label lblEquipment = (Label)gvrow.FindControl("EquipmentName");

                                    RecipeEquipmentInsertView newEquipment = new RecipeEquipmentInsertView();
                                    newEquipment.EquipmentId = lblID.Text;
                                    newEquipment.Link = chk.Checked;
                                    newEquipment.RecipeId = Int32.Parse(idRecipNew);
                                    newEquipment.OperationId = recipe.OperationId;
                                    crud = recipeService.insertRecipeEquipment(newEquipment);
                                }

                                clearFields();
                            }
                        }
                    }
                    else
                    {
                        this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('All parameter values must be numbers')", true);
                    }

                }
                else
                {
                    this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Please complete all fields')", true);
                }
            }
            else
            {
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Please complete all fields.')", true);
            }
        }