Ejemplo n.º 1
0
        public Time_ Subscription(Time_ t)
        {
            var res = new Time_(null);

            if (Start > t.Start)
            {
                res.Start = Start;
            }
            else
            {
                res.Start = t.Start;
            }
            if (End > t.End)
            {
                res.End = t.End;
            }
            else
            {
                res.End = End;
            }
            if (res.Duration.sec < 0)
            {
                res.Duration.sec = 0;
            }
            return(res);
        }
Ejemplo n.º 2
0
        public bool Equals(Time_ t2, double tolerance_percentage = 15)
        {
            var t1 = this;
            var D  = Math.Max(Math.Abs((t1.End - t1.Start).TotalSeconds), Math.Abs((t2.End - t2.Start).TotalSeconds)) + 1;

            return((Utils.Min(t1.End, t2.End) - Utils.Max(t1.Start, t2.Start)).TotalSeconds / D > (1 - tolerance_percentage / 100.0));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// seconds
        /// </summary>
        /// <param name="t2"></param>
        /// <param name="dt"></param>
        /// <returns></returns>
        public double Overlap(Time_ t2)
        {
            var res = (Utils.Min(this.End, t2.End) - Utils.Max(this.Start, t2.Start)).TotalSeconds;

            if (res < 0)
            {
                return(0);
            }
            return(res);
        }
Ejemplo n.º 4
0
 public bool Satisfy(Time_ t)
 {
     if (projects.Count != 0 && !projects.Contains(t.project))
     {
         return(false);
     }
     if (t.Start < t1 || t.End > t2)
     {
         return(false);
     }
     if (search.Trim() != "" && !t.Comment.Contains(search))
     {
         return(false);
     }
     if (place != Place.همه)
     {
         var H   = db.GetByType(hozoor: true);
         var in_ = false;
         foreach (var tt in H.Times)
         {
             if (tt.Overlap(t) / (t.Duration.sec + 1) > 0.5)
             {
                 in_ = true;
                 break;
             }
         }
         if (place == Place.بیرون)
         {
             return(!in_);
         }
         else
         {
             return(in_);
         }
     }
     return(true);
 }
Ejemplo n.º 5
0
        public List <Time_> NotSubscriptionWith(List <Time_> T)
        {
            var res = new List <Time_> {
                this
            };

            foreach (var t in T)
            {
                for (int i = 0; i < res.Count; i++)
                {
                    if (res[i].Subscription(t).Duration.sec != 0)
                    {
                        var r1 = new Time_(null);
                        var r2 = new Time_(null);
                        if (res[i].Start < t.Start)
                        {
                            r1.Start = res[i].Start; r1.End = t.Start;
                        }
                        if (res[i].End > t.End)
                        {
                            r2.Start = t.End; r2.End = res[i].End;
                        }
                        res.RemoveAt(i--);
                        if (r1.Duration.sec > 0)
                        {
                            res.Insert(++i, r1);
                        }
                        if (r2.Duration.sec > 0)
                        {
                            res.Insert(++i, r2);
                        }
                    }
                }
            }
            return(res);
        }
Ejemplo n.º 6
0
 public bool Contains(Time_ t, int tolerance_sec = 0)
 {
     return(Contains(t.Start, tolerance_sec) && Contains(t.End, tolerance_sec));
 }
Ejemplo n.º 7
0
 private void button_ok_Click(object sender, EventArgs e)
 {
     if (ignorEvents)
     {
         return;
     }
     try
     {
         for (int i = 0; i < dataGridView1.ColumnCount; i++)
         {
             dataGridView1[i, 0].ErrorText = "";
         }
         var t = new Time_(db.GetByName(dataGridView1[0, 0].Value.ToString()));
         try
         {
             var date = Utils.PersianParse(dataGridView1[2, 0].Value.ToString());
             try
             {
                 if (!(dataGridView1[3, 0].Value + "").Contains(":"))
                 {
                     dataGridView1[3, 0].Value += ":00";
                 }
                 var start = dataGridView1[3, 0].Value.ToString().Split(new char[] { ':' });
                 t.Start = new DateTime(date.Year, date.Month, date.Day,
                                        Convert.ToInt16(start[0]), Convert.ToInt16(start[1]), 0);
             }
             catch { dataGridView1[3, 0].ErrorText = "?"; }
         }
         catch { dataGridView1[2, 0].ErrorText = "?"; }
         try
         {
             if (!(dataGridView1[5, 0].Value + "").Contains(":"))
             {
                 dataGridView1[5, 0].Value += ":00";
             }
             t.Duration = new TSpan(dataGridView1[5, 0].Value.ToString());
         }
         catch { dataGridView1[5, 0].ErrorText = "?"; }
         t.Comment = dataGridView1[6, 0].Value.ToString().TrimStart();
         if (db.project == t.project)
         {
             if (Form1.Stop())
             {
                 MessageBox.Show(this, "Current time work stopped!");
             }
         }
         {
             if (!t.project.IsHozoor)
             {
                 foreach (var p in db.Projects)
                 {
                     if (p.Active && !p.IsHozoor && p.Times.Count > 0 && Utils.Last(p.Times).Start.AddDays(30) > DateTime.Now)
                     {
                         foreach (var t2 in p.Times)
                         {
                             if (t2.Start.AddDays(30) > DateTime.Now & t2.Duration.sec > 5)
                             {
                                 if (t.Overlap(t2) > 60)
                                 {
                                     if (Form_msg.Show(this, "با ساعت کاری زیر هم پوشانی دارد:\r\n" + p.Name + ": " + Utils.DateTimeString(t2.Start) + " - " + Utils.TimeString(t2.End) + "\r\n" + "با این وجود ادامه می دهید؟", btn: MessageBoxButtons.YesNo) == DialogResult.No)
                                     {
                                         return;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if (t.project.Times.Count == 0 || Utils.Last(t.project.Times).Start <= t.Start)
             {
                 t.project.Times.Add(t);
             }
             else
             {
                 for (int i = 0; i < t.project.Times.Count; i++)
                 {
                     if (t.project.Times[i].Start > t.Start)
                     {
                         t.project.Times.Insert(i, t);
                         break;
                     }
                 }
             }
             t.project.LastComment = t.Comment;
         }
         Utils.Log("++ Add: " + t.project.Name + " - " + Utils.DateTimeString(t.Start) + " - " + t.Duration.ToString(true));
         db.Save(Form1.DataFile);
         Close();
     }
     catch { dataGridView1[0, 0].ErrorText = "?"; }
 }