By a RadGridView, how can I get to show detail information? - c#

I have created a hierarchical relationship in a RadGridView. But the relationship doesn't work. I can't show the detail information. What do I do wrong?
If I generated automatically all relationships works fine. But I need just one field of one table as detail info.
Further: I use VS2013 Prof., WinForms as UI and LINQ to SQL as datasource.
The source code is:
private void OpenConfigurations()
{
bsConfigurations.DataSource = Db.Configurations.Where(c => c.Active == true && c.CompanyId == CurrentCompany.CompanyId).Select(c => c).OrderBy(c => c.Name);
bsConfigurationContracts.DataSource = Db.ConfigurationContracts.Where(c => c.Contract.InsurranceId == CurrentCompany.CompanyId).Select(c =>
c).OrderBy(c => c.Contract.Name);
GridViewRelation gvrConfigurations = new GridViewRelation();
gvrConfigurations.ChildColumnNames.Add("ConfigurationId");
gvrConfigurations.ChildTemplate = this.gridViewTemplate1;
gvrConfigurations.ParentColumnNames.Add("ConfigurationId");
gvrConfigurations.ParentTemplate = this.gvConfiguration.MasterTemplate;
gvConfiguration.Relations.Add(gvrConfigurations);
}
In the designer:
this.gridViewTemplate1.AllowAddNewRow = false;
gridViewTextBoxColumn1.EnableExpressionEditor = false;
gridViewTextBoxColumn1.FieldName = "Contract.Name";
gridViewTextBoxColumn1.HeaderText = "Name";
gridViewTextBoxColumn1.Name = "colName";
gridViewTextBoxColumn1.Width = 250;
gridViewTextBoxColumn2.EnableExpressionEditor = false;
gridViewTextBoxColumn2.FieldName = "ConfigurationId";
gridViewTextBoxColumn2.HeaderText = "ConfigurationId";
gridViewTextBoxColumn2.IsVisible = false;
gridViewTextBoxColumn2.Name = "colConfigurationId";
this.gridViewTemplate1.Columns.AddRange(new Telerik.WinControls.UI.GridViewDataColumn[] { gridViewTextBoxColumn1, gridViewTextBoxColumn2 });
this.gridViewTemplate1.DataSource = this.bsConfigurationContracts;
//
// gvConfiguration
//
this.gvConfiguration.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(233)))), ((int)(((byte)(240)))), ((int)(((byte)(249)))));
this.gvConfiguration.Cursor = System.Windows.Forms.Cursors.Default;
this.gvConfiguration.Dock = System.Windows.Forms.DockStyle.Fill;
this.gvConfiguration.Font = new System.Drawing.Font("Segoe UI", 8.25F);
this.gvConfiguration.ForeColor = System.Drawing.Color.Black;
this.gvConfiguration.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.gvConfiguration.Location = new System.Drawing.Point(0, 30);
//
//
//
this.gvConfiguration.MasterTemplate.AllowAddNewRow = false;
this.gvConfiguration.MasterTemplate.AutoGenerateColumns = false;
gridViewTextBoxColumn3.EnableExpressionEditor = false;
gridViewTextBoxColumn3.FieldName = "Name";
gridViewTextBoxColumn3.HeaderText = "Name";
gridViewTextBoxColumn3.Name = "colName";
gridViewTextBoxColumn3.SortOrder = Telerik.WinControls.UI.RadSortOrder.Ascending;
gridViewTextBoxColumn3.Width = 250;
gridViewTextBoxColumn4.EnableExpressionEditor = false;
gridViewTextBoxColumn4.FieldName = "ConfigurationId";
gridViewTextBoxColumn4.HeaderText = "ConfigurationId";
gridViewTextBoxColumn4.IsVisible = false;
gridViewTextBoxColumn4.Name = "colConfigurationId";
this.gvConfiguration.MasterTemplate.Columns.AddRange(new Telerik.WinControls.UI.GridViewDataColumn[] { gridViewTextBoxColumn3, gridViewTextBoxColumn4 });
this.gvConfiguration.MasterTemplate.DataSource = this.bsConfigurations;
sortDescriptor1.PropertyName = "colName";
this.gvConfiguration.MasterTemplate.SortDescriptors.AddRange(new Telerik.WinControls.Data.SortDescriptor[] { sortDescriptor1 });
this.gvConfiguration.MasterTemplate.Templates.AddRange(new Telerik.WinControls.UI.GridViewTemplate[] { this.gridViewTemplate1 });
this.gvConfiguration.Name = "gvConfiguration";
this.gvConfiguration.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.gvConfiguration.ShowGroupPanel = false;
this.gvConfiguration.Size = new System.Drawing.Size(1098, 72);
this.gvConfiguration.TabIndex = 4;
this.gvConfiguration.Text = "radGridView1";
this.gvConfiguration.CellDoubleClick += new Telerik.WinControls.UI.GridViewCellEventHandler(this.gvConfiguration_CellDoubleClick);

