Пример #1
0
        /// <summary>
        /// Returns a new RepeaterItemEventHandler which sets hidden lookup code ids
        /// as well as bind child checkboxes and check items in relationship
        /// </summary>
        /// <param name="lkpFieldName"></param>
        /// <returns></returns>
        private RepeaterItemEventHandler GetRelationRptrBoundHandler(string lkpFieldName)
        {
            RepeaterItemEventHandler itemBoundHandler = new RepeaterItemEventHandler(delegate(object sender, RepeaterItemEventArgs e)
            {
                string lkpId = DataBinder.Eval(e.Item.DataItem, LookupCode.LookupCodeId).ToString();
                int parLkpId = int.Parse(lkpId);

                HiddenField parLkpIdField = e.Item.FindControl("ParentLookupCodeId") as HiddenField;
                parLkpIdField.Value       = lkpId;

                Repeater curItems   = e.Item.FindControl("CurrentItemsRptr") as Repeater;
                DataTable rptrCodes = da.GetLookupsByFieldName(lkpFieldName).Tables[0];
                curItems.DataSource = rptrCodes;
                curItems.DataBind();

                DataTable childCodes = da.GetChildCodesByLookupIdAndChildLookupName(parLkpId, lkpFieldName);
                foreach (RepeaterItem item in curItems.Items)
                {
                    CheckBox childCheckBox      = item.FindControl("CurrentItemCheckBox") as CheckBox;
                    HiddenField childLkpIdField = item.FindControl("LookupCodeId") as HiddenField;
                    if (!string.IsNullOrEmpty(childLkpIdField.Value))
                    {
                        // See if this item (child lookupcodeid) is in childCode list
                        // and determine if item should be checked
                        string sqlFindChildCode = "ParentCodeId = " + lkpId + " AND ChildCodeId = " + childLkpIdField.Value;
                        if (childCodes.Select(sqlFindChildCode).Length > 0)
                        {
                            childCheckBox.Checked = true;
                        }
                    }
                }
            });

            return(itemBoundHandler);
        }
Пример #2
0
        /// <summary>
        /// Helper function used to create child records for projects based on lookup codes
        /// </summary>
        /// <param name="parentBizo"></param>
        /// <param name="childBizo"></param>
        /// <param name="parentBizoNameField"></param>
        /// <param name="childBizoNameField"></param>
        /// <param name="PARENT_LKP_FIELD_TYPE"></param>
        /// <param name="CHILD_LKP_FIELD_TYPE"></param>
        /// <param name="validate">Whether to check if parent has child records before inserting</param>
        /// <param name="doSave">true if to save populated biz objects before returning </param>
        /// <returns></returns>
        private static List <BusinessObject> CreateChildRecordByBizLkpCodes(BusinessObject parentBizo, BusinessObject childBizo, string parentBizoNameField, string childBizoNameField, string PARENT_LKP_FIELD_TYPE, string CHILD_LKP_FIELD_TYPE, bool validate, bool doSave)
        {
            List <BusinessObject> childBizList = new List <BusinessObject>();
            int    bizPriKey    = int.Parse(parentBizo[parentBizo.PrimaryKeyName].ToString());
            string bizNameField = parentBizo[parentBizoNameField].ToString();

            // Check child Bizo to ensure no records have been created

            //BusinessObject checker = BusinessObjectFactory.BuildBusinessObject(childBizo.TableName);
            //checker.GetByParent(bizPriKey);
            //if (checker.RecordCount > 0 && validate)
            //{
            //    return childBizList;
            //}

            if (validate)
            {
                string tablename     = childBizo.TableName;
                string parentKeyName = BusinessObject.GetParentKeyName(tablename);
                var    criteria      = new Dictionary <string, object>()
                {
                    { parentKeyName, bizPriKey }
                };

                if (BusinessObject.Exists(tablename, criteria))
                {
                    return(childBizList);
                }
            }

            LookupCodeDa da = new LookupCodeDa();

            DataRow[] lkpRecords = da.GetLookupsByFieldName(PARENT_LKP_FIELD_TYPE).Tables[0].Select("", LKP_SORT_ORDER);

            foreach (DataRow lkpRecord in lkpRecords)
            {
                string lkpCode = lkpRecord[LookupCode.LkpCode].ToString();
                if (lkpCode == bizNameField)
                {
                    int       lkpCodeId       = int.Parse(lkpRecord[LookupCode.LookupCodeId].ToString());
                    DataRow[] childLkpRecords = da.GetChildCodesByLookupIdAndChildLookupName(lkpCodeId, CHILD_LKP_FIELD_TYPE).Select("", LKP_SORT_ORDER);
                    foreach (DataRow childLkpRecord in childLkpRecords)
                    {
                        string         childLkpCode = childLkpRecord[LookupCode.LkpCode].ToString();
                        BusinessObject childBiz     = BusinessObjectFactory.BuildBusinessObject(childBizo.TableName);
                        childBiz[childBiz.ParentKeyName] = bizPriKey;
                        childBiz[childBizoNameField]     = childLkpCode;
                        childBiz.Save();

                        childBizList.Add(childBiz);
                    }
                }
            }
            return(childBizList);
        }
