Exemple #1
0
        //public void addColumn(string Cname, int limit)
        //{


        //    Column toAdd = new Column(Cname, limit);
        //    toAdd.GetSave().Invoke(ColumnsList.Count, this.Id);
        //    ColumnsList.Add(toAdd);
        //}

        public void addColumn(string Cname, int limit)
        {
            //check limits
            if (limit == Constants.InfiniteLimit & this.totalLimit != Constants.InfiniteLimit)
            {
                AlmogException exp = new AlmogException();
                exp.Value = "adding the column would make the sum of the columns limit axceed the total limt";
                throw exp;
            }

            int updatedLimit = 0;

            for (int i = 0; i < ColumnsList.Count; i++)
            {
                updatedLimit += ColumnsList[i].getLimit();
            }

            if (updatedLimit + limit > this.totalLimit)
            {
                AlmogException exp = new AlmogException();
                exp.Value = "adding the column would make the sum of the columns limit axceed the total limt";
                throw exp;
            }

            //limits ok
            Column toAdd = new Column(Cname, limit);

            toAdd.GetSave().Invoke(ColumnsList.Count, this.Id);
            ColumnsList.Add(toAdd);
        }
Exemple #2
0
 private void validTask(string title, string description, DateTime duedate)
 {
     if (title == null || title.Length > 50 | title.Length == 0)
     {
         Logger.Log.Error("tried to have taks with the illegal title: " + title);
         this.Legal = false;
         AlmogException kipod = new AlmogException();
         kipod.Value = "title cannot be empty or longer than 50 characters";
         throw kipod;
         //Console.WriteLine("title cannot be empty or longer than 50 characters");
     }
     if (description != null && description.Length > 300)
     {
         Logger.Log.Error("tried to have taks with the illegal description: " + description);
         // Console.WriteLine("descreiption cannot be more than 300 characters");
         this.Legal = false;
         AlmogException kipod = new AlmogException();
         kipod.Value = "descreiption cannot be more than 300 characters";
         throw kipod;
     }
     if (duedate.Date.CompareTo(this.CreationDate.Date) < 0)
     {
         Logger.Log.Error("tried to have taks with the illegal dueDate: " + duedate + "; the creationDate is: " + this.CreationDate);
         //  Console.WriteLine("due date cannot be ealier than creation date");
         this.Legal = false;
         AlmogException kipod = new AlmogException();
         kipod.Value = "due date cannot be ealier than creation date";
         throw kipod;
     }
 }
Exemple #3
0
 public Func <int, bool> GetSave()
 {
     if (!this.Legal)
     {
         Logger.Log.Error("did not save task id: " + this.ID + " becuse it is illegal.  title: '" + this.Title + "'; desciption: '" + this.Description + "'; dueDate: " + this.DueDate.Date + "; creationDate: " + this.CreationDate.Date);
         AlmogException kipod = new AlmogException();
         kipod.Value = "did not save task because it's illegal";
         throw kipod;
     }
     return((Cid) => { TaskDAL.SaveTask(this.toStruct(), Cid); return true; });
 }
Exemple #4
0
        public Func <int, bool> GetUpdate(string title, string description, DateTime?dueDate)
        {
            Func <int, bool> ans = (Cid) =>
            {
                this.Legal = true;
                String validTitle = title;
                if (title == null)
                {
                    validTitle = this.Title;
                }
                String validDescription = description;
                if (description == null)
                {
                    validDescription = this.Description;
                }
                DateTime validduedate = this.DueDate;
                if (dueDate != null)
                {
                    validduedate = (DateTime)dueDate;
                }

                validTask(validTitle, validDescription, validduedate);

                if (!this.Legal)
                {
                    Logger.Log.Error("did not update task id: " + this.ID + " becuse it is still illegal/  title: '" + validTitle + "'; desciption: '" + validDescription + "'; dueDate: " + validduedate.Date + "; creationDate: " + this.CreationDate.Date);
                    // Console.WriteLine("did not update task because it's illegal");
                    AlmogException kipod = new AlmogException();
                    kipod.Value = "did not update task because it's illegal";
                    throw kipod;
                }
                else
                {
                    if (title != null)
                    {
                        this.Title = title;
                    }
                    if (description != null)
                    {
                        this.Description = description;
                    }
                    if (dueDate != null)
                    {
                        this.DueDate = (DateTime)dueDate;
                    }
                    TaskDAL.UpdateTask(this.toStruct(), Cid);
                    return(true);
                }
            };

            return(ans);
        }
Exemple #5
0
        public static void saveBoard(BoardStruct board)
        {
            SQLiteCommand command = new SQLiteCommand();

            try
            {
                DAL.OpenConnect();
                command             = new SQLiteCommand(null, DAL.connection);
                command.CommandText = "INSERT INTO Boards(Bid, TotalLimit, Name)  " +
                                      " VALUES (@Board_id, @Board_TotalLimit, @Board_Name )";
                SQLiteParameter boardID    = new SQLiteParameter("@Board_id", board.Id);
                SQLiteParameter boardLimit = new SQLiteParameter("@Board_TotalLimit", board.totalLimit);
                SQLiteParameter boardName  = new SQLiteParameter("@Board_Name", board.ProjectName);
                command.Parameters.Add(boardID);
                command.Parameters.Add(boardLimit);
                command.Parameters.Add(boardName);
                command.Prepare();
                try
                {
                    int changes = command.ExecuteNonQuery();
                }
                catch (SQLiteException e)
                {
                    if (e.Message.Contains("database is locked"))
                    {
                        AlmogException unicorn = new AlmogException();

                        unicorn.Value = new List <String>()
                        {
                            "DB locked. please try again later"
                        };
                        throw unicorn;
                    }
                    else
                    {
                        throw e;
                    }
                }
                command.Dispose();
                DAL.CloseConnect();
                Logger.Log.Info("saved new board with id: " + board.Id + "; name: '" + board.ProjectName + "'; limit: " + board.totalLimit);
            }
            catch (SQLiteException e)
            {
                Logger.Log.Fatal("sql exception when saving new board with id: " + board.Id + "\n error: " + e.Message);
                command.Dispose();
                DAL.CloseConnect();
            }
        }
Exemple #6
0
        private void checkLimits(int c1Limit, int c2Limit, int c3Limit, int tLimit)
        {
            if (tLimit != Constants.InfiniteLimit && (c1Limit == Constants.InfiniteLimit | c2Limit == Constants.InfiniteLimit | c3Limit == Constants.InfiniteLimit))
            {
                //throw new ArgumentException();
                AlmogException exp = new AlmogException();
                exp.Value = "Limits problem";
                throw exp;
            }

            if ((c1Limit != Constants.InfiniteLimit & c2Limit != Constants.InfiniteLimit & c3Limit != Constants.InfiniteLimit & tLimit != Constants.InfiniteLimit) && tLimit < c1Limit + c2Limit + c3Limit)
            {
                //throw new ArgumentException();
                AlmogException exp = new AlmogException();
                exp.Value = "Limits problem";
                throw exp;
            }
        }