コード例 #1
0
        public ActionResult Delete(IEnumerable <NonHazardousWasteRecordWrapper> models)
        {
            foreach (var source in models)
            {
                // Create a new Product entity and set its properties from productViewModel
                non_hazardous_record s = db.non_hazardous_record.Find(source.id);
                db.non_hazardous_record.Remove(s);
                db.SaveChanges();
                double total = 0;
                List <NonHazardousWasteRecordWrapper> all = db.non_hazardous_record.Where(p => p.date == source.date).Select(p => new NonHazardousWasteRecordWrapper {
                    id = p.id, waste_in = p.waste_in, waste_out = p.waste_out, id_type = p.id_type, date = p.date
                }).ToList();
                if (all.Count() != 0)
                {
                    total = all.Sum(p => p.waste_in).Value;
                    foreach (var a in all)
                    {
                        non_hazardous_record nn = new non_hazardous_record
                        {
                            id           = a.id,
                            date         = a.date,
                            waste_in     = a.waste_in,
                            waste_out    = a.waste_out,
                            id_type      = a.id_type,
                            recycle_rate = a.waste_out / total * 100
                        };
                        db.Entry(nn).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
            }

            return(Json(null));
        }
コード例 #2
0
        public ActionResult Create(IEnumerable <NonHazardousWasteRecordWrapper> models)
        {
            List <NonHazardousWasteRecordWrapper> ss = new List <NonHazardousWasteRecordWrapper>();
            double total = 0;

            foreach (var source in models)
            {
                List <NonHazardousWasteRecordWrapper> all = db.non_hazardous_record.Where(p => p.date == source.date).Select(p => new NonHazardousWasteRecordWrapper {
                    id = p.id, waste_in = p.waste_in, waste_out = p.waste_out, id_type = p.id_type, date = p.date
                }).ToList();
                if (all.Count() != 0)
                {
                    total = all.Sum(p => p.waste_in).Value + source.waste_in.Value;
                    foreach (NonHazardousWasteRecordWrapper a in all)
                    {
                        non_hazardous_record nn = new non_hazardous_record
                        {
                            id           = a.id,
                            date         = a.date,
                            waste_in     = a.waste_in,
                            waste_out    = a.waste_out,
                            id_type      = a.id_type,
                            recycle_rate = a.waste_out / total * 100
                        };
                        db.Entry(nn).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                else
                {
                    total = source.waste_in.Value;
                }

                var s = new non_hazardous_record
                {
                    date         = source.date,
                    waste_in     = source.waste_in,
                    waste_out    = source.waste_out,
                    id_type      = source.id_type,
                    recycle_rate = source.waste_out / total * 100
                };

                db.non_hazardous_record.Add(s);
                db.SaveChanges();



                TypeWasteWrapper tw = db.type_of_waste.Select(p => new TypeWasteWrapper {
                    id = p.id, name = p.name
                }).Where(p => p.id == s.id_type).FirstOrDefault();


                // store the product in the result
                ss.Add(new NonHazardousWasteRecordWrapper {
                    id = s.id, type_name = tw, waste_in = s.waste_in, waste_out = s.waste_out, date = s.date
                });
            }
            return(Json(ss.ToList()));
        }
コード例 #3
0
ファイル: ExcelReader.cs プロジェクト: Desilva/Enviro
        private string saveNonHazardousRecord(List <object> data)
        {
            string err = "";

            try
            {
                DateTime      date    = DateTime.FromOADate(Double.Parse(data[0].ToString()));
                string        name    = data[1].ToString();
                type_of_waste tw      = db.type_of_waste.Where(p => p.name == name).FirstOrDefault();
                int?          id_type = null;
                if (tw == null)
                {
                    err += "Type of waste of " + data[1].ToString() + " not found.";
                }
                else
                {
                    id_type = tw.id;
                }

                double waste_in = 0;
                Double.TryParse(data[2].ToString(), out waste_in);
                double waste_out = 0;
                Double.TryParse(data[3].ToString(), out waste_out);
                CultureInfo provider = CultureInfo.InvariantCulture;
                double      total    = 0;

                List <NonHazardousWasteRecordWrapper> all = db.non_hazardous_record.Where(p => p.date == date).Select(p => new NonHazardousWasteRecordWrapper {
                    id = p.id, waste_in = p.waste_in, waste_out = p.waste_out, id_type = p.id_type, date = p.date
                }).ToList();
                if (all.Count() != 0)
                {
                    total = all.Sum(p => p.waste_in).Value + waste_in;
                    foreach (NonHazardousWasteRecordWrapper a in all)
                    {
                        non_hazardous_record nn = new non_hazardous_record
                        {
                            id           = a.id,
                            date         = a.date,
                            waste_in     = a.waste_in,
                            waste_out    = a.waste_out,
                            id_type      = a.id_type,
                            recycle_rate = a.waste_out / total * 100
                        };
                        db.Entry(nn).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                else
                {
                    total = waste_in;
                }

                var s = new non_hazardous_record
                {
                    date         = date,
                    waste_in     = waste_in,
                    waste_out    = waste_out,
                    id_type      = id_type,
                    recycle_rate = waste_out / total * 100
                };

                db.non_hazardous_record.Add(s);
                db.SaveChanges();
            }
            finally
            {
            }
            return(err);
        }
コード例 #4
0
        public ActionResult Edit(IEnumerable <NonHazardousWasteRecordWrapper> models)
        {
            DateTime prevDate = DateTime.Today;
            double   total    = 0;

            foreach (var source in models)
            {
                non_hazardous_record s = db.non_hazardous_record.Find(source.id);
                List <NonHazardousWasteRecordWrapper> all = db.non_hazardous_record.Where(p => p.date == source.date && p.id != s.id).Select(p => new NonHazardousWasteRecordWrapper {
                    id = p.id, waste_in = p.waste_in, waste_out = p.waste_out, id_type = p.id_type, date = p.date
                }).ToList();
                if (all.Count() != 0)
                {
                    total = all.Sum(p => p.waste_in).Value + source.waste_in.Value;
                    foreach (var a in all)
                    {
                        non_hazardous_record nn = new non_hazardous_record
                        {
                            id           = a.id,
                            date         = a.date,
                            waste_in     = a.waste_in,
                            waste_out    = a.waste_out,
                            id_type      = a.id_type,
                            recycle_rate = a.waste_out / total * 100
                        };
                        db.Entry(nn).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                else
                {
                    total = source.waste_in.Value;
                }

                prevDate       = s.date.Value;
                s.date         = source.date;
                s.waste_in     = source.waste_in;
                s.waste_out    = source.waste_out;
                s.id_type      = source.id_type;
                s.recycle_rate = source.waste_out / total * 100;

                db.Entry(s).State = EntityState.Modified;
                db.SaveChanges();

                if (prevDate != source.date)
                {
                    all = db.non_hazardous_record.Where(p => p.date == prevDate).Select(p => new NonHazardousWasteRecordWrapper {
                        id = p.id, waste_in = p.waste_in, waste_out = p.waste_out, id_type = p.id_type, date = p.date
                    }).ToList();
                    if (all.Count() != 0)
                    {
                        total = all.Sum(p => p.waste_in).Value;
                        foreach (var a in all)
                        {
                            non_hazardous_record nn = new non_hazardous_record
                            {
                                id           = a.id,
                                date         = a.date,
                                waste_in     = a.waste_in,
                                waste_out    = a.waste_out,
                                id_type      = a.id_type,
                                recycle_rate = a.waste_out / total * 100
                            };
                            db.Entry(nn).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                }
            }

            return(Json(null));
        }