-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm2.cs
137 lines (126 loc) · 4.26 KB
/
Form2.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Project
{
public partial class IniPedido : Form
{
private Task<CEP> task;
public IniPedido()
{
InitializeComponent();
this.ControlBox = false;
this.Text = null;
this.KeyPreview = true;
}
private void Form2_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
e.Handled = true;
if (Telefone.MaskCompleted == true)
{
Pesquisar_Click(sender, e);
}
}
}
private void Form2_Load(object sender, EventArgs e)
{
pesquisar.Text = null;
avançar.Enabled = false;
avançar.Visible = false;
Alterar.Text = "alterar";
Alterar.Enabled = false;
Alterar.Visible = false;
voltar.Text = "Cancelar";
TextoCliente.Enabled= false;
}
private void Procurar_Click(object sender, EventArgs e)
{
if (avançar.Text == "Continuar")
{
//abrir forms de pedidos
Pedido w = new Pedido();
w.Show();
}
else
{
//abrir forms cadastro
Cadastro w = new Cadastro(this.Telefone.Text.Replace("(", "").Replace(")", "").Replace(" ", "").Replace("-",""));
w.Show();
}
}
private void Voltar_Click(object sender, EventArgs e)
{
this.Close();
}
private void Pesquisar_Click(object sender, EventArgs e)
{
try
{
task.Dispose();
}
catch (Exception)
{
}
Atual.Reset();
string Tell = Telefone.Text.Replace("(", "").Replace(")", "").Replace("-", "").Trim().Replace(" ", "");
Atual.User = DataBase.Collection.FindCellphone(Tell);
if (Atual.User != new Cliente() && Atual.User != null)
{
task = Task<CEP>.Run(async () => { return await CEP.SetEndereço(Atual.User.Endereço.GetCep()); });
this.avançar.Text = "Continuar";
Local(task);
// Alterar.Enabled = true;
// Alterar.Visible = true;
avançar.Enabled = true;
avançar.Visible = true;
}
else
{
avançar.Text = "Cadastrar";
// Alterar.Enabled = false;
// Alterar.Visible = false;
avançar.Enabled = true;
avançar.Visible = true;
TextoCliente.Text = null;
}
}
public async Task Local(Task<CEP> task)
{
TextoCliente.Lines = new string[]
{
$"Nome: {Atual.User.Name}",
$"Endereço: Procurando Endereço, {Atual.User.Numero}",
$"Complemento: {Atual.User.Complemento}"
};
await (Internet.Connection == false ? Quebra(task) : task);
TextoCliente.Lines = new string[]
{
$"Nome: {Atual.User.Name}",
$"Endereço: {(Internet.Connection == false ? ("Sem Conexão à internet") : task.Result.Logradouro + ", " + Atual.User.Numero)}",
$"Complemento: {Atual.User.Complemento}"
};
Atual.User.Endereço = task.Result;
}
public Task<CEP> Quebra(Task<CEP> task)
{
task.Dispose();
var altTask = Task<CEP>.Run(() => new CEP
{
Logradouro = null
});
return altTask;
}
private void Telefone_Click(object sender, EventArgs e)
{
//(11) 99405-3799
//11994053799
string text = Telefone.Text.Replace("(", "").Replace(")", "").Replace(" ", "").Replace("-", "");
Telefone.SelectionStart = (text.Length > 2 ? (text.Length > 7 ? text.Length + 4 : text.Length + 3) : text.Length + 1);
}
}
}