コード例 #1
0
        private void tsbtnImportar_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Multiselect      = false;
                ofd.Title            = "Importar Xlsx";
                ofd.InitialDirectory = @"C:\";
                //odo.Filter = "Excel (*.xlsx)|*.xlsx|" + "All files (*.*)|*.*";
                ofd.Filter           = "Excel (*.xls)|*.xls";
                ofd.CheckFileExists  = true;
                ofd.CheckPathExists  = true;
                ofd.FilterIndex      = 2;
                ofd.RestoreDirectory = true;
                ofd.ReadOnlyChecked  = true;
                ofd.ShowReadOnly     = true;
                ofd.Title            = "Selecione o Arquivo";

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    this.Cursor = Cursors.AppStarting;
                    cFundo cf = new cFundo();
                    using (DataSet ds = cf.retorna_planilha_fundos(ofd.FileName))
                    {
                        tsprbProgress.Visible = true;
                        tsprbProgress.Value   = 0;
                        tsprbProgress.Maximum = ds.Tables[0].Rows.Count;
                        int count = 1;

                        foreach (DataRow item in ds.Tables[0].Rows)
                        {
                            cf.razao_social = item[1].ToString();
                            cf.SiglaSAC     = item[0].ToString();
                            cf.SiglaFY      = item[3].ToString();
                            cf.CnpjCpf      = item[2].ToString();
                            if (!cf.verifica_fundo_existe(cf))
                            {
                                cf.grava_fundo(cf);
                            }
                            else
                            {
                                cf.id_Fundo = cf.retorna_id_fundo(cf);
                                cf.atualiza_cadastro_fundo(cf);
                            }
                            count++;
                            tsprbProgress.Value++;
                        }
                    }
                    inicio();
                    tsprbProgress.Visible = false;
                    this.Cursor           = Cursors.Arrow;
                }
            }
            catch (Exception ex)
            {
                this.Cursor = Cursors.Arrow;
                #region LOG ERRO
                cLog lg = new cLog();
                lg.log         = ex.Message.Replace("'", "");
                lg.form        = this.Text;
                lg.metodo      = sender.ToString();
                lg.dt          = DateTime.Now;
                lg.usersistema = cGlobal.userlogado;
                lg.userRede    = Environment.UserName;
                lg.terminal    = Environment.MachineName;
                lg.tp_flag     = false;
                lg.grava_log(lg);
                #endregion
            }
        }