Пример #3
0
        protected void GetCodesByParentIdAndChildFieldName()
        {
            int          parentLkpId    = int.Parse(Request.Form[ParentLookupId]);
            string       childFieldName = Request.Form[ChildLookupFieldName];
            LookupCodeDa da             = new LookupCodeDa();
            DataTable    lookupCodes    = da.GetLookupCodesExcludingCodesByParentLookupId(parentLkpId, childFieldName);
            DataTable    childNodes     = da.GetChildCodesByLookupIdAndChildLookupName(parentLkpId, childFieldName);
            string       codes          = "{ \"codes\": " + GetOutputArray(lookupCodes) + ", \"childCodes\": " + GetOutputArray(childNodes) + " }";

            Response.Write(codes);
        }
Пример #4
0
        protected void BuildFilterByParent(object sender, EventArgs e)
        {
            string filterLkpCodeId = FilterByParentLkpCodes.Value;

            if (!string.IsNullOrEmpty(filterLkpCodeId))
            {
                LookupCodeDa da = new LookupCodeDa();
                var          currentChildCodes = da.GetChildCodesByLookupIdAndChildLookupName(int.Parse(filterLkpCodeId), CurrentLkpFieldName.Value);
                SetLookupCodeGridFilter(currentChildCodes, "ApplyToParent", LookupParentChildCode.ParentChildCodeId);
            }
        }
