public SrePropertyGrid(IdpeAttribute attribute, int dataSourceId = 0, bool isAssociatedWithSystemDataSource = false) { this.Attribute = attribute; this.DataSourceId = dataSourceId; this.IsAssociatedWithSystemDataSource = isAssociatedWithSystemDataSource; Assign(); }
public List <IdpeAttribute> GetAttributes() { List <IdpeAttribute> attrbs = new List <IdpeAttribute>(); string commandText = "select [AttributeId],[Name],[Type],[Minimum],[Maximum],[Formula],[IsAcceptable],[CreatedTS],[CreatedBy],[ModifiedTS],[ModifiedBy],[Source] from [IdpeAttribute]"; DataTable table = Core.Data.CoreDatabaseObjects.Instance.ExecuteCommand(commandText); if (table == null) { return(attrbs); } foreach (DataRow row in table.Rows) { IdpeAttribute attrb = new IdpeAttribute(); attrb.AttributeId = (int)row["AttributeId"].ToString().ParseInt(); attrb.Name = row["Name"] != DBNull.Value ? row["Name"].ToString() : null; attrb.Type = row["Type"] != DBNull.Value ? new CultureInfo("en-US", false).TextInfo.ToTitleCase(row["Type"].ToString().ToLower()) : null; attrb.Minimum = row["Minimum"] != DBNull.Value ? row["Minimum"].ToString() : null; attrb.Maximum = row["Maximum"] != DBNull.Value ? row["Maximum"].ToString() : null; attrb.Formula = row["Formula"] != DBNull.Value ? row["Formula"].ToString() : null; attrb.IsAcceptable = row["IsAcceptable"] != DBNull.Value ? row["IsAcceptable"].ToString().ParseBool() : false; attrb.CreatedTS = (DateTime)(row["CreatedTS"] != DBNull.Value ? row["CreatedTS"].ToString().ParseDateTime() : DateTime.MinValue); attrb.CreatedBy = row["CreatedBy"] != DBNull.Value ? row["CreatedBy"].ToString() : null; attrb.ModifiedTS = row["ModifiedTS"] != DBNull.Value ? row["ModifiedTS"].ToString().ParseDateTime() : null; attrb.ModifiedBy = row["ModifiedBy"] != DBNull.Value ? row["ModifiedBy"].ToString() : null; attrb.Source = row["Source"] != DBNull.Value ? row["Source"].ToString() : null; attrbs.Add(attrb); } table.Dispose(); return(attrbs); }
private void listView_Click(object sender, EventArgs e) { listView.SelectedIndexChanged -= listView_SelectedIndexChanged; listView.SuspendLayout(); try { for (int i = listView.Items.Count - 1; i >= 0; i--) { var item = listView.Items[i]; item.BackColor = SystemColors.Window; IdpeAttribute attribute = item.Tag as IdpeAttribute; if ((attribute != null) && (((FormatIsPrintable) && (attribute.IsAcceptable == false)))) { item.ForeColor = Color.LightGray; } else { item.ForeColor = SystemColors.ControlText; } } } finally { listView.SelectedIndexChanged += new EventHandler(listView_SelectedIndexChanged); listView.ResumeLayout(); } }
void ListView_KeyUp(object sender, KeyEventArgs e) { if ((e.KeyCode == Keys.Delete) && (sreListView1.ListView.SelectedItems.Count > 0)) { if (MessageBox.Show("All selected attributes will be deleted if not in use! Are you sure?", "Delete Attributes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { Manager manager = new Manager(); int total = sreListView1.ListView.SelectedItems.Count; int deleted = 0; foreach (ListViewItem item in sreListView1.ListView.SelectedItems) { IdpeAttribute attrib = item.Tag as IdpeAttribute; if (manager.IsAttributeInUse(attrib.AttributeId) == false) { manager.DeleteAttribute(attrib.AttributeId); deleted++; } } MessageBox.Show(string.Format("Total deleted:{0}, Ignored:{1}", deleted, total - deleted), "Delete Attributes", MessageBoxButtons.OK, MessageBoxIcon.Information); RefreshData(); } } }
public static Type ConvertSreTypeIntoDotNetType(this IdpeAttribute attribute, DatabaseTypes databaseType) { switch (databaseType) { default: switch (attribute.Type.ToUpper()) { case "INT": return(typeof(int)); case "BIGINT": return(typeof(long)); case "DECIMAL": return(typeof(double)); case "BIT": return(typeof(bool)); case "GENERATED": case "NOTREFERENCED": case "REFERENCED": case "CODESET": case "STRING": return(typeof(string)); case "DATETIME": return(typeof(DateTime)); default: return(typeof(string)); } } }
void OnAttributeChanged(object sender, EventArgs e) { //if ((SelectedDataSource != null) && (SelectedDataSource.Id == 100)) //{ // m_dm_GlobalAttributes.btnAssociateBoth.Enabled = false; // m_dm_GlobalAttributes.btnAssociateAttributeDataSource.Enabled = false; // m_dm_GlobalAttributes.btnAssociateAttributeSystemDataSource.Enabled = false; // this.Cursor = Cursors.Default; // return; //} m_dm_GlobalAttributes.btnAssociateBoth.Enabled = true; m_dm_GlobalAttributes.btnAssociateAttributeDataSource.Enabled = true; m_dm_GlobalAttributes.btnAssociateAttributeSystemDataSource.Enabled = true; ListViewControl sreListView = sender as ListViewControl; if (sreListView != null) { if (sreListView.ListView.SelectedItems.Count > 0) { IdpeAttribute selectedAttribute = sreListView.ListView.SelectedItems[0].Tag as IdpeAttribute; if ((m_dm_Property.propertyGrid.SelectedObject != null) && (((SrePropertyGrid)m_dm_Property.propertyGrid.SelectedObject).HasChanged)) { this.Cursor = Cursors.WaitCursor; toolStripStatusLabel1.Text = "Please wait...Saving properties..."; Application.DoEvents(); ((SrePropertyGrid)m_dm_Property.propertyGrid.SelectedObject).Save(); toolStripStatusLabel1.Text = "Please wait...Clearing cache..."; Application.DoEvents(); new IdpeClient().ClearCache(); toolStripStatusLabel1.Text = "Please wait...Refresing..."; Application.DoEvents(); m_dm_SystemAttributes.RefreshData(); if (MainWindowShown) { SetToolStripStatusLabel("Ready"); } this.Cursor = Cursors.Default; } m_dm_Property.IsAssociatedWithSystemDataSource = sreListView.Parent is DockPanelDataSourceSystemAttributes; if (sreListView.Parent is DockPanelGlobalAttributes) { m_dm_Property.DataSourceId = 0; } else { m_dm_Property.DataSourceId = m_dm_Property.IsAssociatedWithSystemDataSource == false ? SelectedDataSource.Id : (int)SelectedDataSource.SystemDataSourceId; } m_dm_Property.Attribute = selectedAttribute; sreListView.ListView.Focus(); } } }
void OnAttributeAddButtonClicked(object sender, EventArgs e) { IdpeAttribute newAttribute = new IdpeAttribute(); newAttribute.IsAcceptable = true; newAttribute.Type = "String"; m_dm_Property.IsAssociatedWithSystemDataSource = false; m_dm_Property.Attribute = newAttribute; m_dm_Property.propertyGrid.Focus(); }
private string CheckAttributeDataChange(Manager manager, IdpeAttribute attrib) { IdpeAttribute existingAttribute = manager.GetAttribute(attrib.Name); if ((existingAttribute != null) && (existingAttribute.Type.ToLower() != attrib.Type.ToLower())) { return(existingAttribute.Type); } return(string.Empty); }
public string ImportAttributes(DataTable table, ref List <IdpeAttribute> attributes) { string result = "Total records found = " + table.Rows.Count + Environment.NewLine; Manager manager = new Manager(); int counter = 0; attributes = new List <IdpeAttribute>(); foreach (DataRow row in table.Rows) { IdpeAttribute attrib = new IdpeAttribute(); attrib.Name = row[0].ToString(); attrib.Type = row[1].ToString(); attrib.Formula = row[2].ToString(); attrib.Position = counter + 1; attrib.IsAcceptable = true; string existingDataType = CheckAttributeDataChange(manager, attrib); if (!string.IsNullOrEmpty(existingDataType)) { DialogResult dr = MessageBox.Show(string.Format("You are changing attribute '{0}' data type from '{1}' to '{2}'. This will impact all other data sources where attribute '{0}' is associcated. Are you sure? Press 'No' to skip this attribute and continue, 'Yes' to override, 'Cancel' to abort the operation" , attrib.Name, existingDataType, attrib.Type), "Data Type Change", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (dr == System.Windows.Forms.DialogResult.No) { attrib.Type = existingDataType; } else if (dr == System.Windows.Forms.DialogResult.Cancel) { return("Import operation was aborted!"); } } attributes.Add(attrib); try { manager.Save(attrib); counter++; } catch { } } result += "Total inserted = " + counter + Environment.NewLine; result += "Total failed = " + (table.Rows.Count - counter) + Environment.NewLine; RefreshData(); return(result); }
private void ValidateVersion(IdpeVersion version) { string allErrors = string.Empty; if (version.Type == (int)VersionObjectTypes.Unknown) { allErrors += "Version type cannot be unknown!" + Environment.NewLine; } if (version.ReferenceId == 0) { allErrors += "Version must have a reference Id!" + Environment.NewLine; } else { switch ((VersionObjectTypes)version.Type) { case VersionObjectTypes.Attribute: IdpeAttribute attribute = GetAttribute(version.ReferenceId); if (attribute.AttributeId == 0) { allErrors += "The INSERT statement conflicted with the FOREIGN KEY constraint. The conflict occurred in database, table IdpeAttribute, column 'Id'." + Environment.NewLine; } break; case VersionObjectTypes.DataSource: string dataSourceName = GetApplicationName(version.ReferenceId); if (string.IsNullOrEmpty(dataSourceName)) { allErrors += "The INSERT statement conflicted with the FOREIGN KEY constraint. The conflict occurred in database, table IdpeDataSource, column 'Id'." + Environment.NewLine; } break; case VersionObjectTypes.Rule: IdpeRule rule = GetRule(version.ReferenceId); if (rule.Id == 0) { allErrors += "The INSERT statement conflicted with the FOREIGN KEY constraint. The conflict occurred in database, table IdpeRule, column 'Id'." + Environment.NewLine; } break; } } if (!string.IsNullOrEmpty(allErrors)) { throw new Exception(allErrors); } }
private void mnuMakePrintable_Click(object sender, EventArgs e) { if (CheckIfMultipleDataSources()) { foreach (ListViewItem selectedItem in sreListView1.ListView.SelectedItems) { IdpeAttribute attribute = selectedItem.Tag as IdpeAttribute; bool acceptable = true; ToolStripItem tItem = sender as ToolStripItem; acceptable = !tItem.Text.Contains("Not Printable"); new Manager().MakeAttributeAcceptableNew((int)SelectedDataSource.SystemDataSourceId, attribute.AttributeId, acceptable); } RefreshData(); } }
private void miExport_Click(object sender, EventArgs e) { saveFileDialog1.FileName = "attributes.csv"; saveFileDialog1.Filter = "Comma Delimited Files (*.csv)|*.csv|All Files (*.*)|*.*"; if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { StreamWriter sw = new StreamWriter(saveFileDialog1.FileName); sw.WriteLine("\"Name\",\"Type\""); foreach (ListViewItem item in sreListView1.ListView.Items) { IdpeAttribute attrib = item.Tag as IdpeAttribute; sw.WriteLine(string.Format("\"{0}\",\"{1}\"", attrib.Name, attrib.Type)); } sw.Close(); } }
internal void ExportAttributes(ListViewControl sreListView, bool isSytem = false) { saveFileDialog1.FileName = "attributes.csv"; saveFileDialog1.Filter = "Comma Delimited Files (*.csv)|*.csv|All Files (*.*)|*.*"; if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { StreamWriter sw = new StreamWriter(saveFileDialog1.FileName); sw.WriteLine("\"Name\",\"Type\",\"Formula\""); foreach (ListViewItem item in sreListView.ListView.Items) { IdpeAttribute attrib = item.Tag as IdpeAttribute; sw.WriteLine(string.Format("\"{0}\",\"{1}\",\"{2}\"", attrib.Name, attrib.Type, attrib.Formula)); } sw.Close(); } }
void AddAttributeToListView(ListViewItem selectedItem, ListView listView) { IdpeAttribute attribute = selectedItem.Tag as IdpeAttribute; ListViewItem item = new ListViewItem(attribute.Name); item.SubItems.Add(attribute.Type); item.ImageKey = attribute.Type.ToString() + ".gif"; item.Tag = attribute; if (listView.SelectedIndices.Count > 0) { item.SubItems.Add(listView.SelectedIndices[0].ToString()); listView.Items.Insert(listView.SelectedIndices[0], item); } else { item.SubItems.Add((listView.Items.Count + 1).ToString()); listView.Items.Add(item); } }
public IdpeAttribute GetAttribute(string name, IDal dal = null, IDbConnection connection = null, IDbTransaction transaction = null) { IdpeAttribute attrb = new IdpeAttribute(); string commandText = "select [AttributeId],[Name],[Type],[Minimum],[Maximum],[Formula],[IsAcceptable],[CreatedTS],[CreatedBy],[ModifiedTS],[ModifiedBy],[Source] from [IdpeAttribute] "; commandText += "where [Name] = '" + name + "'"; DataTable table = null; if (dal == null) { table = CoreDatabaseObjects.Instance.ExecuteCommand(commandText); } else { table = CoreDatabaseObjects.Instance.ExecuteCommand(commandText, dal, connection, transaction); } if ((table == null) || (table.Rows.Count == 0)) { return(null); } DataRow row = table.Rows[0]; attrb.AttributeId = (int)row["AttributeId"].ToString().ParseInt(); attrb.Name = row["Name"] != DBNull.Value ? row["Name"].ToString() : null; attrb.Type = row["Type"] != DBNull.Value ? new CultureInfo("en-US", false).TextInfo.ToTitleCase(row["Type"].ToString().ToLower()) : null; attrb.Minimum = row["Minimum"] != DBNull.Value ? row["Minimum"].ToString() : null; attrb.Maximum = row["Maximum"] != DBNull.Value ? row["Maximum"].ToString() : null; attrb.Formula = row["Formula"] != DBNull.Value ? row["Formula"].ToString() : null; attrb.IsAcceptable = row["IsAcceptable"] != DBNull.Value ? row["IsAcceptable"].ToString().ParseBool() : false; attrb.CreatedTS = (DateTime)(row["CreatedTS"] != DBNull.Value ? row["CreatedTS"].ToString().ParseDateTime() : DateTime.MinValue); attrb.CreatedBy = row["CreatedBy"] != DBNull.Value ? row["CreatedBy"].ToString() : null; attrb.ModifiedTS = row["ModifiedTS"] != DBNull.Value ? row["ModifiedTS"].ToString().ParseDateTime() : null; attrb.ModifiedBy = row["ModifiedBy"] != DBNull.Value ? row["ModifiedBy"].ToString() : null; attrb.Source = row["Source"] != DBNull.Value ? row["Source"].ToString() : null; table.Dispose(); return(attrb); }
private void sdInsertAttribute(string name, int position, IDal dal = null, IDbConnection connection = null, IDbTransaction transaction = null) { string strType = "STRING"; if (string.IsNullOrEmpty(name)) { name = "IsValid"; strType = "BIT"; } IdpeAttribute attrb = GetAttribute(name, dal, connection, transaction); if (attrb == null) { attrb = new IdpeAttribute(); attrb.Name = name; attrb.Type = strType; attrb.IsAcceptable = true; attrb.AttributeId = Save(attrb, dal, connection, transaction); } IdpeAttributeDataSource sads = new IdpeAttributeDataSource(); sads.AttributeId = attrb.AttributeId; sads.DataSourceId = -99; sads.Position = position; sads.IsAcceptable = (name != "IsValid") ? true : false; Save(sads, dal, connection, transaction); if (name != "IsValid") { sads = new IdpeAttributeDataSource(); sads.AttributeId = attrb.AttributeId; sads.DataSourceId = 100; sads.Position = position; sads.IsAcceptable = true; Save(sads, dal, connection, transaction); } }
void SaveAssociations(ListView listView, bool isSystemDataSource = false, bool takeCareOfOldVersion = true) { int dataSourceId = isSystemDataSource ? (int)SelectedDataSource.SystemDataSourceId : SelectedDataSource.Id; Manager manager = new Manager(); if (takeCareOfOldVersion) { SreDataSourceProperty.KeepVersion(dataSourceId); } int position = 1; foreach (ListViewItem item in listView.Items) { IdpeAttribute attribute = item.Tag as IdpeAttribute; if (attribute.Name == "IsValid") { continue; } IdpeAttributeDataSource sds = new IdpeAttributeDataSource(); sds.DataSourceId = dataSourceId; sds.IsAcceptable = (bool)attribute.IsAcceptable; sds.AttributeId = attribute.AttributeId; sds.AttributePrintValueType = attribute.AttributePrintValueType; sds.AttributePrintValueCustom = attribute.AttributePrintValueCustom; sds.Position = position; toolStripStatusLabel1.Text = "Please wait...Saving..." + attribute.Name; Application.DoEvents(); try { manager.Save(sds); } catch { MessageBox.Show(string.Format("{0} could not be loaded!", attribute.Name), "Attribute Skipped", MessageBoxButtons.OK, MessageBoxIcon.Information); } position++; } }
void SaveAssociations(ListView listView, bool isSystem) { Manager manager = new Manager(); SreDataSourceProperty.KeepVersion(isSystem ? (int)SelectedDataSource.SystemDataSourceId: SelectedDataSource.Id); int position = 1; foreach (ListViewItem item in listView.Items) { IdpeAttribute attribute = item.Tag as IdpeAttribute; IdpeAttributeDataSource sds = new IdpeAttributeDataSource(); sds.DataSourceId = isSystem ? (int)SelectedDataSource.SystemDataSourceId : SelectedDataSource.Id; sds.AttributeId = attribute.AttributeId; if (isSystem == false) { sds.IsAcceptable = true; } else { sds.IsAcceptable = (bool)attribute.IsAcceptable; } sds.AttributePrintValueType = attribute.AttributePrintValueType; sds.AttributePrintValueCustom = attribute.AttributePrintValueCustom; sds.Position = position; manager.Save(sds); position++; } if (!isSystem) { DockPanelDataSourceAttributes.DataSourceId = SelectedDataSource.Id; } else { DockPanelDataSourceSystemAttributes.SystemDataSourceId = (int)SelectedDataSource.SystemDataSourceId; } }
private void contextMenu_Opening(object sender, CancelEventArgs e) { if (sreListView1.ListView.SelectedItems.Count == 1) { mnuDisassociate.Enabled = true; IdpeAttribute attribute = sreListView1.ListView.SelectedItems[0].Tag as IdpeAttribute; if (attribute.Name != "IsValid") { if (attribute.IsAcceptable == false) { mnuMakePrintable.Text = string.Format("Make [{0}] Printable", attribute.Name); } else { mnuMakePrintable.Text = string.Format("Make [{0}] Not Printable", attribute.Name); } } else { mnuDisassociate.Enabled = false; } } }
private void ValidateCodeSet(IdpeAttribute codeSetAttribute, List <CodeSet> systemCodeSets) { ShowMessage(string.Format("Validating codesets({0})...", codeSetAttribute.Name)); try { string code = SreCodeset.ParseFormulaGetCode(codeSetAttribute.Formula); List <CodeSet> thisCodeSet = (from cs in systemCodeSets where (cs.Code.Equals(code, StringComparison.OrdinalIgnoreCase)) select cs).ToList(); if (thisCodeSet.Count == 0) { throw new Exception(string.Format("Codeset '{0}' of attribute '{1}' is not defined!", code, codeSetAttribute.Name)); } } catch (Exception ex) { ShowMessage(string.Format("Validating codesets({0})...Failed", codeSetAttribute.Name)); AddError(ex.Message); } }
public List <IdpeAttribute> GetAttributes(string dataSourceName) { List <IdpeAttribute> attrbs = new List <IdpeAttribute>(); string commandText = "select a.[AttributeId],a.[Name],a.[Type],a.[Minimum],a.[Maximum],a.[Formula],a.[IsAcceptable],aes.[AttributePrintValueType], aes.[AttributePrintValueCustom], a.[CreatedTS],a.[CreatedBy],a.[ModifiedTS],a.[ModifiedBy],a.[Source] " + " from idpeAttribute a Inner join idpeAttributeDataSource aes on a.AttributeId = aes.AttributeId " + " inner join idpeDataSource es on aes.DataSourceId = es.Id where es.Name = '" + dataSourceName + "' order by aes.Position"; DataTable table = CoreDatabaseObjects.Instance.ExecuteCommand(commandText); if (table == null) { return(attrbs); } foreach (DataRow row in table.Rows) { IdpeAttribute attrb = new IdpeAttribute(); attrb.AttributeId = (int)row["AttributeId"].ToString().ParseInt(); attrb.Name = row["Name"] != DBNull.Value ? row["Name"].ToString() : null; attrb.Type = row["Type"] != DBNull.Value ? new CultureInfo("en-US", false).TextInfo.ToTitleCase(row["Type"].ToString().ToLower()) : null; attrb.Minimum = row["Minimum"] != DBNull.Value ? row["Minimum"].ToString() : null; attrb.Maximum = row["Maximum"] != DBNull.Value ? row["Maximum"].ToString() : null; attrb.Formula = row["Formula"] != DBNull.Value ? row["Formula"].ToString() : null; attrb.IsAcceptable = row["IsAcceptable"] != DBNull.Value ? row["IsAcceptable"].ToString().ParseBool() : false; attrb.AttributePrintValueType = row["AttributePrintValueType"] != DBNull.Value ? row["AttributePrintValueType"].ToString().ParseInt() : 0; attrb.AttributePrintValueCustom = row["AttributePrintValueCustom"] != DBNull.Value ? row["AttributePrintValueCustom"].ToString() : string.Empty; attrb.CreatedTS = (DateTime)(row["CreatedTS"] != DBNull.Value ? row["CreatedTS"].ToString().ParseDateTime() : DateTime.MinValue); attrb.CreatedBy = row["CreatedBy"] != DBNull.Value ? row["CreatedBy"].ToString() : null; attrb.ModifiedTS = row["ModifiedTS"] != DBNull.Value ? row["ModifiedTS"].ToString().ParseDateTime() : null; attrb.ModifiedBy = row["ModifiedBy"] != DBNull.Value ? row["ModifiedBy"].ToString() : null; attrb.Source = row["Source"] != DBNull.Value ? row["Source"].ToString() : null; attrbs.Add(attrb); } table.Dispose(); return(attrbs); }
void ExportAttributes(int dataSourceId) { string sqlStatement = "select a.Name, a.Type, a.Minimum, a.Maximum, a.Formula, ads.IsAcceptable,ads.[AttributePrintValueType],ads.[AttributePrintValueCustom] "; sqlStatement += "from IdpeAttribute a "; sqlStatement += "inner join IdpeAttributeDataSource ads on a.AttributeId = ads.AttributeId "; sqlStatement += "where ads.DataSourceId = " + dataSourceId; sqlStatement += "order by ads.position "; DataTable table = CoreDatabaseObjects.Instance.ExecuteCommand(sqlStatement); foreach (DataRow row in table.Rows) { IdpeAttribute attrb = new IdpeAttribute(); attrb.Name = row["Name"] != DBNull.Value ? row["Name"].ToString() : null; attrb.Type = row["Type"] != DBNull.Value ? row["Type"].ToString() : null; attrb.Minimum = row["Minimum"] != DBNull.Value ? row["Minimum"].ToString() : null; attrb.Maximum = row["Maximum"] != DBNull.Value ? row["Maximum"].ToString() : null; attrb.Formula = row["Formula"] != DBNull.Value ? row["Formula"].ToString() : null; attrb.IsAcceptable = row["IsAcceptable"] != DBNull.Value ? row["IsAcceptable"].ToString().ParseBool() : false; attrb.AttributePrintValueType = row["AttributePrintValueType"] != DBNull.Value ? row["AttributePrintValueType"].ToString().ParseInt() : 0; attrb.AttributePrintValueCustom = row["AttributePrintValueCustom"] != DBNull.Value ? row["AttributePrintValueCustom"].ToString() : string.Empty; Attributes.Add(attrb); } }
private StringBuilder WriteOutputToDatabaseOracle(List <Row> rows) { _Job.PerformanceCounter.Start(_Job.JobIdentifier, JobPerformanceTaskNames.OutputWriterOracle); ExtensionMethods.TraceInformation("Starting oracle bulk insert..."); IDal dal = new DataAccessLayer(DatabaseTypes.Oracle).Instance; IDbConnection connection = dal.CreateConnection(ConnectionStringKey.Value); connection.Open(); IDbCommand command = dal.CreateCommand(); command.GetType().GetProperty("ArrayBindCount").SetValue(command, rows.Count, null); command.Connection = connection; ExtensionMethods.TraceInformation("Communication objects initialized. Creating arrays..."); int counter = 0; //creating arrays & insert statement string insertStatementPart1 = string.Format("insert into {0} (", DatabaseMap.TargetTableName); string insertStatementPart2 = "values ("; foreach (ColumnMapInfo columnMapInfo in DatabaseMap) { if ((!string.IsNullOrEmpty(columnMapInfo.InputColumn)) && (columnMapInfo.InputColumn != ColumnMapInfo.DatabaseDefault)) { counter++; insertStatementPart1 += "\"" + columnMapInfo.OutputColumn + "\","; if (columnMapInfo.InputColumn == ColumnMapInfo.CustomDefined) { insertStatementPart2 += string.Format("\"Customer_Id_Seq\".nextval,", counter); continue; } else { insertStatementPart2 += string.Format(":{0},", counter); } IdpeAttribute attributeAvailable = _Job.DataSource.AcceptableAttributesSystem.Where(a => a.Name == columnMapInfo.InputColumn).SingleOrDefault(); if (attributeAvailable == null) { continue; } Type attributeType = attributeAvailable.ConvertSreTypeIntoDotNetType(DatabaseTypes.Oracle); string[] strList = rows.Select(row => GetAttributeValue(row.ColumnsSystem[columnMapInfo.InputColumn], true)).ToArray(); if (attributeType == typeof(int)) { List <int?> list = strList.Select(s => s.GetValueOrNull <int>()).ToList(); command.AddParameterWithValue(columnMapInfo.OutputColumn, list.ToArray(), true); } else if (attributeType == typeof(long)) { List <long?> list = strList.Select(s => s.GetValueOrNull <long>()).ToList(); command.AddParameterWithValue(columnMapInfo.OutputColumn, list.ToArray(), true); } else if (attributeType == typeof(double)) { List <double?> list = strList.Select(s => s.GetValueOrNull <double>()).ToList(); command.AddParameterWithValue(columnMapInfo.OutputColumn, list.ToArray(), true); } else if (attributeType == typeof(bool)) { List <bool?> list = strList.Select(s => s.GetValueOrNull <bool>()).ToList(); command.AddParameterWithValue(columnMapInfo.OutputColumn, list.ToArray(), true); } else if (attributeType == typeof(DateTime)) { List <DateTime?> list = strList.Select(s => s.GetValueOrNull <DateTime>()).ToList(); command.AddParameterWithValue(columnMapInfo.OutputColumn, list.ToArray(), true); } else { command.AddParameterWithValue(columnMapInfo.OutputColumn, strList, true); } } } if (insertStatementPart1.Length > 1) { insertStatementPart1 = insertStatementPart1.Substring(0, insertStatementPart1.Length - 1); } if (insertStatementPart2.Length > 1) { insertStatementPart2 = insertStatementPart2.Substring(0, insertStatementPart2.Length - 1); } command.CommandText = string.Format("{0}) {1})", insertStatementPart1, insertStatementPart2); ExtensionMethods.TraceInformation("Arrays created. Executing statement - '{0}'", command.CommandText); command.ExecuteNonQuery(); connection.Close(); connection.Dispose(); ExtensionMethods.TraceInformation("Oracle bulk insert finished."); Trace.Flush(); _Job.PerformanceCounter.Stop(_Job.JobIdentifier, JobPerformanceTaskNames.OutputWriterOracle); return(new StringBuilder()); }
public int Save(IdpeAttribute attribute, IDal dal = null, IDbConnection connection = null, IDbTransaction transaction = null) { string cmdText = string.Empty; IDbCommand command = null; bool localTransaction = false; if (dal == null) { dal = new DataAccessLayer(EyediaCoreConfigurationSection.CurrentConfig.Database.DatabaseType).Instance; connection = dal.CreateConnection(_ConnectionString); connection.Open(); transaction = dal.CreateTransaction(connection); localTransaction = true; } command = dal.CreateCommand(); command.Connection = connection; command.Transaction = transaction; try { if (attribute.AttributeId == 0) { attribute.AttributeId = AttributeExists(attribute.Name, dal, connection, transaction); } bool inserted = false; if (attribute.AttributeId == 0) { inserted = true; cmdText = "INSERT INTO [IdpeAttribute] ([Name],[Type],[Minimum],[Maximum],[Formula],[IsAcceptable],[CreatedTS],[CreatedBy],[Source]) VALUES "; cmdText += "(@Name,@Type,@Minimum,@Maximum,@Formula,@IsAcceptable,@CreatedTS,@CreatedBy,@Source)"; command.AddParameterWithValue("Name", attribute.Name); command.AddParameterWithValue("Type", attribute.Type.ToString().ToUpper()); if (!(string.IsNullOrEmpty(attribute.Minimum))) { command.AddParameterWithValue("Minimum", attribute.Minimum); } else { command.AddParameterWithValue("Minimum", DBNull.Value); } if (!(string.IsNullOrEmpty(attribute.Maximum))) { command.AddParameterWithValue("Maximum", attribute.Minimum); } else { command.AddParameterWithValue("Maximum", DBNull.Value); } if (!(string.IsNullOrEmpty(attribute.Formula))) { command.AddParameterWithValue("Formula", attribute.Formula); } else { command.AddParameterWithValue("Formula", DBNull.Value); } command.AddParameterWithValue("IsAcceptable", attribute.IsAcceptable); command.AddParameterWithValue("CreatedTS", DateTime.Now); command.AddParameterWithValue("CreatedBy", Information.LoggedInUser.UserName); command.AddParameterWithValue("Source", "IDPE Util"); } else { cmdText = "UPDATE [IdpeAttribute] SET [Name] = @Name,[Type] = @Type,[Minimum] = @Minimum,[Maximum] = @Maximum,[Formula] = @Formula "; cmdText += "WHERE [AttributeId] = @AttributeId"; command.AddParameterWithValue("Name", attribute.Name); command.AddParameterWithValue("Type", attribute.Type.ToString().ToUpper()); if (!(string.IsNullOrEmpty(attribute.Minimum))) { command.AddParameterWithValue("Minimum", attribute.Minimum); } else { command.AddParameterWithValue("Minimum", DBNull.Value); } if (!(string.IsNullOrEmpty(attribute.Maximum))) { command.AddParameterWithValue("Maximum", attribute.Minimum); } else { command.AddParameterWithValue("Maximum", DBNull.Value); } if (!(string.IsNullOrEmpty(attribute.Formula))) { command.AddParameterWithValue("Formula", attribute.Formula); } else { command.AddParameterWithValue("Formula", DBNull.Value); } command.AddParameterWithValue("AttributeId", attribute.AttributeId); } command.CommandText = cmdText; command.ExecuteNonQuery(); if (inserted) { command.CommandText = "SELECT AttributeId from IdpeAttribute where Name = @Name"; command.Parameters.Clear(); command.AddParameterWithValue("Name", attribute.Name); attribute.AttributeId = (Int32)command.ExecuteScalar(); } if (localTransaction) { transaction.Commit(); } } catch (Exception ex) { if (localTransaction) { transaction.Rollback(); } Trace.TraceError(ex.ToString()); throw new Exception(ex.Message, ex); } finally { if (localTransaction) { if (connection.State == ConnectionState.Open) { connection.Close(); } connection.Dispose(); transaction.Dispose(); } } return(attribute.AttributeId); }
public SreAttributeProperty(IdpeAttribute attribute, int dataSourceId = 0, bool isSystem = false) : base(attribute, dataSourceId, isSystem) { }