Advertisement
Guest User

Untitled

a guest
Jan 4th, 2018
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.46 KB | None | 0 0
  1. using SimpleScan.Model;
  2. using SimpleScan.Model.Context;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Data;
  7. using System.Data.Entity;
  8. using System.Data.SQLite;
  9. using System.Diagnostics;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13.  
  14.  
  15. namespace SimpleScan.SQL
  16. {
  17.     class SqliteUtils : DbContext
  18.     {
  19.         private string database = "test1.sqlite";
  20.  
  21.         public SqliteUtils()
  22.         {
  23.             CreateDbEntity();
  24.         }
  25.  
  26.         private void CreateDbEntity()
  27.         {
  28.             if (!System.IO.File.Exists(database))
  29.             {
  30.                 using (var ctx = new BaseContext())
  31.                 {
  32.                     var users = new List<Operator>();
  33.                     users.Add(new Operator() { Login = "admin", Admin = true, Password = "6898C672C1A6B96ACF58C12F2B3DEF3E359239ADA08BA17ECFB76F1315D8C4DE", Remove = false });
  34.                     users.Add(new Operator() { Login = "a", Admin = true, Password = "CA978112CA1BBDCAFAC231B39A23DC4DA786EFF8147C4E72B9807785AFEE48BB", Remove = false });
  35.                     ctx.Operators.AddRange(users);
  36.  
  37.                     var maint = new List<EventMaintenance>();
  38.                     maint.Add(new EventMaintenance() { FromTime = new DateTime(1995, 3, 25, 11, 45, 23), ToTime = new DateTime(1975, 1, 25, 11, 45, 22), ScopeOfWork = "hahha", OperatorId = 1 });
  39.                     maint.Add(new EventMaintenance() { FromTime = DateTime.Now, ToTime = DateTime.Now, ScopeOfWork = "hahha", OperatorId = 1 });
  40.  
  41.                     ctx.SaveChanges();
  42.                     ctx.Maintenances.AddRange(maint);
  43.  
  44.                     Operat op = new Operat() { Iemz = "P.1234.5678.90", OperatFilesCount = 23 };
  45.                     op.Box = new Box() { Name = "Skrzynia 1", OperatCount = 2, OperatScanFilesCount = 200 };
  46.                     op.Box.Order = new OrderTbl() { Client = "Zlecenie 1" };
  47.                     try
  48.                     {
  49.                         ctx.Operats.Add(op);
  50.                         ctx.SaveChanges();
  51.                     }
  52.                     catch (Exception e)
  53.                     {
  54.                         Debug.WriteLine(e.ToString());
  55.                         MessageBox.Show(e.ToString());
  56.                     }
  57.  
  58.  
  59.                     op = new Operat() { Iemz = "P.1234.6785.99", OperatFilesCount = 23, BoxId = 1 };
  60.                     ctx.Operats.Add(op);
  61.                     ctx.SaveChanges();
  62.  
  63.                     op = new Operat() { Iemz = "P.5678.1234.123", OperatFilesCount = 23 };
  64.                     op.Box = new Box() { Name = "Skrzynia 2", OperatCount = 2, OperatScanFilesCount = 200, OrderId = 1 };
  65.                     ctx.Operats.Add(op);
  66.                     ctx.SaveChanges();
  67.  
  68.                     op = new Operat() { Iemz = "P.5678.4321.321", OperatFilesCount = 23, BoxId = 2 };
  69.                     ctx.Operats.Add(op);
  70.                     ctx.SaveChanges();
  71.  
  72.                     op = new Operat() { Iemz = "P.7890.1234.543", OperatFilesCount = 23 };
  73.                     op.Box = new Box() { Name = "Skrzynia 3", OperatCount = 2, OperatScanFilesCount = 200 };
  74.                     op.Box.Order = new OrderTbl() { Client = "Zlecenie 2" };
  75.                     ctx.Operats.Add(op);
  76.                     ctx.SaveChanges();
  77.  
  78.                     op = new Operat() { Iemz = "P.7890.4321.345", OperatFilesCount = 23, BoxId = 3 };
  79.                     ctx.Operats.Add(op);
  80.                     ctx.SaveChanges();
  81.  
  82.                     OperatDetail opd = new OperatDetail()
  83.                     {
  84.                         DirectoryPath = @"C:\Digitalizacja\asd",
  85.                         FilePath = @"C:\Digitalizacja\asd\pod0001.tif",
  86.                         OperatId = 1,
  87.                         PageNumber = 1,
  88.                         Remove = false,
  89.                         ScanTime = DateTime.Now
  90.                     };
  91.  
  92.                     ctx.OperatDetails.Add(opd);
  93.  
  94.                     ctx.SaveChanges();
  95.  
  96.                     List<Operator> data = ctx.Operators.ToList();
  97.                     foreach (Operator item in data)
  98.                         Console.WriteLine(string.Format("ID : {0} Login : {1}", item.Id, item.Login));
  99.                 }
  100.             }
  101.         }
  102.  
  103.         public Operator ValidatePassword(string login)
  104.         {
  105.             using (var ctx = new BaseContext())
  106.             {
  107.                 return ctx.Operators.Where(user => user.Login == login && user.Remove == false).First();
  108.             }
  109.         }
  110.  
  111.        
  112.  
  113.        
  114.      
  115.         public List<string> GetOrder()
  116.         {
  117.             List<string> order = new List<string>();
  118.             using (var ctx = new BaseContext())
  119.             {
  120.                 order.AddRange(ctx.OrderTbls.Select(p => p.Client));
  121.             }
  122.             return order;
  123.         }
  124.  
  125.         public List<string> GetBox(string order)
  126.         {
  127.             List<string> box = new List<string>();
  128.             using (var ctx = new BaseContext())
  129.             {
  130.                 box.AddRange(ctx.Boxes.Where(p => p.Order.Client == order).Select(p => p.Name));
  131.             }
  132.             return box;
  133.         }
  134.  
  135.         public List<string> GetOperats(string box)
  136.         {
  137.             List<string> operats = new List<string>();
  138.             using (var ctx = new BaseContext())
  139.             {
  140.                 operats.AddRange(ctx.Operats.Where(p => p.Box.Name == box).Select(p => p.Iemz));
  141.             }
  142.             return operats;
  143.         }
  144.  
  145.  
  146.     }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement