Пример #1
0
        private void SaveDbButton_Click(object sender, EventArgs e)
        {
            var logger = NLog.LogManager.GetCurrentClassLogger();

            try
            {
                //String str = "Data Source=ESBA9336;Initial Catalog=ImageDataBase;Persist Security Info=True;User ID=sa;Password=Sunshine123";

                //SqlConnection con = new SqlConnection(str);

                var imageDto = new ImagesLicence
                {
                    dateAdded  = DateTime.Now,
                    active     = true,
                    carLicence = nameB.Text,
                    localRoute = inputB.Text,
                    name       = MyGlobal.imageClassList[int.Parse(indiceB.Text)].ImageName
                };



                using (var context = new ImageDataBaseEntities())
                {
                    IQueryable <ImagesLicence> imageSelected = GetImageDetails(imageDto.name, context);
                    if (imageSelected.Any())
                    {
                        imageSelected.FirstOrDefault().carLicence = nameB.Text;
                    }
                    else
                    {
                        context.ImagesLicences.Add(imageDto);
                    }

                    context.SaveChanges();
                    logger.Trace("New car licence saved name: {0}, car licence: {1}", imageDto.name, imageDto.carLicence);
                }
            }
            catch (Exception es)

            {
                MessageBox.Show(es.Message);
            }
        }
Пример #2
0
        public void CheckLicenceDataBase(int index)
        {
            var first = MyGlobal.imageClassList[index];

            try
            {
                using (var context = new ImageDataBaseEntities())
                {
                    IQueryable <ImagesLicence> imageSelected = GetImageDetails(first, context);
                    if (imageSelected.Any())
                    {
                        nameB.Text = imageSelected.FirstOrDefault().carLicence;
                    }
                }
            }
            catch (Exception es)

            {
                MessageBox.Show(es.Message);
            }
        }
Пример #3
0
        public void DeleteLicenceDataBase(int index)
        {
            var first = MyGlobal.imageClassList[index];

            try
            {
                using (var context = new ImageDataBaseEntities())
                {
                    IQueryable <ImagesLicence> imageSelected = GetImageDetails(first, context);
                    if (imageSelected.Any())
                    {
                        imageSelected.FirstOrDefault().active = false;
                        context.ImagesLicences.Remove(imageSelected.FirstOrDefault());
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception es)

            {
                MessageBox.Show(es.Message);
            }
        }
Пример #4
0
 private static IQueryable <ImagesLicence> GetImageDetails(string name, ImageDataBaseEntities context)
 {
     return(from img in context.ImagesLicences
            where img.name == name
            select img);
 }
Пример #5
0
 private static IQueryable <ImagesLicence> GetImageDetails(ImageStructure first, ImageDataBaseEntities context)
 {
     return(from img in context.ImagesLicences
            where img.name == first.ImageName
            select img);
 }