private void BindAttributes() { Manager manager = new Manager(); List <IdpeAttribute> attributes = DataManager.GetAttributes(FromDataSource.Id); attributes = attributes.Where(a => a.AttributeId != 1).ToList(); List <IdpeAttributeDataSource> sadss = new List <IdpeAttributeDataSource>(); foreach (IdpeAttribute a in attributes) { IdpeAttributeDataSource sads = new IdpeAttributeDataSource(); sads.AttributeId = a.AttributeId; sads.DataSourceId = FromDataSource.Id; sads.IsAcceptable = true; sads.AttributeDataSourceId = 0; sads.AttributePrintValueType = a.AttributePrintValueType; sads.AttributePrintValueCustom = a.AttributePrintValueCustom; TreeNode node = new TreeNode(manager.GetAttribute(a.AttributeId).Name); node.Tag = sads; treeView.Nodes[0].Nodes.Add(node); sadss.Add(sads); } treeView.Nodes[0].Tag = sadss; //DataManager.SaveAssociations(NewDataSourceId, sadss); }
public void SaveSystemAttributeProperty() { if (DataSourceId == 0) { return; } IdpeAttributeDataSource sads = new IdpeAttributeDataSource(); sads.DataSourceId = DataSourceId; sads.AttributeId = Id; sads.Position = Position; sads.IsAcceptable = Printable; sads.AttributePrintValueType = (int)PrintFormat; if (PrintFormat == AttributePrintValueTypes.Custom) { sads.AttributePrintValueCustom = CSharpCode; } else { sads.AttributePrintValueCustom = string.Empty; } new Manager().Save(sads); }
public void CopyAttributes(string fromDataSource, int toDataSourceId) { Manager manager = new Manager(); List <IdpeAttribute> fromAttributes = manager.GetAttributes(fromDataSource); List <IdpeAttributeDataSource> appAttributes = new List <IdpeAttributeDataSource>(); int position = 1; foreach (IdpeAttribute attribute in fromAttributes) { IdpeAttributeDataSource aes = new IdpeAttributeDataSource(); aes.DataSourceId = toDataSourceId; aes.AttributeId = attribute.AttributeId; aes.Position = position; aes.CreatedTS = DateTime.Now; aes.CreatedBy = "IDPE Util"; aes.Source = "IDPE Util"; appAttributes.Add(aes); position++; } manager.SaveAssociations(toDataSourceId, appAttributes); }
public List <IdpeAttributeDataSource> GetSreAttributeDataSources(int attributeDataSourceId = 0) { List <IdpeAttributeDataSource> idpeAttributeDataSources = new List <IdpeAttributeDataSource>(); string commandText = "select [AttributeDataSourceId],[DataSourceId],[AttributeId],[Position],[IsAcceptable],[AttributePrintValueType],[AttributePrintValueCustom],[CreatedTS],[CreatedBy],[ModifiedTS],[ModifiedBy],[Source] from [IdpeAttributeDataSource]"; if (attributeDataSourceId > 0) { commandText += " where [AttributeDataSourceId] = " + attributeDataSourceId; } DataTable table = CoreDatabaseObjects.Instance.ExecuteCommand(commandText); if (table == null) { return(idpeAttributeDataSources); } foreach (DataRow row in table.Rows) { IdpeAttributeDataSource idpeAttributeDataSource = new IdpeAttributeDataSource(); idpeAttributeDataSource.AttributeDataSourceId = (int)row["AttributeDataSourceId"].ToString().ParseInt(); idpeAttributeDataSource.DataSourceId = (int)row["DataSourceId"].ToString().ParseInt(); idpeAttributeDataSource.AttributeId = (int)row["AttributeId"].ToString().ParseInt(); idpeAttributeDataSource.Position = row["Position"] != DBNull.Value ? row["Position"].ToString().ParseInt() : null; idpeAttributeDataSource.IsAcceptable = row["IsAcceptable"] != DBNull.Value ? row["IsAcceptable"].ToString().ParseBool() : false; idpeAttributeDataSource.AttributePrintValueType = row["AttributePrintValueType"] != DBNull.Value ? row["AttributePrintValueType"].ToString().ParseInt() : 0; idpeAttributeDataSource.AttributePrintValueCustom = row["AttributePrintValueCustom"] != DBNull.Value ? row["AttributePrintValueCustom"].ToString() : string.Empty; idpeAttributeDataSource.CreatedTS = (DateTime)(row["CreatedTS"] != DBNull.Value ? row["CreatedTS"].ToString().ParseDateTime() : DateTime.MinValue); idpeAttributeDataSource.CreatedBy = row["CreatedBy"] != DBNull.Value ? row["CreatedBy"].ToString() : null; idpeAttributeDataSource.ModifiedTS = row["ModifiedTS"] != DBNull.Value ? row["ModifiedTS"].ToString().ParseDateTime() : null; idpeAttributeDataSource.ModifiedBy = row["ModifiedBy"] != DBNull.Value ? row["ModifiedBy"].ToString() : null; idpeAttributeDataSource.Source = row["Source"] != DBNull.Value ? row["Source"].ToString() : null; idpeAttributeDataSources.Add(idpeAttributeDataSource); } table.Dispose(); return(idpeAttributeDataSources); }
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; } }
public void Save(IdpeAttributeDataSource idpeAttributeDataSource, IDal dal = null, IDbConnection connection = null, IDbTransaction transaction = null) { string cmdText = string.Empty; 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; } IDbCommand command = dal.CreateCommand(); command.Connection = connection; command.Transaction = transaction; try { cmdText = "SELECT [AttributeDataSourceId] FROM IdpeAttributeDataSource WHERE [DataSourceId] = @DataSourceId and [AttributeId] = @AttributeId"; command.Parameters.Clear(); command.AddParameterWithValue("DataSourceId", idpeAttributeDataSource.DataSourceId); command.AddParameterWithValue("AttributeId", idpeAttributeDataSource.AttributeId); command.CommandText = cmdText; IDataReader reader = command.ExecuteReader(); if (reader.Read()) { cmdText = "UPDATE [IdpeAttributeDataSource] SET [Position] = @Position, [IsAcceptable] = @IsAcceptable, AttributePrintValueType = @AttributePrintValueType, AttributePrintValueCustom = @AttributePrintValueCustom WHERE [AttributeDataSourceId] = @AttributeDataSourceId"; command.Parameters.Clear(); command.AddParameterWithValue("Position", idpeAttributeDataSource.Position); command.AddParameterWithValue("IsAcceptable", idpeAttributeDataSource.IsAcceptable); command.AddParameterWithValue("AttributeDataSourceId", int.Parse(reader[0].ToString())); if ((idpeAttributeDataSource.AttributePrintValueType == 0) || (idpeAttributeDataSource.AttributePrintValueType == null)) { command.AddParameterWithValue("AttributePrintValueType", DBNull.Value); } else { command.AddParameterWithValue("AttributePrintValueType", idpeAttributeDataSource.AttributePrintValueType); } if (string.IsNullOrEmpty(idpeAttributeDataSource.AttributePrintValueCustom)) { command.AddParameterWithValue("AttributePrintValueCustom", DBNull.Value); } else { command.AddParameterWithValue("AttributePrintValueCustom", idpeAttributeDataSource.AttributePrintValueCustom); } } else { cmdText = "INSERT INTO [IdpeAttributeDataSource] ([DataSourceId],[AttributeId],[Position],[IsAcceptable],[AttributePrintValueType],[AttributePrintValueCustom],[CreatedTS],[CreatedBy],[Source]) VALUES "; cmdText += "(@DataSourceId,@AttributeId,@Position,@IsAcceptable,@AttributePrintValueType,@AttributePrintValueCustom,@CreatedTS,@CreatedBy,@Source)"; command.Parameters.Clear(); command.AddParameterWithValue("DataSourceId", idpeAttributeDataSource.DataSourceId); command.AddParameterWithValue("AttributeId", idpeAttributeDataSource.AttributeId); command.AddParameterWithValue("Position", idpeAttributeDataSource.Position); command.AddParameterWithValue("IsAcceptable", idpeAttributeDataSource.IsAcceptable); if ((idpeAttributeDataSource.AttributePrintValueType == 0) || (idpeAttributeDataSource.AttributePrintValueType == null)) { command.AddParameterWithValue("AttributePrintValueType", DBNull.Value); } else { command.AddParameterWithValue("AttributePrintValueType", idpeAttributeDataSource.AttributePrintValueType); } if (!string.IsNullOrEmpty(idpeAttributeDataSource.AttributePrintValueCustom)) { command.AddParameterWithValue("AttributePrintValueCustom", idpeAttributeDataSource.AttributePrintValueCustom); } else { command.AddParameterWithValue("AttributePrintValueCustom", DBNull.Value); } command.AddParameterWithValue("CreatedTS", DateTime.Now); command.AddParameterWithValue("CreatedBy", Information.LoggedInUser == null ? "Debugger" : Information.LoggedInUser.UserName); command.AddParameterWithValue("Source", "IDPE Util"); } reader.Close(); command.CommandText = cmdText; command.ExecuteNonQuery(); 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(); } } }