Пример #5
0
        /// <summary>
        /// Returns true if the selected ProjectType needs an approval record, else false.
        /// </summary>
        /// <param name="projectType"></param>
        /// <returns></returns>
        private bool FormNeedsApprovalStep(string projectType)
        {
            LookupCodeDa da = new LookupCodeDa();
            // LookupCode ProjectApprovalType should contain a single lookup value
            // used to link child codes as needing approval step.
            DataTable dt = da.GetLookupsByFieldName("ProjectApprovalType").Tables[0];

            DataRow[] singleType = dt.Select("LkpCode = 'ProjectApprovalType'");
            if (singleType.Length > 0)
            {
                int parentCodeId = int.Parse(singleType[0]["LookupCodeId"].ToString());
                // Get all the ProjectTypes which need approval
                DataTable childCodes = da.GetChildCodesByLookupIdAndChildLookupName(parentCodeId, "ProjectType");
                // If projectType is in this list, we need an approval step
                if (childCodes.Select("LkpCode = '" + PageUtil.EscapeSingleQuotesForSql(projectType) + "'").Length > 0)
                {
                    return(true);
                }
            }
            return(false);
        }
        protected override void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            string parentCodeId    = Request.QueryString["lookupCodeId"];
            string childLookupType = Request.QueryString["childLookupType"];

            if (!string.IsNullOrEmpty(parentCodeId) && !string.IsNullOrEmpty(childLookupType))
            {
                LookupCodeDa da            = new LookupCodeDa();
                DataTable    myChildCodes  = da.GetChildCodesByLookupIdAndChildLookupName(int.Parse(parentCodeId), childLookupType);
                DataTable    allChildCodes = da.GetLookupsByFieldName(childLookupType).Tables[0];


                foreach (DataRow row in myChildCodes.Rows)
                {
                    string lkpCode = row["LkpCode"].ToString();
                    if (myChildCodes.Select("LkpCode = '" + PageUtil.EscapeSingleQuotesForSql(lkpCode) + "'").Length == 0)
                    {
                        Response.Write(lkpCode + ",");
                    }
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Returns a DataTable of lookupcodes
        /// </summary>
        /// <param name="lkpCode"></param>
        /// <param name="isDistinct"></param>
        /// <returns></returns>
        private DataTable GetLookupCodes(string lkpCode, bool isDistinct)
        {
            DataTable dataSourceTable         = new DataTable();
            string    LookupColumn            = LookupCode.LkpCode;
            string    LookupDescriptionColumn = LookupCode.LkpDescription;

            if (isDistinct)
            {
                string[] lookupDistinctVals = lkpCode.Split(new char[] { ';' });
                string   tablename          = lookupDistinctVals[0].Trim();
                string   valuefield         = lookupDistinctVals[1].Trim();
                string   textfield          = lookupDistinctVals[2].Trim();
                string   restriction        = null;
                string   order = null;

                if (lookupDistinctVals.Length >= 4)
                {
                    restriction = lookupDistinctVals[3].Trim();
                    System.Web.SessionState.HttpSessionState tempSession = Page.Session;
                    if (restriction.Contains("@PatientId") && tempSession != null && tempSession[SessionKey.PatientId] != null)
                    {
                        restriction = restriction.Replace("@PatientId", tempSession[SessionKey.PatientId].ToString());
                    }

                    if (restriction.Contains("@UserName"))
                    {
                        Caisis.Security.SecurityController sc = new Caisis.Security.SecurityController();
                        restriction = restriction.Replace("@UserName", String.Format("'{0}'", sc.GetUserName()));
                    }

                    if (lookupDistinctVals.Length >= 5)
                    {
                        order = lookupDistinctVals[4].Trim();
                    }
                }

                dataSourceTable = LookupCodeDa.GetLookupData(tablename, valuefield, textfield, restriction, order).Table;
                LookupColumn    = "DropDownText";
            }
            else
            {
                string[] specialLkpCode = lkpCode.Split(';');
                if (specialLkpCode.Length == 3)
                {
                    LookupCodeDa da                 = new LookupCodeDa();
                    string       childLkpCode       = specialLkpCode[0];
                    string       parentLkpCode      = specialLkpCode[1];
                    string       parentLkpCodeValue = specialLkpCode[2];

                    DataTable parentLkpCodes = da.GetLookupsByFieldName(parentLkpCode).Tables[0];
                    DataRow[] results        = parentLkpCodes.Select("LkpCode = '" + parentLkpCodeValue + "'");
                    if (results.Length > 0)
                    {
                        int lkpCodeId = int.Parse(results[0][LookupCode.LookupCodeId].ToString());
                        dataSourceTable = da.GetChildCodesByLookupIdAndChildLookupName(lkpCodeId, childLkpCode);
                    }
                }
                else
                {
                    dataSourceTable = CacheManager.GetLookupCodeList(lkpCode);
                }
            }
            return(dataSourceTable);
        }
Пример #8
0
        /// <summary>
        /// Creates child ProjectStage, ProjectStageEvents and ProjectEventAttributes records
        /// based off of child/parent Lookup scheme.
        /// NOTE: Child records will not be created if any ProjectStage records exists.
        /// </summary>
        /// <param name="biz"></param>
        /// <param name="dt"></param>
        public static void CreateProjectStagesRecords(Project biz, DataTable dt)
        {
            // bas: Does a Project have existing children (ProjectStages)?
            var criteria = new Dictionary <string, object>()
            {
                { Project.ProjectId, (int)biz[Project.ProjectId] }
            };
            bool childRecordsExist = BusinessObject.Exists <ProjectStage>(criteria);

            //BusinessObject parentBiz = biz;
            //BusinessObject childBiz = new ProjectStage();
            //ProjectStage projectStage = new ProjectStage();
            //projectStage.GetByParent(int.Parse(biz[Project.ProjectId].ToString()));

            //if (projectStage.DataSourceView.Count == 0)

            if (!childRecordsExist)
            {
                LookupCodeDa da                = new LookupCodeDa();
                string       projectType       = biz[Project.Type].ToString();
                DataTable    projectCodes      = da.GetLookupsByFieldName("ProjectType").Tables[0];
                DataRow[]    projectTypesFound = projectCodes.Select(LookupCode.LkpCode + " = '" + projectType.Replace("'", "''") + "'");
                if (projectTypesFound.Length > 0)
                {
                    int       projectTypeLkpId = int.Parse(projectTypesFound[0][LookupCode.LookupCodeId].ToString());
                    DataRow[] stagesCodes      = da.GetChildCodesByLookupIdAndChildLookupName(projectTypeLkpId, PROJECT_STAGE_TYPE_CODE).Select("", LKP_SORT_ORDER);

                    // Get Color Attribute (should be 1 row)
                    DataTable colorAttributes  = da.GetLookupAttributeByName("Color");
                    DataTable allStagesColors  = null;
                    int       colorAttributeId = -1;
                    if (colorAttributes.Rows.Count > 0)
                    {
                        colorAttributeId = int.Parse(colorAttributes.Rows[0][LookupAttribute.AttributeId].ToString());
                        allStagesColors  = da.GetLookupCodeAttributesByAttributeId(colorAttributeId);
                    }

                    foreach (DataRow stageCode in stagesCodes)
                    {
                        ProjectStage stageBiz = new ProjectStage();
                        stageBiz[ProjectStage.ProjectId] = biz[Project.ProjectId].ToString();
                        stageBiz[ProjectStage.Name]      = stageCode[LookupCode.LkpCode].ToString();

                        // Get color atttibute for this Stage lookup code, if any
                        int stageLkpId = int.Parse(stageCode[LookupCode.LookupCodeId].ToString());
                        if (colorAttributeId > -1 && allStagesColors != null)
                        {
                            // See if there is a color attribute value for this by attribute id and lookup code id
                            DataRow[] stageColors = allStagesColors.Select(LookupCodeAttribute.AttributeId + " = " + colorAttributeId + " AND LookupCodeId = " + stageLkpId);
                            if (stageColors.Length > 0)
                            {
                                stageBiz[ProjectStage.ColorCode] = stageColors[0][LookupCodeAttribute.AttributeValue].ToString();
                            }
                        }

                        stageBiz.Save();
                        CreateProjectStageEvents(stageBiz);
                    }
                }
            }
        }