public ActionResult Index(Acceso login)
        {
            RespAcceso respuesta = new RespAcceso();
            try {
                SqlDataReader reader = null;
                SqlConnection myConnection = new SqlConnection();
                try
                {
                    myConnection.ConnectionString = ConfigurationManager.ConnectionStrings["BaseComercial"].ConnectionString;
                    myConnection.Open();
                    SqlCommand command = new SqlCommand("select * from RESTAURANT a, EMPLEADO b where b.EMPL_COD = " + login.num_empleado + " and a.REST_ID = " + login.rest_id + " and b.EMPL_STAT ='ALTA'", myConnection);
                    reader = command.ExecuteReader();
                    Empleado emp = new Empleado();
                    Restaurant rest = new Restaurant();
                    while (reader.Read())
                    {

                        rest.rest_des = reader["rest_des"].ToString();
                        rest.rest_id = Convert.ToInt32(reader["rest_id"].ToString());
                        rest.succ_id = Convert.ToInt32(reader["succ_id"].ToString());
                        emp.empl_apm = reader["empl_apm"].ToString();
                        emp.empl_app = reader["empl_app"].ToString();
                        emp.empl_cod = Convert.ToInt32(reader["empl_cod"].ToString());
                        emp.empl_nom = reader["empl_nom"].ToString();
                        emp.empl_stat = reader["empl_stat"].ToString();
                        emp.empl_tipo = reader["empl_tipo"].ToString();
                        emp.succ_id = Convert.ToInt32(reader["succ_id"].ToString());

                    }//end while
                    respuesta.restaurant = rest;
                    respuesta.empleado = emp;
                }
                catch (SqlException sqlExc)
                {
                    respuesta.success = false;
                    respuesta.message = "ERROR " + sqlExc.Message;
                }
                finally
                {
                    myConnection.Close();
                }
                //fin try-catch SQL
            }catch(Exception ex){
                respuesta.success = false;
                respuesta.message = "ERROR " + ex.Message;
            }//Fin Try-catch General
            respuesta.success = true;
            respuesta.message = "OK";
            return Json(respuesta);
        }
        public ActionResult appEntrar(Acceso login)
        {
            log.Info("Solicitando appEntrar");
            RespAcceso respuesta = new RespAcceso();
            try
            {
                SqlDataReader reader = null;
                SqlConnection myConnection = new SqlConnection();
                Empleado emp = null;
                RestDetalle rest = null;
                log.Debug("Restaurante " +login.rest_id);
                log.Debug(" |Validando contraseña " + login.password); // " contra contraseña de restaurant " + ConfigurationManager.AppSettings[login.rest_id].ToString());
                log.Debug("1= " + ConfigurationManager.AppSettings["1"].ToString());
                log.Debug("?= " + ConfigurationManager.AppSettings[""+login.rest_id].ToString());
                string pass = null;
                try
                {
                    pass = ConfigurationManager.AppSettings["" + login.rest_id].ToString();
                }catch(Exception exrr){
                    log.Error("ERROR VALIDANDO CONTRASEÑA EN "+ exrr.Message);
                }
                if(pass== null){
                    log.Debug("Configuracion de contraseña, incorrecta");
                    respuesta.success = false;
                    respuesta.message = "CONFIGURACION DE CONTRASEÑA, INCORRECTA";
                    respuesta.restaurant = rest;
                    respuesta.empleado = emp;
                }
                else if ( pass == login.password)
                {
                    log.Debug("Contraseña Valida");
                    try
                    {
                        myConnection.ConnectionString = ConfigurationManager.ConnectionStrings["BaseComercial"].ConnectionString;
                        myConnection.Open();
                        //SqlCommand command = new SqlCommand("select * from RESTAURANT a, EMPLEADO b where b.EMPL_COD = " + login.num_empleado + " and a.REST_ID = " + login.rest_id + " and b.EMPL_STAT ='ALTA'", myConnection);
                        SqlCommand command = new SqlCommand("select (select SUCC_DES from SUCURSAL where SUCC_ID = a.SUCC_ID) as SUCC_DES, * from 	RESTAURANT a, ff_cat_usuario b where b.usr_numempleado = " + login.num_empleado + " and a.REST_ID = " + login.rest_id, myConnection);
                        reader = command.ExecuteReader();

                        while (reader.Read())
                        {
                            emp = new Empleado();
                            rest = new RestDetalle();
                            rest.rest_des = reader["rest_des"].ToString();
                            rest.rest_id = Convert.ToInt32(reader["rest_id"].ToString());
                            rest.succ_id = Convert.ToInt32(reader["succ_id"].ToString());
                            rest.succ_des = reader["succ_des"].ToString();
                            emp.empl_apm = "";
                            emp.empl_app = "";
                            emp.empl_cod = Convert.ToInt32(reader["usr_numempleado"].ToString());
                            emp.empl_nom = reader["usr_nombre"].ToString();
                            emp.empl_stat = "ALTA";
                            emp.empl_tipo = "MESERO";
                            emp.succ_id = Convert.ToInt32(reader["succ_id"].ToString());
                        }//end while
                        if (emp != null && rest != null)
                        {
                            respuesta.success = true;
                            respuesta.message = "OK";
                            respuesta.restaurant = rest;
                            respuesta.empleado = emp;
                        }
                        else
                        {
                            respuesta.success = false;
                            respuesta.message = "CONTRASEÑA INVÁLIDA";
                            respuesta.restaurant = rest;
                            respuesta.empleado = emp;
                        }

                    }
                    catch (SqlException sqlExc)
                    {
                        log.Error("Error en SQLException appEntrar en " + sqlExc.Message);
                        respuesta.success = false;
                        respuesta.message = "ERROR " + sqlExc.Message;
                        return Json(respuesta);
                    }
                    finally
                    {
                        myConnection.Close();
                    }
                }
                else
                {
                    log.Debug("Contraseña incorrecta");
                    respuesta.success = false;
                    respuesta.message = "CONTRASEÑA INVÁLIDA";
                    respuesta.restaurant = rest;
                    respuesta.empleado = emp;
                }
                //fin try-catch SQL
            }
            catch (Exception ex)
            {
                log.Error("Error solicitando appEntrar en "+ ex.Message);
                respuesta.success = false;
                respuesta.message = "ERROR " + ex.Message;
                return Json(respuesta);
            }//Fin Try-catch General
            return Json(respuesta);
        }
 public ActionResult getOrdenesActivas(Acceso acceso)
 {
     log.Info("Solicitando getOrdenesActivas");
     RespOrdenesActivas ordenesActivas = new RespOrdenesActivas();
     try
     {
         SqlDataReader reader = null;
         SqlConnection myConnection = new SqlConnection();
         List<OrdenActiva> listaOrdenes = new List<OrdenActiva>();
         try
         {
             myConnection.ConnectionString = ConfigurationManager.ConnectionStrings["BaseComercial"].ConnectionString;
             myConnection.Open();
             //SqlCommand command = new SqlCommand("select a.ORDN_ID,a.ORDN_NPER, a.ORDN_IMPTOT, a.ORDN_STAT, a.MESA_ID, 		(select d.ordn_hmov from ORDEN_CTRL d where d.ORDN_ID = a.ORDN_ID) as ORDN_HMOV,		(select c.MESA_cve from MESA c where c.MESA_ID = a.MESA_ID) as MESA_CVE		  from orden a where a.ORDN_MESE= "+acceso.num_empleado+" and a.ORDN_STAT= 'INIC' or a.ORDN_STAT = 'CAMM'", myConnection);
             SqlCommand command = new SqlCommand("select a.ORDN_ID,a.ORDN_NPER, a.ORDN_IMPTOT, a.ORDN_STAT, a.MESA_ID, 		(select d.ordn_hmov from ORDEN_CTRL d where d.ORDN_ID = a.ORDN_ID) as ORDN_HMOV,		(select c.MESA_cve from MESA c where c.MESA_ID = a.MESA_ID) as MESA_CVE		  from orden a where a.ORDN_MESE= " + acceso.num_empleado + " and (select c.rest_id from MESA c where c.MESA_ID =a.MESA_ID) = "+acceso.rest_id + " and a.ORDN_STAT= 'INIC' or a.ORDN_STAT = 'CAMM'", myConnection);
             reader = command.ExecuteReader();
             while (reader.Read())
             {
                 OrdenActiva orden = new OrdenActiva();
                 orden.mesa_cve = reader["mesa_cve"].ToString();
                 orden.mesa_id = Convert.ToInt32(reader["mesa_id"].ToString());
                 orden.ordn_hmov = Convert.ToInt32(reader["ordn_hmov"].ToString());
                 orden.ordn_id = Convert.ToInt32(reader["ordn_id"].ToString());
                 orden.ordn_imptot = Convert.ToDecimal(reader["ordn_imptot"].ToString());
                 orden.ordn_nper = Convert.ToInt32(reader["ordn_nper"].ToString());
                 orden.ordn_stat = reader["ordn_stat"].ToString();
                 listaOrdenes.Add(orden);
             }
             ordenesActivas.total_ordenes = listaOrdenes.Count;
             ordenesActivas.ordenesActivas = listaOrdenes;
         }
         catch (SqlException sqlex)
         {
             log.Error("Error en SQLException getOrdenesActivas en " + sqlex.Message);
             ordenesActivas.success = false;
             ordenesActivas.message = "ERROR " + sqlex;
             return Json(ordenesActivas);
         }
         finally
         {
             myConnection.Close();
         }
     }
     catch (Exception exc)
     {
         log.Error("Error  getOrdenesActivas en " + exc.Message);
         ordenesActivas.success = false;
         ordenesActivas.message = "ERROR " + exc.Message;
         return Json(ordenesActivas);
     }
     ordenesActivas.success = true;
     ordenesActivas.message = "OK";
     return Json(ordenesActivas);
 }
 public ActionResult Index(Acceso acceso)
 {
     RespOrdenesActivas ordenesActivas = new RespOrdenesActivas();
     try
     {
         SqlDataReader reader = null;
         SqlConnection myConnection = new SqlConnection();
         List<OrdenActiva> listaOrdenes = new List<OrdenActiva>();
         try
         {
             myConnection.ConnectionString = ConfigurationManager.ConnectionStrings["BaseComercial"].ConnectionString;
             myConnection.Open();
             SqlCommand command = new SqlCommand("SELECT " +
                                                 "A.ORDN_ID, " +
                                                 "A.ORDN_NPER, " +
                                                 "A.ORDN_IMPTOT," +
                                                 "A.ORDN_STAT, " +
                                                 "A.MESA_ID, " +
                                                 "B.ORDN_HMOV, " +
                                                 "C.MESA_CVE "+
                                                 "   FROM "+
                                                 "ORDEN A, "+
                                                 "ORDEN_CTRL B, "+
                                                 "MESA C "+
                                                 "   WHERE "	+
                                                 "A.ORDN_STAT = 'INIC' "+
                                                 " AND	A.ORDN_MESE = " +acceso.num_empleado +
                                                 " AND	B.ORDN_ID = A.ORDN_ID"+
                                                 " AND	C.MESA_ID = A.MESA_ID;", myConnection);
             reader = command.ExecuteReader();
             while(reader.Read()){
                 OrdenActiva orden = new OrdenActiva();
                 orden.mesa_cve = reader["mesa_cve"].ToString();
                 orden.mesa_id = Convert.ToInt32(reader["mesa_id"].ToString());
                 orden.ordn_hmov = Convert.ToInt32(reader["ordn_hmov"].ToString());
                 orden.ordn_id = Convert.ToInt32(reader["ordn_id"].ToString());
                 orden.ordn_imptot = Convert.ToDecimal(reader["ordn_imptot"].ToString());
                 orden.ordn_nper = Convert.ToInt32(reader["ordn_nper"].ToString());
                 orden.ordn_stat = reader["ordn_stat"].ToString();
                 listaOrdenes.Add(orden);
             }
             ordenesActivas.total_ordenes = listaOrdenes.Count;
             ordenesActivas.ordenesActivas = listaOrdenes;
         }
         catch(SqlException sqlex){
             ordenesActivas.success = false;
             ordenesActivas.message = "ERROR " + sqlex;
             return Json(ordenesActivas);
         }
         finally{
             myConnection.Close();
         }
     }
     catch(Exception exc)
     {
         ordenesActivas.success = false;
         ordenesActivas.message = "ERROR " + exc.Message;
         return Json(ordenesActivas);
     }
     ordenesActivas.success = true;
     ordenesActivas.message = "OK";
     return Json(ordenesActivas);
 }