/// <summary>
        /// 新增模板
        /// </summary>
        /// <param name="templateItem"></param>
        public void AddTemplateItem(TemplateItem templateItem)
        {
            if (templateItem.Details == null || templateItem.Details.Count == 0)
            {
                throw new Exception("模板没有明细,不能保存");
            }
            if (templateItem.Tmplate_Name.Trim( ) == "")
            {
                throw new Exception("模板名称不能为空");
            }
            try
            {
                oleDb.BeginTransaction( );
                Model.BASE_TEMPLATE_ITEM base_temp_item = new HIS.Model.BASE_TEMPLATE_ITEM( );
                base_temp_item.CREATE_DATE    = templateItem.Create_Date;
                base_temp_item.CREATOR_ID     = templateItem.Creator_Id;
                base_temp_item.CREATOR_NAME   = templateItem.Creator_Name;
                base_temp_item.EXEC_DEPT_ID   = templateItem.Exec_Dept_Id;
                base_temp_item.EXEC_DEPT_NAME = templateItem.Exce_Dept_Name;
                base_temp_item.DEPT_ID        = templateItem.Dept_Id;
                base_temp_item.DEPT_NAME      = templateItem.Dept_Name;
                base_temp_item.PY_CODE        = templateItem.Py_Code;
                base_temp_item.SHARE_LEVEL    = templateItem.Share_Level;
                base_temp_item.TMPLATE_NAME   = templateItem.Tmplate_Name;
                base_temp_item.TMPLATE_TYPE   = templateItem.Tmplate_Type;
                base_temp_item.VALID_FLAG     = templateItem.Valid_Flag;
                base_temp_item.WB_CODE        = templateItem.Wb_Code;

                BindEntity <Model.BASE_TEMPLATE_ITEM> .CreateInstanceDAL(oleDb).Add(base_temp_item);

                foreach (TemplateDetailItem item in templateItem.Details)
                {
                    Model.BASE_TEMPLATE_DETAIL detail = new HIS.Model.BASE_TEMPLATE_DETAIL( );
                    detail.TEMPLATE_ID  = base_temp_item.TMPLATE_ID;
                    detail.BIGITEMCODE  = item.BIGITEMCODE;
                    detail.COMPLEX_ID   = item.COMPLEX_ID;
                    detail.DAYS         = item.DAYS;
                    detail.DOSAGE       = item.DOSAGE;
                    detail.FREQUEN_ID   = item.FREQUEN_ID;
                    detail.FREQUEN_NAME = item.FREQUEN_NAME;
                    detail.GROUP_FLAG   = item.GROUP_FLAG;
                    detail.ITEM_ID      = item.ITEM_ID;
                    detail.ITEM_NAME    = item.ITEM_NAME;
                    detail.SORT_NO      = item.SORT_NO;
                    detail.STANDARD     = item.STANDARD;
                    detail.UNIT         = item.UNIT;
                    detail.USAGE_NAME   = item.USAGE_NAME;
                    detail.Amount       = item.AMOUNT;
                    BindEntity <Model.BASE_TEMPLATE_DETAIL> .CreateInstanceDAL(oleDb).Add(detail);
                }
                oleDb.CommitTransaction( );
            }
            catch
            {
                oleDb.RollbackTransaction( );
                throw new Exception("保存模板发生错误!");
            }
        }
        /// <summary>
        /// 保存模板修改
        /// </summary>
        /// <param name="templateItem"></param>
        public void UpdateTemplateItem(TemplateItem templateItem)
        {
            if (templateItem.Details == null || templateItem.Details.Count == 0)
            {
                throw new Exception("模板没有明细,不能保存");
            }
            if (templateItem.Tmplate_Name.Trim( ) == "")
            {
                throw new Exception("模板名称不能为空");
            }
            try
            {
                oleDb.BeginTransaction( );
                string strWhere = Tables.base_template_item.TMPLATE_ID + oleDb.EuqalTo() + templateItem.Tmplate_Id;

                BindEntity <Model.BASE_TEMPLATE_ITEM> .CreateInstanceDAL(oleDb).Update(strWhere,
                                                                                       Tables.base_template_item.PY_CODE + oleDb.EuqalTo( ) + "'" + templateItem.Py_Code + "'",
                                                                                       Tables.base_template_item.WB_CODE + oleDb.EuqalTo( ) + "'" + templateItem.Wb_Code + "'",
                                                                                       Tables.base_template_item.SHARE_LEVEL + oleDb.EuqalTo( ) + "" + templateItem.Share_Level + "",
                                                                                       Tables.base_template_item.EXEC_DEPT_ID + oleDb.EuqalTo() + "" + templateItem.Exec_Dept_Id + "",
                                                                                       Tables.base_template_item.EXEC_DEPT_NAME + oleDb.EuqalTo() + "'" + templateItem.Exce_Dept_Name + "'",
                                                                                       Tables.base_template_item.TMPLATE_NAME + oleDb.EuqalTo( ) + "'" + templateItem.Tmplate_Name + "'",
                                                                                       Tables.base_template_item.VALID_FLAG + oleDb.EuqalTo( ) + "" + templateItem.Valid_Flag + "");

                strWhere = Tables.base_template_detail.TEMPLATE_ID + oleDb.EuqalTo( ) + templateItem.Tmplate_Id;
                BindEntity <Model.BASE_TEMPLATE_DETAIL> .CreateInstanceDAL(oleDb).Delete(strWhere);

                foreach (TemplateDetailItem item in templateItem.Details)
                {
                    Model.BASE_TEMPLATE_DETAIL detail = new HIS.Model.BASE_TEMPLATE_DETAIL( );
                    detail.TEMPLATE_ID  = templateItem.Tmplate_Id;
                    detail.BIGITEMCODE  = item.BIGITEMCODE;
                    detail.COMPLEX_ID   = item.COMPLEX_ID;
                    detail.DAYS         = item.DAYS;
                    detail.DOSAGE       = item.DOSAGE;
                    detail.FREQUEN_ID   = item.FREQUEN_ID;
                    detail.FREQUEN_NAME = item.FREQUEN_NAME;
                    detail.GROUP_FLAG   = item.GROUP_FLAG;
                    detail.ITEM_ID      = item.ITEM_ID;
                    detail.ITEM_NAME    = item.ITEM_NAME;
                    detail.SORT_NO      = item.SORT_NO;
                    detail.STANDARD     = item.STANDARD;
                    detail.UNIT         = item.UNIT;
                    detail.USAGE_NAME   = item.USAGE_NAME;
                    detail.Amount       = item.AMOUNT;
                    BindEntity <Model.BASE_TEMPLATE_DETAIL> .CreateInstanceDAL(oleDb).Add(detail);
                }
                oleDb.CommitTransaction( );
            }
            catch
            {
                oleDb.RollbackTransaction( );
                throw new Exception("保存模板发生错误!");
            }
        }