Beispiel #1
0
 partial void OnValidate(System.Data.Linq.ChangeAction action)
 {
     if (!IsValid)
     {
         throw new ApplicationException("Rule violations prevent saving");
     }
 }
Beispiel #2
0
 partial void OnValidate(System.Data.Linq.ChangeAction action)
 {
     if ((this.companyCode == null && this.companyGroupCode == null) || (this.companyCode != null && this.companyGroupCode != null))
     {
         throw new Exception("companyCode or companyGroupCode must be filled!");
     }
 }
 // The CKEditor cannot check the length of myfield, and the 
 // DataAnnotations StringLengthAttribute doesn't work with CKEditor,
 // so you have to do a custom check. 
 // 
 // This works as expected only when NOT debugging. 
 // 
 // In debug mode the application will open a window saying 
 // "ValidationException was unhandled by user code",
 // but the message is shown as it is set below in the code. 
 // Hit F5 again, and application will continue OK.
 partial void OnValidate(System.Data.Linq.ChangeAction action)
 {
     if (this._myfield.Length > 1024)
     {
         throw new ValidationException(
            "Length of myfield must be less than 1025 characters.");
     }    }
 partial void OnValidate(System.Data.Linq.ChangeAction action)
 {
     if (action == System.Data.Linq.ChangeAction.Insert)
     {
         LastChanged = DateTime.Now;
     }
 }
Beispiel #5
0
        partial void OnValidate(System.Data.Linq.ChangeAction action)
        {
            if (action == System.Data.Linq.ChangeAction.None)
            {
                return;
            }

            using (ApplicationDataContext context = new ApplicationDataContext())
            {
                if (action == System.Data.Linq.ChangeAction.Insert || action == System.Data.Linq.ChangeAction.Update)
                {
                    var exists = (from app in context.Applications
                                  where app.ApplicationId != ApplicationId &&
                                  (app.Token.ToLower() == Token.ToLower() || app.Name.ToLower() == Name.ToLower())
                                  select app).Count() > 0;
                    if (exists)
                    {
                        throw new Exception(TextMessages.NameOrTokenAlreadyExists);
                    }
                }
                else if (action == System.Data.Linq.ChangeAction.Delete)
                {
                    // TODO: Handle this case

                    /*var hasSubscriptions = (fromDate sub in context.Subscriptions
                     *                      where sub.ApplicationId == this.ApplicationId
                     *                      select sub).Count() > 0;
                     * if (hasSubscriptions)
                     * {
                     *  throw new Exception(TextMessages.CannotDeleteApplicationBecauseItHasSubscriptions);
                     * }*/
                }
            }
        }
Beispiel #6
0
 partial void OnValidate(System.Data.Linq.ChangeAction action)
 {
     if (action == System.Data.Linq.ChangeAction.Insert ||
         action == System.Data.Linq.ChangeAction.Update)
     {
     }
 }
Beispiel #7
0
        partial void OnValidate(System.Data.Linq.ChangeAction action)
        {
            if (action == System.Data.Linq.ChangeAction.Insert ||
                action == System.Data.Linq.ChangeAction.Update)
            {
                if (string.IsNullOrEmpty(this.Name) ||
                    string.IsNullOrEmpty(this.Name.Trim()))
                {
                    throw new Exception("Nhập họ và tên.");
                }

                if (string.IsNullOrEmpty(this.CMND) ||
                    string.IsNullOrEmpty(this.CMND.Trim()))
                {
                }
                else
                {
                    if (this.CMND.Length < 9)
                    {
                        throw new Exception("Số CMND phải từ 9 số trở lên.");
                    }

                    RedBloodDataContext db = new RedBloodDataContext();

                    int count = (from e in db.Peoples
                                 where object.Equals(e.CMND, this.CMND.Trim()) && e.ID != this.ID
                                 select e).Count();

                    if (count > 0)
                    {
                        throw new Exception("Trùng số CMND với người khác.");
                    }
                }
            }
        }
