protected void GetCodes() { string lkpField = Request.Form[LookupCodeFieldName]; LookupCodeDa da = new LookupCodeDa(); DataTable dt = da.GetLookupsByFieldName(lkpField).Tables[0]; string codes = "{ \"codes\": " + GetOutputArray(dt) + " }"; Response.Write(codes); }
/// <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); }
protected override void Page_Load(object sender, EventArgs e) { bool requestFromMetaDataPage = false; // if page is launched from meta data page populate with lookup code values based on query string if (Request.QueryString["lookupCodeValue"] != null) { requestFromMetaDataPage = true; PopulateLookupFieldDropDown(); fieldName.SelectedValue = Request.QueryString["lookupCodeValue"].ToString(); } lkpName.Disabled = true; if (Page.IsPostBack || requestFromMetaDataPage) { //get look up codes for posted field name if (fieldName.SelectedValue != null && fieldName.SelectedValue.Length > 0) { lkpName.Value = fieldName.SelectedValue; LookupCodeDa lkpDa = new LookupCodeDa(); DataSet lkpDs = lkpDa.GetLookupsByFieldName(fieldName.SelectedValue); if (lkpDs.Tables[0].Rows.Count > 0) { //show repeater table repeaterDiv.Visible = true; //hide table tableDiv.Visible = false; addBtn.Visible = true; if (!Page.IsPostBack) { BindLookupCodesGrid(); } } } else { repeaterDiv.Visible = false; tableDiv.Visible = false; addBtn.Visible = false; } } else { //hide repeaterDiv.Visible = false; tableDiv.Visible = false; //populate the lookup field name drop down PopulateLookupFieldDropDown(); } }
/// <summary> /// Gets the datasoruce for the lookup code, with the Lookup order sorted /// </summary> /// <param name="lkpFieldName"></param> /// <returns></returns> private DataView GetSortedGridDataSource(string lkpFieldName) { DataTable dt = da.GetLookupsByFieldName(lkpFieldName).Tables[0]; string sortHelperName = "_lookupSortHelper"; DataColumn sortHelperCol = new DataColumn(sortHelperName); sortHelperCol.DefaultValue = 0; dt.Columns.Add(sortHelperCol); DataRow[] lkpOrderRows = dt.Select(LookupCode.LkpOrder + " IS NOT NULL"); foreach (DataRow lkpOrderRow in lkpOrderRows) { lkpOrderRow[sortHelperCol] = 1; } string sortExpr = sortHelperName + " DESC, " + LookupCode.LkpOrder + " ASC"; DataView gridDataSource = dt.DefaultView; gridDataSource.Sort = sortExpr; return(gridDataSource); }
protected void BuildFilterByParentLkpCodes(object sender, EventArgs e) { FilterByParentLkpCodes.Items.Clear(); string lkpField = FilterByParentLkpFieldNames.Value; if (!string.IsNullOrEmpty(lkpField)) { LookupCodeDa da = new LookupCodeDa(); var lkpCodes = da.GetLookupsByFieldName(lkpField).Tables[0].DefaultView; FilterByParentLkpCodes.DataSource = lkpCodes; FilterByParentLkpCodes.DataBind(); } }
protected void BindLookupCodesGrid() { string selectedFieldName = fieldName.SelectedValue; if (!string.IsNullOrEmpty(selectedFieldName)) { LookupCodeDa lkpDa = new LookupCodeDa(); DataSet lkpDs = lkpDa.GetLookupsByFieldName(selectedFieldName); DataView view = lkpDs.Tables[0].DefaultView; // Add empty rows for (int i = 0; i < BLANK_LOOKUPCODE_ROWS; i++) { view.AddNew(); } LookupCodeGrid.DataSource = view; LookupCodeGrid.DataBind(); } }
/// <summary> /// Builds checkbox matrix to allow selecting organizations and stages /// </summary> private void BuildCheckBoxMatrix() { LookupCodeDa lookupDa = new LookupCodeDa(); // Set Global Organization List (controls columns) organizationListDataView = da.GetAllOrganizationsByProjectId(projectId).DefaultView; allProjectStageEvents = da.GetStageEventsByProject(projectId).DefaultView; // Determine if we need to filter organization if (!string.IsNullOrEmpty(OrganizationId)) { organizationListDataView.RowFilter = ProjectOrganization.OrganizationId + " = " + OrganizationId; } // Gets all Stage names based on Lookup Codes DataTable stagesLkpCodes = lookupDa.GetLookupsByFieldName("ProjectStages").Tables[0]; // Bind Organization Header Items OrgListRptr.DataSource = organizationListDataView; OrgListRptr.DataBind(); // Bind Stages //ProjectStage projectStages = new ProjectStage(); //projectStages.GetByParent(projectId); //orgStageRecords = projectStages.DataSourceView; orgStageRecords = BusinessObject.GetByParentAsDataView <ProjectStage>(projectId); if (orgStageRecords.Count == 0) { ProjectMgmtUtil.CreateProjectChildRecords(projectId); //projectStages.GetByParent(projectId); //orgStageRecords = projectStages.DataSourceView; orgStageRecords = BusinessObject.GetByParentAsDataView <ProjectStage>(projectId); } orgStageRecords.RowFilter = ProjectStage.OrganizationId + " IS NULL"; //StagesRptr.DataSource = stagesLkpCodes; StagesRptr.DataSource = orgStageRecords; StagesRptr.DataBind(); }
/// <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 + ","); } } } }
/// <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); }
/// <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); } } } }