예제 #1
0
        public static T ConvertTypeFromRealToWS <T>(object i)
            where T : class, new()
        {
            T item = Feng.Utils.ReflectionHelper.CreateInstanceFromType(typeof(T)) as T;

            foreach (var p in typeof(T).GetProperties())
            {
                object value = EntityScript.GetPropertyValue(i, p.Name);
                if (value != null)
                {
                    Type propertyType = value.GetType();
                    if (propertyType.IsValueType || propertyType == typeof(string) || propertyType.IsEnum)
                    {
                    }
                    else if (propertyType.GetInterface("IEnumerable") != null)  // Collections
                    {
                        continue;
                    }
                    else
                    {
                        value = value.ToString();
                    }
                }
                EntityScript.SetPropertyValue(item, p.Name, value);
            }
            return(item);
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="searchExpression"></param>
        /// <param name="searchOrders"></param>
        /// <param name="parentItem"></param>
        public override System.Collections.IEnumerable GetData(ISearchExpression searchExpression, IList <ISearchOrder> searchOrders, object parentItem)
        {
            IList <T> list;
            object    masterItem = parentItem;

            if (masterItem != null)
            {
                if (masterItem.GetType() == typeof(T))
                {
                    list = new List <T>();
                    list.Add((T)masterItem);
                }
                else
                {
                    using (var rep = new Repository(this.RepositoryCfgName))
                    {
                        rep.BeginTransaction();
                        object id = EntityScript.GetPropertyValue(masterItem, TypedEntityMetadata.GenerateEntityInfo(rep.Session.SessionFactory, masterItem.GetType()).IdName);
                        NHibernate.ICriteria criteria = rep.Session.CreateCriteria(typeof(T))
                                                        .Add(NHibernate.Criterion.Expression.IdEq(id));
                        OnCriteriaCreated(criteria);
                        list = criteria.List <T>();

                        rep.CommitTransaction();
                    }
                }
            }
            else
            {
                list = new List <T>();
            }

            return(list);
        }
예제 #3
0
        internal static Tuple <string, object> GetEntityValue(string s2, IDisplayManager dm)
        {
            string s1 = s2;
            // maybe there is '.'
            // '.', ':' is invalid in sql
            int    idx = s1.IndexOf('_');
            string dataControlName, propertyName;

            if (idx == -1)
            {
                dataControlName = s1;
                propertyName    = null;
            }
            else
            {
                dataControlName = s1.Substring(0, idx);
                propertyName    = s1.Substring(idx + 1);
            }


            object o = EntityScript.GetPropertyValue(dm.CurrentItem, dataControlName);

            if (!string.IsNullOrEmpty(propertyName))
            {
                propertyName = propertyName.Replace('_', '.');
                o            = EntityScript.GetPropertyValue(o, propertyName);
            }
            return(new Tuple <string, object>(dataControlName, o));
        }
예제 #4
0
        internal static Tuple <string, object> GetDataControlValue(string s2, IDisplayManager dm)
        {
            string s1 = s2;
            // maybe there is '.'
            // '.', ':' is invalid in sql
            int    idx = s1.IndexOf('_');
            string dataControlName, propertyName;

            if (idx == -1)
            {
                dataControlName = s1;
                propertyName    = null;
            }
            else
            {
                dataControlName = s1.Substring(0, idx);
                propertyName    = s1.Substring(idx + 1);
            }

            if (dm.DataControls[dataControlName] == null)
            {
                throw new ArgumentException("there is no IDataControl with name " + dataControlName + "!");
            }
            object o = dm.DataControls[dataControlName].SelectedDataValue;

            if (!string.IsNullOrEmpty(propertyName))
            {
                propertyName = propertyName.Replace('_', '.');
                o            = EntityScript.GetPropertyValue(o, propertyName);
            }
            return(new Tuple <string, object>(dataControlName, o));
        }
        private List <object> GenerateData(object entity, string gridName, List <SoaDataGridColumn> columns)
        {
            Dictionary <string, object> dict;

            using (GridDataConvert dp = new GridDataConvert())
            {
                dict = dp.Process(entity, gridName);
            }

            List <object> ret = new List <object>();

            foreach (SoaDataGridColumn col in columns)
            {
                if (dict.ContainsKey(col.Name))
                {
                    ret.Add(dict[col.Name]);
                }
                else
                {
                    object o = null;
                    try
                    {
                        o = EntityScript.GetPropertyValue(entity, col.Name);
                    }
                    catch (Exception)    // 不一定有这个属性,例如大写金额
                    {
                    }
                    ret.Add(o);
                }
            }

            return(ret);
        }
예제 #6
0
        public static void 批量生成费用付款(IRepository rep, int 费用实体类型, 普通票 票, IEnumerable 箱s, string 费用项编号, 收付标志?收付标志, IList <业务费用理论值> llzs, bool service)
        {
            if (!收付标志.HasValue || 收付标志.Value == Hd.Model.收付标志.付)
            {
                // 生成付款费用
                付款合同 fkht = HdDataBuffer.Instance.Get付款合同(rep, 费用实体类型);
                if (fkht != null)
                {
                    foreach (付款合同费用项 htfyx in fkht.合同费用项)
                    {
                        // 如果指定费用项,则只生成此费用项下的费用
                        if (!string.IsNullOrEmpty(费用项编号) &&
                            htfyx.费用项编号 != 费用项编号)
                        {
                            continue;
                        }

                        // 不是服务运行时(即界面上点按钮),付款合同费用项.是否生成实际费用 = false 不生产费用
                        if (!service && !htfyx.是否生成实际费用)
                        {
                            continue;
                        }

                        批量生成费用(rep, 票, 箱s, Hd.Model.收付标志.付, htfyx, llzs, !string.IsNullOrEmpty(费用项编号));
                    }
                }
                if (费用实体类型 == 11)
                {
                    bool?cybz = ConvertHelper.ToBoolean(EntityScript.GetPropertyValue(票, "承运标志"));
                    if (cybz.HasValue && cybz.Value)
                    {
                        // 受托人合同
                        string str = ConvertHelper.ToString(EntityScript.GetPropertyValue(票, "承运人编号"));
                        if (!string.IsNullOrEmpty(str))
                        {
                            // 生成付款费用
                            受托人合同 strht = HdDataBuffer.Instance.Get受托人合同(rep, 费用实体类型, str);
                            if (strht != null)
                            {
                                foreach (受托人合同费用项 htfyx in strht.合同费用项)
                                {
                                    // 如果指定费用项,则只生成此费用项下的费用
                                    if (!string.IsNullOrEmpty(费用项编号) &&
                                        htfyx.费用项编号 != 费用项编号)
                                    {
                                        continue;
                                    }

                                    批量生成费用(rep, 票, 箱s, Hd.Model.收付标志.付, htfyx, llzs, !string.IsNullOrEmpty(费用项编号));
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #7
0
        public static string Get相关人(IRepository rep, 普通票 票, 普通箱 箱, 合同费用项 htfyx)
        {
            object entity;

            if (箱 != null)
            {
                entity = 箱;
            }
            else
            {
                entity = 票;
            }
            string ret = null;

            if (htfyx is 委托人合同费用项)
            {
                return(票.委托人编号);
            }
            else if (htfyx is 付款合同费用项)
            {
                string mrxgr = (htfyx as 付款合同费用项).默认相关人;
                object r     = EntityScript.CalculateExpression(mrxgr, entity);
                ret = string.IsNullOrEmpty(mrxgr) || r == null ? null : r.ToString().Replace("\"", "");
                if (string.IsNullOrEmpty(ret))
                {
                    ret = null;
                }
            }
            else if (htfyx is 受托人合同费用项)
            {
                object cyr = EntityScript.GetPropertyValue(票, "承运人编号");
                if (cyr != null)
                {
                    return(cyr.ToString());
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                throw new ArgumentException("Invalid htfyx Type!");
            }


            return(ret);
        }
예제 #8
0
        internal static Tuple <string, object> GetDataCellValue(string s2, Xceed.Grid.Cell cell)
        {
            string s1 = s2;
            // maybe there is '.'
            int    idx = s1.IndexOf('_');
            string dataControlName, propertyName;

            if (idx == -1)
            {
                dataControlName = s1;
                propertyName    = null;
            }
            else
            {
                dataControlName = s1.Substring(0, idx);
                propertyName    = s1.Substring(idx + 1);
            }

            object o = null;

            if (cell.ParentRow.Cells[dataControlName] != null)
            {
                o = cell.ParentRow.Cells[dataControlName].Value;
            }
            else
            {
                // 如果未找到Cell,则找父级DataControl
                IDisplayManagerContainer form = cell.GridControl.FindForm() as IDisplayManagerContainer;
                if (form != null)
                {
                    IDataControl parentDc = form.DisplayManager.DataControls[dataControlName];
                    o = parentDc.SelectedDataValue;
                }
            }

            if (!string.IsNullOrEmpty(propertyName))
            {
                propertyName = propertyName.Replace('_', '.');
                o            = EntityScript.GetPropertyValue(o, propertyName);
            }

            //if (o == null)
            //{
            //    throw new ArgumentException("there is no column or datacontrol with name " + s1 + "!");
            //}

            return(new Tuple <string, object>(dataControlName, o));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="dataSource"></param>
        /// <param name="dataMember"></param>
        public void SetDataBinding(object dataSource, string dataMember)
        {
            foreach (DataTable i in m_ds.Tables)
            {
                i.Rows.Clear();
            }

            DataTable dt = dataSource as DataTable;

            if (dt != null)
            {
                foreach (DataRow row in dt.Rows)
                {
                    DataRow newRow = m_ds.Tables[0].NewRow();

                    foreach (DataColumn col in m_ds.Tables[0].Columns)
                    {
                        newRow[col.ColumnName] = row[col.ColumnName];
                    }

                    m_ds.Tables[0].Rows.Add(newRow);
                }
            }
            else
            {
                IEnumerable list = dataSource as IEnumerable;
                if (list != null)
                {
                    foreach (object row in list)
                    {
                        DataRow newRow = m_ds.Tables[0].NewRow();

                        foreach (DataColumn col in m_ds.Tables[0].Columns)
                        {
                            newRow[col.ColumnName] = EntityScript.GetPropertyValue(row, col.ColumnName);
                        }

                        m_ds.Tables[0].Rows.Add(newRow);
                    }
                }
                else
                {
                    throw new NotSupportedException("MyCrystalReportViewer only support DataTable and IList now!");
                }
            }

            OpenReport();
        }
예제 #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="searchExpression"></param>
        /// <param name="searchOrders"></param>
        /// <param name="parentItem"></param>
        /// <returns></returns>
        public override System.Collections.IEnumerable GetData(ISearchExpression searchExpression, IList <ISearchOrder> searchOrders, object parentItem)
        {
            IList <S> list;
            var       parent = parentItem as T;

            if (parent != null && parent.ChildEntity != null)
            {
                if (base.IsReload || NHibernateHelper.IsProxy(parent.ChildEntity))
                {
                    //NHibernateHelper.Initialize(master.ChildEntity, master, reload);
                    //List<S> list = new List<S>();
                    //list.Add(master.ChildEntity);
                    using (var rep = new Repository(this.RepositoryCfgName))
                    {
                        rep.BeginTransaction();
                        object id = EntityScript.GetPropertyValue(parent, TypedEntityMetadata.GenerateEntityInfo(rep.Session.SessionFactory, typeof(T)).IdName);
                        NHibernate.ICriteria criteria = rep.Session.CreateCriteria(typeof(S))
                                                        .Add(NHibernate.Criterion.Expression.IdEq(id));
                        OnCriteriaCreated(criteria);
                        list = criteria.List <S>();

                        rep.CommitTransaction();
                    }
                    if (list.Count > 0)
                    {
                        parent.ChildEntity   = list[0];
                        list[0].ParentEntity = parent;
                    }
                }
                else
                {
                    list = new List <S>();
                    list.Add(parent.ChildEntity);
                }
            }
            else
            {
                list = new List <S>();
            }

            return(list);
        }
예제 #11
0
        private static void Generate(DataTable dt, object entity, string gridName)
        {
            Dictionary <string, object> dict;

            using (GridDataConvert dp = new GridDataConvert())
            {
                dict = dp.Process(entity, gridName);
            }
            if (dict == null || dict.Count == 0)
            {
                return;
            }

            DataRow newRow = dt.NewRow();

            foreach (DataColumn col in dt.Columns)
            {
                if (dict.ContainsKey(col.ColumnName))
                {
                    newRow[col.ColumnName] = (dict[col.ColumnName] != null ? dict[col.ColumnName] : System.DBNull.Value);
                }
                else
                {
                    object o = null;
                    try
                    {
                        o = EntityScript.GetPropertyValue(entity, col.ColumnName);
                    }
                    catch (Exception)    // 不一定有这个属性,例如大写金额
                    {
                    }
                    newRow[col.ColumnName] = o != null ? o : System.DBNull.Value;
                }
            }

            dt.Rows.Add(newRow);
        }
예제 #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="searchExpression"></param>
        /// <param name="searchOrders"></param>
        /// <param name="parentItem"></param>
        /// <returns></returns>
        public override System.Collections.IEnumerable GetData(ISearchExpression searchExpression, IList <ISearchOrder> searchOrders, object parentItem)
        {
            if (parentItem == null)
            {
                return(null);
            }

            SearchHistoryInfo his = this.ParentDisplayManager.SearchManager.GetHistory(0);

            if (!string.IsNullOrEmpty(his.Expression))
            {
                ISearchExpression exp = SearchExpression.Parse(his.Expression);
                exp = RemoveParentSelectAsExpression(exp);
                searchExpression = SearchExpression.And(searchExpression, exp);
            }

            foreach (string s in m_groupByColumns)
            {
                object            r = EntityScript.GetPropertyValue(parentItem, s);
                ISearchExpression se2;

                if (r != null && r != System.DBNull.Value)
                {
                    se2 = SearchExpression.Eq(s, EntityScript.GetPropertyValue(parentItem, s));
                }
                else
                {
                    se2 = SearchExpression.IsNull(s);
                }
                searchExpression = SearchExpression.And(searchExpression, se2);
            }

            this.SetHistory(searchExpression, searchOrders);

            return(m_innerSearchManager.GetData(searchExpression, searchOrders));
        }
예제 #13
0
        private static bool InternalExecuteWindowMenu2(IControlManager cm, WindowMenuInfo info, Form parentForm)
        {
            object entity = cm.DisplayManager.CurrentItem;
            int    pos    = cm.DisplayManager.Position;

            //ArchiveOperationForm opForm = masterForm as ArchiveOperationForm;
            switch (info.Type)
            {
            case WindowMenuType.Add:
            {
                ArchiveOperationForm.DoAddS(cm);
            }
            break;

            case WindowMenuType.Edit:
            {
                ArchiveOperationForm.DoEditS(cm, (parentForm as IGridNamesContainer).GridNames[0]);
            }
            break;

            case WindowMenuType.Delete:
            {
                ArchiveOperationForm.DoDeleteS(cm, (parentForm as IGridNamesContainer).GridNames[0]);
            }
            break;

            case WindowMenuType.Confirm:
            {
                parentForm.ValidateChildren();
                ArchiveDetailForm.DoSaveS(cm);
            }
            break;

            case WindowMenuType.Cancel:
            {
                ArchiveDetailForm.DoCancelS(cm);
            }
            break;

            case WindowMenuType.Submit:
            {
                if (entity == null)
                {
                    MessageForm.ShowError("请选择要提交的项!");
                    return(true);
                }
                if (!MessageForm.ShowYesNo("是否确认提交?"))
                {
                    return(true);
                }

                ISubmittedEntity se = entity as ISubmittedEntity;
                if (se == null)
                {
                    throw new ArgumentException("Submit Entity should be ISubmittedEntity!");
                }
                if (string.IsNullOrEmpty(info.ExecuteParam))
                {
                    cm.EditCurrent();
                    se.Submitted = true;
                    cm.EndEdit();
                }
                else
                {
                    ISubmittedEntityDao dao = Feng.Utils.ReflectionHelper.CreateInstanceFromName(info.ExecuteParam) as ISubmittedEntityDao;
                    if (dao == null)
                    {
                        throw new ArgumentException("Submit windowMenuType's ExecuteParam should be ISubmittedEntityDao!");
                    }

                    using (IRepository rep = dao.GenerateRepository())
                    {
                        try
                        {
                            se.Submitted = true;
                            rep.BeginTransaction();
                            dao.Submit(rep, entity);
                            rep.CommitTransaction();
                            cm.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, pos));
                        }
                        catch (Exception ex)
                        {
                            se.Submitted = false;
                            rep.RollbackTransaction();
                            ExceptionProcess.ProcessWithNotify(ex);
                        }
                    }
                }
            }
            break;

            case WindowMenuType.Unsubmit:
            {
                if (entity == null)
                {
                    MessageForm.ShowError("请选择要撤销提交的项!");
                    return(true);
                }
                if (!MessageForm.ShowYesNo("是否确认撤销提交?", "确认", true))
                {
                    return(true);
                }

                ISubmittedEntity se = entity as ISubmittedEntity;
                if (se == null)
                {
                    throw new ArgumentException("Submit Entity should be ISubmittedEntity!");
                }
                if (string.IsNullOrEmpty(info.ExecuteParam))
                {
                    cm.EditCurrent();
                    se.Submitted = false;
                    cm.EndEdit();
                }
                else
                {
                    ISubmittedEntityDao dao = Feng.Utils.ReflectionHelper.CreateInstanceFromName(info.ExecuteParam) as ISubmittedEntityDao;
                    if (dao == null)
                    {
                        throw new ArgumentException("Submit windowMenuType's ExecuteParam should be ISubmittedEntityDao!");
                    }

                    using (IRepository rep = dao.GenerateRepository())
                    {
                        try
                        {
                            se.Submitted = false;
                            rep.BeginTransaction();
                            dao.Unsubmit(rep, entity);
                            rep.CommitTransaction();
                            cm.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, pos));
                        }
                        catch (Exception ex)
                        {
                            se.Submitted = true;
                            rep.RollbackTransaction();
                            ExceptionProcess.ProcessWithNotify(ex);
                        }
                    }
                }
            }
            break;

            case WindowMenuType.SubmitMulti:
            {
                if (cm.DisplayManager.Count == 0)
                {
                    MessageForm.ShowError("请选择要提交的项!");
                    return(true);
                }
                if (!MessageForm.ShowYesNo("是否确认提交(当前全部)?"))
                {
                    return(true);
                }

                ISubmittedEntity se = entity as ISubmittedEntity;
                if (se == null)
                {
                    throw new ArgumentException("Submit Entity should be ISubmittedEntity!");
                }
                if (string.IsNullOrEmpty(info.ExecuteParam))
                {
                    IBatchDao batchDao = cm.Dao as IBatchDao;
                    if (batchDao != null)
                    {
                        batchDao.SuspendOperation();
                    }

                    for (int i = 0; i < cm.DisplayManager.Count; ++i)
                    {
                        cm.DisplayManager.Position = i;
                        cm.EditCurrent();
                        (cm.DisplayManager.Items[i] as ISubmittedEntity).Submitted = true;
                        cm.EndEdit();
                    }

                    if (batchDao != null)
                    {
                        batchDao.ResumeOperation();
                    }
                }
                else
                {
                    ISubmittedEntityDao dao = Feng.Utils.ReflectionHelper.CreateInstanceFromName(info.ExecuteParam) as ISubmittedEntityDao;
                    if (dao == null)
                    {
                        throw new ArgumentException("Submit windowMenuType's ExecuteParam should be ISubmittedEntityDao!");
                    }

                    using (IRepository rep = dao.GenerateRepository())
                    {
                        try
                        {
                            rep.BeginTransaction();
                            for (int i = 0; i < cm.DisplayManager.Count; ++i)
                            {
                                (cm.DisplayManager.Items[i] as ISubmittedEntity).Submitted = true;
                                dao.Submit(rep, cm.DisplayManager.Items[i]);
                            }
                            rep.CommitTransaction();
                            cm.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, pos));
                        }
                        catch (Exception ex)
                        {
                            se.Submitted = false;
                            rep.RollbackTransaction();
                            ExceptionProcess.ProcessWithNotify(ex);
                        }
                    }
                }
            }
            break;

            case WindowMenuType.Cancellate:
            {
                if (entity == null)
                {
                    MessageForm.ShowError("请选择要作废的项!");
                    return(true);
                }
                if (!MessageForm.ShowYesNo("是否确认作废?", "确认", true))
                {
                    return(true);
                }

                ICancellateDao dao = Feng.Utils.ReflectionHelper.CreateInstanceFromName(info.ExecuteParam) as ICancellateDao;
                if (dao == null)
                {
                    throw new ArgumentException("Submit windowMenuType's ExecuteParam should be ICancellateDao!");
                }
                using (IRepository rep = dao.GenerateRepository())
                {
                    try
                    {
                        rep.BeginTransaction();
                        dao.Cancellate(rep, entity);
                        rep.CommitTransaction();
                        cm.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, pos));
                    }
                    catch (Exception ex)
                    {
                        rep.RollbackTransaction();
                        ExceptionProcess.ProcessWithNotify(ex);
                    }
                }
            }
            break;

            case WindowMenuType.DaoProcess:
            {
                if (entity == null)
                {
                    MessageForm.ShowError("请选择要操作的项!");
                    return(true);
                }
                if (!MessageForm.ShowYesNo("是否要执行" + info.Text + "?"))
                {
                    return(true);
                }

                string[] ss = info.ExecuteParam.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                if (ss.Length != 2)
                {
                    throw new ArgumentException("DaoProcess windowMenuType's ExecuteParam should be IDao;MethodName!");
                }
                IRepositoryDao dao = Feng.Utils.ReflectionHelper.CreateInstanceFromName(ss[0].Trim()) as IRepositoryDao;
                if (dao == null)
                {
                    throw new ArgumentException("DaoProcess windowMenuType's ExecuteParam's first part should be IDao!");
                }

                using (IRepository rep = dao.GenerateRepository())
                {
                    try
                    {
                        rep.BeginTransaction();
                        Feng.Utils.ReflectionHelper.RunInstanceMethod(ss[0].Trim(), ss[1].Trim(), dao, new object[] { rep, entity });
                        rep.CommitTransaction();
                        cm.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, pos));
                    }
                    catch (Exception ex)
                    {
                        rep.RollbackTransaction();
                        ExceptionProcess.ProcessWithNotify(ex);
                    }
                }
            }
            break;

            case WindowMenuType.Select:
            {
                string[] ss = info.ExecuteParam.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                if (ss.Length == 0)
                {
                    throw new ArgumentException("WindowMenu's ExecuteParam is Invalid of WindowMenu " + info.Name);
                }
                ArchiveCheckForm form = ServiceProvider.GetService <IWindowFactory>().CreateWindow(ADInfoBll.Instance.GetWindowInfo(ss[0])) as ArchiveCheckForm;
                if (ss.Length > 1)
                {
                    string exp = ss[1];
                    exp = EntityHelper.ReplaceEntity(exp, new EntityHelper.GetReplaceValue(delegate(string paramName)
                        {
                            Tuple <string, object> t = EventProcessUtils.GetDataControlValue(paramName, cm.DisplayManager);
                            if (t.Item2 == null)
                            {
                                throw new InvalidUserOperationException(string.Format("请先填写{0}!", paramName));
                            }
                            cm.DisplayManager.DataControls[t.Item1].ReadOnly = true;
                            // save controlValue to entity because readonly will not save
                            EntityScript.SetPropertyValue(cm.DisplayManager.CurrentItem, t.Item1, t.Item2);

                            return(t.Item2);
                        }));
                    if (string.IsNullOrEmpty(form.DisplayManager.SearchManager.AdditionalSearchExpression))
                    {
                        form.DisplayManager.SearchManager.AdditionalSearchExpression = exp;
                    }
                    else
                    {
                        form.DisplayManager.SearchManager.AdditionalSearchExpression = "(" + form.DisplayManager.SearchManager.AdditionalSearchExpression + ") and " + exp;
                    }
                }

                int detailGridIdx = 0;
                if (ss.Length > 2)
                {
                    detailGridIdx = Feng.Utils.ConvertHelper.ToInt(ss[2]).Value;
                }
                if (form.ShowDialog(parentForm) == System.Windows.Forms.DialogResult.OK)
                {
                    IControlManager detailCm = (((IArchiveDetailFormWithDetailGrids)(parentForm as IArchiveMasterForm).ArchiveDetailForm).DetailGrids[detailGridIdx] as IArchiveGrid).ControlManager;

                    var nowList = detailCm.DisplayManager.Items;
                    foreach (object i in form.SelectedEntites)
                    {
                        if (nowList.Contains(i))
                        {
                            continue;
                        }

                        detailCm.AddNew();
                        detailCm.DisplayManager.Items[detailCm.DisplayManager.Position] = i;
                        detailCm.EndEdit();
                    }
                }
                form.Dispose();
            }
            break;

            case WindowMenuType.Input:
                throw new NotSupportedException("Not supported now!");

            case WindowMenuType.ManyToOneWindow:
            {
                if (cm.DisplayManager.CurrentItem == null)
                {
                    MessageForm.ShowInfo("无当前项,不能操作!");
                    return(true);
                }
                string[] ss = info.ExecuteParam.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                if (ss.Length < 2)
                {
                    throw new ArgumentException("WindowMenu's ExecuteParam is Invalid of WindowMenu " + info.Name);
                }
                ArchiveDetailForm selectForm   = ServiceProvider.GetService <IWindowFactory>().CreateWindow(ADInfoBll.Instance.GetWindowInfo(ss[0])) as ArchiveDetailForm;
                string            propertyName = ss[1];
                object            masterEntity = EntityScript.GetPropertyValue(cm.DisplayManager.CurrentItem, propertyName);
                if (masterEntity == null)
                {
                    ArchiveOperationForm.DoAddS(selectForm.ControlManager);
                    selectForm.UpdateContent();
                    if (selectForm.ShowDialog(parentForm) == System.Windows.Forms.DialogResult.OK)
                    {
                        cm.EditCurrent();
                        EntityScript.SetPropertyValue(cm.DisplayManager.CurrentItem, propertyName, selectForm.DisplayManager.CurrentItem);
                        cm.EndEdit();

                        cm.OnCurrentItemChanged();
                    }
                }
                else
                {
                    selectForm.ControlManager.AddNew();
                    selectForm.DisplayManager.Items[selectForm.DisplayManager.Position] = masterEntity;
                    selectForm.ControlManager.EndEdit(false);
                    ArchiveOperationForm.DoEditS(selectForm.ControlManager, selectForm.GridName);
                    selectForm.UpdateContent();

                    if (selectForm.ShowDialog(parentForm) == System.Windows.Forms.DialogResult.OK)
                    {
                        ((parentForm as IArchiveMasterForm).MasterGrid as IBoundGrid).ReloadData();
                    }
                }
                selectForm.Dispose();
            }
            break;

            default:
                return(false);
            }
            return(true);
        }