Beispiel #8
0
    partial void OnValidate(System.Data.Linq.ChangeAction action)
    {
        if (action == System.Data.Linq.ChangeAction.Insert ||
            action == System.Data.Linq.ChangeAction.Update)
        {
            if (string.IsNullOrEmpty(this.Name) ||
                string.IsNullOrEmpty(this.Name.Trim()))
            {
                throw new Exception("Nhập danh mục");
            }


            RedBloodDataContext db = new RedBloodDataContext();

            int count = (from cats in db.SideEffects
                         where cats.ID != this.ID && object.Equals(cats.ParentID, this.ParentID) &&
                         cats.Name.Trim() == this.Name.Trim()
                         select cats).Count();

            if (count > 0)
            {
                throw new Exception("Trùng tên");
            }

            SideEffectBLL.SetFullname(this);
        }
    }
Beispiel #9
0
 public void OnValidate(System.Data.Linq.ChangeAction action)
 {
     if (action != System.Data.Linq.ChangeAction.Delete)
     {
         //hook for code generator
     }
     OnValidateCustomization();
 }
Beispiel #10
0
 partial void OnValidate(System.Data.Linq.ChangeAction action)
 {
     switch (action)
     {
     case System.Data.Linq.ChangeAction.Insert:
     case System.Data.Linq.ChangeAction.Update:
         CreatedOn = Util.Now;
         break;
     }
 }
Beispiel #11
0
 partial void OnValidate(System.Data.Linq.ChangeAction action)
 {
     if (!char.IsUpper(this._LastName[0]) ||
         !char.IsUpper(this._FirstName[0]) ||
         !char.IsUpper(this._Title[0]))
     {
         throw new ValidationException(
                   "Data value must start with an uppercase letter.");
     }
 }
Beispiel #12
0
        partial void OnValidate(System.Data.Linq.ChangeAction action)
        {
            if (action == System.Data.Linq.ChangeAction.Insert ||
                action == System.Data.Linq.ChangeAction.Update)
            {
                RedBloodDataContext db = new RedBloodDataContext();

                int count = (from e in db.TestDefs
                             where object.Equals(e.ParentID, this.ParentID) && e.Name == this.Name.Trim()
                             select e).Count();

                if (count > 0)
                {
                    throw new Exception("Trùng tên");
                }
            }
        }
Beispiel #13
0
        partial void OnValidate(System.Data.Linq.ChangeAction action)
        {
            if (action == System.Data.Linq.ChangeAction.Update || action == System.Data.Linq.ChangeAction.Insert)
            {
                if (ModelProgress < 0)
                {
                    ModelProgress = 0;
                }
                if (ModelProgress > 100)
                {
                    ModelProgress = 100;
                }

                if (TextureProgress < 0)
                {
                    TextureProgress = 0;
                }
                if (TextureProgress > 100)
                {
                    TextureProgress = 100;
                }

                if (ScriptProgress < 0)
                {
                    ScriptProgress = 0;
                }
                if (ScriptProgress > 100)
                {
                    ScriptProgress = 100;
                }


                OverallProgress = (int)(50 * (LicenseType / 2.0) + 20 * (ModelProgress / 100.0) + 20 * (TextureProgress / 100.0) + 10 * (ScriptProgress / 100.0));
                if (Global.LoggedUserID != null)
                {
                    LastChangeUserID = Global.LoggedUserID;
                }
            }
        }
 partial void OnValidate(System.Data.Linq.ChangeAction action);
 partial void OnValidate(System.Data.Linq.ChangeAction action)
 {
     LastEditTime = DateTime.Now;
 }
Beispiel #16
0
 public void Onvalidate(System.Data.Linq.ChangeAction action)
 {
 }
 protected override void OnValidate(System.Data.Linq.ChangeAction action)
 {
     base.OnValidate(action);
 }
Beispiel #18
0
 partial void OnValidate(System.Data.Linq.ChangeAction action)
 {
     if(action == System.Data.Linq.ChangeAction.Insert)
        // Do insert
     ... etc. ...
 }
Beispiel #19
0
 partial void OnValidate(System.Data.Linq.ChangeAction action)
 {
     ModelTool.ValidateStringLength(this);
 }