コード例 #2
0
        private void tsbtnSalvar_Click(object sender, EventArgs e)
        {
            try
            {
                cFundo cfun = new cFundo();

                #region VALIDAÇÃO
                if (string.IsNullOrEmpty(txtFundo.Text))
                {
                    tsslblMsg.Text = "Nome do setor não informado";
                    txtFundo.Focus();
                    return;
                }
                #endregion

                if (!cGlobal.editando)
                {
                    cfun.codfundo = txtID.Text;
                    cfun.fundo    = txtFundo.Text.ToUpper();
                    cfun.grava_fundo(cfun);
                    MessageBox.Show("Fundo registrado com sucesso.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    #region LOG
                    cLog lg = new cLog();
                    lg.log = string.Concat("Cadastro de Registro.", Environment.NewLine,
                                           "Setor: ", txtFundo.Text.ToUpper()
                                           );
                    lg.form        = this.Text;
                    lg.metodo      = sender.ToString();
                    lg.dt          = DateTime.Now;
                    lg.usersistema = cGlobal.userlogado;
                    lg.userRede    = Environment.UserName;
                    lg.terminal    = Environment.MachineName;
                    lg.tp_flag     = true;
                    lg.grava_log(lg);
                    #endregion
                }
                else
                {
                    cfun.codfundo = txtID.Text;
                    cfun.fundo    = txtFundo.Text.ToUpper();
                    cfun.atualiza_fundo(cfun);
                    MessageBox.Show("O Fundo foi alterado com sucesso.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    #region LOG
                    cLog lg = new cLog();
                    lg.log = string.Concat("Alteração de Registro.", Environment.NewLine,
                                           "Fundo: ", txtFundo.Text.ToUpper()
                                           );
                    lg.form        = this.Text;
                    lg.metodo      = sender.ToString();
                    lg.dt          = DateTime.Now;
                    lg.usersistema = cGlobal.userlogado;
                    lg.userRede    = Environment.UserName;
                    lg.terminal    = Environment.MachineName;
                    lg.tp_flag     = true;
                    lg.grava_log(lg);
                    #endregion
                }

                inicio();
            }
            catch (Exception ex)
            {
                #region LOG ERRO
                cLog lg = new cLog();
                lg.log         = ex.Message.Replace("'", "");
                lg.form        = this.Text;
                lg.metodo      = sender.ToString();
                lg.dt          = DateTime.Now;
                lg.usersistema = cGlobal.userlogado;
                lg.userRede    = Environment.UserName;
                lg.terminal    = Environment.MachineName;
                lg.tp_flag     = false;
                lg.grava_log(lg);
                #endregion
            }
        }
コード例 #3
0
        private void tsbtnSalvar_Click(object sender, EventArgs e)
        {
            try
            {
                #region VALIDACAO
                if (string.IsNullOrEmpty(txtRazaoSocial.Text))
                {
                    tsslblMsg.Text = "Razão Social não informada";
                    txtRazaoSocial.Focus();
                    return;
                }
                #endregion

                cFundo fd = new cFundo();
                fd.razao_social = txtRazaoSocial.Text.ToUpper();
                fd.SiglaSAC     = txtSiglaSac.Text.ToUpper();
                fd.SiglaFY      = txtSiglaFy.Text.ToUpper();
                fd.CnpjCpf      = mktCnpjCpf.Text.Replace(".", "").Replace(",", "").Replace("-", "").Replace("/", "");

                if (!cGlobal.editando)
                {
                    fd.grava_fundo(fd);
                    MessageBox.Show("Fundo cadastrado com sucesso.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    #region LOG
                    cLog lg = new cLog();
                    lg.log = string.Concat("Cadastro de Registro.", Environment.NewLine,
                                           "Razão Social(Fundo): ", txtRazaoSocial.Text.ToUpper(), Environment.NewLine,
                                           "Sigla SAC: ", txtSiglaSac.Text.ToUpper(), Environment.NewLine,
                                           "Sigla FY: ", txtSiglaFy.Text.ToUpper(), Environment.NewLine,
                                           "CNPJ/CPF: ", mktCnpjCpf.Text.Replace(".", "").Replace(",", "").Replace("-", "").Replace("/", "")
                                           );
                    lg.form        = this.Text;
                    lg.metodo      = sender.ToString();
                    lg.dt          = DateTime.Now;
                    lg.usersistema = cGlobal.userlogado;
                    lg.userRede    = Environment.UserName;
                    lg.terminal    = Environment.MachineName;
                    lg.tp_flag     = true;
                    lg.grava_log(lg);
                    #endregion
                }
                else
                {
                    fd.id_Fundo = fd.retorna_id_fundo(fd);
                    fd.atualiza_cadastro_fundo(fd);
                    MessageBox.Show("Fundo alterado com sucesso.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    #region LOG
                    cLog lg = new cLog();
                    lg.log = string.Concat("Alteração de Registro.", Environment.NewLine,
                                           "Razão Social(Fundo): ", txtRazaoSocial.Text.ToUpper(), Environment.NewLine,
                                           "Sigla SAC: ", txtSiglaSac.Text.ToUpper(), Environment.NewLine,
                                           "Sigla FY: ", txtSiglaFy.Text.ToUpper(), Environment.NewLine,
                                           "CNPJ/CPF: ", mktCnpjCpf.Text.Replace(".", "").Replace(",", "").Replace("-", "").Replace("/", "")
                                           );
                    lg.form        = this.Text;
                    lg.metodo      = sender.ToString();
                    lg.dt          = DateTime.Now;
                    lg.usersistema = cGlobal.userlogado;
                    lg.userRede    = Environment.UserName;
                    lg.terminal    = Environment.MachineName;
                    lg.tp_flag     = true;
                    lg.grava_log(lg);
                    #endregion
                }

                inicio();
            }
            catch (Exception ex)
            {
                tsslblMsg.Text = "Erro ao cadastrar o fundo. Para mais detalhes, consulte o Log.";
                #region LOG ERRO
                cLog lg = new cLog();
                lg.log         = ex.Message.Replace("'", "");
                lg.form        = this.Text;
                lg.metodo      = sender.ToString();
                lg.dt          = DateTime.Now;
                lg.usersistema = cGlobal.userlogado;
                lg.userRede    = Environment.UserName;
                lg.terminal    = Environment.MachineName;
                lg.tp_flag     = false;
                lg.grava_log(lg);
                #endregion
            }
        }