示例#1
0
        /// <summary>
        /// Verify
        /// </summary>
        /// <typeparam name="T"></typeparam>
        protected EntityDML <T> Verify <T>(GridView gv, BindingSource bind) where T : BaseDataContract
        {
            if (gv != null)
            {
                gv.CloseEditor();
            }
            EntityDML <T> voDML = new EntityDML <T>();

            voDML.AddSource       = new List <T>();
            voDML.UpdateSource    = new List <T>();
            voDML.UpdatePreSource = new List <T>();
            if (bind == null || bind.DataSource == null)
            {
                return(voDML);
            }
            List <T> lstT = new List <T>((bind.DataSource as BindingListView <T>));

            if (bind.DataSource is BindingListView <T> && (bind.DataSource as BindingListView <T>).RemoveItemSource != null && (bind.DataSource as BindingListView <T>).RemoveItemSource.Count > 0)
            {
                voDML.DeleteSource = new List <T>();
                foreach (T item in (bind.DataSource as BindingListView <T>).RemoveItemSource)
                {
                    if (item.CopyFieldObject != null)   // 删除
                    {
                        voDML.DeleteSource.Add(item);
                    }
                }
                if (voDML.DeleteSource != null && voDML.DeleteSource.Count > 0)
                {
                    voDML.IsDelete = true;
                }
            }

            if (lstT == null || lstT.Count == 0)
            {
                return(voDML);
            }

            bool          isNumber = false;
            bool          isEqual  = false;
            string        orgValue = string.Empty;
            string        newValue = string.Empty;
            List <string> keys     = null;

            foreach (T item in lstT)
            {
                if (item.CopyFieldObject == null)   // 新加
                {
                    voDML.AddSource.Add(item);
                }
                else                                // 修改
                {
                    if (keys == null)
                    {
                        keys = new List <string>(item.CopyFieldObject.Keys);
                    }
                    item.CopyNewValue();
                    foreach (string key in keys)
                    {
                        if (item.CopyFieldObject[key] == null)
                        {
                            orgValue = string.Empty;
                        }
                        else
                        {
                            orgValue = item.CopyFieldObject[key].ToString();
                        }
                        if (item.NewFieldObject[key] == null)
                        {
                            newValue = string.Empty;
                        }
                        else
                        {
                            newValue = item.NewFieldObject[key].ToString();
                        }
                        isNumber = (Function.IsNumber(orgValue) && Function.IsNumber(newValue)) ? true : false;
                        if (isNumber)
                        {
                            isEqual = Function.Dec(orgValue) == Function.Dec(newValue) ? true : false;
                        }
                        else
                        {
                            isEqual = orgValue == newValue ? true : false;
                        }
                        if (isEqual == false)
                        {
                            item.IsModify = true;
                            voDML.UpdateSource.Add(item);
                            if (item.CloneObject != null)
                            {
                                voDML.UpdatePreSource.Add(item.CloneObject as T);
                            }
                            break;
                        }
                    }
                }
            }
            if (voDML.AddSource != null && voDML.AddSource.Count > 0)
            {
                voDML.IsAdd = true;
            }
            if (voDML.UpdateSource != null && voDML.UpdateSource.Count > 0)
            {
                voDML.IsUpdate = true;
            }
            return(voDML);
        }
示例#2
0
        /// <summary>
        /// Verify
        /// </summary>
        /// <typeparam name="T"></typeparam>
        protected EntityDML <T> Verify <T>() where T : BaseDataContract
        {
            if (gridView != null)
            {
                gridView.CloseEditor();
            }
            else if (gridViewBanded != null)
            {
                gridViewBanded.CloseEditor();
            }
            EntityDML <T> voDML = new EntityDML <T>();

            voDML.AddSource       = new List <T>();
            voDML.UpdateSource    = new List <T>();
            voDML.UpdatePreSource = new List <T>();
            if (gvDataBindingSource == null || gvDataBindingSource.DataSource == null)
            {
                return(voDML);
            }
            List <T> lstT = new List <T>((gvDataBindingSource.DataSource as BindingListView <T>));

            if (gvDataBindingSource.DataSource is BindingListView <T> && (gvDataBindingSource.DataSource as BindingListView <T>).RemoveItemSource != null && (gvDataBindingSource.DataSource as BindingListView <T>).Count > 0)
            {
                voDML.DeleteSource = new List <T>();
                foreach (T item in (gvDataBindingSource.DataSource as BindingListView <T>).RemoveItemSource)
                {
                    if (item.CopyFieldObject != null)   // 删除
                    {
                        voDML.DeleteSource.Add(item);
                    }
                }
                if (voDML.DeleteSource != null && voDML.DeleteSource.Count > 0)
                {
                    voDML.IsDelete = true;
                }
            }

            if (lstT == null || lstT.Count == 0)
            {
                return(voDML);
            }

            string        orgValue = string.Empty;
            string        newValue = string.Empty;
            List <string> keys     = null;

            foreach (T item in lstT)
            {
                if (item.CopyFieldObject == null)   // 新加
                {
                    voDML.AddSource.Add(item);
                }
                else                                // 修改
                {
                    if (keys == null)
                    {
                        keys = new List <string>(item.CopyFieldObject.Keys);
                    }
                    item.CopyNewValue();
                    foreach (string key in keys)
                    {
                        if (item.CopyFieldObject[key] == null)
                        {
                            orgValue = string.Empty;
                        }
                        else
                        {
                            orgValue = item.CopyFieldObject[key].ToString();
                        }
                        if (item.NewFieldObject[key] == null)
                        {
                            newValue = string.Empty;
                        }
                        else
                        {
                            newValue = item.NewFieldObject[key].ToString();
                        }
                        if (orgValue != newValue)
                        {
                            item.IsModify = true;
                            voDML.UpdateSource.Add(item);
                            if (item.CloneObject != null)
                            {
                                voDML.UpdatePreSource.Add(item.CloneObject as T);
                            }
                            break;
                        }
                    }
                }
            }
            if (voDML.AddSource != null && voDML.AddSource.Count > 0)
            {
                voDML.IsAdd = true;
            }
            if (voDML.UpdateSource != null && voDML.UpdateSource.Count > 0)
            {
                voDML.IsUpdate = true;
            }
            return(voDML);
        }