Пример #1
0
 public static int GetAllRecordsCount()
 {
     using (BadBeeEntities db = new BadBeeEntities())
     {
         return(db.Item.Count());
     }
 }
Пример #2
0
 public static void FillDictionaryCache()
 {
     using (BadBeeEntities db = new BadBeeEntities())
     {
         GlobalVars.DictionaryCache.Add(typeof(Brand), db.Brand.OrderBy(q => q.Name).ToList());
         GlobalVars.DictionaryCache.Add(typeof(Serie), db.Serie.OrderBy(q => q.Name).ToList());
         GlobalVars.DictionaryCache.Add(typeof(Model), db.Model.OrderBy(q => q.Name).ToList());
         GlobalVars.DictionaryCache.Add(typeof(DAL.BadBee), db.BadBee.OrderBy(q => q.BadBeeNo).ToList());
         GlobalVars.DictionaryCache.Add(typeof(Wva), db.Wva.OrderBy(q => q.WvaNo).ToList());
         GlobalVars.DictionaryCache.Add(typeof(Systems), db.Systems.OrderBy(q => q.Abbreviation).ToList());
         GlobalVars.DictionaryCache.Add(typeof(Width), db.Width.OrderBy(q => q.Width1).ToList());
         GlobalVars.DictionaryCache.Add(typeof(Height), db.Height.OrderBy(q => q.Height1).ToList());
         GlobalVars.DictionaryCache.Add(typeof(Thickness), db.Thickness.OrderBy(q => q.Thickness1).ToList());
         GlobalVars.DictionaryCache.Add(typeof(Date), db.Date.OrderBy(q => q.Date1).ToList());
     }
 }
        public ActionResult GetBadBeePadsList()
        {
            try
            {
                List <string> BadBeeNames = new List <string>();

                using (BadBeeEntities bbe = new BadBeeEntities())
                {
                    BadBeeNames = bbe.BadBee.Select(q => q.BadBeeNo).OrderBy(q => q).ToList();
                }
                return(Json(BadBeeNames, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                log.Error(e);
                throw;
            }
        }
        public ActionResult FileUpload(HttpPostedFileBase file, string caption, string type, string BadBees)
        {
            try
            {
                Item ifExist = db.Item.Where(q => (q.BadBee.BadBeeNo == BadBees)).FirstOrDefault();
                if (ifExist == null)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    PicturesModel pictures = new PicturesModel();

                    if (file != null)
                    {
                        if (!string.IsNullOrEmpty(BadBees))
                        {
                            caption = BadBees;
                        }

                        string pic  = "";
                        string path = "";

                        if (type == "schema1")
                        {
                            pic = Path.GetFileName(caption + "a.jpg");
                        }
                        else if (type == "schema2")
                        {
                            pic = Path.GetFileName(caption + "b.jpg");
                        }
                        else if (type == "picture2")
                        {
                            pic = Path.GetFileName(caption + "_2.jpg");
                        }
                        else if (type == "picture1")
                        {
                            pic = Path.GetFileName(caption + "_1.jpg");
                        }

                        if (BadBees == null)
                        {
                            BadBees = "";
                        }

                        Picture obj = db.Picture.Where(q => (q.BadBeeNo == BadBees)).FirstOrDefault();

                        if (obj != null)
                        {
                            List <Item> product = db.Item.Where(q => (q.BadBee.BadBeeNo == obj.BadBeeNo)).ToList();

                            if (type == "schema1" && obj.Picture1 != pic)
                            {
                                obj.Picture1 = pic;
                                using (var dbCtx = new BadBeeEntities())
                                {
                                    db.Picture.Attach(obj);
                                    db.Entry(obj).Property(x => x.Picture1).IsModified = true;
                                    dbCtx.SaveChanges();
                                }
                            }
                            if (type == "schema2" && obj.Picture2 != pic)
                            {
                                obj.Picture2 = pic;
                                using (var dbCtx = new BadBeeEntities())
                                {
                                    db.Picture.Attach(obj);
                                    db.Entry(obj).Property(x => x.Picture2).IsModified = true;
                                    dbCtx.SaveChanges();
                                }
                            }
                            if (type == "picture2" && obj.Picture3 != pic)
                            {
                                obj.Picture3 = pic;
                                using (var dbCtx = new BadBeeEntities())
                                {
                                    db.Picture.Attach(obj);
                                    db.Entry(obj).Property(x => x.Picture3).IsModified = true;
                                    dbCtx.SaveChanges();
                                }
                            }

                            Picture newPict = new Picture();
                            newPict = db.Picture.Where(q => q.PictureId == obj.PictureId).FirstOrDefault();
                        }
                        else
                        {
                            Picture newObj = new Picture();
                            //var np = db.Pictures.OrderByDescending(q => q.Id).Select(q => q).FirstOrDefault();
                            //int newid = np.Id + 1;

                            //newObj.BadBeeNo = BadBees;
                            //if (type == "schema1") { newObj.Schema1 = pic; };
                            //if (type == "schema2") { newObj.Schema2 = pic; };

                            //if (type == "picture1") { newObj.Picture1 = pic; };
                            //if (type == "picture2") { newObj.Picture2 = pic; };
                            //newObj.Id = newid;

                            //List<ItemsDb> product = db.ItemsDb.Where(q => (q.BadBeeNumber == newObj.BadBeeNo)).ToList();
                            //foreach (var item in product)
                            //{
                            //    item.PictureId = newObj.Id;
                            //}

                            using (var dbCtx = new BadBeeEntities())
                            {
                                dbCtx.Picture.Add(newObj);
                                dbCtx.SaveChanges();
                            }
                        }

                        path = Path.Combine(Server.MapPath("~/Images/Pictures"), pic);

                        // file is uploaded

                        file.SaveAs(path);

                        using (MemoryStream ms = new MemoryStream())
                        {
                            file.InputStream.CopyTo(ms);
                            byte[] array = ms.GetBuffer();
                        }

                        db.SaveChanges();
                    }
                    //}
                    // after successfully uploading redirect the user
                    return(RedirectToAction("List", pictures));
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw ex;
            }
        }
Пример #5
0
        public void GeneratePDFCatalog()
        {
            List <CvlItem> data = new List <CvlItem>();


            using (BadBeeEntities bbe = new BadBeeEntities())
            {
                data = (from item in bbe.Item
                        join model in bbe.Model
                        on item.ModelId equals model.ModelId
                        join serie in bbe.Serie
                        on model.SerieId equals serie.SerieId
                        join brand in bbe.Brand
                        on serie.BrandId equals brand.BrandId
                        join year in bbe.Year
                        on model.YearId equals year.YearId
                        join datefrom in bbe.Date
                        on year.DateFromFK.DateId equals datefrom.DateId
                        join dateto in bbe.Date
                        on year.DateToFK.DateId equals dateto.DateId
                        join badbee in bbe.BadBee
                        on item.BadBeeId equals badbee.BadBeeId
                        join wva in bbe.Wva
                        on badbee.WvaId equals wva.WvaId
                        join system in bbe.Systems
                        on badbee.SystemId equals system.SystemId
                        join dimension in bbe.Dimension
                        on badbee.DimensionId equals dimension.DimensionId
                        join width in bbe.Width
                        on dimension.WidthId equals width.WidthId
                        join height in bbe.Height
                        on dimension.HeightId equals height.HeightId
                        join thickness in bbe.Thickness
                        on dimension.ThicknessId equals thickness.ThicknessId

                        select new CvlItem
                {
                    Brand = brand.Name,
                    Serie = serie.Name,
                    Model = model.Name,
                    DateFrom = year.DateFromFK.Date1,
                    DateTo = year.DateToFK.Date1,
                    BadBeeNumber = badbee.BadBeeNo,
                    Fr = badbee.FR,
                    Wva = wva.WvaNo,
                    WvaDesc = wva.Description,
                    Size = height.Height1 + "x" + width.Width1 + "x" + thickness.Thickness1,
                    BrakeSystem = system.Abbreviation,
                    Height = height.Height1.ToString(),
                    Thickness = thickness.Thickness1.ToString(),
                    Width = width.Width1.ToString(),
                }).OrderBy(q => q.Brand).ThenBy(q => q.Serie).ThenBy(q => q.Model).ThenBy(q => q.Fr).ToList();
            }


            PdfDocument document  = new PdfDocument();
            int         maxWidth  = 595;
            int         maxHeight = 845;
            int         PageNo    = 0;
            // Create an empty page or load existing
            PdfPage page = document.AddPage();
            //    // Get an XGraphics object for drawing
            XGraphics gfx = XGraphics.FromPdfPage(page);

            DrawImage2(gfx, PDFResources.BadBeeCover, 0, 0, maxWidth, maxHeight);
            gfx.Dispose();

            page = document.AddPage();
            gfx  = XGraphics.FromPdfPage(page);
            gfx.Dispose();

            page = document.AddPage();
            gfx  = XGraphics.FromPdfPage(page);
            gfx.Dispose();

            page = document.AddPage();
            gfx  = XGraphics.FromPdfPage(page);
            DrawImage2(gfx, PDFResources.Page3_applications, 0, 0, maxWidth, maxHeight);
            gfx.Dispose();


            PageNo = AddDataPages(gfx, data, page, document, maxHeight, maxWidth);

            page = document.AddPage();
            gfx  = XGraphics.FromPdfPage(page);
            DrawImage2(gfx, PDFResources.Page_drawing, 0, 0, maxWidth, maxHeight);
            gfx.Dispose();

            PageNo = AddPicturePages(gfx, page, document, maxHeight, maxWidth, PageNo);

            page = document.AddPage();
            gfx  = XGraphics.FromPdfPage(page);
            gfx.Dispose();

            page = document.AddPage();
            gfx  = XGraphics.FromPdfPage(page);
            //      DrawImage2(gfx, Properties.Resources.end_page, 0, 0, maxWidth, maxHeight);
            gfx.Dispose();

            // Save and start View
            document.Save(GetPath());
            Process.Start(GetPath());
        }
Пример #6
0
 public ListProvider()
 {
     db = new BadBeeEntities();
 }