Ejemplo n.º 1
0
        protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
        {
            // we only process commands with a datasource (our image buttons)
            if (e.CommandSource == null)
            {
                return;
            }
            string typeOfControl = e.CommandSource.GetType().ToString();

            if (typeOfControl.Equals("System.Web.UI.WebControls.ImageButton"))
            {
                int         id   = 0;
                ImageButton imgb = (ImageButton)e.CommandSource;
                if (imgb.ID != "New" && imgb.ID != "Exit" && imgb.ID != "Program")
                {
                    id = (int)e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex][e.Item.OwnerTableView.DataKeyNames[0]];
                }
                switch (imgb.ID)
                {
                case "Select":
                    break;

                case "Edit":
                    break;

                case "Program":
                    bool     firstTime = true;
                    Programa prog      = null;
                    string   jCommand  = "";
                    foreach (GridDataItem dataItem in RadGrid1.MasterTableView.Items)
                    {
                        if (dataItem.Selected == true)
                        {
                            if (firstTime)
                            {
                                // Creamos el programa
                                prog             = new Programa();
                                prog.Usuario     = usuario;
                                prog.Comentarios = String.Format("Programación creada el {0:dd/MM/yyyy hh:mm:ss}", DateTime.Now);
                                firstTime        = false;
                            }
                            id = (int)dataItem.OwnerTableView.DataKeyValues[dataItem.ItemIndex][dataItem.OwnerTableView.DataKeyNames[0]];
                            Revision r = CntLainsaSci.GetRevision(id, ctx);
                            if (r != null)
                            {
                                r.Programa = prog;
                                r.Estado   = "PROGRAMADA";
                                prog.Revisions.Add(r);
                                CntLainsaSci.AgruparCompanyeros(r, prog, ctx);
                            }
                        }
                    }
                    CntLainsaSci.EliminarProgramadasInferiores(prog);
                    CntLainsaSci.ProgramarSustituciones(prog, ctx);
                    if (!CntLainsaSci.ProgramaMezclado(prog))
                    {
                        CntLainsaSci.CTXGuardar(ctx);
                        if (!firstTime)
                        {
                            //var url = "RevisionForm.aspx?Caller=ProgramarGrid&RevisionId=" + id;
                            //var name = "RevisionForm";
                            //openOutSide(url, name);
                            string url = String.Format("ProgramaForm.aspx?Caller=ProgramarGrid&ProgramaId={0}", prog.ProgramaId);
                            jCommand = String.Format("openOutSide('{0}','{1}');", url, "ProgramaForm");
                            RadAjaxManager1.ResponseScripts.Add(jCommand);
                        }
                    }
                    else
                    {
                        RadNotification1.Text = "No debe mezclar instalaciones";
                        RadNotification1.Show();
                    }
                    RefreshGrid(true);
                    break;

                case "Delete":
                    try
                    {
                        Revision revision = CntLainsaSci.GetRevision(id, ctx);
                        //PlanificacionRevision plan = revision.PlanificacionRevision;
                        //plan.Revisions.Remove(revision);
                        foreach (DatosRevision item in revision.DatosRevisions)
                        {
                            CntLainsaSci.CTXEliminar(item, ctx);
                        }
                        CntLainsaSci.CTXEliminar(revision, ctx);

                        //plan.FechaUltimaRevision = CntLainsaSci.GetFUltimarevision(plan, ctx);
                        CntLainsaSci.CTXGuardar(ctx);

                        RefreshGrid(true);
                    }
                    catch (Exception ex)
                    {
                        ControlDeError(ex);
                    }
                    break;
                }
            }
        }