The solution is in the relation you have to add the column name in stead of the field name.
So this is the right code:
GridViewRelation gvrConfigurations = new GridViewRelation();
gvrConfigurations.ChildColumnNames.Add("colConfigurationId");
gvrConfigurations.ChildTemplate = this.gridViewTemplate1;
gvrConfigurations.ParentColumnNames.Add("colConfigurationId");
gvrConfigurations.ParentTemplate = this.gvConfiguration.MasterTemplate;
gvConfiguration.Relations.Add(gvrConfigurations);

Related

How can I make EPPlus excel format to tabular instead of Compact?

I tried to set some of the settings such as Compact =false, CompactData = false, etc but nothing worked.
I wanted to separate the "Reviewer and Engagement instead of them in one field. I have posted two photos. The first is the output I have, Second is the one that I am trying to achieve.
enter code
//define the data range on the source sheet
var dataRange = workSheetDataSource.Cells[workSheetDataSource.Dimension.Address];
//create the pivot table
var pivotTable = workSheetMgrAndEng.PivotTables.Add(workSheetMgrAndEng.Cells["A4"], dataRange, "PivotTable");
//label field
pivotTable.RowFields.Add(pivotTable.Fields["Reviewer"]);
pivotTable.RowFields.Add(pivotTable.Fields["Engagement"]);
//pivot field settings
pivotTable.Compact = false;
pivotTable.CompactData = false;
pivotTable.Indent = 0;
//pivotTable.RowGrandTotals = false;
pivotTable.UseAutoFormatting = true;
//pivotTable.ShowMemberPropertyTips = false;
pivotTable.DataOnRows = false;
//data fields
var field1 = pivotTable.DataFields.Add(pivotTable.Fields["Engagement"]);
field1.Name = "Count of Engagement";
field1.Function = DataFieldFunctions.Count;
var field2 = pivotTable.DataFields.Add(pivotTable.Fields["Prep Complete"]);
field2.Name = "Count of Prep Complete";
field2.Function = DataFieldFunctions.Count;
var field3 = pivotTable.DataFields.Add(pivotTable.Fields["Sent Delivered"]);
field3.Name = "Sent/Delivered";
field3.Function = DataFieldFunctions.Count;
var field4 = pivotTable.DataFields.Add(pivotTable.Fields["Return to Tax Office"]);
field4.Name = "Count of Return to Tax Office";
field4.Function = DataFieldFunctions.Count;
//data fields settings
//field1.Field.Outline = false;
field1.Field.Compact = false;
field1.Field.ShowAll = false;
//field1.Field.SubtotalTop = false;
//field2.Field.Outline = false;
field2.Field.Compact = false;
field2.Field.ShowAll = false;
//field2.Field.SubtotalTop = false;
//field3.Field.Outline = false;
field3.Field.Compact = false;
field3.Field.ShowAll = false;
//field3.Field.SubtotalTop = false;
//field4.Field.Outline = false;
field4.Field.Compact = false;
field4.Field.ShowAll = false;
//field4.Field.SubtotalTop = false;

SQL SMO is generating insert statements incorrectly

