Пример #1
0
        protected void GridView_InitNewRow(object sender, DevExpress.Web.Data.ASPxDataInitNewRowEventArgs e)
        {
            StdTypeVM CloneItem = new StdTypeVM();

            if (bool.Parse(HttpContext.Current.Session["isCloneRow_Com"].ToString()) == true && GridView.FocusedRowIndex >= 0)
            {
                //List<int> selectedIds = GridView.GetSelectedFieldValues("Id").ConvertAll(id => (int)id);
                //CloneItem = StandardTypeProvider.GetSingleById(selectedIds.Last());

                CloneItem = Mapper.Map <StdTypeVM>(StdTypeProvider.GetSingleById(GridView.GetRowValues(GridView.FocusedRowIndex, "Id").ToString()));


                HttpContext.Current.Session["isCloneRow_Com"] = false;

                PropertyInfo myFieldInfo;
                foreach (var myProperty in typeof(StdTypeVM).GetProperties())
                {
                    myFieldInfo = typeof(StdTypeVM).GetProperty(myProperty.Name);
                    if (myFieldInfo == null)
                    {
                        continue;
                    }
                    var ttt = myFieldInfo.GetValue(CloneItem);

                    e.NewValues[myProperty.Name] = myFieldInfo.GetValue(CloneItem);
                }
            }
        }
Пример #2
0
        public static void Update(StdTypeVM item)
        {
            StdType dbItem = GetSingleById(item.Id);

            dbItem.UpdateStandardType(item);
            RepositoryBase <StdType> .Update(dbItem);

            RepositoryBase <StdType> .SaveChanges();
        }
Пример #3
0
        public static StdType Add(StdTypeVM item)
        {
            StdType dbItem = new StdType();

            dbItem.UpdateStandardType(item);

            dbItem.Id      = item.Id;
            dbItem.Actived = item.Actived;

            dbItem.CreatedDate = DateTime.Now;
            dbItem.CreatedBy   = HttpContext.Current.User.Identity.Name;

            StdType model = RepositoryBase <StdType> .Add(dbItem);

            RepositoryBase <StdType> .SaveChanges();

            return(dbItem);
        }
Пример #4
0
 public static void UpdateStandardType(this StdType item, StdTypeVM itemVM)
 {
     item.Name = itemVM.Name;
 }
Пример #5
0
        protected void GridView_RowValidating(object sender, DevExpress.Web.Data.ASPxDataValidationEventArgs e)
        {
            StdTypeVM item = new StdTypeVM();

            if (GridView.IsNewRowEditing)
            {
                //foreach (var itemKey in e.NewValues.Keys)
                foreach (GridViewColumn column in GridView.Columns)
                {
                    GridViewDataColumn dataColumn = column as GridViewDataColumn;
                    if (dataColumn == null)
                    {
                        continue;
                    }

                    PropertyInfo myFieldInfo = typeof(StdTypeVM).GetProperty(dataColumn.FieldName);
                    if (myFieldInfo == null)
                    {
                        continue;
                    }

                    myFieldInfo.SetValue(item, e.NewValues[dataColumn.FieldName]);

                    ValidationContext context = new ValidationContext(item)
                    {
                        MemberName = dataColumn.FieldName
                    };
                    var errors = new List <ValidationResult>();

                    var myProperty = item.GetType().GetProperty(dataColumn.FieldName).GetValue(item, null);

                    bool isValid = Validator.TryValidateProperty(myProperty, context, errors);

                    if (!isValid)
                    {
                        //e.Errors[dataColumn] = errors[0].ErrorMessage;
                        AddError(e.Errors, dataColumn, errors[0].ErrorMessage);
                    }
                    //var myPropertyInfo = item.GetType().GetProperty(dataColumn.FieldName);
                    //myFieldInfo.SetValue(item, e.NewValues[itemKey.ToString()]);
                }
            }
            else
            {
                //foreach (var itemKey in e.NewValues.Keys)
                foreach (GridViewColumn column in GridView.Columns)
                {
                    GridViewDataColumn dataColumn = column as GridViewDataColumn;
                    if (dataColumn == null)
                    {
                        continue;
                    }

                    PropertyInfo myFieldInfo = typeof(StdTypeVM).GetProperty(dataColumn.FieldName);
                    if (myFieldInfo == null)
                    {
                        continue;
                    }

                    myFieldInfo.SetValue(item, e.NewValues[dataColumn.FieldName]);

                    ValidationContext context = new ValidationContext(item)
                    {
                        MemberName = dataColumn.FieldName
                    };
                    var errors = new List <ValidationResult>();

                    var myProperty = item.GetType().GetProperty(dataColumn.FieldName).GetValue(item, null);

                    bool isValid = Validator.TryValidateProperty(myProperty, context, errors);

                    if (!isValid)
                    {
                        if (dataColumn.FieldName != "FastStandardTypeName" && dataColumn.FieldName != "UserName" && dataColumn.FieldName != "Password" && dataColumn.FieldName != "ConfirmPassword")
                        {
                            //e.Errors[dataColumn] = errors[0].ErrorMessage;
                            AddError(e.Errors, dataColumn, errors[0].ErrorMessage);
                        }
                    }
                    //var myPropertyInfo = item.GetType().GetProperty(dataColumn.FieldName);
                    //myFieldInfo.SetValue(item, e.NewValues[itemKey.ToString()]);
                }
            }
            if (e.Errors.Count > 0)
            {
                e.RowError = "Vui lòng nhập đầy đủ thông tin theo yêu cầu.";
            }
        }
Пример #6
0
 public static void Delete(StdTypeVM item)
 {
     Delete(item.Id);
 }