예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void OnLookupGridRowUpdaing(object sender, GridViewUpdateEventArgs e)
        {
            GridViewRow row = LookupCodeGrid.Rows[e.RowIndex];
            List <ICaisisInputControl> cicList = PageUtil.GetCaisisInputControlsInContainer(row);
            LookupCode biz    = new LookupCode();
            object     priKey = LookupCodeGrid.DataKeys[e.RowIndex].Value;

            // Insert/No Key Present
            if (!priKey.ToString().Equals(string.Empty))
            {
                int lkpCodeId = (int)priKey;
                biz.Get(lkpCodeId);
            }
            if (Request.Form["lkpName"] != null)
            {
                biz[LookupCode.LkpFieldName] = Request.Form["lkpName"];
            }
            else if (!string.IsNullOrEmpty(lkpFieldName.Value))
            {
                biz[LookupCode.LkpFieldName] = lkpFieldName.Value;
            }
            else if (!string.IsNullOrEmpty(fieldName.SelectedValue))
            {
                biz[LookupCode.LkpFieldName] = fieldName.SelectedValue;
            }
            else
            {
                return;
            }
            // Manually Extract values to fix issues with LkpSupress
            foreach (ICaisisInputControl cic in cicList)
            {
                if (cic is CaisisCheckBox)
                {
                    CaisisCheckBox cb = cic as CaisisCheckBox;
                    biz[cic.Field] = cb.Checked;
                }
                else
                {
                    biz[cic.Field] = cic.Value;
                }
            }
            biz.Save();
        }
예제 #2
0
        /// <summary>
        /// Update lookup code record
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void HandleLookupUpdate(object sender, GridViewUpdateEventArgs e)
        {
            GridView    lkpCodeGrid = sender as GridView;
            GridViewRow updateRow   = lkpCodeGrid.Rows[e.RowIndex];

            // Fill dictionary from row controls
            CaisisGridView.ExtractCaisisInputValuesFromContainer(updateRow, e.NewValues);

            // Create a new biz for updating/inserting
            LookupCode biz = new LookupCode();
            // Determine if a lookupcodeid exists
            object lkpCodeIdKey = lkpCodeGrid.DataKeys[e.RowIndex][LookupCode.LookupCodeId];

            if (lkpCodeIdKey != null && !string.IsNullOrEmpty(lkpCodeIdKey.ToString()))
            {
                int lkpCodeId = int.Parse(lkpCodeIdKey.ToString());
                biz.Get(lkpCodeId);
            }
            else
            {
                return;
            }
            // Set the lkpcode extracted from textbox
            foreach (string col in e.NewValues.Keys)
            {
                //if (biz.HasColumn(col))
                if (biz.HasField(col))
                {
                    biz[col] = e.NewValues[col];
                }
            }

            biz.Save();

            // Notify the built-in update event to cancel/i.e., not bubble
            e.Cancel = true;
        }