I'm working on a C# application to generate the script. I have the following settings below, but tables/insert statements are being generated for other schemas. I just want one specific schema and all the schema/data from it.
I tried to set options.WithDependencies = false;, but then it wouldn't give me everything I needed as in scripting the data.
What other setting am I missing?
private void GeneratingMainSQLScript(string schema)
{
Server srv = new Server(#".\sql2017");
Database dbs = srv.Databases["SOURCE_T"];
ScriptingOptions options = new ScriptingOptions();
options.TargetServerVersion = SqlServerVersion.Version140;
options.EnforceScriptingOptions = true;
options.ScriptData = true;
options.ScriptDrops = false;
options.FileName = GenerateScriptFileName(schema, false);
options.EnforceScriptingOptions = true;
options.ScriptSchema = true;
options.IncludeHeaders = true;
options.AppendToFile = true;
options.Indexes = true;
options.WithDependencies = true;
var tableNames = GetTableNames(schema);
int progressCounter = 1;
foreach (var tbl in tableNames)
{
if (tbl.SchemaName == "dbo" && tbl.TableName == "FileDatas")
{
options.ScriptData = false;
}
dbs.Tables[tbl.TableName, tbl.SchemaName].EnumScript(options);
DisplayDebug(string.Format("Running migration schema's ({2}) main genreated script | Total: {0} | Processing #: {1}", tableNames.Count, progressCounter, schema));
progressCounter++;
}
}
UPDATE:
I made these changes after working with my lead and we are close. The issue now: it is generating the FKS after creating the table and not at the END of the file like when you do it via SSMS directly?
Server srv = new Server(#".\sql2017");
Database dbs = srv.Databases["SOURCE_T"];
ScriptingOptions options = new ScriptingOptions();
options.FileName = GenerateScriptFileName(schema, isSchemaOnly);
options.EnforceScriptingOptions = true;
// start
options.AnsiPadding = false;
options.AppendToFile = true;
options.ContinueScriptingOnError = false;
options.ConvertUserDefinedDataTypesToBaseType = false;
options.WithDependencies = false;
options.IncludeHeaders = true;
options.IncludeScriptingParametersHeader = false;
options.SchemaQualify = true;
options.Bindings = false;
options.NoCollation = true;
options.Default = true;
options.ScriptDrops = false;
options.ScriptSchema = isSchemaOnly;
options.ExtendedProperties = true;
options.TargetServerVersion = SqlServerVersion.Version140;
options.TargetDatabaseEngineType = Microsoft.SqlServer.Management.Common.DatabaseEngineType.Standalone;
options.LoginSid = false;
options.Statistics = false;
options.ScriptData = !isSchemaOnly;
options.ChangeTracking = false;
options.DriAllConstraints = true;
options.ScriptDataCompression = false;
options.DriForeignKeys = true;
options.FullTextIndexes = false;
options.Indexes = false;
options.DriPrimaryKey = true;
options.Triggers = false;
options.DriUniqueKeys = true;
options.DriAll = true;
Here is the solution I am using. The key here is all the options that I have set, but also how I pull the table names. GetTablesNames will obtain the tables in the order that they need to be made in, which allows for everything to process properly along with the FKs.
Obtaining the tables properly
setting this variable to false: options.WithDependencies = false;
Are the keys to my solution.
private void GeneratingMainSQLScript(string schema, bool isSchemaOnly)
{
Server srv = new Server(sqlServer);
Database dbs = srv.Databases["SOURCE_T"];
ScriptingOptions options = new ScriptingOptions();
options.FileName = GenerateScriptFileName(schema, isSchemaOnly);
options.EnforceScriptingOptions = true;
// start
options.AnsiPadding = false;
options.AppendToFile = true;
options.ContinueScriptingOnError = false;
options.ConvertUserDefinedDataTypesToBaseType = false;
options.WithDependencies = false;
options.IncludeHeaders = true;
options.IncludeScriptingParametersHeader = false;
options.SchemaQualify = true;
options.Bindings = false;
options.NoCollation = true;
options.Default = true;
options.ScriptDrops = false;
options.ScriptSchema = true;
options.ExtendedProperties = true;
options.TargetServerVersion = SqlServerVersion.Version140;
options.TargetDatabaseEngineType = Microsoft.SqlServer.Management.Common.DatabaseEngineType.Standalone;
options.LoginSid = false;
options.Statistics = false;
options.ScriptData = true;
options.ChangeTracking = false;
options.DriAllConstraints = true;
options.ScriptDataCompression = false;
options.DriForeignKeys = true;
options.FullTextIndexes = false;
options.Indexes = false;
options.DriPrimaryKey = true;
options.Triggers = false;
options.DriUniqueKeys = true;
if (isSchemaOnly == true)
{
options.ScriptSchema = true;
options.DriForeignKeys = true;
options.SchemaQualify = true;
options.SchemaQualifyForeignKeysReferences = true;
options.DriAll = true;
options.ScriptData = false;
}
else
{
options.ScriptSchema = false;
options.ScriptData = true;
options.DriAll = false;
}
var tableNames = GetTablesNames(schema, sourceDefaultConnection, true);
int progressCounter = 1;
foreach (var tbl in tableNames)
{
if (tbl.SchemaName == "HR" && tbl.TableName == "FileDatas" && isSchemaOnly == false)
{
continue;
}
else
{
dbs.Tables[tbl.TableName, tbl.SchemaName].EnumScript(options);
}
DisplayDebug(string.Format("Running migration schema's ({2}) main generated script | Total: {0} | Processing #: {1}", tableNames.Count, progressCounter, schema));
progressCounter++;
}
}
private IList<DatabaseTableDTO> GetTablesNames(string schema, string connectionName, bool isAscending)
{
string sql = string.Format(#"WITH cte (lvl, object_id, name, schema_Name) AS
(SELECT 1, object_id, sys.tables.name, sys.schemas.name as schema_Name
FROM sys.tables Inner Join sys.schemas on sys.tables.schema_id = sys.schemas.schema_id
WHERE type_desc = 'USER_TABLE'
AND is_ms_shipped = 0
UNION ALL SELECT cte.lvl + 1, t.object_id, t.name, S.name as schema_Name
FROM cte
JOIN sys.tables AS t ON EXISTS
(SELECT NULL FROM sys.foreign_keys AS fk
WHERE fk.parent_object_id = t.object_id
AND fk.referenced_object_id = cte.object_id )
JOIN sys.schemas as S on t.schema_id = S.schema_id
AND t.object_id <> cte.object_id
AND cte.lvl < 30
WHERE t.type_desc = 'USER_TABLE'
AND t.is_ms_shipped = 0 )
SELECT schema_Name, name, MAX (lvl) AS dependency_level
FROM cte
where schema_Name = '{0}'
GROUP BY schema_Name, name
ORDER BY dependency_level {1},schema_Name, name;", schema, isAscending == true ? "ASC" : "DESC");
var connectionString = ConfigurationManager.ConnectionStrings[connectionName];
var listOfTables = new List<DatabaseTableDTO>();
using (SqlConnection conn = new SqlConnection(connectionString.ConnectionString))
{
conn.Open();
using (var command = new SqlCommand(sql, conn))
{
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
listOfTables.Add(new DatabaseTableDTO { SchemaName = schema, TableName = reader.GetString(1) });
}
}
}
}
return listOfTables;
}
public class DatabaseTableDTO
{
public string SchemaName { get; set; }
public string TableName { get; set; }
}

DevExpress RepositoryItemComboBox cannot show combobox list data

I'm using gridControl.DataSource from WCF Service and add manual RepositoryItemComboBox to gridControl. but RepositoryItemComboBox cannot show combo-box list data.
this my code :
gridControl8.DataSource = service.jadwalUmumStaff(data).Select(r => new
{
hari = r.jadwal_umum.hari,
shift = r.jadwal_umum.fk_jadwalUmum_Shift.id_shift,
waktu = r.jadwal_umum.fk_jadwalUmum_Shift.waktu,
mata_kuliah = r.jadwal_umum.fk_jadwalUmum_matakuliah.mata_kuliah,
nama = r.staff.nama,
} ).ToList();
RepositoryItemComboBox nama = new RepositoryItemComboBox()
{
TextEditStyle = TextEditStyles.DisableTextEditor,
ShowDropDown = ShowDropDown.SingleClick
};
var a = service.getStaffID();
string[] _a = new string[a.Count()];
for (int i = 0; i < a.Count(); i++)
{
_a[i] = a[i].id_staff;
}
nama.Items.AddRange(_a);
gridControl8.RepositoryItems.Add(nama);
gridView8.Columns[4].ColumnEdit = nama;
gridControl8.ForceInitialize();
you need AllowDropDownWhenReadOnly and set value true
following this code :
RepositoryItemComboBox nama = new RepositoryItemComboBox()
{
TextEditStyle = TextEditStyles.DisableTextEditor,
AllowDropDownWhenReadOnly = DevExpress.Utils.DefaultBoolean.True
};

Telerik Winforms RadGridView not filtering

I am trying to get the Telerik RadGridview control to filter, and am not having any luck. I am getting data back, and sorting is working. The FilterExpressionChanged is firing. Can someone spot what I'm doing wrong?
Data retrieval:
public void LoadData()
{
DataSet oDataSet = new DataSet();
using (SqlConnection oConnection = new SqlConnection(frm_Main.GetConnectionString()))
{
using (SqlCommand oCommand = new SqlCommand())
{
oConnection.Open();
oCommand.Connection = oConnection;
oCommand.CommandText = "SELECT * FROM ip.t_Dataload UNION ALL SELECT * FROM ip.t_Dataload_his ORDER BY Started DESC";
using (SqlDataAdapter oDataAdapter = new SqlDataAdapter(oCommand))
{
oDataAdapter.Fill(oDataSet);
radGridView1.DataSource = oDataSet.Tables[0];
}
}
}
}
Form.designer.cs:
//
// radGridView1
//
this.radGridView1.BackColor = System.Drawing.SystemColors.Desktop;
this.radGridView1.CausesValidation = false;
this.radGridView1.Cursor = System.Windows.Forms.Cursors.Default;
this.radGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.radGridView1.EnableCustomFiltering = true;
this.radGridView1.Font = new System.Drawing.Font("Segoe UI", 8.25F);
this.radGridView1.ForeColor = System.Drawing.SystemColors.ControlText;
this.radGridView1.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.radGridView1.Location = new System.Drawing.Point(0, 24);
//
// radGridView1
//
this.radGridView1.MasterTemplate.AllowAddNewRow = false;
this.radGridView1.MasterTemplate.AllowDeleteRow = false;
this.radGridView1.MasterTemplate.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.MasterTemplate.EnableCustomFiltering = true;
this.radGridView1.MasterTemplate.EnableFiltering = true;
this.radGridView1.MasterTemplate.SelectionMode = Telerik.WinControls.UI.GridViewSelectionMode.CellSelect;
this.radGridView1.Name = "radGridView1";
this.radGridView1.NewRowEnterKeyMode = Telerik.WinControls.UI.RadGridViewNewRowEnterKeyMode.None;
this.radGridView1.ReadOnly = true;
this.radGridView1.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.radGridView1.ShowGroupPanel = false;
this.radGridView1.Size = new System.Drawing.Size(1277, 746);
this.radGridView1.TabIndex = 2;
this.radGridView1.Text = "radGridView1";
this.radGridView1.EnableFiltering = true;
this.radGridView1.RowFormatting += new Telerik.WinControls.UI.RowFormattingEventHandler(this.radGridView1_RowFormatting);
this.radGridView1.CellFormatting += new Telerik.WinControls.UI.CellFormattingEventHandler(this.radGridView1_CellFormatting);
this.radGridView1.CellDoubleClick += new Telerik.WinControls.UI.GridViewCellEventHandler(this.radGridView1_CellDoubleClick);
this.radGridView1.DataBindingComplete += new Telerik.WinControls.UI.GridViewBindingCompleteEventHandler(this.radGridView1_DataBindingComplete);
this.radGridView1.FilterExpressionChanged += new Telerik.WinControls.UI.GridViewFilterExpressionChangedEventHandler(this.radGridView1_FilterExpressionChanged);
//
If you set
EnableCustomFiltering = true
and
EnableFiltering = true
filtering does not work.
To make the filtering work, set EnableCustomFiltering = false and EnableFiltering = true.

Using eBay SDK API: internationalShippingOptions.ShipToLocation.Add("Worldwide"); causes:"Object reference not set to an instance of an object"

My goal here so to make the listing say "Free International Shipping". Trying to set up international options and it said I need to set ShipToLocation I tried the line below:
internationalShippingOptions.ShipToLocation.Add("Worldwide");
But when the program hits it I get this error:
"Object reference not set to an instance of an object"
If you would like to see the full method it is:
static ShippingDetailsType BuildShippingDetails()
{
ShippingDetailsType sd = new ShippingDetailsType();
sd.ApplyShippingDiscount = false;
sd.ShippingType = ShippingTypeCodeType.Flat;
AmountType amount = new AmountType();
amount.Value = 0;
amount.currencyID = CurrencyCodeType.USD;
ShippingServiceOptionsTypeCollection shippingOptions = new ShippingServiceOptionsTypeCollection();
ShippingServiceOptionsType domesticShippingOptions = new ShippingServiceOptionsType();
domesticShippingOptions.ShippingService = ShippingServiceCodeType.EconomyShippingFromOutsideUS.ToString();
domesticShippingOptions.FreeShipping = true;
domesticShippingOptions.ShippingServiceCost = amount;
domesticShippingOptions.ShippingServicePriority = 1;
shippingOptions.Add(domesticShippingOptions);
ShippingServiceOptionsType internationalShippingOptions = new ShippingServiceOptionsType();
InternationalShippingServiceOptionsType internationalShippingOptions = new InternationalShippingServiceOptionsType();
internationalShippingOptions.ShippingService = ShippingServiceCodeType.StandardInternational.ToString();
internationalShippingOptions.ShipToLocation.Add("Worldwide");
internationalShippingOptions.FreeShipping = true;
sd.InternationalShippingServiceOption = new InternationalShippingServiceOptionsTypeCollection(new InternationalShippingServiceOptionsType[] { internationalShippingOptions });
sd.ShippingServiceOptions = shippingOptions;
return sd;
}
Here is the code to make it say "Free Standard Intl Shipping". At first in the sandbox it says "Free Standard Shipping" but if you change the shipping destination in the sandbox it will say "Free Standard Intl Shipping".
static ShippingDetailsType BuildShippingDetails()
{
// Shipping details
ShippingDetailsType sd = new ShippingDetailsType();
sd.ApplyShippingDiscount = true;
sd.PaymentInstructions = "eBay .Net SDK test instruction.";
sd.ShippingRateType = ShippingRateTypeCodeType.StandardList;
// Shipping type and shipping service options
//adding international shipping
InternationalShippingServiceOptionsType internationalShipping1 = new InternationalShippingServiceOptionsType();
internationalShipping1.ShippingService = ShippingServiceCodeType.StandardInternational.ToString();
internationalShipping1.ShippingServiceCost = new AmountType { Value = 0, currencyID = CurrencyCodeType.USD };
internationalShipping1.ShippingServicePriority = 1;
internationalShipping1.ShipToLocation = new StringCollection(new[] { "Worldwide" });
sd.ShippingServiceUsed = ShippingServiceCodeType.StandardInternational.ToString();
sd.InternationalShippingServiceOption = new InternationalShippingServiceOptionsTypeCollection(new[] { internationalShipping1 });
//adding domestic shipping
ShippingServiceOptionsType domesticShipping1 = new ShippingServiceOptionsType();
domesticShipping1.ShippingService = ShippingServiceCodeType.ShippingMethodStandard.ToString();
domesticShipping1.ShippingServiceCost = new AmountType { Value = 0, currencyID = CurrencyCodeType.USD };
domesticShipping1.ShippingInsuranceCost = new AmountType { Value = 0, currencyID = CurrencyCodeType.USD };
domesticShipping1.ShippingServicePriority = 4;
domesticShipping1.LocalPickup = true;
domesticShipping1.FreeShipping = true;
sd.ShippingServiceOptions = new ShippingServiceOptionsTypeCollection(new[] { domesticShipping1 });
sd.ShippingType = ShippingTypeCodeType.Flat;
return sd;
To call the method:
item.ShippingDetails = BuildShippingDetails();

Categories

Resources