Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.39 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Text;
  6. using System.Windows.Forms;
  7. using System.Threading;
  8. using System.Runtime.Serialization.Formatters.Binary;
  9. using System.IO;
  10. using System.Web;
  11.  
  12.  
  13. namespace Cadastro_e_Informações_de_Clientes
  14. {
  15. public partial class Form1 : Form
  16. {
  17.  
  18.  
  19. public Form1()
  20. {
  21. InitializeComponent();
  22. }
  23.  
  24. private void bSalvar_Click(object sender, EventArgs e)
  25. {
  26. //Fiz um botão para pegar os dados escritos nas text boxes (tNome, tLocacao, tProduto etc...) e passar-los para o GridView
  27. //Como eu ainda não sei um método de salvar o texto diretamente da célula do GridView, eu fiz isso para salvar no momento do cadastro.
  28.  
  29. if (this.tNome.Text == String.Empty || this.tProduto.Text == String.Empty || this.tLocacao.Text == String.Empty || this.tVencimento.Text == String.Empty || this.tPago.Text == String.Empty || this.tDivida.Text == String.Empty || this.tAdicional.Text == String.Empty)
  30. {
  31.  
  32. string mensagem = "Um dos campos de texto não foi preenchido.nDeseja continuar?";
  33. string titulo = "Aviso!";
  34. MessageBoxButtons Botoes = MessageBoxButtons.OKCancel;
  35.  
  36. DialogResult resultado = MessageBox.Show(mensagem, titulo, Botoes, MessageBoxIcon.Warning);
  37.  
  38. if (resultado == DialogResult.OK)
  39. {
  40. this.Planilha.Rows.Add(tNome.Text, tProduto.Text, tLocacao.Text, tVencimento.Text, tPago.Text, tDivida.Text, tAdicional.Text);
  41. FileStream Dados = new FileStream("C:/Users/Win/Desktop/Empresa/Dados.txt", FileMode.Append);
  42.  
  43. BinaryWriter bw = new BinaryWriter(Dados);
  44. //grava uma string no arquivo
  45. bw.Write(tNome.Text + "t" + tProduto.Text + "t" + tLocacao.Text + "t" + tVencimento.Text + "t" + tPago.Text + "t" + tDivida.Text + "t" + tAdicional.Text + "n");
  46. bw.Close();
  47. }
  48. else
  49. {
  50. string mCancelada = "Operação cancelada.";
  51. string tCancelada = "Cancelado!";
  52. MessageBoxButtons cBotoes = MessageBoxButtons.OK;
  53. MessageBox.Show(mCancelada, tCancelada, cBotoes, MessageBoxIcon.Information);
  54.  
  55. }
  56. }
  57. else
  58. {
  59. this.Planilha.Rows.Add(tNome.Text, tProduto.Text, tLocacao.Text, tVencimento.Text, tPago.Text, tDivida.Text, tAdicional.Text);
  60.  
  61. FileStream Dados = new FileStream("C:/Users/Win/Desktop/Empresa/Dados.@hR", FileMode.Append);
  62.  
  63. BinaryWriter bw = new BinaryWriter(Dados);
  64. //grava uma string no arquivo
  65. bw.Write(tNome.Text + tProduto.Text + tLocacao.Text + tVencimento.Text + tPago.Text + tDivida.Text + tAdicional.Text);
  66. bw.Close();
  67.  
  68. }
  69. tAdicional.Clear();
  70. tNome.Clear();
  71. tProduto.Clear();
  72. tVencimento.Clear();
  73. tPago.Clear();
  74. tDivida.Clear();
  75. tLocacao.Clear();
  76.  
  77. }
  78.  
  79.  
  80. private void timerEditavel_Tick(object sender, EventArgs e)
  81. {
  82. // Esta é a opção de editar o GridView, porém, aqui está um de meus principais problemas.
  83. //Preciso ler o texto das células para que quando eu edite uma delas, eu possa ler as celulas e salvar no arquivo.txt.
  84. if (checkEditar.Checked)
  85. {
  86. cCliente.ReadOnly = false;
  87. cProduto.ReadOnly = false;
  88. cPago.ReadOnly = false;
  89. cAdic.ReadOnly = false;
  90. cVencimento.ReadOnly = false;
  91. cLocação.ReadOnly = false;
  92. cDivida.ReadOnly = false;
  93. timerEditavel.Stop();
  94.  
  95.  
  96.  
  97.  
  98.  
  99. }
  100. else
  101. {
  102. timerEditavel.Start();
  103. cCliente.ReadOnly = true;
  104. cProduto.ReadOnly = true;
  105. cPago.ReadOnly = true;
  106. cAdic.ReadOnly = true;
  107. cCliente.ReadOnly = true;
  108. cLocação.ReadOnly = true;
  109. cDivida.ReadOnly = true;
  110. //Isso abaixo foram as tentativas que fiz para ler as células. Más nenhuma delas lê realmente
  111. //o texto escrito nas células.
  112. tNome.Text = cCliente.ToString();
  113. tProduto.Text = cProduto.Index.ToString();
  114. tPago.Text = cPago.ToolTipText.ToString();
  115. tAdicional.Text = cPago.Index.ToString();
  116. tVencimento.Text = cVencimento.Index.ToString();
  117. tLocacao.Text = cLocação.Index.ToString();
  118. tDivida.Text = cDivida.Index.ToString();
  119.  
  120. }
  121. }
  122.  
  123. private void checkTimer_Tick(object sender, EventArgs e)
  124. {
  125. if (!checkEditar.Checked)
  126. {
  127. timerEditavel.Start();
  128. }
  129. }
  130.  
  131. private void button1_Click(object sender, EventArgs e)
  132. {
  133. //Adiciona uma linha vazia ao GridView
  134.  
  135. this.Planilha.Rows.Add("", "", "", "", "", "", "");
  136. }
  137.  
  138. private void lTimer_Tick(object sender, EventArgs e)
  139. {
  140. lInfo.Text = "Preencha os campos mostrados acima com as informações do Cliente e clique no botão para salvar na planilha.nOs dados serão mostrados na planilha da aba 'Cadastros' e serão salvos no arquivo 'dados.bin' na pasta do programa.nNo caso de algum erro ou problema durante a utilização deste programa, por favor, clique na aba 'Ajuda' e digite o erro acontecido.nAtualizações com mais optimizações e aperfeissoamentos do código poderão vir.nObrigado!";
  141. }
  142.  
  143.  
  144.  
  145.  
  146. }
  147.  
  148.  
  149.  
  150.  
  151.  
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement