Ejemplo n.º 1
0
        private void repProgramButton_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            // --- save partial or final report
            if (e.Button.Index == 0)
            {
                #region save program

                bool result_insert_program = false;

                CRecep_sample_program oRecep_sample_program = new CRecep_sample_program();
                CRecep_sample_programFactory faRecep_sample_program = new CRecep_sample_programFactory();
                Reception oReception = new Reception();

                oRecep_sample_program = faRecep_sample_program.GetByPrimaryKey(
                    new CRecep_sample_programKeys(Convert.ToInt64(gvProgram.GetFocusedRowCellValue(gcRep_idrecep_sample_report))));

                short report_status = Convert.ToInt16(gvReport.GetFocusedRowCellValue(gcRep_report_status));

                // si es un reporte en creación poner como reservado
                if (report_status == Convert.ToInt16(Comun.ReportStatus.EnCreacion)) // --- creacion
                {
                    oRecep_sample_program = new CRecep_sample_program();
                    gvReport.SetFocusedRowCellValue(gcProg_Program_status, Convert.ToInt16(Comun.ReportStatus.Reportado));
                    oRecep_sample_program.Idrecep_sample = oRecep_sample.Idrecep_sample;
                    oRecep_sample_program.Idrecep_sample_program = Convert.ToInt64(gvProgram.GetFocusedRowCellValue(gcProg_Idrecep_sample_program));
                    oRecep_sample_program.Order_report = Convert.ToInt16(gvProgram.GetFocusedRowCellValue(gcProg_Order_report));
                    oRecep_sample_program.Program_status = Convert.ToInt16(Comun.ReportStatus.Reportado);
                    oRecep_sample_program.Cod_recep_sample_program = oReception.GetNewCodProgram();
                    oRecep_sample_program.Date_report = Convert.ToDateTime(gvProgram.GetFocusedRowCellValue(gcProg_Date_report));
                    oRecep_sample_program.Time_report = Convert.ToDateTime(gvProgram.GetFocusedRowCellValue(gcProg_Time_report));

                    result_insert_program = faRecep_sample_program.Insert(oRecep_sample_program);

                    gvProgram.SetFocusedRowCellValue(gcProg_Program_status, oRecep_sample_program.Program_status);
                    gvProgram.SetFocusedRowCellValue(gcProg_Idrecep_sample_program, oRecep_sample_program.Idrecep_sample_program);
                    gvProgram.SetFocusedRowCellValue(gcProg_Cod_recep_sample_program, oRecep_sample_program.Cod_recep_sample_program);
                    gvProgram.SetFocusedRowCellValue(gcProg_Str_cod_recep_sample_program, oReception.GetFormatProgramCode(oRecep_sample_program.Cod_recep_sample_program));

                    if (result_insert_program)
                    {
                        // --- create the partial report
                        List<CPositionValueProgram> lstPositionValueProgram = new List<CPositionValueProgram>();

                        foreach (GridCell[] cells in lstItemsSelProgram)
                        {
                            foreach (GridCell cell in cells)
                            {
                                CTagInfoMethod tagMethod = (CTagInfoMethod)cell.Column.Tag;

                                int idtemplate_method = tagMethod.IDTemplate_method;
                                long idrecep_sample_detail = Convert.ToInt64(gvReception.GetRowCellValue(cell.RowHandle, gcRec_idrecep_sample_detail));
                                long idrecep_sample_program = oRecep_sample_program.Idrecep_sample_program;

                                CPositionValueProgram position = GetObjectPositionProgram(idrecep_sample_detail, tagMethod.IDTemplate_method);
                                CCells_programFactory faCells_reported = new CCells_programFactory();
                                CCells_program oCell_program = new CCells_program();

                                oCell_program.Idtemplate_method = idtemplate_method;
                                oCell_program.Idrecep_sample_detail = idrecep_sample_detail;
                                oCell_program.Idrecep_sample_program = idrecep_sample_program;
                                oCell_program.Idrecep_sample_detail_elem = position.idrecep_sample_detail_elem;

                                bool result_cell_reported = false;

                                if (!(result_cell_reported = faCells_reported.Update(oCell_program)))
                                    result_cell_reported = faCells_reported.Insert(oCell_program);

                                if (result_cell_reported)
                                {
                                    position.idrecep_sample_program = idrecep_sample_program;
                                    position.row = cell.RowHandle;
                                    position.col = cell.Column;
                                    position.idcell_program = oCell_program.Idcell_reported;
                                    position.color = Comun.ColorRojo;

                                    if (!lstPositionValueProgram.Exists(c => c.idrecep_sample_detail_elem == position.idrecep_sample_detail_elem))
                                        lstPositionValueProgram.Add(position);
                                }
                            }
                        }
                        lstItemsSelProgram.Clear();
                        DicCellsSaveProgram.Add(Convert.ToInt32(oRecep_sample_program.Order_report), lstPositionValueProgram);
                    }
                }

                #endregion

                lstItemsSelProgram.Clear();
                gvReception.Focus();
            }
        }