public DateTime tinhthoigiannt(Tbldetai dt, DateTime tg)
        {
            double?  c = 0;
            double?  n = 0;
            double?  s = 1;
            double?  d = 0;
            DateTime a = new DateTime();

            using (sql_NCKHContext db = new sql_NCKHContext())
            {
                if (!string.IsNullOrEmpty(dt.Thoigiankt.ToString()))
                {
                    c = db.Tblloainhiemvus.SingleOrDefault(x => x.Id == dt.Idloainv).C;
                    n = Convert.ToDateTime(dt.Thoigiankt).Year - tg.Year;
                    s = 900 * c * n;
                    s = s + db.Tblhoatdongnckhs.SingleOrDefault(x => x.Id == dt.Idhdnckh).Dinhmuc;
                    List <Tblsohuudetai> ds = db.Tblsohuudetais.Where(x => x.Iddetai == dt.Id).ToList();
                    foreach (Tblsohuudetai ss in ds)
                    {
                        s = s + db.Tblsohuus.SingleOrDefault(x => x.Id == ss.Idsohuu).Dm;
                    }
                    if (float.TryParse(s.ToString(), out float x))
                    {
                        string[] b = s.ToString().Split('.');
                        int      m = int.Parse(b[0]);
                        d = (s - m) * 60;
                        s = m;
                    }
                    TimeSpan span = new TimeSpan(Convert.ToInt32(s), Convert.ToInt32(d), 0);
                }
            }
            return(a);
        }
        public Tbldetai get_detai_id(int id)
        {
            Tbldetai dv = new Tbldetai();

            using (sql_NCKHContext db = new sql_NCKHContext())
            {
                dv = db.Tbldetais.SingleOrDefault(x => x.Id == id);
            }
            return(dv);
        }
 public bool create_detai([FromBody] Tbldetai dt)
 {
     try
     {
         using (sql_NCKHContext db = new sql_NCKHContext())
         {
             db.Tbldetais.Add(dt);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
        public bool chuyen_trang_thai(int id, int trangthai, string time)
        {
            try
            {
                using (sql_NCKHContext db = new sql_NCKHContext())
                {
                    Tbldetai dt = db.Tbldetais.SingleOrDefault(x => x.Id == id);
                    if (string.IsNullOrEmpty(dt.ToString()))
                    {
                        return(false);
                    }
                    switch (trangthai)
                    {
                    case 2:
                        dt.Tinhtrang  = 2;    //duyệt
                        dt.Thoigianbd = DateTime.Now;
                        dt.Thoigiannt = tinhthoigiannt(dt, Convert.ToDateTime(dt.Thoigianbd));
                        break;

                    case 3:
                        dt.Tinhtrang = 3;     //Hoan thanh
                        break;

                    case 4:
                        dt.Thoigiangiahan = giahan(time);
                        dt.Tinhtrang      = 4; //Xin them thoi gian
                        break;

                    case 5:
                        dt.Tinhtrang = 5;     //áp dụng thực tế
                        break;

                    case -1:
                        dt.Tinhtrang = -1;     //huỷ
                        break;
                    }
                    db.SaveChanges();
                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
 public bool delete_detai(int id)
 {
     try
     {
         using (sql_NCKHContext db = new sql_NCKHContext())
         {
             Tbldetai d = db.Tbldetais.SingleOrDefault(x => x.Id == id);
             if (string.IsNullOrEmpty(d.ToString()))
             {
                 return(true);
             }
             db.Tbldetais.Remove(d);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Example #6
0
        public List <nhomtg> get_nhomtg_all(int id)
        {
            List <nhomtg> ds = new List <nhomtg>();

            using (sql_NCKHContext db = new sql_NCKHContext())
            {
                ds = db.Tblnhomtgs.Join(db.Tblnhanviens, ntg => ntg.Idnv, nv => nv.Id, (ntg, nv) => new nhomtg
                {
                    Id      = ntg.Id,
                    Iddetai = ntg.Iddetai,
                    Idnv    = ntg.Idnv,
                    Chucvu  = ntg.Chucvu,
                    Hoten   = nv.Hoten
                }).Where(x => x.Iddetai == id).ToList();
                foreach (Tblnhomtg tg in db.Tblnhomtgs)
                {
                    if (tg.Iddetai == id && tg.Idnv == null)
                    {
                        nhomtg a = new nhomtg();
                        a.Id      = tg.Id;
                        a.Idnv    = -1;
                        a.Iddetai = tg.Iddetai;
                        a.Chucvu  = tg.Chucvu;
                        a.Hoten   = tg.Hoten;
                        ds.Add(a);
                    }
                }
                Tbldetai    dt   = db.Tbldetais.SingleOrDefault(x => x.Id == id);
                Tblnhanvien dsnv = db.Tblnhanviens.SingleOrDefault(x => x.Id == dt.Idnv);
                nhomtg      b    = new nhomtg();
                b.Id      = 0;
                b.Iddetai = id;
                b.Idnv    = dsnv.Id;
                b.Chucvu  = "Chủ đề tài";
                b.Hoten   = dsnv.Hoten;
                ds.Add(b);
            }
            return(ds);
        }