示例#1
0
        public ActionResult Post(string applier, string type, IFormCollection files)
        {
            var       stream = files.Files[0].OpenReadStream();
            DataEntry entry  = new DataEntry();

            using (ExcelPackage excel = new ExcelPackage(stream))
            {
                try
                {
                    entry.GenesList = new List <int[]>();
                    ExcelWorksheet worksheet = excel.Workbook.Worksheets[1];
                    int            rowCount  = worksheet.Dimension.Rows;
                    int            ColCount  = worksheet.Dimension.Columns;
                    int            row       = 2;
                    entry.Name = worksheet.Cells[row, 1].Value.ToString();
                    for (int col = 2; col <= ColCount; col += 2)
                    {
                        if (true)
                        {
                            var gene1 = Convert.ToInt32(worksheet.Cells[row, col].Value);
                            var gene2 = Convert.ToInt32(worksheet.Cells[row, col + 1].Value);
                            entry.GenesList.Add(new int[] { gene1, gene2 });
                        }
                    }
                    var profileID = Guid.NewGuid().ToString();
                    HttpContext.Session.SetString("ProfileID", profileID);
                    profileDictionary[profileID] = entry;
                }
                catch (Exception)
                {
                    throw;
                }
                using (SqlManipulation sm = new SqlManipulation(@"Server=127.0.0.1;Port=5432;Database=genelib;User Id=postgres;Password = CCBFU6233;", SqlType.PostgresQL))
                {
                    sm.Init();
                    var result = sm.ExcuteQuery($"select * from {type}");
                    for (int i = 1; i < result.Columns.Count; i++)
                    {
                        entry.GeneNameList.Add(result.Columns[i].ColumnName);
                    }
                    foreach (System.Data.DataRow n in result.Rows)
                    {
                        var name = n[0].ToString();
                        var list = new List <int[]>();
                        for (int i = 1; i < result.Columns.Count;)
                        {
                            list.Add(n[i++] as int[]);
                        }
                        entry.SourceDictionary[name] = list;
                    }
                }
                Compare(entry);
                return(new JsonResult(entry.ResultDictionary));
            }
        }
示例#2
0
        public void Put(string type, IFormCollection files)
        {
            var stream = files.Files[0].OpenReadStream();

            using (ExcelPackage excel = new ExcelPackage(stream))
            {
                try
                {
                    ExcelWorksheet   worksheet = excel.Workbook.Worksheets[1];
                    int              rowCount  = worksheet.Dimension.Rows;
                    int              ColCount  = worksheet.Dimension.Columns;
                    List <DataEntry> datalist  = new List <DataEntry>();
                    for (int row = 2; row <= rowCount; row++)
                    {
                        DataEntry entry = new DataEntry();
                        entry.GenesList = new List <int[]>();
                        entry.Name      = worksheet.Cells[row, 1].Value.ToString();
                        for (int col = 2; col <= ColCount; col += 2)
                        {
                            if (true)
                            {
                                var gene1 = Convert.ToInt32(worksheet.Cells[row, col].Value);
                                var gene2 = Convert.ToInt32(worksheet.Cells[row, col + 1].Value);
                                entry.GenesList.Add(new int[] { gene1, gene2 });
                            }
                        }
                        datalist.Add(entry);
                    }
                    using (SqlManipulation sm = new SqlManipulation(@"Server=127.0.0.1;Port=5432;Database=genelib;User Id=postgres;Password = CCBFU6233;", SqlType.PostgresQL))
                    {
                        sm.Init();
                        foreach (var n in datalist)
                        {
                            var sql = $"insert into {type} values('{n.Name}',";
                            foreach (var xn in n.GenesList)
                            {
                                sql += $"'{{{xn[0]},{xn[1]}}}',";
                            }
                            sql  = sql.Substring(0, sql.Length - 1);
                            sql += ")";
                            sm.ExcuteNonQuery(sql);
                        }
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }