Exemplo n.º 1
0
        /// <summary>
        /// Creates controls for placing the Position and Box name in a grid.
        /// In addition, the rows positionid and boxid are tracked in the viewstate to trigger SpecimenPosition records updates/deletes.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LocateAndWireReferencedControls(object sender, EventArgs e)
        {
            if (specimensGrid != null)
            {
                List <ICaisisInputControl> tmpKeys = new List <ICaisisInputControl>();

                string jsArray = "";
                foreach (GridViewRow row in specimensGrid.Rows)
                {
                    int    rowIndex   = row.RowIndex;
                    string specimenId = specimensGrid.DataKeyNames[0] == Specimen.SpecimenId ? specimensGrid.DataKeys[0].Value.ToString() : string.Empty;

                    ICaisisInputControl boxId      = PageUtil.DeepFindICaisisInputControl(row, Specimen.BoxId);
                    ICaisisInputControl positionId = PageUtil.DeepFindICaisisInputControl(row, SpecimenPosition.PositionId);
                    string uniqueClientKey         = (boxId as Control).UniqueID;

                    TextBox boxName = new TextBox();
                    boxName.ID = uniqueClientKey + "RefBoxName";
                    boxName.Style.Add(HtmlTextWriterStyle.Display, "none");
                    controlsToRender.Add(boxName);

                    TextBox positionName = new TextBox();
                    positionName.ID = uniqueClientKey + "RefPositionName";
                    positionName.Style.Add(HtmlTextWriterStyle.Display, "none");
                    controlsToRender.Add(positionName);

                    // Set Box Name and Position Name based off of records
                    if (!string.IsNullOrEmpty(boxId.Value))
                    {
                        SpecimenBox box = new SpecimenBox();
                        box.Get(int.Parse(boxId.Value));
                        boxName.Text = box[SpecimenBox.BoxName].ToString();
                        if (Page.IsPostBack)
                        {
                            if (!string.IsNullOrEmpty(positionId.Value))
                            {
                                SpecimenPosition pos = new SpecimenPosition();
                                pos.Get(int.Parse(positionId.Value));
                                positionName.Text = pos[SpecimenPosition.Position].ToString();
                            }
                            else if (this.ViewState["SpecimenId$" + rowIndex] != null)
                            {
                                string posName = Request.Form[(this.ViewState["SpecimenId$" + rowIndex] as string[])[3]];
                                positionName.Text = posName;
                            }
                        }
                        else if (!string.IsNullOrEmpty(positionId.Value))
                        {
                            SpecimenPosition pos = new SpecimenPosition();
                            pos.Get(int.Parse(positionId.Value));
                            positionName.Text = pos[SpecimenPosition.Position].ToString();
                        }
                    }

                    SpecimenFormHelper helper = new SpecimenFormHelper(rowIndex.ToString(), specimenId, boxId as Control, positionId as Control, boxName as Control, positionName as Control);
                    jsArray += helper.ClientIdsJavaScriptArray + ",";

                    string   key = helper.AccessKey;
                    string[] val = helper.FormArray;
                    this.ViewState.Add(key, val);
                }

                // Register ClientIds Array to page, where populating is handled via JavaScript
                jsArray = jsArray.TrimEnd(",".ToCharArray());
                Page.ClientScript.RegisterArrayDeclaration("SpecimenLocationRefList", jsArray);
                string disableControls = (!specimensGrid.Enabled).ToString().ToLower();
                Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "DisabledPickerControls", "var disablePickerControls = " + disableControls + ";", true);
            }
        }