예제 #1
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     try
     {
         if (dgvValues.Rows.Count > 0)
         {
             var mapList = new List <Settings.Mappings>();
             foreach (DataGridViewRow row in dgvValues.Rows)
             {
                 var map = new Settings.Mappings
                 {
                     ConfigId     = _configId,
                     DataSource   = _datasource,
                     ApiFieldName = Convert.ToString(row.Cells["clmRcde"].Value),
                     NbsFieldName = Convert.ToString(row.Cells["clmNbsDe"].Value),
                     TableName    = Convert.ToString(row.Cells["clmNbsTn"].Value),
                     ColumnName   = Convert.ToString(row.Cells["clmNbsCn"].Value)
                 };
                 mapList.Add(map);
             }
             if (_objSql.SaveMappings(mapList))
             {
                 CommonData.ShowMessage("Successfully saved.", CommonData.MsgBoxType.Info);
             }
             else
             {
                 CommonData.ShowMessage("Not successfully saved.", CommonData.MsgBoxType.Info);
             }
         }
     }
     catch (Exception ex)
     {
         Log.WriteToErrorLog(ex);
     }
 }
예제 #2
0
        private void FillEpimappings(DataTable tbl, string url)
        {
            List <string> FldMappingList = new List <string>();
            var           objClient      = new Project(url, false);

            redCapElemList = objClient.GetFields(1);
            var xmlDoc = new XmlDocument();

            _configPath = string.Format(FileName, Application.StartupPath);
            xmlDoc.Load(_configPath);
            XmlNode selectedNode = xmlDoc.SelectSingleNode("/Settings/TableNames");
            Dictionary <string, string> settingconfig = new Dictionary <string, string>();// <prefix,tablename>
            var mapList = new List <Settings.Mappings>();

            foreach (XmlNode childnode in selectedNode.ChildNodes)
            {
                settingconfig.Add(childnode.Attributes[0].Value, childnode.InnerText);
            }
            foreach (string fieldname in redCapElemList)
            {
                foreach (KeyValuePair <string, string> mapping in settingconfig)
                {
                    if (mapping.Key.ToLower() == fieldname.ToLower().Substring(0, mapping.Key.ToLower().Length))
                    {
                        var map = new Settings.Mappings
                        {
                            ConfigId     = _configId,
                            DataSource   = _datasource,
                            ApiFieldName = fieldname,
                            NbsFieldName = " ",
                            TableName    = mapping.Value,
                            ColumnName   = fieldname
                        };
                        mapList.Add(map);
                        break;
                    }
                }
            }
            if (mapList.Count > 0)
            {
                _objSql.SaveMappings(mapList);
                tbl = _objSql.LoadFieldMappings(_configId);
                if (tbl != null && tbl.Rows.Count > 0)
                {
                    foreach (DataRow row in tbl.Rows)
                    {
                        string fldMapId        = Convert.ToString(row["Fld_mapping_id"]);
                        string sourceFieldName = Convert.ToString(row["Source_Fld_NM "]);
                        string nbsFieldName    = Convert.ToString(row["NBS_Fld_NM "]);
                        string tableNm         = Convert.ToString(row["Table_NM"]);
                        string columnNm        = Convert.ToString(row["Column_NM"]);
                        dgvValues.Rows.Add(new object[] { false, fldMapId, sourceFieldName, nbsFieldName, tableNm, columnNm });
                        FldMappingList.Add(sourceFieldName);
                    }
                }
                foreach (string fieldnm in redCapElemList)
                {
                    if (!(FldMappingList.Contains(fieldnm)))
                    {
                        unMappedList.Add(fieldnm);
                    }
                }
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                bool anyerrors = false;
                if (dgvOrders.Rows.Count > 0)
                {
                    DataTable tbl = _objSql.LoadFieldMappings1(Convert.ToString(cmbConfigList.SelectedItem));
                    if (tbl != null && tbl.Rows.Count > 0)
                    {
                        var rows =
                            dgvOrders.Rows.OfType <DataGridViewRow>().Where(row => Convert.ToBoolean(row.Cells[0].Value));
                        if (rows.Any())
                        {
                            foreach (DataGridViewRow dgrow in rows)
                            {
                                var mapList = new List <Settings.Mappings>();
                                foreach (DataRow drow in tbl.Rows)
                                {
                                    try
                                    {
                                        string tblName      = Convert.ToString(drow["Table_NM"]);
                                        string columnNm     = Convert.ToString(drow["Column_NM"]);
                                        string apiFieldName = Convert.ToString(drow["Source_Fld_NM"]);
                                        string nbsFldNm     = Convert.ToString(drow["NBS_Fld_NM"]);
                                        string datasource   = Convert.ToString(drow["DataSource"]);
                                        string configid     = Convert.ToString(drow["Config_id"]);
                                        string value        = Convert.ToString(dgrow.Cells[apiFieldName].Value);
                                        string modvalue     = value;
                                        if (tblName == "MSG_PATIENT" && datasource == "Epi Info" && columnNm == "PAT_ETHNIC_GROUP_IND_CD" || columnNm == "PAT_RACE_CATEGORY_CD" && !string.IsNullOrEmpty(value))
                                        {
                                            modvalue = value.Replace(":", "-");
                                        }
                                        if (!string.IsNullOrEmpty(value))
                                        {
                                            var mapping = new Settings.Mappings
                                            {
                                                TableName  = tblName,
                                                ColumnName = columnNm,
                                                ApiValue   = modvalue.Replace("_", "-")
                                            };
                                            mapping.NbsFieldName = nbsFldNm;
                                            mapping.RecordId     = Convert.ToString(dgrow.Cells["record_id"].Value);
                                            mapping.DocumentId   = _siteOid + "^" +
                                                                   Convert.ToString(dgrow.Cells["record_id"].Value);
                                            mapping.DocTypeCd           = _siteOid + "^" + DateTime.Now.ToString("yyyy-MM-dd");
                                            mapping.EffectiveTime       = DateTime.Now.ToString();
                                            mapping.RecordStatusCd      = CommonData.Credentials.RecordStatus;
                                            mapping.RecordStatusTime    = DateTime.Now.ToString();
                                            mapping.MsgContainerStartId = CommonData.Credentials.MsgContainerStartId;
                                            mapping.PatLocalId          = CommonData.Credentials.PatLocalId;
                                            mapping.InvLocalId          = CommonData.Credentials.InvLocalId;
                                            mapping.HideImported        = CommonData.Credentials.HideImported;
                                            mapping.DataSource          = datasource;
                                            mapping.ConfigId            = configid;
                                            mapping.Ongoing_case        = toStringYesNo(Convert.ToBoolean(dgrow.Cells[2].Value));
                                            mapList.Add(mapping);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                    }
                                }

                                if (_objSql.InsertApiValues1(mapList))
                                {
                                    string    formName = Convert.ToString(cmbConfigList.SelectedItem);
                                    DataTable dt       = _objSql.ReadSettings(formName);
                                    if (dt != null && dt.Rows.Count > 0)
                                    {
                                        foreach (DataRow row in dt.Rows)
                                        {
                                            string formname   = Convert.ToString(row["form_nm"]);
                                            string datasource = Convert.ToString(row["datasource"]);
                                            string id         = Convert.ToString(row["Config_id"]);
                                            _objSql.UpdateConfig(id);
                                            dgrow.DefaultCellStyle.ForeColor = Color.Gray;
                                            if (CommonData.Credentials.HideImported != null && CommonData.Credentials.HideImported.ToLower() == "true")
                                            {
                                                CurrencyManager currencyManager1 = (CurrencyManager)BindingContext[dgvOrders.DataSource];
                                                currencyManager1.SuspendBinding();
                                                dgvOrders.CurrentCell = null;
                                                dgrow.Visible         = false;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    anyerrors = true;
                                }

                                dgrow.Cells[0].Value = false;
                            }
                        }
                    }
                    else
                    {
                        CommonData.ShowMessage("Not all the selected records were exported successfully. See error log.",
                                               CommonData.MsgBoxType.Error);
                        UpdateStatus("No Mappings creatd. See error log.");
                    }
                }

                if (anyerrors)
                {
                    CommonData.ShowMessage("Not all the selected records were exported successfully. See error log.",
                                           CommonData.MsgBoxType.Error);
                    UpdateStatus("Not all the selected records were exported successfully. See error log.");
                }
                else
                {
                    CommonData.ShowMessage("All the selected records were successfully exported to NBS database.",
                                           CommonData.MsgBoxType.Info);
                    UpdateStatus("All the selected records were successfully exported to NBS database.");
                }
            }
            catch (Exception ex)
            {
                Log.WriteToErrorLog(ex);
            }
        }