Esempio n. 1
0
        /// <summary>
        /// 在医嘱的DataTable中找到指定医嘱对象对应的行,并返回
        /// </summary>
        /// <param name="order"></param>
        /// <returns>医嘱所在行,不存在则返回null</returns>
        public DataRow GetOrderRow(Order order)
        {
            if (order == null)
            {
                throw new ArgumentNullException();
            }

            if ((order.EditState == OrderEditState.Added) ||
                (order.EditState == OrderEditState.Detached))
            {
                return(null);
            }

            // 通过医嘱序号来定位
            DataRow[] rows = OrderDataTable.Select(String.Format(CultureInfo.CurrentCulture
                                                                 , "{0} = {1}"
                                                                 , CoreBusinessLogic.GetSerialNoField(IsTempOrder)
                                                                 , order.SerialNo));
            if (rows.Length == 1)
            {
                return(rows[0]);
            }
            else if (rows.Length > 1)
            {
                throw new ArgumentException(ConstMessages.ExceptionHaveManyMatchRows);
            }
            else
            {
                throw new ArgumentOutOfRangeException();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 同步医嘱对象集合和DataTable的数据
        /// </summary>
        /// <param name="changedOrders"></param>
        /// <param name="autoDeleteNewOrder">是否主动删除所有新增状态的医嘱</param>
        /// <returns>返回DataTable的更新内容</returns>
        public DataTable SyncObjectData2Table(Order[] changedOrders, bool autoDeleteNewOrder)
        {
            // 新增和修改过的医嘱,统一将更新标志设为0

            // 首先同步修改过的医嘱,取出新医嘱稍后处理
            StringBuilder      deletedSerialNos = new StringBuilder("0, ");
            Collection <Order> newOrders        = new Collection <Order>();

            if ((changedOrders != null) && (changedOrders.Length > 0))
            {
                DataRow row;
                foreach (Order order in changedOrders)
                {
                    if (order.EditState == OrderEditState.Deleted)
                    {
                        deletedSerialNos.Append(order.SerialNo.ToString() + ",");
                    }
                    else if (order.State == OrderState.New)
                    {
                        newOrders.Add(order);
                    }
                    else
                    {
                        row = GetOrderRow(order);
                        PersistentObjectFactory.SetDataRowValueFromObject(row, order);
                        row[ConstSchemaNames.OrderColSynchFlag] = 0;
                    }
                }
            }
            deletedSerialNos.Append("0");

            // 如果自动删除新医嘱,则将DataTable中的新医嘱全部删除, 否则只删除标记为删除的医嘱
            string filter;

            if (autoDeleteNewOrder)
            {
                filter = String.Format(CultureInfo.CurrentCulture, "{1} = {0:D}", OrderState.New, ConstSchemaNames.OrderColState);
            }
            else
            {
                filter = String.Format(CultureInfo.CurrentCulture, "{0} in ({1})"
                                       , CoreBusinessLogic.GetSerialNoField(IsTempOrder), deletedSerialNos.ToString());
            }
            DataRow[] deletedRow = OrderDataTable.Select(filter);
            if (deletedRow != null)
            {
                foreach (DataRow row in deletedRow)
                {
                    row.Delete();
                }
            }

            foreach (Order order in newOrders) // 插入新医嘱
            {
                DataRow row;
                decimal groupSerialNo;

                groupSerialNo       = order.GroupSerialNo;// 新医嘱的分组序号通过触发器来更新,在这里先将其分组序号与分组标志设为一致
                order.GroupSerialNo = (int)order.GroupPosFlag;
                row = OrderDataTable.NewRow();
                PersistentObjectFactory.SetDataRowValueFromObject(row, order);
                row[ConstSchemaNames.OrderColSynchFlag] = 0;
                OrderDataTable.Rows.Add(row);
                order.GroupSerialNo = groupSerialNo; // 恢复原先的分组序号
            }

            DataTable changedTable = OrderDataTable.GetChanges();

            if ((changedTable != null) && (changedTable.Rows.Count > 0))
            {
                return(changedTable.Copy());
            }
            else
            {
                return(null);
            }
        }