private void btnCancelar_Click(object sender, EventArgs e)
 {
     if (ClaseCompartida.tipoCliente == 0)
     {
         if (tipoA == 0)
         {
             CargaDatos();
             DeshabilitaBTN();
             Blanco();
             GBdatos.Enabled = false;
             tipoA           = 2;
         }
         else if (tipoA == 1)
         {
             CargaDatos();
             DeshabilitaBTN();
             Blanco();
             GBdatos.Enabled = false;
             tipoA           = 2;
         }
         else
         {
             Pantalla_Menu form = new Pantalla_Menu();
             form.Show();
             this.Close();
         }
     }
     else
     {
         Pantalla_ClienteVenta form = new Pantalla_ClienteVenta();
         form.Show();
         this.Close();
     }
 }
        private void btnCancelar_Click(object sender, EventArgs e)
        {
            Pantalla_ClienteVenta formMenu = new Pantalla_ClienteVenta();

            formMenu.Show();
            this.Close();
        }
 private void btnProceder_Click(object sender, EventArgs e)
 {
     ClaseCompartida.nombreProducto = CBprod.Text;
     ClaseCompartida.cantidadVenta  = txtCant.Text;
     if (Convert.ToInt32(txtCarrito.Text) <= 0)
     {
         MessageBox.Show("No agrego algun producto a su carrito");
     }
     else
     {
         ClaseCompartida.carrito = Convert.ToInt32(txtCarrito.Text);
         Pantalla_ClienteVenta formMenu = new Pantalla_ClienteVenta();
         formMenu.Show();
         this.Close();
     }
 }
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            int m = 0;

            if (ClaseCompartida.tipoCliente == 0)
            {
                if (tipoA == 0)
                {
                    if (txtCodigo.Text != "" && txtNombre.Text != "" && txtPaterno.Text != "" &&
                        txtCi.Text != "" && txtDireccion.Text != "" && txtTelefono.Text != "")
                    {
                        Cliente cli1 = new Cliente();
                        using (ProyectoFarmaciaEntities1 DB = new ProyectoFarmaciaEntities1())
                        {
                            var max = (from d in DB.Cliente
                                       select d.Codigo_Cliente).Max();
                            int maxi = Convert.ToInt32(max);

                            for (int n = 1; n <= maxi; n++)
                            {
                                cli1 = DB.Cliente.Find(n);

                                if (txtCi.Text == Convert.ToString(cli1.NIT_CI))
                                {
                                    //MessageBox.Show("Existe ya uno");
                                    m = 1;
                                    n = maxi + 1;
                                }
                                else
                                {
                                    //MessageBox.Show("Es Nuevo");
                                    m = 0;
                                }
                            }

                            if (m == 0)
                            {
                                Cliente emp = new Cliente();
                                emp.Codigo_Cliente = Convert.ToInt32(txtCodigo.Text);
                                emp.Nombre         = txtNombre.Text;
                                emp.Paterno        = txtPaterno.Text;
                                emp.NIT_CI         = Convert.ToInt32(txtCi.Text);
                                emp.Direccion      = txtDireccion.Text;
                                emp.Telefono       = Convert.ToInt32(txtTelefono.Text);
                                DB.Cliente.Add(emp);
                                DB.SaveChanges();
                                //DB.Entry(emp).State = System.Data.Entity.EntityState.Modified;
                                //DB.SaveChanges();

                                MessageBox.Show("Registro Realizado!!!");
                                Cliente emp1 = new Cliente();

                                CargaDatos();
                                DeshabilitaBTN();
                                GBdatos.Enabled = false;

                                DialogResult Respuesta;
                                Respuesta = MessageBox.Show("Desea crear un Usuario para la plataforma online?", "Usuario Online", MessageBoxButtons.YesNo);
                                if (Respuesta == DialogResult.Yes)
                                {
                                    ClaseCompartida.tipoUser  = 5;
                                    ClaseCompartida.formaUser = 1;
                                    Pantalla_Usuarios formProd = new Pantalla_Usuarios();
                                    formProd.Show();
                                    this.Close();
                                }
                                //emp1.Show();
                            }
                            else
                            {
                                MessageBox.Show("El carnet introducido ya fue registrado");
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Faltan datos!!!");
                    }
                }
                else
                {
                    if (txtCodigo.Text != "" && txtNombre.Text != "" && txtPaterno.Text != "" &&
                        txtCi.Text != "" && txtDireccion.Text != "" && txtTelefono.Text != "")
                    {
                        Cliente cli1 = new Cliente();
                        using (ProyectoFarmaciaEntities1 DB = new ProyectoFarmaciaEntities1())
                        {
                            /*
                             * var max = (from d in DB.Cliente
                             *         select d.Codigo_Cliente).Max();
                             * int maxi = Convert.ToInt32(max);
                             *
                             * for (int n = 1; n <= maxi; n++)
                             * {
                             *  cli1 = DB.Cliente.Find(n);
                             *
                             *  if (txtCi.Text == Convert.ToString(cli1.NIT_CI))
                             *  {
                             *      //MessageBox.Show("Existe ya uno");
                             *      m = 1;
                             *      n = maxi + 1;
                             *  }
                             *  else
                             *  {
                             *      //MessageBox.Show("Es Nuevo");
                             *      m = 0;
                             *  }
                             * }*/

                            Cliente emp = new Cliente();
                            emp.Codigo_Cliente  = Convert.ToInt32(txtCodigo.Text);
                            emp.Nombre          = txtNombre.Text;
                            emp.Paterno         = txtPaterno.Text;
                            emp.NIT_CI          = Convert.ToInt32(txtCi.Text);
                            emp.Direccion       = txtDireccion.Text;
                            emp.Telefono        = Convert.ToInt32(txtTelefono.Text);
                            DB.Entry(emp).State = System.Data.Entity.EntityState.Modified;
                            DB.SaveChanges();

                            MessageBox.Show("Registro Modificado!!!");
                            Cliente emp1 = new Cliente();

                            CargaDatos();
                            DeshabilitaBTN();
                            GBdatos.Enabled = false;
                            //emp1.Show();

                            /*
                             * if (m == 0)
                             * {
                             *
                             * }
                             * else
                             * {
                             *  MessageBox.Show("El carnet introducido ya fue registrado");
                             * }*/
                        }
                    }
                    else
                    {
                        MessageBox.Show("Faltan datos!!!");
                    }
                }
            }
            else
            {
                if (txtCodigo.Text != "" && txtNombre.Text != "" && txtPaterno.Text != "" &&
                    txtCi.Text != "" && txtDireccion.Text != "" && txtTelefono.Text != "")
                {
                    Cliente cli1 = new Cliente();
                    using (ProyectoFarmaciaEntities1 DB = new ProyectoFarmaciaEntities1())
                    {
                        var max = (from d in DB.Cliente
                                   select d.Codigo_Cliente).Max();
                        int maxi = Convert.ToInt32(max);

                        for (int n = 1; n <= maxi; n++)
                        {
                            cli1 = DB.Cliente.Find(n);

                            if (txtCi.Text == Convert.ToString(cli1.NIT_CI))
                            {
                                //MessageBox.Show("Existe ya uno");
                                m = 1;
                                n = maxi + 1;
                            }
                            else
                            {
                                //MessageBox.Show("Es Nuevo");
                                m = 0;
                            }
                        }

                        if (m == 0)
                        {
                            Cliente emp = new Cliente();
                            emp.Codigo_Cliente = Convert.ToInt32(txtCodigo.Text);
                            emp.Nombre         = txtNombre.Text;
                            emp.Paterno        = txtPaterno.Text;
                            emp.NIT_CI         = Convert.ToInt32(txtCi.Text);
                            emp.Direccion      = txtDireccion.Text;
                            emp.Telefono       = Convert.ToInt32(txtTelefono.Text);
                            DB.Cliente.Add(emp);
                            DB.SaveChanges();
                            //DB.Entry(emp).State = System.Data.Entity.EntityState.Modified;
                            //DB.SaveChanges();

                            MessageBox.Show("Registro Realizado!!!");

                            //emp1.Show();

                            Pantalla_ClienteVenta form = new Pantalla_ClienteVenta();
                            form.Show();
                            this.Close();
                        }
                        else
                        {
                            MessageBox.Show("El carnet introducido ya fue registrado");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Faltan datos!!!");
                }
            }
        }