Пример #1
0
        /*
         * -------------------------------------------------------------------------
         */

        /*
         * [ INICIO ] METODO PARA FECHAR A FORM TECLANDO "ESC" Escape
         */
        public void deletarComDEL(object sender, KeyEventArgs e)
        {
            fecharFormComEsc(sender, e);

            if ((e.KeyCode == Keys.Delete))
            {
                int idExclusao = int.Parse(listView_servicos.SelectedItems[0].SubItems[0].Text);
                if (idExclusao > 0)
                {
                    DialogResult dialogResult = MessageBox.Show("Deseja realmente excluir o item selecionado?", "Excluir item?", MessageBoxButtons.YesNo);
                    if (dialogResult == DialogResult.Yes)
                    {
                        ServicosController servicosController = new ServicosController();
                        servicosController.deletarServico(idExclusao, listView_servicos);
                    }
                    //else if (dialogResult == DialogResult.No)
                    //{
                    // faça algo...
                    //}
                }
            }
            else
            if ((e.KeyCode == Keys.Escape))
            {
                Close();
            }
        }
Пример #2
0
        static public void importarExcel(Servico servico, ServicosController servicosController, String folhaDoExcel)
        {
            OleDbConnection  conexao = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\prontovetdb_backup\\Pagos.xlsx;Extended Properties='Excel 12.0 Xml;HDR = YES';");
            OleDbDataAdapter adapter = new OleDbDataAdapter("select * from[" + folhaDoExcel + "$]", conexao);
            DataSet          ds      = new DataSet();

            try
            {
                conexao.Open();
                adapter.Fill(ds);
                foreach (DataRow linha in ds.Tables[0].Rows)
                {
                    String[] list = linha["PET - PROPRIETÁRIO"].ToString().Split('-');
                    try
                    {
                        if (linha["PET - PROPRIETÁRIO"].ToString() != "")
                        {
                            servico.Nome_pet          = list[0].ToString().ToUpper();
                            servico.Nome_proprietario = list[1].ToString().ToUpper();
                            servico.Valor             = linha["VALOR"].ToString().ToUpper();
                            servico.Forma_pagamento   = linha["FORMA DE PAGAMENTO"].ToString().ToUpper();
                            servico.Observacoes       = linha["OBSERVAÇÃO"].ToString().ToUpper();
                            servico.Data = linha["DATA"].ToString().ToUpper();
                            servico.Hora = DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString();
                            servicosController.SalvarServicoExcel(servico);
                        }
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("Erro (importarExcel - Util): " + e);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro (importarExcel catch - Util): " + ex);
            }
            finally
            {
                conexao.Close();
            }
        }