Exemplo n.º 1
0
        void RetrieveRegisterReception()
        {
            // --- return date of recep_sample
            DicCellsSavedReport.Clear();
            DicCellsSaveProgram.Clear();

            Reception oReception = new Reception();

            if (oRecep_sample != null)
            {
                tpRightReports.PageVisible = true;
                tpRightAttach.PageVisible = true;
                tpRightProgram.PageVisible = true;

                txIdrecep_sample.Text = oRecep_sample.Idrecep_sample.ToString();
                statusRegReception = StatusRegRecep.reg_recep_saved;
                tbCod_recep_sample.Text = oRecep_sample.Cod_recep_sample;
                deReception.DateTime = Convert.ToDateTime(oRecep_sample.Date_reception);
                deHourReception.EditValue = Convert.ToDateTime(oRecep_sample.Date_reception);
                deResult.DateTime = Convert.ToDateTime(oRecep_sample.Date_result);
                deHourResult.EditValue = Convert.ToDateTime(oRecep_sample.Date_result);
                cbTypeSample.EditValue = oRecep_sample.Cod_type_sample;

                tbNumDays.Value = Convert.ToDecimal(Convert.ToDateTime(oRecep_sample.Date_result).Subtract(Convert.ToDateTime(oRecep_sample.Date_reception)).TotalDays);

                tbSubTotalAmount.Text = oRecep_sample.Total_amount.ToString();
                tbTotalIgv.Text = oRecep_sample.Total_igv.ToString();
                tbTotalAmount.Text = oRecep_sample.Total_amount_igv.ToString();
                tbAmortization.Text = oRecep_sample.Amortization.ToString();

                if (oRecep_sample.Amortization.Value == 0)
                    tbResidue.BackColor = Color.Coral;

                CCompany oCompany = new CCompanyFactory().GetByPrimaryKey(new CCompanyKeys(Convert.ToInt16(oRecep_sample.Idcompany)));

                // --- retrieve dispatch
                CRecep_sample_dispatch oRecep_sample_dispatch = new CRecep_sample_dispatchFactory().GetByPrimaryKey(new CRecep_sample_dispatchKeys(oRecep_sample.Idrecep_sample));
                if (oRecep_sample_dispatch != null)
                {
                    // --- person
                    if (oRecep_sample_dispatch.Dispatch_person > 0)
                        ckDispatchPerson.Checked = true;
                    else
                        ckDispatchPerson.Checked = false;
                    // --- curier
                    if (oRecep_sample_dispatch.Dispatch_curier > 0)
                        ckDispatchCurier.Checked = true;
                    else
                        ckDispatchCurier.Checked = false;
                    // --- transport
                    if (oRecep_sample_dispatch.Dispatch_transport > 0)
                        ckDispatchTransport.Checked = true;
                    else
                        ckDispatchTransport.Checked = false;
                    // --- fax
                    if (oRecep_sample_dispatch.Dispatch_fax > 0)
                        ckDispatchFax.Checked = true;
                    else
                        ckDispatchFax.Checked = false;
                }
                else
                {
                    ckDispatchPerson.Checked = false;
                    ckDispatchCurier.Checked = true;
                    ckDispatchTransport.Checked = false;
                    ckDispatchFax.Checked = false;
                }

                // --- return date of client
                if (oCompany != null)
                {
                    IDCompany = oCompany.Idcompany;
                    cbCompany.EditValue = oCompany.Idcompany;
                    tbClientRuc.Text = oCompany.Ruc;
                    tbClientPhone.Text = oCompany.Phone_client;
                    tbClientDomicile.Text = oCompany.Domicile;

                    // --- get contacts
                    gcContact.DataSource = new BindingList<CContact>(oReception.GetLstContactsByRecep(oRecep_sample.Idrecep_sample));

                    // --- return recep_sample_detail
                    CRecep_sample_detail oRecep_sample_detail = new CRecep_sample_detail();
                    CRecep_sample_detailFactory faRecep_sample_detail = new CRecep_sample_detailFactory();

                    DTReceptionDetail = oReception.GetReceptionDetail(oRecep_sample.Idrecep_sample);
                    gcReception.DataSource = DTReceptionDetail;

                    // --- return columns
                    List<CTemplate_method> lstTemplate_method = oReception.GetReceptionElem(oRecep_sample.Idrecep_sample);

                    // --- modify the dictionary show columns

                    if (loadData != LoadData.FromRR_ToExtendRR)
                    {
                        foreach (CTemplate_method oTemplate_method in lstTemplate_method)
                            AddColumn(oTemplate_method.Cod_template_method);

                        // --- get columns and value cells
                        GetSampleByElems();
                    }

                    // ==================< Retrieve report groups >==============================================
                    gcReport.DataSource = oReception.GetRecep_sample_report(oRecep_sample.Idrecep_sample);
                    CCells_reportedFactory faCells_reported = new CCells_reportedFactory();
                    for (int i = 0; i < gvReport.RowCount; i++)
                    {
                        long idrecep_sample_report = Convert.ToInt64(gvReport.GetRowCellValue(i, gcRep_idrecep_sample_report));
                        short order = Convert.ToInt16(gvReport.GetRowCellValue(i, gcRep_order_report));

                        Color color = dicColorReport[Convert.ToInt16(gvReport.GetRowCellValue(i, gcRep_report_status))];

                        List<CCells_reported> lstRsder = faCells_reported.GetAll().Where(x=> x.Idrecep_sample_report == idrecep_sample_report).ToList();
                        List<CPositionValue> lstPositionValue = new List<CPositionValue>();

                        foreach (CCells_reported item in lstRsder)
                        {
                            if (item.Idrecep_sample_report == idrecep_sample_report)
                            {
                                CPositionValue oPosition = new CPositionValue();
                                oPosition = GetObjectPosition(Convert.ToInt64(item.Idrecep_sample_detail_elem), Convert.ToInt32(item.Idtemplate_method));

                                oPosition.idtemplate_method = Convert.ToInt32(item.Idtemplate_method);
                                oPosition.idrecep_sample_report = Convert.ToInt64(item.Idrecep_sample_report);
                                oPosition.idrecep_sample_detail = Convert.ToInt64(item.Idrecep_sample_detail);
                                oPosition.idrecep_sample_detail_elem = Convert.ToInt64(item.Idrecep_sample_detail_elem);
                                oPosition.idcell_reported = Convert.ToInt64(item.Idcell_reported);

                                if (Convert.ToInt16(gvReport.GetRowCellValue(i, gcRep_type_report)) == 1)
                                    oPosition.color = Partial_report_color;
                                else
                                    oPosition.color = Final_report_color;

                                lstPositionValue.Add(oPosition);
                            }
                        }

                        DicCellsSavedReport.Add(order, lstPositionValue);
                    }

                    // ==================< Unreport data >======================================================
                    GetUnreportData(oRecep_sample.Idrecep_sample);

                    // ==================< Retrieve attach files >==============================================
                    gcAttachFile.DataSource = new BindingList<CDocAttach>(oReception.GetLstDocAttach(oRecep_sample.Idrecep_sample));
                    CCells_attach_fileFactory faCells_attach_file = new CCells_attach_fileFactory();
                    for (int i = 0; i < gvAttachFile.RowCount; i++)
                    {
                        long idrecep_sample_attach = Convert.ToInt64(gvAttachFile.GetRowCellValue(i, gcAtt_Idrecep_sample_attach));
                        short order = Convert.ToInt16(gvAttachFile.GetRowCellValue(i, gcAtt_Order_file));

                        Color color = dicColorAttach[Convert.ToInt16(gvAttachFile.GetRowCellValue(i, gcAtt_Attach_status))];

                        List<CCells_attach_file> lstRsder = oReception.GetLstCellsAttachFile(idrecep_sample_attach);
                        List<CpositionValueAttach> lstPositionValue = new List<CpositionValueAttach>();

                        foreach (CCells_attach_file item in lstRsder)
                        {
                            if (item.Idrecep_sample_attach == idrecep_sample_attach)
                            {
                                CpositionValueAttach oPosition = new CpositionValueAttach();
                                oPosition = GetObjectPositionAttach(Convert.ToInt64(item.Idrecep_sample_detail_elem), Convert.ToInt32(item.Idtemplate_method));
                                oPosition.idrecep_sample_detail_elem = Convert.ToInt64(item.Idrecep_sample_detail_elem);
                                oPosition.idtemplate_method = Convert.ToInt32(item.Idtemplate_method);
                                oPosition.color = color;

                                lstPositionValue.Add(oPosition);
                            }
                        }

                        DicCellsSavedAttach.Add(order, lstPositionValue);
                    }

                    // ==================< Retrieve program >==============================================
                    gcProgram.DataSource = oReception.GetRecep_sample_program(oRecep_sample.Idrecep_sample);
                    CCells_programFactory faCells_program = new CCells_programFactory();

                    for (int i = 0; i < gvProgram.RowCount; i++)
                    {
                        long idrecep_sample_program = Convert.ToInt64(gvProgram.GetRowCellValue(i, gcProg_Idrecep_sample_program));
                        short order = Convert.ToInt16(gvProgram.GetRowCellValue(i, gcProg_Order_report));

                        Color color = Comun.ColorRojo;

                        List<CCells_program> lstProgram = oReception.GetLstCellsProgram(idrecep_sample_program);
                        List<CPositionValueProgram> lstPositionValueProgram = new List<CPositionValueProgram>();

                        foreach (CCells_program item in lstProgram)
                        {
                            if (item.Idrecep_sample_program == idrecep_sample_program)
                            {
                                CPositionValueProgram oPosition = new CPositionValueProgram();
                                oPosition = GetObjectPositionProgram(Convert.ToInt64(item.Idrecep_sample_detail_elem), Convert.ToInt32(item.Idtemplate_method));

                                oPosition.idrecep_sample_program = Convert.ToInt64(item.Idrecep_sample_program);
                                oPosition.idrecep_sample_detail_elem = Convert.ToInt64(item.Idrecep_sample_detail_elem);
                                oPosition.idrecep_sample_detail = Convert.ToInt64(item.Idrecep_sample_detail);
                                oPosition.idtemplate_method = Convert.ToInt32(item.Idtemplate_method);
                                oPosition.color = color;

                                lstPositionValueProgram.Add(oPosition);
                            }
                        }

                        DicCellsSaveProgram.Add(order, lstPositionValueProgram);
                    }

                }
                SortColumnsByCodTemplate();
            }
            else
            {
                ///No existe un registro de recepción, entonces recuperar todo vacio
                // --- hide tappages
                tpRightReports.PageVisible = false;
                tpRightAttach.PageVisible = false;
                tpRightProgram.PageVisible = false;

                // --- return empty report
                CRecep_sample_reportFactory faRecep_sample_report = new CRecep_sample_reportFactory();
                gcReport.DataSource = oReception.GetRecep_sample_report(0);

                // --- return empty attach files
                gcAttachFile.DataSource = new BindingList<CDocAttach>(oReception.GetLstDocAttach(0));

                // --- recuperar contactos
                if (cbCompany.EditValue != null)
                    gcContact.DataSource = new BindingList<CContact>(oReception.GetLstContactsByCompany(Convert.ToInt16(cbCompany.EditValue)));
            }
        }
Exemplo n.º 2
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();
            }
        }