예제 #14
0
        /// <summary>
        /// 根据Entity的值设置row's cell值
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="entity"></param>
        /// <param name="row"></param>
        public static void SetDataRowsIListData(this IBoundGrid grid, object entity, Xceed.Grid.DataRow row)
        {
            // 如果同一个实体类,只是里面内容变了,重新设置不会设置成功
            row.Tag = null;
            if (entity == null)
            {
                return;
            }

            row.Tag = entity;

            foreach (GridColumnInfo info in ADInfoBll.Instance.GetGridColumnInfos(grid.GridName))
            {
                try
                {
                    switch (info.GridColumnType)
                    {
                    case GridColumnType.Normal:
                        if (row.Cells[info.GridColumnName] != null && !string.IsNullOrEmpty(info.PropertyName))
                        {
                            row.Cells[info.GridColumnName].Value = EntityScript.GetPropertyValue(entity, info.Navigator, info.PropertyName);
                        }
                        break;

                    case GridColumnType.WarningColumn:
                        row.Cells[info.GridColumnName].Value = (row.Cells[info.GridColumnName].ParentColumn as WarningColumn).Calculate(entity);
                        break;

                    case GridColumnType.StatColumn:
                    {
                        if (row.DetailGrids.Count == 0)
                        {
                            return;
                            //throw new ArgumentException("stateColumn should has detailgrids.");
                        }

                        row.Cells[info.GridColumnName].Value = Feng.Utils.ConvertHelper.ChangeType(
                            MySummaryRow.GetSummaryResult(row.DetailGrids[0].GetSortedDataRows(true), info.PropertyName), row.Cells[info.GridColumnName].ParentColumn.DataType);
                    }
                    break;

                    case GridColumnType.ExpressionColumn:
                    {
                        //var info2 = info;
                        //var row2 = row;
                        //Feng.Async.AsyncHelper.Start(() =>
                        //{
                        //    if (info2.PropertyName.Contains("%"))
                        //    {
                        //        return EntityScript.CalculateExpression(info2.PropertyName, entity);
                        //    }
                        //    else
                        //    {
                        //        return Feng.Utils.ProcessInfoHelper.TryExecutePython(info2.PropertyName,
                        //            new Dictionary<string, object>() { { "entity", entity }, { "row", row2 } });
                        //    }
                        //}, (result) =>
                        //{
                        //    row2.Cells[info2.GridColumnName].Value = result;
                        //});
                        if (info.PropertyName.Contains("%"))
                        {
                            row.Cells[info.GridColumnName].Value = EntityScript.CalculateExpression(info.PropertyName, entity);
                        }
                        else
                        {
                            row.Cells[info.GridColumnName].Value = ProcessInfoHelper.TryExecutePython(info.PropertyName,
                                                                                                      new Dictionary <string, object>()
                                {
                                    { "entity", entity }, { "row", row }
                                });
                        }
                    }
                    break;

                    case GridColumnType.ImageColumn:
                    {
                        var i = Feng.Windows.ImageResource.Get(info.PropertyName);
                        row.Cells[info.GridColumnName].Value = i == null ? null : i.Reference;
                    }
                    break;

                    case GridColumnType.CheckColumn:
                    {
                        row.Cells[info.GridColumnName].Value = false;
                    }
                    break;

                    case GridColumnType.NoColumn:
                    case GridColumnType.SplitColumn:
                        break;

                    case GridColumnType.UnboundColumn:
                    {
                        try
                        {
                            row.Cells[info.GridColumnName].Value = Feng.Utils.ConvertHelper.ChangeType(info.PropertyName, Feng.Utils.ReflectionHelper.GetTypeFromName(info.TypeName));
                        }
                        catch (Exception)
                        {
                        }
                    }
                    break;

                    case GridColumnType.IndexColumn:
                    {
                        row.Cells[info.GridColumnName].Value = row.Index + 1;
                    }
                    break;

                    default:
                        throw new NotSupportedException("invalid GridColumnType of " + info.GridColumnType);
                    }
                }
                catch (Exception ex)
                {
                    ExceptionProcess.ProcessWithResume(new ArgumentException(info.PropertyName + " info is invalid!", ex));
                }
            }
        }
