92 lines
1.9 KiB
C#
92 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Diplom_B.DB
|
|
{
|
|
public static class WorkDB
|
|
{
|
|
public static void Init()
|
|
{
|
|
using (var DB = new MainDB())
|
|
{
|
|
var usr = (from u in DB.Users
|
|
where u.Name == "admin"
|
|
select u).ToArray();
|
|
if (usr.Length < 1)
|
|
{
|
|
DB.Users.Add(new DB.User()
|
|
{
|
|
Name = "admin",
|
|
Pass = "admin"
|
|
});
|
|
}
|
|
DB.SaveChanges();
|
|
}
|
|
}
|
|
public static Izdelie[] ListIzdelie(string filter = "")
|
|
{
|
|
try
|
|
{
|
|
using (var db = new MainDB())
|
|
{
|
|
if (string.IsNullOrEmpty(filter))
|
|
{
|
|
var tmp = (from a in db.Izdeliya
|
|
select a).ToArray();
|
|
return tmp;
|
|
}
|
|
else
|
|
{
|
|
var tmp = (from a in db.Izdeliya
|
|
where
|
|
a.Id.ToString().Contains(filter) ||
|
|
a.Name.Contains(filter) ||
|
|
a.DecNum.Contains(filter) ||
|
|
a.Shifr.Contains(filter) ||
|
|
a.Litera.Contains(filter) ||
|
|
a.Cena.ToString("F2").Contains(filter) ||
|
|
a.OtdelRazrab.ToString().Contains(filter) ||
|
|
a.Ved.Contains(filter) ||
|
|
a.GlavKonstr.Contains(filter)
|
|
select a).ToArray();
|
|
return tmp;
|
|
}
|
|
}
|
|
}
|
|
catch { throw; }
|
|
}
|
|
public static void AddIzdelie(Izdelie izd)
|
|
{
|
|
try
|
|
{
|
|
using (var db = new MainDB())
|
|
{
|
|
db.Izdeliya.Add(izd);
|
|
db.SaveChanges();
|
|
}
|
|
}
|
|
catch { throw; }
|
|
}
|
|
public static Izdelie GetIzdelie(int id)
|
|
{
|
|
try
|
|
{
|
|
using (var db = new MainDB())
|
|
{
|
|
var res = (from a in db.Izdeliya
|
|
where a.Id == id
|
|
select a).ToArray();
|
|
if (res.Length != 1)
|
|
return null;
|
|
else
|
|
return res[0];
|
|
}
|
|
}
|
|
catch { throw; }
|
|
}
|
|
}
|
|
}
|