internal static ISearchExpression GetSearchExpressionFromGrid(IArchiveMasterForm sourceForm, GridRelatedAddressInfo info, bool onlyFirstOne)
        {
            if (sourceForm == null)
            {
                throw new ArgumentException("未能找到父窗体!", "sourceForm");
            }

            if (info.RelatedType == GridRelatedType.ByRows)
            {
                if (sourceForm.MasterGrid == null)
                {
                    throw new ArgumentException("未能找到主表格!", "sourceForm");
                }

                List <object> selectedEntities = new List <object>();
                if (sourceForm.MasterGrid.GridControl.SelectedRows.Count == 0)
                {
                    Xceed.Grid.Row     row     = sourceForm.MasterGrid.CurrentRow;
                    Xceed.Grid.DataRow dataRow = row as Xceed.Grid.DataRow;
                    if (dataRow != null && dataRow.Visible &&
                        (Feng.Grid.MyGrid.GetGridLevel(dataRow.ParentGrid) == info.GridLevel || string.IsNullOrEmpty(info.GridLevel)))
                    {
                        selectedEntities.Add(dataRow.Tag);
                    }
                }
                else
                {
                    foreach (Xceed.Grid.Row row in sourceForm.MasterGrid.GridControl.SelectedRows)
                    {
                        if (!row.Visible)
                        {
                            continue;
                        }

                        Xceed.Grid.DataRow dataRow = row as Xceed.Grid.DataRow;
                        if (dataRow == null)
                        {
                            continue;
                        }

                        if (Feng.Grid.MyGrid.GetGridLevel(dataRow.ParentGrid) == info.GridLevel ||
                            string.IsNullOrEmpty(info.GridLevel))
                        {
                            selectedEntities.Add(dataRow.Tag);
                        }
                        else
                        {
                            foreach (Xceed.Grid.DetailGrid dg in dataRow.DetailGrids)
                            {
                                GetDetailGridRows(info, dataRow.DetailGrids[0], selectedEntities);
                            }
                        }

                        if (onlyFirstOne && selectedEntities.Count > 0)
                        {
                            break;
                        }
                    }
                }

                if (selectedEntities.Count == 0)
                {
                    throw new InvalidOperationException("请选择表格行!");
                }


                Dictionary <string, string> exps = new Dictionary <string, string>();
                foreach (object entity in selectedEntities)
                {
                    //if (entity.GetType() != Feng.Utils.ReflectionHelper.GetTypeFromName(info.EntityType))
                    //    continue;

                    string exp = EntityHelper.ReplaceEntity(info.SearchExpression, entity);
                    exps[exp] = exp;
                }
                ISearchExpression se = null;
                foreach (string exp in exps.Keys)
                {
                    ISearchExpression subSearch = SearchExpression.Parse(exp);
                    if (se == null)
                    {
                        se = subSearch;
                    }
                    else
                    {
                        se = SearchExpression.Or(se, subSearch);
                    }
                }
                return(se);

                //string[] fromColumns = info.FromColumnName.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                //for (int i = 0; i < fromColumns.Length; ++i)
                //{
                //    fromColumns[i] = fromColumns[i].Replace(":", ".");
                //}
                //int count = fromColumns.Length;
                //string[] toColumns = info.ToColumnName.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                //Debug.Assert(count == toColumns.Length, "FromColumnName必须和ToColumnName内容个数相同");

                //ArrayList[] selected = new ArrayList[count];

                //for (int i = 0; i < count; ++i)
                //{
                //    selected[i] = new ArrayList();
                //    string columnName = fromColumns[i];

                //    foreach (object entity in selectedEntities)
                //    {
                //        object o = EntityHelper.GetPropertyValue(entity, columnName);
                //        //if (o != null && !string.IsNullOrEmpty(o.ToString()))
                //        {
                //            selected[i].Add(o);
                //        }
                //    }
                //}
            }
            else
            {
                throw new NotSupportedException("Not Supported now!");
            }
        }
Ejemplo n.º 2
0
        public static void EditLlz(ArchiveSeeForm masterForm)
        {
            Xceed.Grid.Row row = (masterForm.ArchiveDetailForm as IArchiveDetailFormWithDetailGrids).DetailGrids[0].CurrentRow;
            if (row == null)
            {
                throw new InvalidUserOperationException("请选择要编辑理论值的合同费用项!");
            }
            合同费用项 htfyx = (row as Xceed.Grid.DataRow).Tag as 合同费用项;

            using (IRepository rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository <费用理论值信息>())
            {
                rep.Initialize(htfyx.费用理论值, htfyx);
            }

            IList <string> llzs = new List <string>();

            if (htfyx.费用理论值 != null)
            {
                foreach (费用理论值信息 i in htfyx.费用理论值)
                {
                    llzs.Add(i.条件);
                    llzs.Add(i.结果);
                }
            }

            Hd.Service.理论值编辑.FrmEditor form = new Hd.Service.理论值编辑.FrmEditor(
                new Dictionary <string, string> {
                { "委托人编号", "人员单位_委托人" }, { "船公司编号", "人员单位_船公司" },
                { "箱型编号", "备案_箱型_全部" }, { "提箱地编号", "人员单位_港区堆场" }, { "费用项编号", "费用项_全部" }
            },
                llzs);
            if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                IList <string> ret = form.GetResult();
                using (IRepository rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository <费用理论值信息>())
                {
                    try
                    {
                        rep.BeginTransaction();
                        foreach (费用理论值信息 i in htfyx.费用理论值)
                        {
                            rep.Delete(i);
                        }
                        htfyx.费用理论值.Clear();
                        for (int i = 0; i < ret.Count; i += 2)
                        {
                            费用理论值信息 item = new 费用理论值信息();
                            item.合同费用项 = htfyx;
                            item.结果    = ret[i + 1];
                            item.条件    = ret[i];
                            item.序号    = i / 2;

                            (new HdBaseDao <费用理论值信息>()).Save(rep, item);
                            htfyx.费用理论值.Add(item);
                        }

                        rep.CommitTransaction();
                    }
                    catch (Exception ex)
                    {
                        rep.RollbackTransaction();
                        ServiceProvider.GetService <IExceptionProcess>().ProcessWithNotify(ex);
                    }
                }
            }
        }