예제 #15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="gridName"></param>
        /// <returns></returns>
        public Dictionary <string, object> Process(object entity, string gridName)
        {
            Dictionary <string, object> r = new Dictionary <string, object>();

            // grid
            if (!Authority.AuthorizeByRule(ADInfoBll.Instance.GetGridInfo(gridName).Visible))
            {
                return(r);
            }

            // row
            if (!Permission.AuthorizeByRule(ADInfoBll.Instance.GetGridRowInfo(gridName).Visible, entity))
            {
                return(r);
            }

            // column
            foreach (GridColumnInfo info in ADInfoBll.Instance.GetGridColumnInfos(gridName))
            {
                object v = null;
                if ((m_useColumnVisible && !Authority.AuthorizeByRule(info.ColumnVisible)) ||
                    (!m_useColumnVisible && !Authority.AuthorizeByRule(info.DataControlVisible)))
                {
                    continue;
                }
                else
                {
                    if (info.GridColumnType != GridColumnType.Normal &&
                        info.GridColumnType != GridColumnType.ExpressionColumn)
                    {
                        continue;
                    }
                    if (string.IsNullOrEmpty(info.PropertyName))
                    {
                        v = null;
                    }
                    else if (info.GridColumnType == GridColumnType.Normal)
                    {
                        v = EntityScript.GetPropertyValue(entity, info.Navigator, info.PropertyName);
                    }
                    else if (info.GridColumnType == GridColumnType.ExpressionColumn)
                    {
                        if (info.PropertyName.Contains("%"))
                        {
                            v = EntityScript.CalculateExpression(info.PropertyName, entity);
                        }
                        else
                        {
                            v = ProcessInfoHelper.TryExecutePython(info.PropertyName,
                                                                   new Dictionary <string, object>()
                            {
                                { "entity", entity }
                            });
                        }
                    }
                    else
                    {
                        continue;
                    }
                }

                if (v == System.DBNull.Value)
                {
                    v = null;
                }
                if (v == null)
                {
                    r[info.GridColumnName] = null;
                    continue;
                }

                string vs = null;
                if (GridColumnInfoHelper.CreateType(info).IsEnum)
                {
                    vs = v.ToString();
                }

                switch (info.CellViewerManager)
                {
                case "Combo":
                case "MultiCombo":
                    vs = GetViewerText(v, info);
                    break;

                case "Object":
                    vs = EntityHelper.ReplaceEntity(info.CellViewerManagerParam, v, null);
                    break;

                case "Numeric":
                case "Integer":
                case "Long":
                case "Currency":
                    vs = Convert.ToDouble(v).ToString(GetFormatString(info));
                    break;

                case "Date":
                case "DateTime":
                    vs = Convert.ToDateTime(v).ToString(GetFormatString(info));
                    break;

                default:
                    vs = v.ToString();
                    break;
                }

                r[info.GridColumnName] = vs;

                //// cell
                //foreach (GridCellInfo info in GridSettingInfoCollection.Instance[gridName].GridCellInfos)
                //{
                //}
            }

            return(r);
        }
