예제 #1
0
 public ActionResult CreateMasivo()
 {
     ConsultaMasiva cM = new ConsultaMasiva();
     cM.success = false;
     cM.warning = false;
     cM.danger = false;
     return View("CreateMasivo",cM);
 }
예제 #2
0
        public ActionResult Upload(FormCollection formCollection)
        {
            ConsultaMasiva cM = new ConsultaMasiva();
            Boolean okConsultas = true;
            cM.danger = false;
            cM.warning = false;
            cM.success = false;
            if (Request != null)
            {
                HttpPostedFileBase file = Request.Files["UploadedFile"];

                if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName))
                {
                    string fileName = file.FileName;
                    string fileContentType = file.ContentType;
                    byte[] fileBytes = new byte[file.ContentLength];
                    var data = file.InputStream.Read(fileBytes, 0, Convert.ToInt32(file.ContentLength));

                    //Creo las consultas
                    var consultaList = new List<SAREM.Shared.Entities.Consulta>();
                    try
                    {
                        using (var package = new ExcelPackage(file.InputStream))
                        {
                            var currentSheet = package.Workbook.Worksheets;
                            var workSheet = currentSheet.First();
                            var noOfCol = workSheet.Dimension.End.Column;
                            var noOfRow = workSheet.Dimension.End.Row;

                            for (int rowIterator = 2; rowIterator <= noOfRow; rowIterator++)
                            {
                                var c = new SAREM.Shared.Entities.Consulta();
                                Boolean ok = true;

                                if(!(workSheet.Cells[rowIterator, 1].Value == null &&
                                    workSheet.Cells[rowIterator, 2].Value == null &&
                                    workSheet.Cells[rowIterator, 3].Value == null &&
                                    workSheet.Cells[rowIterator, 4].Value == null &&
                                    workSheet.Cells[rowIterator, 5].Value == null && workSheet.Cells[rowIterator, 6].Value == null && workSheet.Cells[rowIterator, 7].Value == null))
                                {
                                 for (int columnIterator = 1; (columnIterator <= 7 && ok); columnIterator++)
                                  {

                                    switch (columnIterator)
                                    {
                                        case 1:
                                            //ID LOCAL
                                            try
                                            {
                                                if (!String.IsNullOrEmpty(workSheet.Cells[rowIterator, columnIterator].Value.ToString()))
                                                {

                                                    c.LocalID = Convert.ToInt64(workSheet.Cells[rowIterator, columnIterator].Value.ToString());
                                                   // c.local =  fabrica.ilocales.obtenerLocal(c.LocalID);

                                                }
                                                else
                                                {
                                                    ok = false;
                                                }
                                            }
                                            catch (Exception e)
                                            {
                                                ok = false;
                                            }

                                            break;
                                        case 2:
                                            //ID ESPECIALIDAD
                                            try
                                            {
                                                if (!String.IsNullOrEmpty(workSheet.Cells[rowIterator, columnIterator].Value.ToString())) {
                                                    c.EspecialidadID = Convert.ToInt64(workSheet.Cells[rowIterator, columnIterator].Value.ToString());
                                                   // c.especialidad =  fabrica.iagenda.obtenerEspecialidad(c.EspecialidadID);
                                                }
                                                else
                                                {
                                                    ok = false;
                                                }
                                            }
                                            catch (Exception e)
                                            {
                                                ok = false;
                                            }
                                            break;
                                        case 3:
                                            //ID MEDICO
                                            try
                                            {
                                                if (!String.IsNullOrEmpty(workSheet.Cells[rowIterator, columnIterator].Value.ToString()))
                                                {
                                                    string nroDoc = workSheet.Cells[rowIterator, columnIterator].Value.ToString();

                                                    if (String.IsNullOrEmpty(nroDoc) || !Regex.IsMatch(nroDoc, @"^\d+$"))
                                                    {

                                                        ok = false;

                                                    }
                                                    else
                                                    {
                                                        c.FuncionarioID = nroDoc;
                                                    }
                                                }
                                                else
                                                {
                                                    ok = false;
                                                }
                                            }
                                            catch (Exception e)
                                            {
                                                ok = false;
                                            }
                                            break;
                                        case 4:
                                            //Fecha Inicio

                                            try
                                            {
                                                if (!String.IsNullOrEmpty(workSheet.Cells[rowIterator, columnIterator].Value.ToString())) {

                                                    c.fecha_inicio = DateTime.Parse(workSheet.Cells[rowIterator, columnIterator].Value.ToString()).ToUniversalTime();
                                                }
                                                else
                                                {
                                                    ok = false;
                                                }
                                            }
                                            catch (Exception e)
                                            {
                                                ok = false;
                                            }

                                            break;

                                        case 5:
                                            //Fecha Fin

                                            try
                                            {
                                                if (!String.IsNullOrEmpty(workSheet.Cells[rowIterator, columnIterator].Value.ToString()))
                                                {
                                                    c.fecha_fin = DateTime.Parse(workSheet.Cells[rowIterator, columnIterator].Value.ToString()).ToUniversalTime();
                                                }
                                                else
                                                {
                                                    ok = false;
                                                }
                                            }
                                            catch (Exception e)
                                            {
                                                ok = false;
                                            }

                                            break;

                                        case 6:
                                            //Cantidad de pacientes en consulta
                                            try
                                            {
                                                if (!String.IsNullOrEmpty(workSheet.Cells[rowIterator, columnIterator].Value.ToString()))
                                                {
                                                    c.numpacientes = Convert.ToInt16(workSheet.Cells[rowIterator, columnIterator].Value.ToString());
                                                }
                                                else
                                                {
                                                    ok = false;
                                                }
                                            }
                                            catch (Exception e)
                                            {
                                                ok = false;
                                            }

                                            break;
                                        case 7:
                                            //Cantidad de pacientes en lista de espera
                                            try
                                            {
                                                if (!String.IsNullOrEmpty(workSheet.Cells[rowIterator, columnIterator].Value.ToString()))
                                                {
                                                    c.maxpacientesespera = Convert.ToInt16(workSheet.Cells[rowIterator, columnIterator].Value.ToString());
                                                }
                                                else
                                                {
                                                    ok = false;
                                                }
                                            }
                                            catch (Exception e)
                                            {
                                                ok = false;
                                            }

                                            break;
                                    }

                                }

                                if (ok)
                                {
                                     fabrica.iagenda.agregarConsulta(c);
                                } else
                                {
                                    okConsultas = ok && okConsultas;

                                }

                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        cM.danger = true;
                        cM.warning = false;
                        cM.success = false;
                        return View("CreateMasivo", cM);
                    }
                }
                else
                {
                    cM.danger = true;
                    cM.warning = false;
                    cM.success = false;
                    return View("CreateMasivo", cM);

                }
            }

            if (okConsultas)
            {
                cM.danger = false;
                cM.warning = false;
                cM.success = true;

            }
            else
            {
                cM.danger = false;
                cM.warning = true;
                cM.success = false;
            }

            return View("CreateMasivo", cM);
        }