예제 #3
0
        /// <summary>
        /// Save's all "dirty" rows as well as update/delete association to current disease
        /// </summary>
        private void Save()
        {
            // validation
            List <string> existingCodes  = new List <string>();
            List <string> duplicateCodes = new List <string>();

            // check each row, need to check for associate with disease
            foreach (GridViewRow row in LookupCodeGrid.Rows)
            {
                int?   lkpCodeId    = null;
                object rowLkpCodeId = LookupCodeGrid.DataKeys[row.RowIndex][LookupCode.LookupCodeId];
                if (!string.IsNullOrEmpty(rowLkpCodeId.ToString()))
                {
                    lkpCodeId = (int)rowLkpCodeId;
                }
                bool isDirtyRow = LookupCodeGrid.DirtyGridRows.Contains(row);
                ICaisisInputControl lkpCodeField = row.FindControl("LkpCode") as ICaisisInputControl;
                // validate empty values, duplicates, etc...
                if (!string.IsNullOrEmpty(lkpCodeField.Value))
                {
                    if (!lkpCodeId.HasValue && existingCodes.Contains(lkpCodeField.Value, StringComparer.OrdinalIgnoreCase))
                    {
                        // mark as duplicate and prevent insert
                        duplicateCodes.Add(lkpCodeField.Value);
                        isDirtyRow = false;
                        lkpCodeId  = null;
                    }
                    // track running list
                    else
                    {
                        existingCodes.Add(lkpCodeField.Value);
                    }
                }
                else
                {
                    isDirtyRow = false;
                    lkpCodeId  = null;
                }

                // if dirty, update/insert
                if (isDirtyRow)
                {
                    // update/insert
                    LookupCode lkpCode = new LookupCode();
                    if (lkpCodeId.HasValue)
                    {
                        lkpCode.Get(lkpCodeId.Value);
                    }
                    else
                    {
                        lkpCode[LookupCode.LkpFieldName] = CurrentLkpFieldName.Value;
                    }
                    CICHelper.SetBOValues(row.Controls, lkpCode, -1);
                    lkpCode.Save();
                    // update pri key
                    lkpCodeId = (int)lkpCode[LookupCode.LookupCodeId];
                }
                // continue if valid
                if (lkpCodeId.HasValue)
                {
                    // APPLY TO DISEASE
                    CheckBox    diseaseAttribute   = row.FindControl("DiseaseAttribute") as CheckBox;
                    HiddenField diseaseAttributeId = row.FindControl("DiseaseAttributeId") as HiddenField;
                    if (diseaseAttribute.Checked)
                    {
                        // only insert if key not set, as already assigned
                        if (string.IsNullOrEmpty(diseaseAttributeId.Value))
                        {
                            LookupCodeAttribute lkpCodeAttribute = new LookupCodeAttribute();
                            // set required
                            lkpCodeAttribute[LookupCodeAttribute.LookupCodeId]      = lkpCodeId;
                            lkpCodeAttribute[LookupCodeAttribute.AttributeId]       = _lkpDiseaseAttributeId;
                            lkpCodeAttribute[LookupCodeAttribute.AttributeValue]    = _diseaseName;
                            lkpCodeAttribute[LookupCodeAttribute.AttributeSuppress] = 0;
                            lkpCodeAttribute.Save();
                            // update hidden field
                            diseaseAttributeId.Value = lkpCodeAttribute[LookupCodeAttribute.LookupCodeAttributeId].ToString();
                        }
                    }
                    // if unchecking and pri key set, delete
                    else
                    {
                        if (!string.IsNullOrEmpty(diseaseAttributeId.Value))
                        {
                            int lkpCodeAttributeId = int.Parse(diseaseAttributeId.Value);
                            LookupCodeAttribute lkpCodeAttribute = new LookupCodeAttribute();
                            lkpCodeAttribute.Delete(lkpCodeAttributeId);
                            // udpate hidden field
                            diseaseAttributeId.Value = string.Empty;
                        }
                    }
                    // APPLY FILTERS: only when NOT in disease mode
                    if (!QueryDiseaseId.HasValue)
                    {
                        // APPLY TO ATTRIBUTE
                        CheckBox    applyToAttribute   = row.FindControl("ApplyToAttribute") as CheckBox;
                        HiddenField applyToAttributeId = row.FindControl("ApplyToAttributeId") as HiddenField;
                        if (applyToAttribute.Checked)
                        {
                            // no udpates, just inserts
                            if (string.IsNullOrEmpty(applyToAttributeId.Value))
                            {
                                LookupCodeAttribute lkpCodeAttribute = new LookupCodeAttribute();
                                lkpCodeAttribute[LookupCodeAttribute.LookupCodeId]      = lkpCodeId.Value;
                                lkpCodeAttribute[LookupCodeAttribute.AttributeId]       = int.Parse(FilterByAttributeNames.Value);
                                lkpCodeAttribute[LookupCodeAttribute.AttributeValue]    = FilterByAttributeValues.Value;
                                lkpCodeAttribute[LookupCodeAttribute.AttributeSuppress] = 0;
                                lkpCodeAttribute.Save();
                                applyToAttributeId.Value = lkpCodeAttribute[lkpCodeAttribute.PrimaryKeyName].ToString();
                            }
                        }
                        // if unchecking, delete only if key exists
                        else if (!string.IsNullOrEmpty(applyToAttributeId.Value))
                        {
                            LookupCodeAttribute lkpCodeAttribute = new LookupCodeAttribute();
                            lkpCodeAttribute.Delete(int.Parse(applyToAttributeId.Value));
                            applyToAttributeId.Value = string.Empty;
                        }

                        // APPLY TO PARENT
                        CheckBox    applyToParent   = row.FindControl("ApplyToParent") as CheckBox;
                        HiddenField applyToParentId = row.FindControl("ApplyToParentId") as HiddenField;
                        if (applyToParent.Checked)
                        {
                            // no udpates, just inserts
                            if (string.IsNullOrEmpty(applyToParentId.Value))
                            {
                                LookupParentChildCode parentChildCode = new LookupParentChildCode();
                                parentChildCode[LookupParentChildCode.ParentCodeId] = int.Parse(FilterByParentLkpCodes.Value);
                                parentChildCode[LookupParentChildCode.ChildCodeId]  = lkpCodeId.Value;
                                parentChildCode.Save();
                                applyToParentId.Value = parentChildCode[parentChildCode.PrimaryKeyName].ToString();
                            }
                        }
                        // if unchecking, delete only if key exists
                        else if (!string.IsNullOrEmpty(applyToParentId.Value))
                        {
                            LookupParentChildCode parentChildCode = new LookupParentChildCode();
                            parentChildCode.Delete(int.Parse(applyToParentId.Value));
                            applyToParentId.Value = string.Empty;
                        }
                    }
                }
            }
            // Save new CSV values
            var bulkLkpCodesRows = (from rowCodes in BulkLkpCodes.Text.Split(System.Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
                                    let lkpCode = from code in rowCodes.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
                                                  select code.Trim()
                                                  select lkpCode).SelectMany(s => s);

            foreach (string code in bulkLkpCodesRows)
            {
                LookupCode lkpCode = new LookupCode();
                // set required fields
                lkpCode[LookupCode.LkpFieldName] = CurrentLkpFieldName.Value;
                lkpCode[LookupCode.LkpSuppress]  = 0;
                // set code
                lkpCode[LookupCode.LkpCode] = code;
                // insert
                lkpCode.Save();
            }
            // reset bulk codes
            BulkLkpCodes.Text = string.Empty;

            // refresh cache for item
            CacheManager.ResetLookupCodeCache();

            // register warning for missing codes
            if (duplicateCodes.Count() > 0)
            {
                // create safe js array
                string[] duplicateCodesArray = duplicateCodes.Select(c => PageUtil.EscapeSingleQuotes(c)).ToArray();
                string   clientArray         = "['" + string.Join("', '", duplicateCodesArray) + "']";
                Page.ClientScript.RegisterStartupScript(this.GetType(), "duplicateCodesMessage", "warnDuplicateCodes(" + clientArray + ");", true);
            }
        }