예제 #16
0
        private void tsbAttachment_Click(object sender, EventArgs e)
        {
            if (this.AttachmentForm == null)
            {
                return;
            }

            object entity = this.DisplayManager.CurrentItem;

            if (entity == null)
            {
                MessageForm.ShowWarning("请选择当前行!");
                return;
            }

            Type entityType = entity.GetType();
            var  sm         = ServiceProvider.GetService <Feng.NH.ISessionFactoryManager>();

            if (sm == null)
            {
                return;
            }
            NHibernate.ISessionFactory sessionFactory = sm.GetSessionFactory(Feng.Utils.RepositoryHelper.GetConfigNameFromType(entityType));
            if (sessionFactory == null)
            {
                return;
            }

            bool hasCollection;

            int idx = m_attachmentEntityIdExp.LastIndexOf('.');

            if (idx != -1)
            {
                string navi = m_attachmentEntityIdExp.Substring(0, idx);
                entityType = Feng.NH.NHibernateHelper.GetPropertyType(sessionFactory, entityType, navi, out hasCollection);
            }

            NHibernate.Metadata.IClassMetadata metaData = sessionFactory.GetClassMetadata(entityType);
            string entityName = metaData.EntityName;
            object id         = EntityScript.GetPropertyValue(entity, m_attachmentEntityIdExp);
            string entityId;

            //object id = EntityHelper.GetPropertyValue(entity, metaData.IdentifierPropertyName);
            if (id != null)
            {
                entityId = id.ToString();
            }
            else
            {
                MessageForm.ShowWarning("当前行无Id!");
                return;
            }

            string formText = entityName + ":" + entityId;
            IArhiveOperationMasterForm form = this.AttachmentForm;
            var form2 = form as ArchiveSeeForm;

            form2.tsbSearch.Visible = false;
            form.Text = formText + " 的附件";
            form.Show();
            form.DoView();

            form.DisplayManager.SearchManager.LoadData(SearchExpression.And(
                                                           SearchExpression.Eq("EntityName", entityName), SearchExpression.Eq("EntityId", entityId)), null);

            m_attachmentEntityName = entityName;
            m_attachmentEntityId   = entityId;
            //(form.ControlManager.Dao as BaseDao<AttachmentInfo>).EntityOperating += new EventHandler<OperateArgs<AttachmentInfo>>(delegate(object sender1, OperateArgs<AttachmentInfo> e1)
            //{
            //    e1.Entity.EntityName = entityName;
            //    e1.Entity.EntityId = entityId;
            //});

            (form.ControlManager.Dao as BaseDao <AttachmentInfo>).EntityOperating -= new EventHandler <OperateArgs <AttachmentInfo> >(AttachmentForm_EntityOperating);
            (form.ControlManager.Dao as BaseDao <AttachmentInfo>).EntityOperating += new EventHandler <OperateArgs <AttachmentInfo> >(AttachmentForm_EntityOperating);
        }
