Esempio n. 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

                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);
        }
Esempio n. 2
0
        public override bool doEvent(int event_number, object arg)
        {
            switch (event_number)
            {
                #region - event_Load -

            case event_Load:
            {
                //InitEventCode event_Load

                doEvent(event_Translate, null);
                doEvent(event_FormIsOpening, null);

                //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

                string st_csv_files = "";

                i_Form.LblCmd.Text = "Buscando ultima versão do programa de atualização...";
                i_Form.Show();

                Application.DoEvents();
                Thread.Sleep(500);

                                        #if LINUX_DIST
                //var_exchange.infra_fetchUpdaterVersion ( Context.FALSE, ref st_csv_files );
                                        #else
                var_exchange.infra_fetchUpdaterVersion(ref st_csv_files);
                                        #endif

                // pares de "nome_arquivo,indice"
                int tot = var_util.indexCSV(st_csv_files);

                int num = 1;

                for (int t = 0, dot = 0; t < tot; ++t)
                {
                    string fileName  = var_util.getCSV(t);                                      // busca nome
                    string next_part = var_util.getCSV(++t);                                    // busca indice

                    // mostrador no diálogo
                    string basicTag = "Buscando arquivo [" + num.ToString() + " de " + (tot / 2).ToString() + "] ";

                    ++num;

                    StringBuilder archive = new StringBuilder();

                    while (next_part != "")
                    {
                        string current_tag = basicTag,
                               tmp_content = "";

                        // pequena animação indicando download...
                        if (++dot == 15)
                        {
                            dot = 1;
                        }

                        for (int g = 0; g < dot; ++g)
                        {
                            current_tag += ".";
                        }

                        Application.DoEvents();
                        i_Form.LblCmd.Text = current_tag;
                        Application.DoEvents();

                        var_exchange.infra_fetchFile(next_part, ref next_part, ref tmp_content);

                        archive.Append(tmp_content);
                    }

                    if (File.Exists(fileName))
                    {
                        File.Delete(fileName);
                    }

                    FileStream   fs = new FileStream(fileName, FileMode.CreateNew);
                    BinaryWriter bw = new BinaryWriter(fs);

                    bw.Write(HexEncoding.GetBytes(archive.ToString()));

                    bw.Close();
                    fs.Close();
                }

                var_exchange.m_Client.ExitSession();

                Process p = new Process();

                                    #if LINUX_DIST
                p.StartInfo.FileName = "LinuxUpdater.exe";
                                    #else
                p.StartInfo.FileName = "Updater.exe";
                                    #endif

                p.StartInfo.Arguments      = "";
                p.StartInfo.CreateNoWindow = false;
                p.Start();

                i_Form.Close();

                Application.ExitThread();

                //EndEventCode
                return(true);
            }

                #endregion

            default: break;
            }

            return(false);
        }
Esempio n. 3
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);
        }
        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);
        }
Esempio n. 5
0
        public override bool doEvent(int event_number, object arg)
        {
            switch (event_number)
            {
                #region - event_Start -

            case event_Start:
            {
                //InitEventCode event_Start

                                        #if ROBOT
                                        #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

                string st_csv_files   = "";
                string st_new_version = "";

                StreamReader sr = new StreamReader("app.txt");

                string app = sr.ReadLine();

                sr.Close();

                i_Form.LblCmd.Text = "Buscando lista de arquivos...";
                i_Form.Show();

                Application.DoEvents();
                Thread.Sleep(500);

                                        #if LINUX_DIST
                var_exchange.infra_fetchIncomingVersion(app, Context.FALSE, ref st_csv_files, ref st_new_version);
                                        #else
                var_exchange.infra_fetchIncomingVersion(app, ref st_csv_files, ref st_new_version);
                                        #endif

                // pares de "nome_arquivo,indice"
                int tot = var_util.indexCSV(st_csv_files);

                int num = 1;

                for (int t = 0, dot = 0; t < tot; ++t)
                {
                    string fileName  = var_util.getCSV(t);                                      // busca nome
                    string next_part = var_util.getCSV(++t);                                    // busca indice

                    // mostrador no diálogo
                    string basicTag = "Buscando arquivo [" + num.ToString() + " de " + (tot / 2).ToString() + "] ";

                    ++num;

                    StringBuilder archive = new StringBuilder();

                    while (next_part != "")
                    {
                        string current_tag = basicTag,
                               tmp_content = "";

                        // pequena animação indicando download...
                        if (++dot == 15)
                        {
                            dot = 1;
                        }

                        for (int g = 0; g < dot; ++g)
                        {
                            current_tag += ".";
                        }

                        Application.DoEvents();
                        i_Form.LblCmd.Text = current_tag;
                        Application.DoEvents();

                        var_exchange.infra_fetchFile(next_part, ref next_part, ref tmp_content);

                        archive.Append(tmp_content);
                    }

                    if (File.Exists(fileName))
                    {
                        File.Delete(fileName);
                    }

                    FileStream   fs = new FileStream(fileName, FileMode.CreateNew);
                    BinaryWriter bw = new BinaryWriter(fs);

                    bw.Write(HexEncoding.GetBytes(archive.ToString()));

                    bw.Close();
                    fs.Close();
                }

                InstallData ins = new InstallData();

                i_Form.LblCmd.Text = "Alterando versão do software...";
                Application.DoEvents();
                Thread.Sleep(250);

                ins.st_version = st_new_version;

                ins.ins_registration();

                string ver_path = System.Environment.GetEnvironmentVariable("COMMONPROGRAMFILES") +
                                  "\\" +
                                  InfraSoftwareClient.nameClient + " " + app + "\\version.txt";

                if (File.Exists(ver_path))
                {
                    File.Delete(ver_path);
                }

                StreamWriter sw = new StreamWriter(ver_path);
                sw.WriteLine(st_new_version);
                sw.Close();

                File.Delete("app.txt");

                var_exchange.m_Client.ExitSession();

                Process p = new Process();

                                        #if LINUX_DIST
                p.StartInfo.FileName = "Linux" + app + ".exe";
                                    #else
                p.StartInfo.FileName = app + ".exe";
                                    #endif

                p.StartInfo.Arguments      = "";
                p.StartInfo.CreateNoWindow = false;
                p.Start();

                i_Form.Close();

                Application.ExitThread();

                //EndEventCode
                return(true);
            }

                #endregion

                #region - event_FormIsClosing -

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

                #endregion

                #region - robot_ShowDialog -

            case robot_ShowDialog:
            {
                //InitEventCode robot_ShowDialog

                if (i_Form.IsDisposed)
                {
                    i_Form = new MainForm(this);
                }

                i_Form.Show();

                //EndEventCode
                return(true);
            }

                #endregion

                #region - robot_CloseDialog -

            case robot_CloseDialog:
            {
                //InitEventCode robot_CloseDialog

                i_Form.Close();

                //EndEventCode
                return(true);
            }

                #endregion

            default: break;
            }

            return(false);
        }