Beispiel #1
0
        /// <summary>
        /// Handle the row updating event, by updating the position Id for this Specimen Record
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void SpecimenGridRowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            object boxId      = e.NewValues[Specimen.BoxId];
            object positionId = e.NewValues[Specimen.PositionId];
            object specimenId = e.Keys[Specimen.SpecimenId];

            if (boxId != null)
            {
                string specimenIdKey = specimenId.ToString();
                string boxIdKey      = boxId.ToString();
                string positionIdKey = positionId.ToString();
                string accessKey     = SpecimenFormHelper.GetAccessKey(e.RowIndex.ToString(), specimenIdKey);

                // Cannot insert record without an int BoxId (parent key)
                if (this.ViewState[accessKey] != null && !string.IsNullOrEmpty(boxIdKey))
                {
                    string[] a            = this.ViewState[accessKey] as string[];
                    string   boxName      = Request.Form[a[2]];
                    string   positionName = Request.Form[a[3]];

                    if (!string.IsNullOrEmpty(boxName))
                    {
                        //checking for Position in order to add/update the Specimens with or without selection of Positions
                        if (!string.IsNullOrEmpty(positionName))
                        {
                            PositionBizHelper helper = new PositionBizHelper(boxIdKey, positionIdKey, positionName);
                            e.NewValues[Specimen.PositionId] = helper.SaveRecord();
                        }
                        else
                        {
                            e.NewValues[Specimen.PositionId] = string.Empty;
                        }
                    }
                    else
                    {
                        e.NewValues[Specimen.BoxId]      = string.Empty;
                        e.NewValues[Specimen.PositionId] = string.Empty;
                    }
                }
            }
        }
Beispiel #2
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);
            }
        }