예제 #17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="columnName"></param>
        /// <returns></returns>
        protected object GetListValue(object entity, string columnName)
        {
            GridColumnInfo info = m_infos[columnName];

            return(EntityScript.GetPropertyValue(entity, info.Navigator, info.PropertyName));
        }
예제 #18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dataSource"></param>
        /// <param name="dataMember"></param>
        /// <param name="hereLevel"></param>
        protected void SetDataRows(object dataSource, string dataMember, int hereLevel)
        {
            try
            {
                this.DisplayManager.BeginBatchOperation();

                this.DataRows.Clear();

                System.Collections.Generic.Dictionary <string, Xceed.Grid.DataRow> masterRows =
                    new System.Collections.Generic.Dictionary <string, Xceed.Grid.DataRow>();

                DataTable dt = dataSource as DataTable;
                if (dt == null)
                {
                    IEnumerable list = dataSource as IEnumerable;
                    if (list != null)
                    {
                        foreach (object entity in list)
                        {
                            for (int i = 0; i <= hereLevel; ++i)
                            {
                                Xceed.Grid.DataRow gridRow = null;

                                if (i < hereLevel || i == 0)
                                {
                                    if (!masterRows.ContainsKey(GetListValue(entity, m_levelParents[i]).ToString()))
                                    {
                                        if (i == 0)
                                        {
                                            gridRow = this.DataRows.AddNew();
                                            masterRows[GetListValue(entity, m_levelParents[i]).ToString()] = gridRow;
                                        }
                                        else
                                        {
                                            gridRow = masterRows[GetListValue(entity, m_levelParents[i - 1]).ToString()].DetailGrids[0].DataRows.AddNew();
                                        }
                                    }
                                    else
                                    {
                                        gridRow = masterRows[GetListValue(entity, m_levelParents[i]).ToString()];
                                    }
                                }
                                else
                                {
                                    gridRow = masterRows[GetListValue(entity, m_levelParents[i - 1]).ToString()].DetailGrids[0].DataRows.AddNew();
                                }
                                gridRow.EndEdit();

                                gridRow.Tag = entity;
                                foreach (string columnName in m_gridColumnNames[i])
                                {
                                    GridColumnInfo info = m_infos[columnName];

                                    switch (info.GridColumnType)
                                    {
                                    case GridColumnType.Normal:
                                        if (gridRow.Cells[info.GridColumnName] != null && !string.IsNullOrEmpty(info.PropertyName))
                                        {
                                            gridRow.Cells[info.GridColumnName].Value = EntityScript.GetPropertyValue(entity, info.Navigator, info.PropertyName);
                                        }
                                        break;

                                    case GridColumnType.WarningColumn:
                                        gridRow.Cells[info.GridColumnName].Value = (gridRow.Cells[info.GridColumnName].ParentColumn as WarningColumn).Calculate(entity);
                                        break;

                                    case GridColumnType.StatColumn:
                                    case GridColumnType.ExpressionColumn:
                                    case GridColumnType.ImageColumn:
                                    case GridColumnType.SplitColumn:
                                    case GridColumnType.CheckColumn:
                                    case GridColumnType.NoColumn:
                                        break;

                                    default:
                                        throw new NotSupportedException("invalid GridColumnType of " + info.GridColumnType);
                                    }
                                    //
                                    //gridRow.Cells[columnName].Value = GetListValue(entity, columnName);
                                }
                                gridRow.EndEdit();
                            }
                        }
                    }

                    Dictionary <Xceed.Grid.DataRow, bool> m_processdRows = new Dictionary <Xceed.Grid.DataRow, bool>();
                    foreach (object entity in list)
                    {
                        for (int i = 0; i < hereLevel; ++i)
                        {
                            Xceed.Grid.DataRow gridRow = masterRows[GetListValue(entity, m_levelParents[i]).ToString()];
                            if (!m_processdRows.ContainsKey(gridRow))
                            {
                                m_processdRows[gridRow] = true;
                            }
                            else
                            {
                                continue;
                            }
                            foreach (string columnName in m_gridColumnNames[i])
                            {
                                GridColumnInfo info = m_infos[columnName];
                                switch (info.GridColumnType)
                                {
                                case GridColumnType.StatColumn:
                                {
                                    if (gridRow.DetailGrids.Count == 0)
                                    {
                                        throw new ArgumentException("stateColumn should has detailgrids.");
                                    }
                                    gridRow.Cells[info.GridColumnName].Value = Feng.Utils.ConvertHelper.ChangeType(
                                        MySummaryRow.GetSummaryResult(gridRow.DetailGrids[0].GetSortedDataRows(true), info.PropertyName), gridRow.Cells[info.GridColumnName].ParentColumn.DataType);
                                }
                                break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    foreach (System.Data.DataRow dataRow in dt.Rows)
                    {
                        for (int i = 0; i <= hereLevel; ++i)
                        {
                            Xceed.Grid.DataRow gridRow = null;

                            if (i < hereLevel || i == 0)
                            {
                                if (!masterRows.ContainsKey(dataRow[m_levelParents[i]].ToString()))
                                {
                                    if (i == 0)
                                    {
                                        gridRow = this.DataRows.AddNew();

                                        masterRows[dataRow[m_levelParents[i]].ToString()] = gridRow;
                                    }
                                    else
                                    {
                                        gridRow = masterRows[dataRow[m_levelParents[i - 1]].ToString()].DetailGrids[0].DataRows.AddNew();
                                    }
                                }
                                else
                                {
                                    gridRow = masterRows[dataRow[m_levelParents[i]].ToString()];
                                }
                            }
                            else
                            {
                                gridRow = masterRows[dataRow[m_levelParents[i - 1]].ToString()].DetailGrids[0].DataRows.AddNew();
                            }

                            // 如果在下方EndEdit,DetailGrid可能不会生成,不知原因
                            gridRow.EndEdit();

                            gridRow.Tag = dataRow;
                            foreach (string columnName in m_gridColumnNames[i])
                            {
                                GridColumnInfo info = m_infos[columnName];

                                switch (info.GridColumnType)
                                {
                                case GridColumnType.Normal:
                                {
                                    if (!dt.Columns.Contains(columnName))
                                    {
                                        continue;
                                    }
                                    if (gridRow.Cells[info.GridColumnName] != null && !string.IsNullOrEmpty(info.PropertyName))
                                    {
                                        gridRow.Cells[info.GridColumnName].Value = (dataRow[columnName] == System.DBNull.Value ?
                                                                                    null : Feng.Utils.ConvertHelper.TryIntToEnum(dataRow[columnName], GridColumnInfoHelper.CreateType(m_infos[columnName])));
                                    }
                                }
                                break;

                                case GridColumnType.WarningColumn:
                                    throw new NotSupportedException("warning column is not supported in datarow.");

                                case GridColumnType.StatColumn:
                                case GridColumnType.ExpressionColumn:
                                case GridColumnType.ImageColumn:
                                case GridColumnType.SplitColumn:
                                case GridColumnType.CheckColumn:
                                case GridColumnType.NoColumn:
                                    break;

                                default:
                                    throw new NotSupportedException("invalid GridColumnType of " + info.GridColumnType);
                                }
                            }
                            gridRow.EndEdit();
                        }
                    }

                    Dictionary <Xceed.Grid.DataRow, bool> m_processdRows = new Dictionary <Xceed.Grid.DataRow, bool>();
                    foreach (System.Data.DataRow dataRow in dt.Rows)
                    {
                        for (int i = 0; i < hereLevel; ++i)
                        {
                            Xceed.Grid.DataRow gridRow = masterRows[dataRow[m_levelParents[i]].ToString()];
                            if (!m_processdRows.ContainsKey(gridRow))
                            {
                                m_processdRows[gridRow] = true;
                            }
                            else
                            {
                                continue;
                            }
                            foreach (string columnName in m_gridColumnNames[i])
                            {
                                GridColumnInfo info = m_infos[columnName];
                                switch (info.GridColumnType)
                                {
                                case GridColumnType.StatColumn:
                                {
                                    if (gridRow.DetailGrids.Count == 0)
                                    {
                                        throw new ArgumentException("stateColumn should has detailgrids.");
                                    }

                                    gridRow.Cells[info.GridColumnName].Value = Feng.Utils.ConvertHelper.ChangeType(
                                        MySummaryRow.GetSummaryResult(gridRow.DetailGrids[0].GetSortedDataRows(true), info.PropertyName), gridRow.Cells[info.GridColumnName].ParentColumn.DataType);
                                }
                                break;
                                }
                            }
                        }
                    }
                }

                this.AfterLoadData();
            }
            finally
            {
                this.DisplayManager.EndBatchOperation();
                this.DisplayManager.OnPositionChanged(System.EventArgs.Empty);
            }
        }