Example #1
0
        public override bool doEvent(int event_number, object arg)
        {
            switch (event_number)
            {
                #region - event_Load -

            case event_Load:
            {
                //InitEventCode event_Load

                                        #if ROBOT
                var_util.execDefinedRobot(this, var_alias);
                                        #else
                doEvent(event_Translate, null);
                doEvent(event_FormIsOpening, null);
                                        #endif

                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_Translate -

            case event_Translate:
            {
                //InitEventCode event_Translate
                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_FormIsOpening -

            case event_FormIsOpening:
            {
                //InitEventCode event_FormIsOpening

                doEvent(event_val_TxtEmpresa, null);

                //EndEventCode
                return(true);
            }

                #endregion

                #region - robot_ShowDialog -

            case robot_ShowDialog:
            {
                //InitEventCode robot_ShowDialog
                //EndEventCode
                return(true);
            }

                #endregion

                #region - robot_CloseDialog -

            case robot_CloseDialog:
            {
                //InitEventCode robot_CloseDialog
                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_Confirmar -

            case event_Confirmar:
            {
                //InitEventCode event_Confirmar

                if (i_Form.CboEmpresa.SelectedIndex == -1)
                {
                    MessageBox.Show("Nenhuma empresa disponível");
                    return(false);
                }

                if (i_Form.TxtFile.Text.Length == 0)
                {
                    MessageBox.Show("Escolha um arquivo de destino");
                    return(false);
                }

                i_Form.BtnConfirmar.Enabled = false;

                string st_csv = "";

                if (!var_exchange.fetch_cartoes_grafica(i_Form.CboEmpresa.SelectedItem.ToString(), ref header, ref st_csv))
                {
                    i_Form.BtnConfirmar.Enabled = true;
                    return(false);
                }

                ArrayList full_memory = new ArrayList();

                while (st_csv != "")
                {
                    ArrayList tmp_memory = new ArrayList();

                    if (var_exchange.fetch_memory(st_csv, "400", ref st_csv, ref tmp_memory))
                    {
                        for (int t = 0; t < tmp_memory.Count; ++t)
                        {
                            full_memory.Add(tmp_memory[t]);
                        }
                    }
                }

                ArrayList desc    = new TipoConfirmacaoDesc().GetArray();
                ArrayList desc_op = new OperacaoCartaoDesc().GetArray();

                StreamWriter sw = new StreamWriter(i_Form.TxtFile.Text);

                for (int t = 0; t < full_memory.Count; ++t)
                {
                    DadosExpedicao port = new DadosExpedicao(full_memory[t] as DataPortable);

                    sw.WriteLine(port.get_st_line());
                }

                sw.Close();

                MessageBox.Show("Arquivo gerado sucesso", "Aviso");

                i_Form.BtnConfirmar.Enabled = true;

                doEvent(event_val_TxtEmpresa, null);

                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_val_TxtEmpresa -

            case event_val_TxtEmpresa:
            {
                //InitEventCode event_val_TxtEmpresa

                ArrayList lst = new ArrayList();

                dlgStatus st = new dlgStatus("Empresas com novos cartões");

                st.LblActivity.Text = "Buscando cartões";
                st.Show();

                Application.DoEvents();

                var_exchange.fetch_empresasGrafica(ref header, ref lst);

                i_Form.TxtFile.Text = "";
                i_Form.CboEmpresa.Items.Clear();
                hshEmp.Clear();

                for (int t = 0; t < lst.Count; ++t)
                {
                    DadosEmpresa de = new DadosEmpresa(lst[t] as DataPortable);

                    i_Form.CboEmpresa.Items.Add(de.get_st_empresa());

                    hshEmp [de.get_st_empresa()] = de;
                }

                if (lst.Count > 0)
                {
                    i_Form.CboEmpresa.SelectedIndex = 0;
                }

                st.Close();

                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_ComboChanged -

            case event_ComboChanged:
            {
                //InitEventCode event_ComboChanged

                DadosEmpresa de = hshEmp [i_Form.CboEmpresa.SelectedItem.ToString()] as DadosEmpresa;

                i_Form.TxtNome.Text = de.get_st_fantasia();

                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_BtnDirClick -

            case event_BtnDirClick:
            {
                //InitEventCode event_BtnDirClick
                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_BtnConfirmarClick -

            case event_BtnConfirmarClick:
            {
                //InitEventCode event_BtnConfirmarClick
                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_CboEmpresaSelectedIndexChanged -

            case event_CboEmpresaSelectedIndexChanged:
            {
                //InitEventCode event_CboEmpresaSelectedIndexChanged
                //EndEventCode
                return(true);
            }

                #endregion

            default: break;
            }

            return(false);
        }
        public override bool doEvent(int event_number, object arg)
        {
            switch (event_number)
            {
                #region - event_Load -

            case event_Load:
            {
                //InitEventCode event_Load

                                        #if ROBOT
                var_util.execDefinedRobot(this, var_alias);
                                        #else
                doEvent(event_Translate, null);
                doEvent(event_FormIsOpening, null);
                                        #endif

                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_Translate -

            case event_Translate:
            {
                //InitEventCode event_Translate
                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_FormIsOpening -

            case event_FormIsOpening:
            {
                //InitEventCode event_FormIsOpening

                ctrl_TxtDtIni.AcquireTextBox(i_Form.TxtDtIni, this, event_val_TxtDtIni, dateTextController.FORMAT_DDMMYYYY);
                ctrl_TxtDtFim.AcquireTextBox(i_Form.TxtDtFim, this, event_val_TxtDtFim, dateTextController.FORMAT_DDMMYYYY);

                ctrl_TxtDtIni.SetupErrorProvider(ErrorIconAlignment.MiddleRight, false);
                ctrl_TxtDtFim.SetupErrorProvider(ErrorIconAlignment.MiddleRight, false);

                ctrl_TxtDtIni.SetTextBoxText("01" +
                                             DateTime.Now.Month.ToString().PadLeft(2, '0') +
                                             DateTime.Now.Year.ToString().PadLeft(4, '0'));


                ctrl_TxtDtFim.SetTextBoxText("15" +
                                             DateTime.Now.Month.ToString().PadLeft(2, '0') +
                                             DateTime.Now.Year.ToString().PadLeft(4, '0'));


                //EndEventCode
                return(true);
            }

                #endregion

                #region - robot_ShowDialog -

            case robot_ShowDialog:
            {
                //InitEventCode robot_ShowDialog
                //EndEventCode
                return(true);
            }

                #endregion

                #region - robot_CloseDialog -

            case robot_CloseDialog:
            {
                //InitEventCode robot_CloseDialog
                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_val_TxtDtIni -

            case event_val_TxtDtIni:
            {
                //InitEventCode event_val_TxtDtIni

                switch (arg as string)
                {
                case dateTextController.DATE_VALID:
                {
                    i_Form.TxtDtIni.BackColor     = Color.White;
                    ctrl_TxtDtIni.IsUserValidated = true;
                    ctrl_TxtDtIni.CleanError();
                    break;
                }

                case dateTextController.DATE_INVALID:
                {
                    i_Form.TxtDtIni.BackColor     = colorInvalid;
                    ctrl_TxtDtIni.IsUserValidated = false;
                    break;
                }

                default: break;
                }

                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_val_TxtDtFim -

            case event_val_TxtDtFim:
            {
                //InitEventCode event_val_TxtDtFim

                switch (arg as string)
                {
                case dateTextController.DATE_VALID:
                {
                    i_Form.TxtDtFim.BackColor     = Color.White;
                    ctrl_TxtDtFim.IsUserValidated = true;
                    ctrl_TxtDtFim.CleanError();
                    break;
                }

                case dateTextController.DATE_INVALID:
                {
                    i_Form.TxtDtFim.BackColor     = colorInvalid;
                    ctrl_TxtDtFim.IsUserValidated = false;
                    break;
                }

                default: break;
                }

                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_Confirmar -

            case event_Confirmar:
            {
                //InitEventCode event_Confirmar

                bool bOk = true;

                if (!ctrl_TxtDtFim.IsUserValidated)
                {
                    ctrl_TxtDtFim.SetErrorMessage("Informe o dia final");
                    bOk = false;
                }

                if (!ctrl_TxtDtIni.IsUserValidated)
                {
                    ctrl_TxtDtIni.SetErrorMessage("Informe o dia inicial");
                    bOk = false;
                }

                if (i_Form.CboRelat.SelectedIndex == -1)
                {
                    MessageBox.Show("Informe a opção de cobrança", "Aviso");
                    bOk = false;
                }

                if (!bOk)
                {
                    return(false);
                }

                i_Form.BtnConfirmar.Enabled = false;

                if (i_Form.CboRelat.SelectedIndex == 0)
                {
                    #region - pendentes com detalhe -

                    // ##############################
                    // # SETUP LISTS ################
                    // ##############################

                    ArrayList lstHeader     = new ArrayList();
                    ArrayList lstContent    = new ArrayList();
                    ArrayList lstTableSizes = new ArrayList();
                    ArrayList lstFooter     = new ArrayList();
                    ArrayList lstMessages   = new ArrayList();
                    ArrayList lstFilters    = new ArrayList();

                    // ##############################
                    // # CUSTOMIZE
                    // ##############################

                    string output_st_total                 = "";
                    string output_st_total_desconto        = "";
                    string output_st_csv_subtotal          = "";
                    string output_st_csv_subtotal_desconto = "";
                    string output_st_content_block         = "";
                    string output_st_emp_loj_block         = "";

                    string output_CartaoAtiv = "";
                    string output_Extras     = "";
                    string output_FixoTrans  = "";
                    string output_Percent    = "";
                    string output_TBM        = "";

                    i_Form.Visible = false;

                    dlgStatus stat = new dlgStatus("Relatório");

                    stat.LblActivity.Text = "Processando relatório no servidor";
                    stat.Show();
                    Application.DoEvents();

                    if (!var_exchange.fetch_rel_6_fat(var_util.GetDataBaseTimeFormat(ctrl_TxtDtIni.getTextBoxValue_Date()),
                                                      var_util.GetDataBaseTimeFormat(ctrl_TxtDtFim.getTextBoxValue_Date().AddDays(1)),
                                                      ref header,
                                                      ref output_st_total,
                                                      ref output_st_total_desconto,
                                                      ref output_st_csv_subtotal,
                                                      ref output_st_csv_subtotal_desconto,
                                                      ref output_st_content_block,
                                                      ref output_st_emp_loj_block,
                                                      ref output_CartaoAtiv,
                                                      ref output_Extras,
                                                      ref output_FixoTrans,
                                                      ref output_Percent,
                                                      ref output_TBM))
                    {
                        stat.Close();
                        return(false);
                    }

                    stat.LblActivity.Text = "Buscando detalhes de faturamento";
                    Application.DoEvents();

                    // index de todos os itens de cobrança
                    Hashtable hsh_Memory = new Hashtable();

                    while (output_st_content_block != "")
                    {
                        ArrayList tmp_memory = new ArrayList();

                        if (var_exchange.fetch_memory(output_st_content_block, "200",
                                                      ref output_st_content_block,
                                                      ref tmp_memory))
                        {
                            for (int t = 0; t < tmp_memory.Count; ++t)
                            {
                                Rel_FAT f_t = new Rel_FAT(tmp_memory [t] as DataPortable);

                                if (hsh_Memory [f_t.get_fk_fatura()] == null)
                                {
                                    hsh_Memory [f_t.get_fk_fatura()] = new ArrayList();
                                }

                                ArrayList tmp = hsh_Memory [f_t.get_fk_fatura()] as ArrayList;

                                tmp.Add(f_t);
                            }
                        }
                    }

                    // lista de todas as empresas e lojas
                    ArrayList full_memory_ent = new ArrayList();

                    stat.LblActivity.Text = "Buscando lista de lojas e empresas";
                    Application.DoEvents();

                    while (output_st_emp_loj_block != "")
                    {
                        ArrayList tmp_memory = new ArrayList();

                        if (var_exchange.fetch_memory(output_st_emp_loj_block, "200",
                                                      ref output_st_emp_loj_block,
                                                      ref tmp_memory))
                        {
                            for (int t = 0; t < tmp_memory.Count; ++t)
                            {
                                Entidade ent = new Entidade(tmp_memory[t] as DataPortable);

                                full_memory_ent.Add(ent);
                            }
                        }
                    }

                    stat.LblActivity.Text = "Gerando relatório para web";
                    Application.DoEvents();

                    stat.pgStatus.Maximum = full_memory_ent.Count;
                    stat.pgStatus.Minimum = 0;

                    money money_helper = new money();

                    // tradução do indice para texto
                    ArrayList desc = new TipoFatDesc().GetArray();

                    // Passa por todas as empresas e lojas
                    for (int g = 0; g < full_memory_ent.Count; ++g)
                    {
                        Entidade ent = full_memory_ent [g] as Entidade;

                        stat.pgStatus.Value = g + 1;

                        Application.DoEvents();

                        // Sub-título
                        lstMessages.Add(ent.get_st_nome());
                        lstTableSizes.Add(500);

                        ArrayList lst_sub_tbl_head = new ArrayList();

                        lst_sub_tbl_head.Add("Descrição de item faturado");
                        lst_sub_tbl_head.Add("Valor Cobrança R$");

                        lstHeader.Add(lst_sub_tbl_head);

                        // Lista de items
                        ArrayList my_cobranca = new ArrayList();

                        // Obtem index da memoria
                        ArrayList lstMemory = hsh_Memory [ent.get_fk_fatura()] as ArrayList;

                        if (lstMemory == null)
                        {
                            my_cobranca.Add(new ArrayList());
                        }
                        else
                        {
                            for (int t = 0; t < lstMemory.Count; ++t)
                            {
                                Rel_FAT f_t = lstMemory [t] as Rel_FAT;

                                // Lista de items para uma linha
                                ArrayList lst_sub_content = new ArrayList();

                                string st_desc = "";
                                string vr_cob  = "";

                                switch (f_t.get_tg_tipoFat())
                                {
                                case TipoFat.Extras:            st_desc = "Extra: " + f_t.get_st_extra();       break;

                                case TipoFat.TBM:                       st_desc = "Tarifa básica mensal";                       break;

                                case TipoFat.CartaoAtiv:        st_desc = "Tarifa por cartões ativos";          break;

                                case TipoFat.FixoTrans:         st_desc = "Valor sobre Transações";             break;

                                case TipoFat.Percent:           st_desc = "Percentual sobre Transações";        break;

                                default: break;
                                }

                                if (f_t.get_tg_desconto() == Context.TRUE)
                                {
                                    vr_cob = "-" + f_t.get_vr_cob();
                                }
                                else
                                {
                                    vr_cob = f_t.get_vr_cob();
                                }

                                lst_sub_content.Add(st_desc);
                                lst_sub_content.Add(money_helper.formatToMoney(vr_cob));

                                my_cobranca.Add(lst_sub_content);
                            }
                        }

                        lstContent.Add(my_cobranca);

                        ArrayList lst_sub_foot = new ArrayList();

                        var_util.indexCSV(output_st_csv_subtotal);
                        lst_sub_foot.Add("Sub-Total: R$ " + money_helper.formatToMoney(var_util.getCSV(g)));

                        var_util.indexCSV(output_st_csv_subtotal_desconto);
                        lst_sub_foot.Add("Sub-Total desconto: R$ " + money_helper.formatToMoney(var_util.getCSV(g)));

                        if (g == full_memory_ent.Count - 1)
                        {
                            lst_sub_foot.Add("");
                            lst_sub_foot.Add("Total de faturamento no período: R$ " + money_helper.formatToMoney(output_st_total));
                            lst_sub_foot.Add("Total em descontos no faturamento no período: R$ " + money_helper.formatToMoney(output_st_total_desconto));
                            lst_sub_foot.Add("");
                            lst_sub_foot.Add("Valor em cartões ativos: " + money_helper.formatToMoney(output_CartaoAtiv));
                            lst_sub_foot.Add("Valor em despesas extras: " + money_helper.formatToMoney(output_Extras));
                            lst_sub_foot.Add("Valor fixo por transações: " + money_helper.formatToMoney(output_FixoTrans));
                            lst_sub_foot.Add("Valor por percentual em transações: " + money_helper.formatToMoney(output_Percent));
                            lst_sub_foot.Add("Valor em mensalidades: " + money_helper.formatToMoney(output_TBM));
                        }

                        lstFooter.Add(lst_sub_foot);
                    }

                    stat.Close();

                    SyCrafReport rel = new SyCrafReport("Relatório de faturamento pendente",
                                                        "RFP",
                                                        "",
                                                        ctrl_TxtDtIni.getTextBoxValue(),
                                                        ctrl_TxtDtFim.getTextBoxValue(),
                                                        ref lstHeader,
                                                        ref lstContent,
                                                        ref lstTableSizes,
                                                        ref lstFooter,
                                                        ref lstMessages,
                                                        ref lstFilters);

                    #endregion
                }
                else
                {
                    #region - pagos -

                    // ##############################
                    // # SETUP LISTS ################
                    // ##############################

                    ArrayList lstHeader     = new ArrayList();
                    ArrayList lstContent    = new ArrayList();
                    ArrayList lstTableSizes = new ArrayList();
                    ArrayList lstFooter     = new ArrayList();
                    ArrayList lstMessages   = new ArrayList();
                    ArrayList lstFilters    = new ArrayList();

                    // ##############################
                    // # CUSTOMIZE
                    // ##############################

                    string output_st_total         = "";
                    string output_st_content_block = "";

                    int sel = i_Form.CboRelat.SelectedIndex;

                    string tg_type = "";
                    string st_rel  = "";

                    switch (sel)
                    {
                    case 1:         tg_type = TipoSitFat.EmCobrança;        st_rel = "Relatório de faturamento em cobrança";                                               break;

                    case 2:         tg_type = TipoSitFat.PagoDoc;           st_rel = "Relatório de faturamento pago com doc";                                              break;

                    case 3:         tg_type = TipoSitFat.PagoCC;            st_rel = "Relatório de faturamento pago em débito em conta";                   break;

                    case 4:         tg_type = TipoSitFat.BaixaCfeInst;      st_rel = "Relatório de faturamento baixado conforme instrução banco";  break;
                    }

                    dlgStatus stat = new dlgStatus("Relatório");

                    stat.LblActivity.Text = "Processando relatório no servidor";
                    stat.Show();
                    Application.DoEvents();

                    if (!var_exchange.fetch_relFat(var_util.GetDataBaseTimeFormat(ctrl_TxtDtIni.getTextBoxValue_Date()),
                                                   var_util.GetDataBaseTimeFormat(ctrl_TxtDtFim.getTextBoxValue_Date().AddDays(1)),
                                                   tg_type,
                                                   ref header,
                                                   ref output_st_total,
                                                   ref output_st_content_block))
                    {
                        stat.Close();
                        i_Form.BtnConfirmar.Enabled = true;
                        return(false);
                    }

                    stat.LblActivity.Text = "Buscando detalhes de faturamento";
                    Application.DoEvents();

                    ArrayList full_memory = new ArrayList();

                    ArrayList sortMem = new ArrayList();

                    while (output_st_content_block != "")
                    {
                        ArrayList tmp_memory = new ArrayList();

                        if (var_exchange.fetch_memory(output_st_content_block, "500",
                                                      ref output_st_content_block,
                                                      ref tmp_memory))
                        {
                            for (int t = 0; t < tmp_memory.Count; ++t)
                            {
                                Rel_FatCompleto tmp = new Rel_FatCompleto(tmp_memory[t] as DataPortable);

                                sortMem.Add(tmp.get_st_nome());

                                full_memory.Add(tmp);
                            }
                        }
                    }

                    sortMem.Sort();

                    stat.LblActivity.Text = "Gerando relatório para web";
                    Application.DoEvents();

                    stat.pgStatus.Maximum = full_memory.Count;
                    stat.pgStatus.Minimum = 0;

                    money money_helper = new money();

                    ArrayList lst_sub_tbl_head = new ArrayList();

                    lst_sub_tbl_head.Add("Empresa/Loja");
                    lst_sub_tbl_head.Add("Cobrança R$");
                    lst_sub_tbl_head.Add("Vencimento");
                    lst_sub_tbl_head.Add("Cód. Banco");
                    lst_sub_tbl_head.Add("Mensagem");
                    lst_sub_tbl_head.Add("Data Baixa");

                    lstHeader.Add(lst_sub_tbl_head);

                    // Sub-título
                    lstMessages.Add("");
                    lstTableSizes.Add(800);

                    ArrayList lst_lines = new ArrayList();

                    for (int g = 0; g < sortMem.Count; ++g)
                    {
                        stat.pgStatus.Value = g + 1;
                        Application.DoEvents();

                        for (int u = 0; u < full_memory.Count; ++u)
                        {
                            Rel_FatCompleto rel = full_memory [u] as Rel_FatCompleto;

                            if (rel.get_st_nome() != sortMem[g].ToString())
                            {
                                continue;
                            }

                            // Lista de items para uma linha
                            ArrayList lst_sub_content = new ArrayList();

                            lst_sub_content.Add(rel.get_st_nome());
                            lst_sub_content.Add(money_helper.formatToMoney(rel.get_vr_cobranca()));
                            lst_sub_content.Add(var_util.getDDMMYYYY_format(rel.get_dt_vencimento()).Substring(0, 10));

                            if (rel.get_dt_baixa() == "")
                            {
                                lst_sub_content.Add("-");
                                lst_sub_content.Add("-");
                                lst_sub_content.Add("-");
                            }
                            else
                            {
                                lst_sub_content.Add(rel.get_cod_retBanco());
                                lst_sub_content.Add(rel.get_st_msgBanco());
                                lst_sub_content.Add(var_util.getDDMMYYYY_format(rel.get_dt_baixa()).Substring(0, 10));
                            }

                            lst_lines.Add(lst_sub_content);

                            if (g == full_memory.Count - 1)
                            {
                                ArrayList lst_sub_foot = new ArrayList();

                                lst_sub_foot.Add("Total contabilizado no período: R$ " +
                                                 money_helper.formatToMoney(output_st_total));

                                lstFooter.Add(lst_sub_foot);
                            }
                        }
                    }

                    lstContent.Add(lst_lines);

                    stat.Close();
                    Application.DoEvents();

                    SyCrafReport relat = new SyCrafReport(st_rel,
                                                          "RFD",
                                                          "Lista completa de empresas e lojas",
                                                          ctrl_TxtDtIni.getTextBoxValue(),
                                                          ctrl_TxtDtFim.getTextBoxValue(),
                                                          ref lstHeader,
                                                          ref lstContent,
                                                          ref lstTableSizes,
                                                          ref lstFooter,
                                                          ref lstMessages,
                                                          ref lstFilters);
                    #endregion
                }

                i_Form.BtnConfirmar.Enabled = true;

                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_BtnConfirmarClick -

            case event_BtnConfirmarClick:
            {
                //InitEventCode event_BtnConfirmarClick
                //EndEventCode
                return(true);
            }

                #endregion

            default: break;
            }

            return(false);
        }
        public override bool doEvent(int event_number, object arg)
        {
            switch (event_number)
            {
                #region - event_Load -

            case event_Load:
            {
                //InitEventCode event_Load

                                        #if ROBOT
                var_util.execDefinedRobot(this, var_alias);
                                        #else
                doEvent(event_Translate, null);
                doEvent(event_FormIsOpening, null);
                                        #endif

                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_Translate -

            case event_Translate:
            {
                //InitEventCode event_Translate
                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_FormIsOpening -

            case event_FormIsOpening:
            {
                //InitEventCode event_FormIsOpening

                if (header.get_tg_user_type() == TipoUsuario.Lojista)
                {
                    ArrayList lst = new ArrayList();

                    var_exchange.fetch_lojistaEmpresas(header.get_st_empresa(), ref header, ref lst);

                    for (int t = 0; t < lst.Count; ++t)
                    {
                        DadosEmpresa de = new DadosEmpresa(lst[t] as DataPortable);

                        i_Form.LstEmp.Items.Add(de.get_st_empresa() + " " + de.get_st_fantasia());
                    }
                }

                //EndEventCode
                return(true);
            }

                #endregion

                #region - robot_ShowDialog -

            case robot_ShowDialog:
            {
                //InitEventCode robot_ShowDialog
                //EndEventCode
                return(true);
            }

                #endregion

                #region - robot_CloseDialog -

            case robot_CloseDialog:
            {
                //InitEventCode robot_CloseDialog
                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_Confirmar -

            case event_Confirmar:
            {
                //InitEventCode event_Confirmar

                if (i_Form.LstEmp.SelectedIndex == -1)
                {
                    return(false);
                }

                string st_empresa = i_Form.LstEmp.SelectedItem.ToString();

                st_empresa = st_empresa.Substring(0, st_empresa.IndexOf(" "));

                // ##############################
                // # SETUP LISTS ################
                // ##############################

                ArrayList lstHeader     = new ArrayList();
                ArrayList lstContent    = new ArrayList();
                ArrayList lstTableSizes = new ArrayList();
                ArrayList lstFooter     = new ArrayList();
                ArrayList lstMessages   = new ArrayList();
                ArrayList lstFilters    = new ArrayList();

                // ##############################
                // # CUSTOMIZE
                // ##############################

                string st_csv_contents = "";

                dlgStatus stat = new dlgStatus("Relatório");

                stat.LblActivity.Text = "Processando relatório no servidor";
                stat.Show();
                Application.DoEvents();

                if (!var_exchange.fetch_rel_prevLojista(st_empresa,
                                                        ref header,
                                                        ref st_csv_contents))
                {
                    stat.Close();
                    return(false);
                }

                ArrayList full_memory = new ArrayList();

                stat.LblActivity.Text = "Buscando detalhes...";
                Application.DoEvents();

                while (st_csv_contents != "")
                {
                    ArrayList tmp_memory = new ArrayList();

                    if (var_exchange.fetch_memory(st_csv_contents, "400", ref st_csv_contents, ref tmp_memory))
                    {
                        for (int t = 0; t < tmp_memory.Count; ++t)
                        {
                            full_memory.Add(tmp_memory[t]);
                        }
                    }
                }

                money money_helper = new money();

                stat.LblActivity.Text = "Gerando relatório para web";
                Application.DoEvents();

                lstMessages.Add("Transações confirmadas para a loja: " + header.get_st_empresa());

                lstTableSizes.Add(650);

                ArrayList lst_sub_tbl_head = new ArrayList();

                lst_sub_tbl_head.Add("Cartão");
                lst_sub_tbl_head.Add("NSU");
                lst_sub_tbl_head.Add("Data e Hora");
                lst_sub_tbl_head.Add("Parcela");
                lst_sub_tbl_head.Add("Valor R$");
                lst_sub_tbl_head.Add("Valor Repasse R$");

                lstHeader.Add(lst_sub_tbl_head);

                long tot_repasse = 0;

                ArrayList my_line_container = new ArrayList();

                for (int t = 0; t < full_memory.Count; ++t)
                {
                    DadosRepasse dr = new DadosRepasse(full_memory[t] as DataPortable);

                    ArrayList lst_line_content = new ArrayList();

                    lst_line_content.Add(dr.get_st_cartao());
                    lst_line_content.Add(dr.get_st_nsu());
                    lst_line_content.Add(var_util.getDDMMYYYY_format(dr.get_dt_trans()));
                    lst_line_content.Add(dr.get_id_parcela());
                    lst_line_content.Add(money_helper.formatToMoney(dr.get_vr_total()));
                    lst_line_content.Add(money_helper.formatToMoney(dr.get_vr_repasse()));

                    tot_repasse += Convert.ToInt64(dr.get_vr_repasse());

                    my_line_container.Add(lst_line_content);
                }

                lstContent.Add(my_line_container);

                ArrayList lst_sub_foot = new ArrayList();

                lst_sub_foot.Add("Total de repasse: " + money_helper.formatToMoney(tot_repasse.ToString()));

                lstFooter.Add(lst_sub_foot);

                stat.Close();

                SyCrafReport rel = new SyCrafReport("Relatório de previsão de repasse ao lojista",
                                                    "RPR",
                                                    i_Form.LstEmp.SelectedItem.ToString(),
                                                    var_util.getDDMMYYYY_format(DateTime.Now.ToString()),
                                                    "",
                                                    ref lstHeader,
                                                    ref lstContent,
                                                    ref lstTableSizes,
                                                    ref lstFooter,
                                                    ref lstMessages,
                                                    ref lstFilters);

                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_BtnConfirmarClick -

            case event_BtnConfirmarClick:
            {
                //InitEventCode event_BtnConfirmarClick
                //EndEventCode
                return(true);
            }

                #endregion

            default: break;
            }

            return(false);
        }
        public override bool doEvent(int event_number, object arg)
        {
            switch (event_number)
            {
                #region - event_Load -

            case event_Load:
            {
                //InitEventCode event_Load

                                        #if ROBOT
                var_util.execDefinedRobot(this, var_alias);
                                        #else
                doEvent(event_Translate, null);
                doEvent(event_FormIsOpening, null);
                                        #endif

                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_Translate -

            case event_Translate:
            {
                //InitEventCode event_Translate
                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_FormIsOpening -

            case event_FormIsOpening:
            {
                //InitEventCode event_FormIsOpening

                i_Form.Text += " " + st_cod_empresa.PadLeft(6, '0');

                i_Form.CboReport.SelectedIndex = 0;

                ctrl_TxtMes.AcquireTextBox(i_Form.TxtMes, this, event_val_TxtMes, 2);
                ctrl_TxtAno.AcquireTextBox(i_Form.TxtAno, this, event_val_TxtAno, 4);

                ctrl_TxtMes.SetTextBoxText(DateTime.Now.Month.ToString());
                ctrl_TxtAno.SetTextBoxText(DateTime.Now.Year.ToString());

                ArrayList lst = new ArrayList();

                string nome_emp = "";

                var_exchange.fetch_empresasAfiliadas(st_cod_empresa,
                                                     ref header,
                                                     ref nome_emp,
                                                     ref lst);

                for (int t = 0; t < lst.Count; ++t)
                {
                    DadosEmpresa de = new DadosEmpresa(lst [t] as DataPortable);

                    i_Form.CboAfiliada.Items.Add(de.get_st_empresa());
                }

                if (lst.Count == 0)
                {
                    i_Form.CboAfiliada.Items.Add("");
                }

                i_Form.CboAfiliada.SelectedIndex = 0;

                //EndEventCode
                return(true);
            }

                #endregion

                #region - robot_ShowDialog -

            case robot_ShowDialog:
            {
                //InitEventCode robot_ShowDialog
                //EndEventCode
                return(true);
            }

                #endregion

                #region - robot_CloseDialog -

            case robot_CloseDialog:
            {
                //InitEventCode robot_CloseDialog
                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_Confirmar -

            case event_Confirmar:
            {
                //InitEventCode event_Confirmar

                if (!ctrl_TxtAno.IsUserValidated && !ctrl_TxtMes.IsUserValidated)
                {
                    return(false);
                }

                switch (i_Form.CboReport.SelectedIndex)
                {
                case 0: doEvent(event_PorEmpresa, null);     break;

                case 1: doEvent(event_PorCartao, null);      break;
                }

                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_val_TxtMes -

            case event_val_TxtMes:
            {
                //InitEventCode event_val_TxtMes

                if (ctrl_TxtMes.getTextBoxValue() == "" ||
                    ctrl_TxtMes.getTextBoxValue_Long() > 12)
                {
                    i_Form.TxtMes.BackColor     = colorInvalid;
                    ctrl_TxtMes.IsUserValidated = false;
                }
                else
                {
                    i_Form.TxtMes.BackColor     = Color.White;
                    ctrl_TxtMes.IsUserValidated = true;
                }

                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_val_TxtAno -

            case event_val_TxtAno:
            {
                //InitEventCode event_val_TxtAno

                if (ctrl_TxtAno.getTextBoxValue().Length < 4)
                {
                    i_Form.TxtAno.BackColor     = colorInvalid;
                    ctrl_TxtAno.IsUserValidated = false;
                }
                else
                {
                    i_Form.TxtAno.BackColor     = Color.White;
                    ctrl_TxtAno.IsUserValidated = true;
                }

                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_PorEmpresa -

            case event_PorEmpresa:
            {
                //InitEventCode event_PorEmpresa

                // ##############################
                // # SETUP LISTS ################
                // ##############################

                ArrayList lstHeader     = new ArrayList();
                ArrayList lstContent    = new ArrayList();
                ArrayList lstTableSizes = new ArrayList();
                ArrayList lstFooter     = new ArrayList();
                ArrayList lstMessages   = new ArrayList();
                ArrayList lstFilters    = new ArrayList();

                string st_empresa             = "";
                string st_csv_cartao          = "";
                string st_csv_loja            = "";
                string st_csv_loja_content    = "";
                string st_csv_subtotal_loja   = "";
                string st_csv_subtotal_cartao = "";
                string st_csv_cartao_content  = "";
                string st_total = "";

                dlgStatus stat = new dlgStatus("Relatório");

                stat.LblActivity.Text = "Processando relatório no servidor";
                stat.Show();
                Application.DoEvents();

                if (!var_exchange.fetch_rel_3_fech("0",
                                                   ctrl_TxtMes.getTextBoxValue(),
                                                   ctrl_TxtAno.getTextBoxValue(),
                                                   st_cod_empresa,
                                                   i_Form.CboAfiliada.SelectedItem.ToString(),
                                                   ref header,
                                                   ref st_empresa,
                                                   ref st_csv_cartao,
                                                   ref st_csv_loja,
                                                   ref st_csv_loja_content,
                                                   ref st_csv_subtotal_loja,
                                                   ref st_csv_subtotal_cartao,
                                                   ref st_csv_cartao_content,
                                                   ref st_total))
                {
                    stat.Close();
                    return(false);
                }

                money     money_helper = new money();
                Hashtable mem_Lojas    = new Hashtable();

                stat.LblActivity.Text = "Obtendo resultados";

                Application.DoEvents();

                #region Busca todos os registros de todos as lojas
                {
                    ArrayList full_memory = new ArrayList();

                    while (st_csv_loja_content != "")
                    {
                        ArrayList tmp_memory = new ArrayList();

                        if (var_exchange.fetch_memory(st_csv_loja_content, "400", ref st_csv_loja_content, ref tmp_memory))
                        {
                            for (int t = 0; t < tmp_memory.Count; ++t)
                            {
                                full_memory.Add(tmp_memory[t]);
                            }
                        }
                    }

                    for (int t = 0; t < full_memory.Count; ++t)
                    {
                        DadosFechamento df = new DadosFechamento(full_memory[t] as DataPortable);

                        string tmp_loja = df.get_st_loja();

                        if (mem_Lojas [tmp_loja] == null)
                        {
                            mem_Lojas [tmp_loja] = new ArrayList();
                        }

                        ArrayList memoryLoja = mem_Lojas [tmp_loja] as ArrayList;

                        memoryLoja.Add(df);
                    }
                }
                #endregion

                stat.LblActivity.Text = "Gerando relatório para web";

                Application.DoEvents();

                int tot_Lojas = var_util.indexCSV(st_csv_loja);

                long tot_repasse = 0;

                ApplicationUtil var_utilFooter = new ApplicationUtil();

                var_utilFooter.indexCSV(st_csv_subtotal_loja);

                for (int h = 0; h < tot_Lojas; ++h)
                {
                    string loja = var_util.getCSV(h);

                    ArrayList memLojaList = mem_Lojas [loja] as ArrayList;

                    ArrayList lstFooterSub  = new ArrayList();
                    ArrayList lstHeaderSub  = new ArrayList();
                    ArrayList lstContentSub = new ArrayList();

                    lstMessages.Add("Fechamento da loja: " + loja);

                    lstTableSizes.Add(650);

                    lstHeaderSub.Add("NSU");
                    lstHeaderSub.Add("Cartão");
                    lstHeaderSub.Add("Nome");
                    lstHeaderSub.Add("Data e Hora");
                    lstHeaderSub.Add("Valor R$");
                    lstHeaderSub.Add("Parcela");
                    lstHeaderSub.Add("Terminal");

                    long sub_repasse = 0;

                    if (memLojaList != null)
                    {
                        for (int t = 0; t < memLojaList.Count; ++t)
                        {
                            DadosFechamento df = new DadosFechamento(memLojaList[t] as DataPortable);

                            ArrayList lstLine = new ArrayList();

                            lstLine.Add(df.get_st_nsu().PadLeft(6, '0'));
                            lstLine.Add(df.get_st_cartao());
                            lstLine.Add(df.get_st_nome());
                            lstLine.Add(var_util.getDDMMYYYY_format(df.get_dt_trans()));
                            lstLine.Add(money_helper.formatToMoney(df.get_vr_valor()));
                            lstLine.Add(df.get_nu_parcela());
                            lstLine.Add(df.get_st_terminal());

                            sub_repasse += Convert.ToInt64(df.get_vr_repasse());

                            lstContentSub.Add(lstLine);
                        }
                    }

                    lstFooterSub.Add("Sub-Total: " + "R$ " + money_helper.formatToMoney(var_utilFooter.getCSV(h)));
                    lstFooterSub.Add("Sub-Total repasse: " + "R$ " + money_helper.setMoneyFormat(sub_repasse));

                    tot_repasse += sub_repasse;

                    lstHeader.Add(lstHeaderSub);
                    lstFooter.Add(lstFooterSub);
                    lstContent.Add(lstContentSub);

                    if (h == tot_Lojas - 1)
                    {
                        lstFooterSub.Add("");
                        lstFooterSub.Add("Total de vendas nas lojas: " + "R$ " + money_helper.formatToMoney(st_total));
                        lstFooterSub.Add("Total de repasse para lojas: " + "R$ " + money_helper.setMoneyFormat(tot_repasse));
                    }
                }

                stat.Close();

                SyCrafReport rel = new SyCrafReport("Relatório de Fechamento por loja",
                                                    "RFE",
                                                    st_empresa,
                                                    "Mês " + ctrl_TxtMes.getTextBoxValue(),
                                                    "Ano " + ctrl_TxtAno.getTextBoxValue(),
                                                    ref lstHeader,
                                                    ref lstContent,
                                                    ref lstTableSizes,
                                                    ref lstFooter,
                                                    ref lstMessages,
                                                    ref lstFilters);


                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_PorCartao -

            case event_PorCartao:
            {
                //InitEventCode event_PorCartao

                // ##############################
                // # SETUP LISTS ################
                // ##############################

                ArrayList lstHeader     = new ArrayList();
                ArrayList lstContent    = new ArrayList();
                ArrayList lstTableSizes = new ArrayList();
                ArrayList lstFooter     = new ArrayList();
                ArrayList lstMessages   = new ArrayList();
                ArrayList lstFilters    = new ArrayList();

                string st_empresa             = "";
                string st_csv_cartao          = "";
                string st_csv_loja            = "";
                string st_csv_loja_content    = "";
                string st_csv_subtotal_loja   = "";
                string st_csv_subtotal_cartao = "";
                string st_csv_cartao_content  = "";
                string st_total = "";

                dlgStatus stat = new dlgStatus("Relatório");

                stat.LblActivity.Text = "Processando relatório no servidor";
                stat.Show();
                Application.DoEvents();

                if (!var_exchange.fetch_rel_3_fech("1",
                                                   ctrl_TxtMes.getTextBoxValue(),
                                                   ctrl_TxtAno.getTextBoxValue(),
                                                   st_cod_empresa,
                                                   i_Form.CboAfiliada.SelectedItem.ToString(),
                                                   ref header,
                                                   ref st_empresa,
                                                   ref st_csv_cartao,
                                                   ref st_csv_loja,
                                                   ref st_csv_loja_content,
                                                   ref st_csv_subtotal_loja,
                                                   ref st_csv_subtotal_cartao,
                                                   ref st_csv_cartao_content,
                                                   ref st_total))
                {
                    stat.Close();
                    return(false);
                }

                money     money_helper = new money();
                Hashtable mem_Cartoes  = new Hashtable();

                stat.LblActivity.Text = "Obtendo resultados";

                Application.DoEvents();

                #region Busca todos os registros de todos os cartoes
                {
                    ArrayList full_memory = new ArrayList();

                    while (st_csv_cartao_content != "")
                    {
                        ArrayList tmp_memory = new ArrayList();

                        if (var_exchange.fetch_memory(st_csv_cartao_content, "400", ref st_csv_cartao_content, ref tmp_memory))
                        {
                            for (int t = 0; t < tmp_memory.Count; ++t)
                            {
                                full_memory.Add(tmp_memory[t]);
                            }
                        }
                    }

                    for (int t = 0; t < full_memory.Count; ++t)
                    {
                        DadosFechamento df = new DadosFechamento(full_memory[t] as DataPortable);

                        string tmp_cartao = df.get_st_cartao();

                        if (mem_Cartoes [tmp_cartao] == null)
                        {
                            mem_Cartoes [tmp_cartao] = new ArrayList();
                        }

                        ArrayList memoryCart = mem_Cartoes [tmp_cartao] as ArrayList;

                        memoryCart.Add(df);
                    }
                }

                #endregion

                stat.LblActivity.Text = "Gerando relatório para web";

                Application.DoEvents();

                int tot_Cartoes = var_util.indexCSV(st_csv_cartao);

                ApplicationUtil var_utilFooter = new ApplicationUtil();

                var_utilFooter.indexCSV(st_csv_subtotal_cartao);

                for (int h = 0; h < tot_Cartoes; ++h)
                {
                    string cart = var_util.getCSV(h);

                    ArrayList lstFooterSub  = new ArrayList();
                    ArrayList lstHeaderSub  = new ArrayList();
                    ArrayList lstContentSub = new ArrayList();

                    lstMessages.Add("Fechamento do cartão: " + cart);

                    lstTableSizes.Add(800);

                    lstHeaderSub.Add("NSU");
                    lstHeaderSub.Add("Loja");
                    lstHeaderSub.Add("Data e Hora");
                    lstHeaderSub.Add("Valor R$");
                    lstHeaderSub.Add("Parcela");

                    ArrayList memCartList = mem_Cartoes [cart] as ArrayList;

                    if (memCartList != null)
                    {
                        for (int t = 0; t < memCartList.Count; ++t)
                        {
                            DadosFechamento df = new DadosFechamento(memCartList[t] as DataPortable);

                            ArrayList lstLine = new ArrayList();

                            lstLine.Add(df.get_st_nsu().PadLeft(6, '0'));
                            lstLine.Add(df.get_st_loja());
                            lstLine.Add(var_util.getDDMMYYYY_format(df.get_dt_trans()));
                            lstLine.Add(money_helper.formatToMoney(df.get_vr_valor()));
                            lstLine.Add(df.get_nu_parcela());

                            lstContentSub.Add(lstLine);
                        }
                    }

                    lstFooterSub.Add("Sub-Total: R$ " + money_helper.formatToMoney(var_utilFooter.getCSV(h)));

                    lstHeader.Add(lstHeaderSub);
                    lstFooter.Add(lstFooterSub);
                    lstContent.Add(lstContentSub);

                    if (h == tot_Cartoes - 1)
                    {
                        lstFooterSub.Add("");
                        lstFooterSub.Add("Total: " + "R$ " + money_helper.formatToMoney(st_total));
                    }
                }

                stat.Close();

                SyCrafReport rel = new SyCrafReport("Relatório de Fechamento por cartões",
                                                    "RFE",
                                                    st_empresa,
                                                    "Mês : " + ctrl_TxtMes.getTextBoxValue(),
                                                    "Ano : " + ctrl_TxtAno.getTextBoxValue(),
                                                    ref lstHeader,
                                                    ref lstContent,
                                                    ref lstTableSizes,
                                                    ref lstFooter,
                                                    ref lstMessages,
                                                    ref lstFilters);


                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_BDF -

            case event_BDF:
            {
                //InitEventCode event_BDF

                if (i_Form.CboReport.SelectedIndex != 1)
                {
                    MessageBox.Show("Geração somente para relatório de cartões", "Aviso");
                    return(false);
                }

                event_dlgDBF_Fechamento ev_call = new event_dlgDBF_Fechamento(var_util, var_exchange);

                ev_call.header = header;

                ev_call.mes            = ctrl_TxtMes.getTextBoxValue();
                ev_call.ano            = ctrl_TxtAno.getTextBoxValue();
                ev_call.st_cod_empresa = st_cod_empresa;

                ev_call.i_Form.ShowDialog();

                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_BtnConfirmarClick -

            case event_BtnConfirmarClick:
            {
                //InitEventCode event_BtnConfirmarClick
                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_BtnDBFClick -

            case event_BtnDBFClick:
            {
                //InitEventCode event_BtnDBFClick
                //EndEventCode
                return(true);
            }

                #endregion

            default: break;
            }

            return(false);
        }
        public override bool doEvent(int event_number, object arg)
        {
            switch (event_number)
            {
                #region - event_Load -

            case event_Load:
            {
                //InitEventCode event_Load

                                        #if ROBOT
                var_util.execDefinedRobot(this, var_alias);
                                        #else
                doEvent(event_Translate, null);
                doEvent(event_FormIsOpening, null);
                                        #endif

                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_Translate -

            case event_Translate:
            {
                //InitEventCode event_Translate
                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_FormIsOpening -

            case event_FormIsOpening:
            {
                //InitEventCode event_FormIsOpening

                ctrl_TxtDtIni.AcquireTextBox(i_Form.TxtDtIni, this, event_val_TxtDtIni, dateTextController.FORMAT_DDMMYYYY);
                ctrl_TxtDtFim.AcquireTextBox(i_Form.TxtDtFim, this, event_val_TxtDtFim, dateTextController.FORMAT_DDMMYYYY);

                ctrl_TxtDtIni.SetupErrorProvider(ErrorIconAlignment.MiddleRight, false);
                ctrl_TxtDtFim.SetupErrorProvider(ErrorIconAlignment.MiddleRight, false);

                //EndEventCode
                return(true);
            }

                #endregion

                #region - robot_ShowDialog -

            case robot_ShowDialog:
            {
                //InitEventCode robot_ShowDialog
                //EndEventCode
                return(true);
            }

                #endregion

                #region - robot_CloseDialog -

            case robot_CloseDialog:
            {
                //InitEventCode robot_CloseDialog
                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_Confirmar -

            case event_Confirmar:
            {
                //InitEventCode event_Confirmar

                bool bOk = true;

                if (!ctrl_TxtDtFim.IsUserValidated)
                {
                    ctrl_TxtDtFim.SetErrorMessage("Informe o dia final");
                    bOk = false;
                }

                if (!ctrl_TxtDtIni.IsUserValidated)
                {
                    ctrl_TxtDtIni.SetErrorMessage("Informe o dia inicial");
                    bOk = false;
                }

                if (i_Form.TxtFile.Text == "")
                {
                    MessageBox.Show("Informe o arquivo de saída", "Aviso");
                    bOk = false;
                }

                if (i_Form.CboOption.SelectedIndex == -1)
                {
                    MessageBox.Show("Informe a opção de cobrança", "Aviso");
                    bOk = false;
                }

                if (!bOk)
                {
                    return(false);
                }

                i_Form.BtnConfirmar.Enabled = false;

                string st_block = "";
                string nu_nsFat = "";

                dlgStatus stat = new dlgStatus("Faturamento");

                stat.LblActivity.Text = "Processando dados no servidor";

                stat.pgStatus.Maximum = 1;
                stat.pgStatus.Minimum = 0;

                stat.Show();
                Application.DoEvents();

                if (var_exchange.fetch_arquivoFat(var_util.GetDataBaseTimeFormat(ctrl_TxtDtIni.getTextBoxValue_Date()),
                                                  var_util.GetDataBaseTimeFormat(ctrl_TxtDtFim.getTextBoxValue_Date().AddDays(1)),
                                                  i_Form.CboOption.SelectedIndex.ToString(),
                                                  ref header,
                                                  ref st_block,
                                                  ref nu_nsFat))
                {
                    ArrayList full_memory = new ArrayList();

                    while (st_block != "")
                    {
                        ArrayList tmp_memory = new ArrayList();

                        if (var_exchange.fetch_memory(st_block, "600", ref st_block, ref tmp_memory))
                        {
                            for (int t = 0; t < tmp_memory.Count; ++t)
                            {
                                full_memory.Add(tmp_memory[t]);
                            }
                        }
                    }

                    string file = i_Form.TxtFile.Text.Replace("ZZ", nu_nsFat.PadLeft(2, '0'));

                    StreamWriter sw = new StreamWriter(file, false, Encoding.Default);

                    for (int t = 0; t < full_memory.Count; ++t)
                    {
                        DataPortable port = full_memory[t] as DataPortable;

                        sw.WriteLine(port.getValue("line"));
                    }

                    sw.Close();

                    MessageBox.Show("Arquivo '" + file + "' gerado com sucesso", "Aviso");
                }

                stat.Close();
                Application.DoEvents();

                i_Form.BtnConfirmar.Enabled = true;

                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_Dir -

            case event_Dir:
            {
                //InitEventCode event_Dir
                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_val_TxtDtFim -

            case event_val_TxtDtFim:
            {
                //InitEventCode event_val_TxtDtFim

                switch (arg as string)
                {
                case dateTextController.DATE_VALID:
                {
                    i_Form.TxtDtFim.BackColor     = Color.White;
                    ctrl_TxtDtFim.IsUserValidated = true;
                    ctrl_TxtDtFim.CleanError();
                    break;
                }

                case dateTextController.DATE_INVALID:
                {
                    i_Form.TxtDtFim.BackColor     = colorInvalid;
                    ctrl_TxtDtFim.IsUserValidated = false;
                    break;
                }

                default: break;
                }

                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_val_TxtDtIni -

            case event_val_TxtDtIni:
            {
                //InitEventCode event_val_TxtDtIni

                switch (arg as string)
                {
                case dateTextController.DATE_VALID:
                {
                    i_Form.TxtDtIni.BackColor     = Color.White;
                    ctrl_TxtDtIni.IsUserValidated = true;
                    ctrl_TxtDtIni.CleanError();
                    break;
                }

                case dateTextController.DATE_INVALID:
                {
                    i_Form.TxtDtIni.BackColor     = colorInvalid;
                    ctrl_TxtDtIni.IsUserValidated = false;
                    break;
                }

                default: break;
                }

                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_BtnDirClick -

            case event_BtnDirClick:
            {
                //InitEventCode event_BtnDirClick
                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_BtnConfirmarClick -

            case event_BtnConfirmarClick:
            {
                //InitEventCode event_BtnConfirmarClick
                //EndEventCode
                return(true);
            }

                #endregion

            default: break;
            }

            return(false);
        }
Example #6
0
        public override bool doEvent(int event_number, object arg)
        {
            switch (event_number)
            {
                #region - event_Load -

            case event_Load:
            {
                //InitEventCode event_Load

                                        #if ROBOT
                var_util.execDefinedRobot(this, var_alias);
                                        #else
                doEvent(event_Translate, null);
                doEvent(event_FormIsOpening, null);
                                        #endif

                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_Translate -

            case event_Translate:
            {
                //InitEventCode event_Translate
                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_FormIsOpening -

            case event_FormIsOpening:
            {
                //InitEventCode event_FormIsOpening

                i_Form.LblText.Text += mes + "/" + ano + " - Empresa " + st_cod_empresa;

                //EndEventCode
                return(true);
            }

                #endregion

                #region - robot_ShowDialog -

            case robot_ShowDialog:
            {
                //InitEventCode robot_ShowDialog
                //EndEventCode
                return(true);
            }

                #endregion

                #region - robot_CloseDialog -

            case robot_CloseDialog:
            {
                //InitEventCode robot_CloseDialog
                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_Procurar -

            case event_Procurar:
            {
                //InitEventCode event_Procurar

                i_Form.folderBrowserDialog1.ShowNewFolderButton = true;
                i_Form.folderBrowserDialog1.Description         = "Selecione o diretório para o arquivo BDF:";
                i_Form.folderBrowserDialog1.ShowDialog();

                i_Form.TxtFile.Text = i_Form.folderBrowserDialog1.SelectedPath + "fechamen.dbf";

                if (MessageBox.Show("Confirma geração de arquivo?",
                                    "Aviso",
                                    MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Question,
                                    MessageBoxDefaultButton.Button2) == DialogResult.No)
                {
                    return(false);
                }

                string st_empresa             = "";
                string st_csv_cartao          = "";
                string st_csv_loja            = "";
                string st_csv_loja_content    = "";
                string st_csv_subtotal_loja   = "";
                string st_csv_subtotal_cartao = "";
                string st_csv_cartao_content  = "";
                string st_total = "";

                dlgStatus stat = new dlgStatus("Relatório");

                stat.LblActivity.Text = "Processando no servidor";
                stat.Show();
                Application.DoEvents();

                if (!var_exchange.fetch_rel_3_fech("1",
                                                   mes,
                                                   ano,
                                                   st_cod_empresa,
                                                   "",
                                                   ref header,
                                                   ref st_empresa,
                                                   ref st_csv_cartao,
                                                   ref st_csv_loja,
                                                   ref st_csv_loja_content,
                                                   ref st_csv_subtotal_loja,
                                                   ref st_csv_subtotal_cartao,
                                                   ref st_csv_cartao_content,
                                                   ref st_total))
                {
                    stat.Close();
                    return(false);
                }

                DBfileGen dbf = new DBfileGen(i_Form.folderBrowserDialog1.SelectedPath,
                                              "fechamen",
                                              "dbf");

                dbf.addCampo("data", "date");
                dbf.addCampo("nsu", "varchar(6)");
                dbf.addCampo("matricula", "varchar(6)");
                dbf.addCampo("valor", "currency");
                dbf.addCampo("parcela", "varchar(6)");
                dbf.addCampo("cnpj", "varchar(14)");

                money     money_helper = new money();
                Hashtable mem_Cartoes  = new Hashtable();

                stat.LblActivity.Text = "Obtendo resultados";

                Application.DoEvents();

                #region Busca todos os registros de todos os cartoes
                {
                    ArrayList full_memory = new ArrayList();

                    while (st_csv_cartao_content != "")
                    {
                        ArrayList tmp_memory = new ArrayList();

                        if (var_exchange.fetch_memory(st_csv_cartao_content, "400", ref st_csv_cartao_content, ref tmp_memory))
                        {
                            for (int t = 0; t < tmp_memory.Count; ++t)
                            {
                                full_memory.Add(tmp_memory[t]);
                            }
                        }
                    }

                    for (int t = 0; t < full_memory.Count; ++t)
                    {
                        DadosFechamento df = new DadosFechamento(full_memory[t] as DataPortable);

                        string tmp_cartao = df.get_st_cartao();

                        if (mem_Cartoes [tmp_cartao] == null)
                        {
                            mem_Cartoes [tmp_cartao] = new ArrayList();
                        }

                        ArrayList memoryCart = mem_Cartoes [tmp_cartao] as ArrayList;

                        memoryCart.Add(df);
                    }
                }

                #endregion

                stat.LblActivity.Text = "Escrevendo arquivo";

                Application.DoEvents();

                int tot_Cartoes = var_util.indexCSV(st_csv_cartao);

                ApplicationUtil var_utilFooter = new ApplicationUtil();

                var_utilFooter.indexCSV(st_csv_subtotal_cartao);

                for (int h = 0; h < tot_Cartoes; ++h)
                {
                    string cart = var_util.getCSV(h);

                    ArrayList memCartList = mem_Cartoes [cart] as ArrayList;

                    if (memCartList != null)
                    {
                        for (int t = 0; t < memCartList.Count; ++t)
                        {
                            DadosFechamento df = new DadosFechamento(memCartList[t] as DataPortable);

                            ArrayList lstLine = new ArrayList();

                            lstLine.Add(var_util.getDDMMYYYY_format(df.get_dt_trans()).Substring(0, 10));
                            lstLine.Add(df.get_st_nsu().PadLeft(6, '0'));
                            lstLine.Add(df.get_st_matricula());

                            string vr_val = df.get_vr_valor().PadLeft(3, '0');

                            vr_val = vr_val.Insert(vr_val.Length - 2, ".");

                            lstLine.Add(vr_val);
                            lstLine.Add(df.get_nu_parcela());
                            lstLine.Add(df.get_st_cnpj());

                            dbf.addReg(lstLine);
                        }
                    }
                }

                dbf.save();

                stat.Close();

                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_BtnProcurarClick -

            case event_BtnProcurarClick:
            {
                //InitEventCode event_BtnProcurarClick
                //EndEventCode
                return(true);
            }

                #endregion

            default: break;
            }

            return(false);
        }