Пример #1
0
        public string LoadMesas()
        {
            HttpPostedFileBase fileUpload = Request.Files[0];

            if (fileUpload != null)
            {
                fileUpload.SaveAs(Server.MapPath("~/temp/" + fileUpload.FileName));
                var fi = new FileInfo(Server.MapPath("~/temp/" + fileUpload.FileName));
                var package = new ExcelPackage(fi);
                ExcelWorksheet worksheet = package.Workbook.Worksheets[1];

                var db = new edayRoomEntities();
                var centros = (db.Centroes.Select(cc => new {cc.id, cc.unique_id})).ToDictionary(t => t.unique_id);

                var mesas = new List<Mesa>();
                for (int i = 2; i <= worksheet.Dimension.End.Row; i++)
                {
                    double numero = worksheet.Cells[i, 2].Value == null ? 0 : (double) worksheet.Cells[i, 2].Value;
                    double votantes = worksheet.Cells[i, 3].Value == null ? 0 : (double) worksheet.Cells[i, 3].Value;
                    string centroId = worksheet.Cells[i, 1].Value == null ? "" : worksheet.Cells[i, 1].Value.ToString();

                    if (centros.ContainsKey(centroId))
                    {
                        int idcentro = centros[centroId].id;
                        var mesa = new Mesa
                                       {
                                           uniqueId = centroId + "-" + numero,
                                           numero = (int) numero,
                                           votantes = (int) votantes,
                                           id_centro = idcentro,
                                           lastContact = DateTime.Now
                                       };
                        mesas.Add(mesa);
                    }
                }

                using (
                    var con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbConnSimple"].ConnectionString)
                    )
                {
                    con.Open();
                    using (SqlTransaction tran = con.BeginTransaction())
                    {
                        var bc = new SqlBulkCopy(con,
                                                 SqlBulkCopyOptions.CheckConstraints |
                                                 SqlBulkCopyOptions.FireTriggers |
                                                 SqlBulkCopyOptions.KeepNulls, tran)
                                     {BatchSize = 1000, DestinationTableName = "mesa"};

                        bc.WriteToServer(mesas.AsDataReader());

                        tran.Commit();
                    }
                    con.Close();
                }

                return new JavaScriptSerializer().Serialize("");
            }
            return "";
        }
Пример #2
0
 /// <summary>
 /// Create a new Mesa object.
 /// </summary>
 /// <param name="id">Initial value of the id property.</param>
 /// <param name="numero">Initial value of the numero property.</param>
 /// <param name="votantes">Initial value of the votantes property.</param>
 /// <param name="id_centro">Initial value of the id_centro property.</param>
 /// <param name="participacion">Initial value of the participacion property.</param>
 /// <param name="abierta">Initial value of the abierta property.</param>
 /// <param name="cerrada">Initial value of the cerrada property.</param>
 /// <param name="lastContact">Initial value of the lastContact property.</param>
 /// <param name="alertBlocked">Initial value of the alertBlocked property.</param>
 /// <param name="totalizada">Initial value of the totalizada property.</param>
 public static Mesa CreateMesa(global::System.Int32 id, global::System.Int32 numero, global::System.Int32 votantes, global::System.Int32 id_centro, global::System.Int32 participacion, global::System.Boolean abierta, global::System.Boolean cerrada, global::System.DateTime lastContact, global::System.Boolean alertBlocked, global::System.Boolean totalizada)
 {
     Mesa mesa = new Mesa();
     mesa.id = id;
     mesa.numero = numero;
     mesa.votantes = votantes;
     mesa.id_centro = id_centro;
     mesa.participacion = participacion;
     mesa.abierta = abierta;
     mesa.cerrada = cerrada;
     mesa.lastContact = lastContact;
     mesa.alertBlocked = alertBlocked;
     mesa.totalizada = totalizada;
     return mesa;
 }
Пример #3
0
        public bool Save()
        {
            using (var db = new edayRoomEntities())
            {
                bool returnValue = true;
                Mesa mesa = (from m in db.Mesas
                             where m.id_centro == IdCentro
                                   && m.uniqueId == UniqueId
                             select m).SingleOrDefault();
                if (mesa == null)
                {
                    mesa = new Mesa
                               {
                                   id_centro = IdCentro,
                                   numero = Numero,
                                   uniqueId = UniqueId,
                                   votantes = Votantes
                               };
                    db.Mesas.AddObject(mesa);
                    mesa.ParticipacionTimelines.Add(new ParticipacionTimeline
                                                        {
                                                            activa = true,
                                                            fecha = DateTime.Now,
                                                        });

                    mesa.Participacions.Add(new Participacion
                                                {
                                                    conteo = 0,
                                                    active = true,
                                                    cola = 0,
                                                    fecha = DateTime.Now,
                                                    id_testigo = null
                                                });

                    db.SaveChanges();
                }
                else
                {
                    returnValue = false;
                }

                Id = mesa.id;

                return returnValue;
            }
        }
Пример #4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Mesas EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToMesas(Mesa mesa)
 {
     base.AddObject("Mesas", mesa);
 }