namespace ColaCircular_Vis
{
public partial class Form1 : Form
{
int tam = 0;
Cola_Circular<int> cola;
Cola_Circular<string> c2;
Cola_Circular<char> c3;
Cola_Circular<double> c4;
Cola_Circular<double> c5;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
tam = Convert.ToInt32(textBox1.Text);
dgv1.RowCount = 1;
dgv1.ColumnCount = tam;
//textBox1.Enabled = false;
//button1.Enabled = false;
comboBox1.Enabled = true;
}
catch
{
MessageBox.Show("Ingrese puros números, intente de nuevo");
textBox1.Text = " ";
textBox1.Focus();
}
}
private void button2_Click(object sender, EventArgs e)
{
int op = 0;
if (comboBox1.Text == "Int")
{
op = 1;
}
if (comboBox1.Text == "String")
{
op = 2;
}
if (comboBox1.Text == "Char")
{
op = 3;
}
if (comboBox1.Text == "Double")
{
op = 4;
}
if (comboBox1.Text == "Float")
{
op = 5;
}
switch (op)
{
case 1:
cola = new Cola_Circular<int>(tam);
button2.Enabled = false;
comboBox1.Enabled = false;
break;
case 2:
c2 = new Cola_Circular<string>(tam, " ");
button2.Enabled = false;
comboBox1.Enabled = false;
break;
case 3:
c3 = new Cola_Circular<char>(tam, ' ');
button2.Enabled = false;
comboBox1.Enabled = false;
break;
case 4:
c4 = new Cola_Circular<double>(tam);
button2.Enabled = false;
comboBox1.Enabled = false;
break;
case 5:
c5 = new Cola_Circular<double>(tam);
button2.Enabled = false;
comboBox1.Enabled = false;
break;
default:
MessageBox.Show("Solo las opciones mostradas estan disponibles");
comboBox1.Text = "";
break;
}
}
private void button3_Click(object sender, EventArgs e)
{
int op = 0;
if (comboBox1.Text == "Int")
{
op = 1;
}
if (comboBox1.Text == "String")
{
op = 2;
}
if (comboBox1.Text == "Char")
{
op = 3;
}
if (comboBox1.Text == "Double")
{
op = 4;
}
if (comboBox1.Text == "Float")
{
op = 5;
}
switch (op)
{
case 1:
try
{
int num = Convert.ToInt32(textBox2.Text);
if (!cola.insertar(num, dgv1))
{
MessageBox.Show("Insuficiencia de memoria");
button3.Enabled = false;
}
//button4.Enabled = true;
textBox2.Focus();
textBox2.Text = " ";
}
catch
{
MessageBox.Show("Solo numeros, por favor");
textBox2.Focus();
textBox2.Text = "";
}
break;
case 2:
try
{
string cad = Convert.ToString(textBox2.Text);
if (!c2.insertar(cad, dgv1))
{
MessageBox.Show("Insuficiencia de memoria");
button3.Enabled = false;
//button4.Enabled = true;
}
//button4.Enabled = true;
textBox2.Focus();
textBox2.Text = "";
}
catch
{
MessageBox.Show("Solo cadena de caracteres");
textBox2.Text = " ";
textBox2.Focus();
}
break;
case 3:
{
try
{
char a = Convert.ToChar(textBox2.Text);
if (!c3.insertar(a, dgv1))
{
MessageBox.Show("Insuficiencia de memoria");
button3.Enabled = false;
//button4.Enabled = true;
}
//button4.Enabled = true;
textBox2.Focus();
textBox2.Text = "";
}
catch
{
MessageBox.Show("Solo caracteres (una sola letra 'a','b'....)");
textBox2.Text = "";
textBox2.Focus();
}
}
break;
case 4:
{
try
{
double n = Convert.ToDouble(textBox2.Text);
if (!c4.insertar(n, dgv1))
{
MessageBox.Show("Insuficiencia de memoria");
button3.Enabled = false;
//button4.Enabled = true;
}
//button4.Enabled = true;
textBox2.Focus();
textBox2.Text = "";
}
catch
{
MessageBox.Show("Solo numeros");
textBox2.Focus();
textBox2.Text = "";
}
}
break;
case 5:
{
try
{
double m = Convert.ToDouble(textBox2.Text);
if (!c5.insertar(m, dgv1))
{
MessageBox.Show("Insuficiencia de memoria");
button3.Enabled = false;
//button4.Enabled = true;
}
}
catch
{
MessageBox.Show("Solo numeros");
textBox2.Focus();
textBox2.Text = "";
}
break;
}
}
}
private void button5_Click(object sender, EventArgs e)
{
int op = 0;
if (comboBox1.Text == "Int")
{
op = 1;
}
if (comboBox1.Text == "String")
{
op = 2;
}
if (comboBox1.Text == "Char")
{
op = 3;
}
if (comboBox1.Text == "Double")
{
op = 4;
}
if (comboBox1.Text == "Float")
{
op = 5;
}
switch (op)
{
case 1:
int num = 1;
if (!cola.eliminar(ref num, 0, dgv1))
{
MessageBox.Show("Ya no hay datos a eliminar, inserte nuevos datos");
button3.Enabled = true;
//button5.Enabled = false;
}
textBox3.Text = num.ToString();
button3.Enabled = true;
break;
case 2:
string cad = " ";
if (!c2.eliminar(ref cad, "0", dgv1))
{
MessageBox.Show("Ya no hay datos a eliminar, inserte nuevos datos");
button3.Enabled = true;
//button5.Enabled = false;
}
textBox3.Text = cad.ToString();
button3.Enabled = true;
break;
case 3:
char c=' ';
if(!c3.eliminar(ref c, '0',dgv1))
{
MessageBox.Show("Ya no hay datos a eliminar, inserte nuevos datos");
button3.Enabled = true;
//button5.Enabled = false;
}
textBox3.Text = c.ToString();
button3.Enabled = true;
break;
case 4:
double dato = 2;
if(!c4.eliminar(ref dato, 0, dgv1))
{
MessageBox.Show("Ya no hay datos a eliminar, inserte nuevos datos");
button3.Enabled = true;
//button5.Enabled = false;
}
textBox3.Text = dato.ToString();
button3.Enabled = true;
break;
case 5:
double dato2 = 2;
if(!c5.eliminar(ref dato2, 0, dgv1))
{
MessageBox.Show("Ya no hay datos a eliminar, inserte nuevos datos");
button3.Enabled = true;
//button5.Enabled = false;
}
textBox3.Text = dato2.ToString();
button3.Enabled = true;
break;
}
}
private void button4_Click(object sender, EventArgs e)
{
textBox1.Text = "ESCRIBA EL NUMERO..";
textBox2.Text = "";
textBox3.Text = "";
comboBox1.Text = "";
for (int i = 0; i < dgv1.ColumnCount; i++)
{
dgv1[i, 0].Value = " ";
}
button5.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
textBox1.Enabled = true;
}
private void button6_Click(object sender, EventArgs e)
{
Close();
}
}
}