Guest User

Untitled

a guest
Oct 20th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.28 KB | None | 0 0
  1. public class Conteudo
  2. {
  3. public long Id { get; set; }
  4. public string Categoria { get; set; }
  5. public string SubCategoria { get; set; }
  6. public string Descricao { get; set; }
  7.  
  8. public string Status { get; set; }
  9. public string Obs { get; set; }
  10. public string Evidencias { get; set; }
  11. public string NSerie { get; set; }
  12.  
  13. [ForeignKey("UsuarioAbertura")]
  14. public long? UsuarioAberturaId { get; set; }
  15. public virtual Usuario UsuarioAbertura { get; set; }
  16.  
  17. [ForeignKey("UsuarioFechamento")]
  18. public long? UsuarioFechamentoId { get; set; }
  19. public virtual Usuario UsuarioFechamento { get; set; }
  20.  
  21. public DateTime? DataHoraAbertura { get; set; }
  22. public DateTime? DataHoraFechamento { get; set; }
  23.  
  24.  
  25. public long ManifestacaoId { get; set; }
  26. [ForeignKey("ManifestacaoId")]
  27. public virtual Manifestacao Manifestacao { get; set; }
  28. }
  29.  
  30. System.ObjectDisposedException: 'The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.'
  31.  
  32. public class Usuario
  33. {
  34. public long Id { get; set; }
  35. public string Apelido { get; set; }
  36. public string Nome { get; set; }
  37. public string Categoria { get; set; }
  38. public string Senha { get; set; }
  39. public string Status { get; set; }
  40.  
  41. public virtual ICollection<Conteudo> ConteudosAbertura { get; set; }
  42.  
  43. public virtual ICollection<Conteudo> ConteudosFechamento { get; set; }
  44. }
  45.  
  46. public class EFContext : DbContext
  47. {
  48. public EFContext() : base("Pos_Venda_SAC")
  49. {
  50. //this.Configuration.LazyLoadingEnabled = false;
  51. Database.SetInitializer<EFContext>(
  52. new DropCreateDatabaseIfModelChanges<EFContext>()
  53. );
  54. }
  55. public DbSet<Cliente> Clientes { get; set; }
  56. public DbSet<Conteudo> Conteudos { get; set; }
  57. public DbSet<Manifestacao> Manifestacoes { get; set; }
  58. public DbSet<Usuario> Usuarios { get; set; }
  59. public DbSet<Destinatario> Destinatarios { get; set; }
  60.  
  61. protected override void OnModelCreating(DbModelBuilder modelBuilder)
  62. {
  63. base.OnModelCreating(modelBuilder);
  64.  
  65. modelBuilder.Entity<Usuario>()
  66. .HasMany<Conteudo>(c => c.ConteudosAbertura)
  67. .WithOptional(c => c.UsuarioAbertura)
  68. .WillCascadeOnDelete(false);
  69.  
  70. modelBuilder.Entity<Usuario>()
  71. .HasMany<Conteudo>(c => c.ConteudosFechamento)
  72. .WithOptional(c => c.UsuarioFechamento)
  73. .WillCascadeOnDelete(false);
  74.  
  75. }
  76. }
  77.  
  78. using System;
  79.  
  80. private bool textoEmailAlterado;
  81. private bool textoTelefoneAlterado;
  82. private bool textoRamalAlterado;
  83. private bool textoCelularAlterado;
  84. private bool textoContatoAlterado;
  85.  
  86. public FrmDetalhesConteudo(long idRow)
  87. {
  88. InitializeComponent();
  89. nomeUsuario = UsuarioLogado.Nome;
  90. conteudoAtual = dalConteudos.GetConteudoByID(idRow);
  91. PreencheCampos(conteudoAtual);
  92. DesabilitarEdicaoCampos();
  93. VerificarStatusFinalizado();
  94. textoEmailAlterado = false;
  95. textoTelefoneAlterado = false;
  96. textoRamalAlterado = false;
  97. textoCelularAlterado = false;
  98. textoContatoAlterado = false;
  99. }
  100.  
  101. private void PreencheCampos(Conteudo conteudo)
  102. {
  103. txtEmpresaCliente.Text = conteudo.Manifestacao.Cliente.Empresa;
  104. txtContatoCliente.Text = conteudo.Manifestacao.Cliente.Contato;
  105. txtEmailCliente.Text = conteudo.Manifestacao.Cliente.Email;
  106. mskTelefoneCliente.Text = conteudo.Manifestacao.Cliente.Telefone;
  107. txtRamalCliente.Text = conteudo.Manifestacao.Cliente.Ramal;
  108. mskCelularCliente.Text = conteudo.Manifestacao.Cliente.Celular;
  109. txtCategoria.Text = conteudo.Categoria;
  110. txtSubCategoria.Text = conteudo.SubCategoria;
  111. txtConteudo.Text = conteudo.Descricao;
  112. txtStatus.Text = conteudo.Status;
  113. txtObs.Text = conteudo.Obs;
  114. txtEvidencias.Text = conteudo.Evidencias;
  115. lblTimeAbertura.Text = conteudo.DataHoraAbertura.ToString();
  116. lblTimeFechamento.Text = conteudo.DataHoraFechamento.ToString();
  117. lblUsuAbertura.Text = conteudo.UsuarioAbertura.Nome.ToString();
  118. txtNChamado.Text = conteudo.Manifestacao.NumeroChamado;
  119. txtNSerie.Text = conteudo.NSerie;
  120. }
  121.  
  122. private void VerificarStatusFinalizado()
  123. {
  124. if (txtStatus.Text == "Finalizado")
  125. {
  126. if (!UsuarioLogado.IsEng())
  127. {
  128. cboNovoStatus.Enabled = false;
  129. cboNovoStatus.Text = "Status finalizado não pode ser alterado";
  130. }
  131. lblTimeFechamento.Visible = true;
  132. lblTitFechamento.Visible = true;
  133. lblTitIntervalo.Visible = true;
  134. lblDiasIntervalo.Visible = true;
  135. lblTitUsuFechamento.Visible = true;
  136. lblUsuFechamento.Text = conteudoAtual.UsuarioFechamento.Nome;
  137. lblUsuFechamento.Visible = true;
  138. CalculaIntervalo();
  139. }
  140. }
  141.  
  142. private void DesabilitarEdicaoCampos()
  143. {
  144. foreach (Control ctrl in gbxConteudo.Controls)
  145. {
  146. if (ctrl is TextBox)
  147. {
  148. ((TextBox)ctrl).ReadOnly = true;
  149. }
  150. }
  151.  
  152. txtNSerie.ReadOnly = false;
  153. txtEmpresaCliente.ReadOnly = true;
  154. txtStatus.ReadOnly = true;
  155. }
  156.  
  157. private void cmdSalvar_Click(object sender, EventArgs e)
  158. {
  159. //VerificaAlteracaoDadosContato();
  160. VerificaAlteracaoStatus();
  161. System.Threading.Thread.Sleep(200);
  162. this.Close();
  163. }
  164.  
  165. private void VerificaAlteracaoStatus()
  166. {
  167. if (cboNovoStatus.Text == "Finalizado")
  168. {
  169. DialogResult dialogResult = MessageBox.Show("Confirma a alteração do status para 'Finalizado'? Após finalizado um registro não pode mais ser alterado.", "Importante!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
  170. if (dialogResult == DialogResult.Yes)
  171. {
  172. UpdateConteudo();
  173. System.Threading.Thread.Sleep(200);
  174. VerificarStatusFinalizado();
  175. NotificaTermino();
  176. MessageBox.Show("Registro atualizado com sucesso.");
  177. }
  178. else
  179. {
  180. return;
  181. }
  182. }
  183. else
  184. {
  185. UpdateConteudo();
  186. }
  187. }
  188.  
  189. private void UpdateConteudo()
  190. {
  191. using (var context = new EFContext())
  192. {
  193. var newConteudo = context.Conteudos.Find(conteudoAtual.Id);
  194. if (cboNovoStatus.Text == "Finalizado")
  195. {
  196. newConteudo.DataHoraFechamento = PegaDataHoraUsuario.DataHoraPadrao();
  197. newConteudo.UsuarioFechamentoId = UsuarioLogado.Id;
  198. }
  199. if (cboNovoStatus.SelectedIndex > -1)
  200. {
  201. newConteudo.Status = cboNovoStatus.Text;
  202. }
  203. newConteudo.Obs = txtObs.Text;
  204. newConteudo.Evidencias = txtEvidencias.Text;
  205. newConteudo.NSerie = txtNSerie.Text;
  206. context.SaveChanges();
  207. }
  208. }
  209.  
  210. private void UpdateDadosContato()
  211. {
  212. using (var context = new EFContext())
  213. {
  214. var newContato = context.Clientes.Find(conteudoAtual.Manifestacao.Cliente.Id);
  215. newContato.Email = txtEmailCliente.Text;
  216. newContato.Celular = mskCelularCliente.Text;
  217. newContato.Ramal = txtRamalCliente.Text;
  218. newContato.Telefone = mskTelefoneCliente.Text;
  219. newContato.Contato = txtContatoCliente.Text;
  220. context.SaveChanges();
  221. }
  222. }
  223.  
  224. private void NotificaTermino()
  225. {
  226. string procedimento = "fechamento";
  227. string dataHora = PegaDataHoraUsuario.DataHoraInvertida();
  228.  
  229. string corpoEmailString = "<p><strong><font size='4'>Manifestação Finalizada</font></p>";
  230. corpoEmailString += "<p>Chamado: " + txtNChamado.Text + "</p>";
  231. corpoEmailString += "<p><strong><font size='3'>Empresa: " + txtEmpresaCliente.Text + "</font></p>";
  232. corpoEmailString += "<p><font size='2'> Conteúdo " + ": </font> </p>";
  233. corpoEmailString += "<p>Categoria: " + txtCategoria.Text + "</p>";
  234. corpoEmailString += "<p>Subcategoria: " + txtSubCategoria.Text + "</p>";
  235. corpoEmailString += "<p>Conteúdo: " + txtConteudo.Text + "</p>";
  236. corpoEmailString += "<br/>";
  237. corpoEmailString += "<p>Contato: " + txtContatoCliente.Text + "</p>";
  238. corpoEmailString += "<p>e-mail: " + txtEmailCliente.Text + "</p>";
  239. corpoEmailString += "<p>Telefone: " + mskTelefoneCliente.Text + "</p>";
  240. corpoEmailString += "<p>Ramal: " + txtRamalCliente.Text + "</p>";
  241. corpoEmailString += "<p>Celular: " + mskCelularCliente.Text + "</p>";
  242. corpoEmailString += "<p>Conteúdo encerrado por: " + nomeUsuario + "</p>";
  243. corpoEmailString += "<p>Data e hora do encerramento: " + lblTimeFechamento.Text + "</p>";
  244. corpoEmailString += "<p>Aberto em: " + lblTimeAbertura.Text + " por: " + lblUsuAbertura.Text + "</p>";
  245. corpoEmailString += "<p>Tempo decorrido até o fechamento: " + lblDiasIntervalo.Text + "</p>";
  246.  
  247. List<string> vazio = new List<string>() { "", "" };
  248.  
  249. string resultado = SendMail.EnviaMensagemEmail(StringsProjeto.remetente, "Manifestação Finalizada", corpoEmailString, procedimento, vazio);
  250. }
  251.  
  252. private void CalculaIntervalo()
  253. {
  254. DateTime fechamento = Convert.ToDateTime(lblTimeFechamento.Text.ToString());
  255. DateTime abertura = Convert.ToDateTime(lblTimeAbertura.Text.ToString());
  256. TimeSpan ts1 = fechamento.Subtract(abertura);
  257. string intervaloDias = ts1.ToString("dd");
  258. string intervaloHoras = ts1.ToString("hh");
  259. lblDiasIntervalo.Text = intervaloDias + " dias e " + intervaloHoras + " horas ";
  260.  
  261. }
  262.  
  263. private void txtEmailCliente_TextChanged(object sender, EventArgs e)
  264. {
  265. textoEmailAlterado = true;
  266. }
  267.  
  268. private void mskTelefoneCliente_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
  269. {
  270. textoTelefoneAlterado = true;
  271. }
  272.  
  273. private void txtRamalCliente_TextChanged(object sender, EventArgs e)
  274. {
  275. textoRamalAlterado = true;
  276. }
  277.  
  278. private void mskCelularCliente_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
  279. {
  280. textoCelularAlterado = true;
  281. }
  282.  
  283. private void txtContatoCliente_TextChanged(object sender, EventArgs e)
  284. {
  285. textoContatoAlterado = true;
  286. }
  287. }
Add Comment
Please, Sign In to add comment