|
Context.InvokeAsynchronousTask(() =>
{
});
I have this code, its not getting called from the unit test project.
|
|
|
|
|
Well, without seeing the code for the unit test project, how do you expect anyone to give you any kind of usable answer?
|
|
|
|
|
Most likely the test finishes before the asynchronous task has a chance to execute.
You'll have to wait in the test for the completion of the asynchronous task. If you don't have a callback method that gets executed on completion you might just have to wait a few moments.
I usually use the ManualResetEvent with the WaitOne Method for such cases.
You can specify a timeout after which the execution should continue even if you don't receive a signal.
|
|
|
|
|
Thanks a lot
|
|
|
|
|
I am using WPF TestBlock control and activating a font which family id is Adolescence using Win32 API AddFontResource. This font is available on various document and also can be easily usable just adding the familyname on html web control. But for WPF TextBox it is not working just passing the family name.
I am using following code snippet.
<TextBlock Grid.Row="0" x:Name="SampleText" Text="{Binding
SampleText}" FontFamily="Adolescence" FontStyle="Normal"
FontSize="20"/>
I cannot put our fonts into windows font directory and also cannot add the directory path in FontFamily parameter and cannot add font into package.
I did googling a lot but could not found any solution. I also very curious to know why WPF is application is not able to detect Font while other application is able to detect the same.
Thanks in advance.
|
|
|
|
|
|
Some apps will "infer" a font based on a "name" and some properties; e.g. "Myriad Pro" and italic weight gives "Myriad Pro Italic", etc.
WPF needs the exact font name.
You should check the names of the fonts in the Control Panel "Fonts" app.
There are fonts (indicated with a little "stack" icon) that when clicked in Control Panel will yield other "sub-fonts" (which names one would use in WPF; besides the font properties).
|
|
|
|
|
<connectionstrings>
<add name="CostAllocationEntities2"
="" connectionstring="Data Source=PC210090\SQLEXPRESS;initial catalog=testdb1;Persist Security Info=True;User ID=sa;Password=password1$" providername="System.Data.SqlClient">
SqlConnection conn;
public SqlConnection openconn()
{
conn = new SqlConnection(ConfigurationManager.ConnectionStrings["CostAllocationEntities2"].ConnectionString);
try
{
if (conn.State == ConnectionState.Closed)
{<br />
conn.Open();
return conn;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Failed to Connect with Database.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return null;
}
return conn;
}
public void GetBackup(string strDBName)
{
if (string.IsNullOrEmpty(strDBName))
{
MessageBox.Show("Server Name & Database can not be Blank");
return;
}
else
{
string destinationPath = ConfigurationManager.AppSettings.Get("BackupDestinationPath");
BackupDeviceItem deviceItem = new BackupDeviceItem(destinationPath, DeviceType.File);
ServerConnection connection = new ServerConnection(ConfigurationManager.ConnectionStrings["CostAllocationEntities2"].ConnectionString);
Server sqlServer = new Server(connection);
Database db = sqlServer.Databases[strDBName];
Backup bkpDBFull = new Backup();
bkpDBFull.Action = BackupActionType.Database;
bkpDBFull.Database = strDBName;<br />
bkpDBFull.Devices.AddDevice(String.Format("{0}{1}-{2}.bak", destinationPath, strDBName, DateTime.Now.ToString("yyyy-MM-dd")), DeviceType.File);
bkpDBFull.BackupSetName = strDBName + " Backup";
bkpDBFull.BackupSetDescription = strDBName + "- Full Backup";
bkpDBFull.ExpirationDate = DateTime.Today.AddDays(10);<br />
bkpDBFull.Initialize = false;
bkpDBFull.SqlBackup(sqlServer);
MessageBox.Show("Backup Done");
}
}
On this line
Database db = sqlServer.Databases[strDBName];
I get an error:
Not allowed to change the 'ConnectionString' property. The connection's current state is connecting."
-- modified 28-Oct-15 2:27am.
|
|
|
|
|
|
Hello guys/gals,
Since a few months i have rather a real head desturbing issue :/
I have developed a plugin architecture that exists of a Host app and several plugins.
The host app basicly loads all the plugins availible, and allows any plugin to interact with the host, and vice versa.
Everything works fine when it comes to using methods/properties ect...accept for the events...
The events are used to send info to any asigned instance, including the plugins.
Whenever i assign the event inside plugin to recieve info from the host then i get the 'System.Reflection.TargetInvocationException'.
The exception is thrown whenever the host invokes the event that has been assigned from plugin instance.
Though i should mention that the event is used by the plugin AND the host.
They both should be revieving the plugin info...
I know ive used several events in a plugin system before, but that was the other way around.
The host was recieving info from plugin , witch works, just the other way arround seems to be a issue.
The Plugins are loaded by system.reflection as raw data and not as a file...
i did this because the plugins are stored in a custom container, compressed and encrypted.
Here is the manager interface (HOST):
public interface IPluginManager : IPluginBase
{
bool IsLoaded { get; }
Settings AppPreferences { get; }
ILogin Server { get; }
byte[] Signature { get; }
AppInfo[] Plugins { get; }
#region Events
event PluginRequestHandler PluginUpdate;
event PluginRequestHandler PluginInstall;
event PluginRequestHandler PluginRemove;
event PluginInstallHandler PluginsToInstall;
event PluginInstallHandler PluginsToUpdate;
event PluginInstallHandler PluginsToRemove;
event PluginHandler PluginActionChanged;
event PluginsHandler PluginsInstalled;
event PluginsHandler PluginsUpdated;
event PluginsHandler PluginsRemoved;
event EventHandler ManagerLoaded;
event EventHandler ManagerLoading;
event EventHandler ManagerDisposed;
#endregion
#region Methods
void LoadAsync();
void Dispose();
void RemovePluginAsync(AppInfo plugin);
bool RemovePlugin(AppInfo plugin);
void InstallPluginAsync(AppInfo plugin);
bool InstallPlugin(AppInfo plugin);
bool InstallNewPlugins();
void InstallNewPluginsAsync();
void MountPluginAsync(AppInfo info);
void UnmountPluginAsync(AppInfo info);
void EnableApp(AppInfo info);
void DisableApp(AppInfo info);
AppInfo[] GetOnlineApps();
#endregion
}
Here the code from plugin instance that init the Host event.
private void MainForm_Shown(object sender, EventArgs e)
{
if (Host != null && Host.PluginManager != null)
{
SCManager = Host.PluginManager;
SCManager.PluginActionChanged += X_PluginActionChanged;
Server = SCManager.Server;
if (Server == null)
{
var x = SCManager.Plugins.FirstOrDefault(t => t.Type == 1);
if (x != null)
SCManager.MountPluginAsync(x);
}
}
OnWindowShown(this);
}
Here is the Code that triggers the event:
protected virtual void OnPluginActionChanged(AppInfo info,PluginActionType action,Exception error = null,object param = null)
{
PluginHandler handler;
lock (_eventlock)
handler = _PluginActionChanged;
handler?.Invoke(this, info, action, error,param);
}
I really hope someone inhere can point me to the right direction, as i'm totally lost...
Thanks! and sorry for my bad english, let me know please if you guys/gals have any more question.
|
|
|
|
|
A TargetInvocationException occurs when an exception is thrown from a constructor. The stacktrace should show where it is trying to create the object that blows.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
MSDN says "The exception that is thrown by methods invoked through reflection. This class cannot be inherited."
so my take is that the issue occurs exactly at the
?.Invoke call.
What I don't understand is why the original poster doesn't just debug the code, and set the debugger to break on all exceptions - easy peasy.
The Plugins are loaded by system.reflection as raw data and not as a file...
i did this because the plugins are stored in a custom container, compressed and encrypted.
This sounds unnecessarily complicated - but I would first test uncompressing/decrypting them first, then go one step at a time, see when the issue occurs.
Best,
John
|
|
|
|
|
John Torjo wrote: MSDN says ..and so begins my favorite line of argumenting.
Upvoted
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
I have a WinForm C# application which works perfet on my laptop but when I installed on on another it';s crashing and not throwing any error. When I checked the Windows EventLog I found below errors but can't understand where is the issue and what IO Fle is missing? Can anyone help please..
Thanks,
Jassim[^]
Log Name: Application
Source: Application Error
Date: 27-Oct-15 11:59:36 AM
Event ID: 1000
Task Category: (100)
Level: Error
Keywords: Classic
User: N/A
Computer: AUDITOR
Description:
Faulting application name: TrueAsset.exe, version: 1.0.0.0, time stamp: 0x561e711d
Faulting module name: KERNELBASE.dll, version: 6.2.9200.16384, time stamp: 0x5010ab2d
Exception code: 0xe0434352
Fault offset: 0x00000000000189cc
Faulting process ID: 0x12e0
Faulting application start time: 0x01d11095ce59ce4c
Faulting application path: C:\Program Files (x86)\TrueAsset\TrueAsset\TrueAsset.exe
Faulting module path: C:\Windows\system32\KERNELBASE.dll
Report ID: 0c124612-7c89-11e5-befb-50b7c3624f32
Faulting package full name:
Faulting package-relative application ID:
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="Application Error" />
<EventID Qualifiers="0">1000</EventID>
<Level>2</Level>
<Task>100</Task>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2015-10-27T08:59:36.000000000Z" />
<EventRecordID>66461</EventRecordID>
<Channel>Application</Channel>
<Computer>AUDITOR</Computer>
<Security />
</System>
<EventData>
<Data>TrueAsset.exe</Data>
<Data>1.0.0.0</Data>
<Data>561e711d</Data>
<Data>KERNELBASE.dll</Data>
<Data>6.2.9200.16384</Data>
<Data>5010ab2d</Data>
<Data>e0434352</Data>
<Data>00000000000189cc</Data>
<Data>12e0</Data>
<Data>01d11095ce59ce4c</Data>
<Data>C:\Program Files (x86)\TrueAsset\TrueAsset\TrueAsset.exe</Data>
<Data>C:\Windows\system32\KERNELBASE.dll</Data>
<Data>0c124612-7c89-11e5-befb-50b7c3624f32</Data>
<Data>
</Data>
<Data>
</Data>
</EventData>
</Event>
Log Name: Application
Source: .NET Runtime
Date: 27-Oct-15 11:59:36 AM
Event ID: 1026
Task Category: None
Level: Error
Keywords: Classic
User: N/A
Computer: AUDITOR
Description:
Application: TrueAsset.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
Stack:
at Inventory_Management_System.Program.Main()
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name=".NET Runtime" />
<EventID Qualifiers="0">1026</EventID>
<Level>2</Level>
<Task>0</Task>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2015-10-27T08:59:36.000000000Z" />
<EventRecordID>66460</EventRecordID>
<Channel>Application</Channel>
<Computer>AUDITOR</Computer>
<Security />
</System>
<EventData>
<Data>Application: TrueAsset.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
Stack:
at Inventory_Management_System.Program.Main()
</Data>
</EventData>
</Event>
Technology News @ www.JassimRahma.com
|
|
|
|
|
Well, as we have no idea at all what files your application is using, there's no possible way we can answer this. What I would suggest is that you add unhandled exception handling at the top of your application (e.g. AppDomain.UnhandledException or Application.ThreadException ). Log in here, the trace of where your code failed.
|
|
|
|
|
Probably your app depends on a DLL that is not signed properly (maybe delay-signed?)
But yeah, we'd definitely need more info to give you a more informed answer.
Best,
John
|
|
|
|
|
Well, in your second event log there is a FileNotFoundException in your Main method, so there's a start.
It's impossible to be any more specific with the information you've given.
|
|
|
|
|
Hello,
I'm working on a Winforms multithreading application.
I need some control over the thread(s) with a start and stop button. So to start and stop running the threads.
I have a list with places on a gui map and want to iterate the list but while iterating places can be added on the list and i have to sort them by by distance.
My question is can i do this with 2 threads or do i need more? And how can i start/pause threads? So when i add places to the list before starting nothing should happen only the sorting part. When pressing the start button the list need to be iterated.
|
|
|
|
|
Synchronization is essential when you have one thread modifying a datum while another thread is reading it. If I understand your design correctly, you have the following threads:
- The GUI thread (reads the shared structure and displays the map)
- Working thread(s) (update and sort the shared structure)
You may only have one GUI thread in a program, so the number of readers is fixed. The number of writers is variable, but unless there are special conditions that you are not telling us about - one writer thread should be sufficient.
Locking/Synchronisation between the two threads is left as an exercise for the student. Look up "Threads" and "Synchronisation Primitives" in any decent C# book.
The best way to terminate the working thread is to set some sort of flag that is checked by the working thread, which causes the thread to shut itself down cleanly. Terminating a thread any other way is asking for trouble.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
|
|
|
|
|
+5 Daniel, this is, as I would expect from any code/comment from you, five-worthy; the one thing I wonder about is:
In this scenario, when the update/sort thread does anything that changes the "display list:" at that point, doesn't the reading-the-list thread have to not only terminate, but reset (discarding its current whatever state-data representation) ?
And, then the reading-the-list thread has to "start over" when the update/sort thread finishes ?
Just curious if there is an order of complexity (the interdependency of the threads in terms of logic) here.
thanks, Bill
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
Not unless the display must be updated within a very short time of the map update (e.g. well under 1 second).
What you need is some sort of event that notifies the GUI thread that an update has occurred. The GUI thread may then (in its own good time) take a "snapshot" of the data, and process it. Note that this is an event like any other, so it should fit nicely into the event-driven model used by the GUI thread.
Assuming that any single update of the map does not consume too much processor time, this will appear transparent to the user. At most, the display will lag slightly behind the updates if many updates are to be performed at the same time.
If you use blocking synchronization, the trick is to ensure that (a) the writing thread does not block the GUI thread for too long, and (b) that neither thread crashes while holding the lock. If you use "lock-free" methods, these problems go away.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
|
|
|
|
|
One way is to put your worker thread in an infinite loop of sorts, kind of like a thread pool would. The loop needs to have clear paths to terminate the thread in any event.
You'll also need to use Wait Handles
class ControllableThread
{
Thread _thread;
Action _task;
bool _shutdown;
ManualResetEvent[] _resetEvents
public void ThreadProc()
{
while (!_shutdown)
{
WaitHandle.WaitAny(_resetEvents);
if (_task != null)
{
_task();
}
}
}
}
Now this example is an oversimplification but it can point in the right direction. The Wait Handles act as crossing guards that allow the thread to execute whatever method is set to the _task variable and hold the thread's execution until their state is changed.
|
|
|
|
|
Starting out, I would wonder why the "list" needs to be "sorted" once created.
If the requirement is for an "ordered list", and items are added dynamically, then I would look at adding / inserting items "in order".
There are classes for "sorted lists" and lists where items can be added / inserted in any order and therefore do not need "sorting" afterwards.
Having eliminated the need to sort the list when new items are added, the problem becomes simpler.
|
|
|
|
|
Can anyone explain what this code is doing, got this code from codeproject - how this is cponnectipon tpo database?
namespace WindowsFormsApplication2
{
partial class Form1
{
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
///
/// <param name="disposing" />true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.dataGridView1 = new System.Windows.Forms.DataGridView();
this.dataGridView2 = new System.Windows.Forms.DataGridView();
this.cboX = new System.Windows.Forms.ComboBox();
this.cboY = new System.Windows.Forms.ComboBox();
this.cboZ = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.txttNullValue = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.chkSumValues = new System.Windows.Forms.CheckBox();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout();
this.SuspendLayout();
//
// dataGridView1
//
this.dataGridView1.AllowUserToOrderColumns = true;
this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Location = new System.Drawing.Point(0, 23);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.Size = new System.Drawing.Size(274, 491);
this.dataGridView1.TabIndex = 0;
//
// dataGridView2
//
this.dataGridView2.AllowUserToOrderColumns = true;
this.dataGridView2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dataGridView2.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView2.Location = new System.Drawing.Point(3, 156);
this.dataGridView2.Name = "dataGridView2";
this.dataGridView2.Size = new System.Drawing.Size(284, 355);
this.dataGridView2.TabIndex = 2;
//
// cboX
//
this.cboX.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.cboX.FormattingEnabled = true;
this.cboX.Location = new System.Drawing.Point(74, 8);
this.cboX.Name = "cboX";
this.cboX.Size = new System.Drawing.Size(87, 21);
this.cboX.TabIndex = 3;
//
// cboY
//
this.cboY.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.cboY.FormattingEnabled = true;
this.cboY.Location = new System.Drawing.Point(74, 35);
this.cboY.Name = "cboY";
this.cboY.Size = new System.Drawing.Size(87, 21);
this.cboY.TabIndex = 4;
//
// cboZ
//
this.cboZ.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.cboZ.FormattingEnabled = true;
this.cboZ.Location = new System.Drawing.Point(74, 62);
this.cboZ.Name = "cboZ";
this.cboZ.Size = new System.Drawing.Size(87, 21);
this.cboZ.TabIndex = 5;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(13, 11);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(52, 13);
this.label1.TabIndex = 6;
this.label1.Text = "Column X";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(13, 35);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(52, 13);
this.label2.TabIndex = 7;
this.label2.Text = "Column Y";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(13, 62);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(52, 13);
this.label3.TabIndex = 8;
this.label3.Text = "Column Z";
//
// button1
//
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button1.Location = new System.Drawing.Point(173, 8);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(114, 78);
this.button1.TabIndex = 9;
this.button1.Text = "update";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click_1);
//
// splitContainer1
//
this.splitContainer1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.splitContainer1.Location = new System.Drawing.Point(12, 15);
this.splitContainer1.Name = "splitContainer1";
//
// splitContainer1.Panel1
//
this.splitContainer1.Panel1.Controls.Add(this.label5);
this.splitContainer1.Panel1.Controls.Add(this.dataGridView1);
//
// splitContainer1.Panel2
//
this.splitContainer1.Panel2.Controls.Add(this.label6);
this.splitContainer1.Panel2.Controls.Add(this.chkSumValues);
this.splitContainer1.Panel2.Controls.Add(this.label4);
this.splitContainer1.Panel2.Controls.Add(this.txttNullValue);
this.splitContainer1.Panel2.Controls.Add(this.label1);
this.splitContainer1.Panel2.Controls.Add(this.button1);
this.splitContainer1.Panel2.Controls.Add(this.dataGridView2);
this.splitContainer1.Panel2.Controls.Add(this.label3);
this.splitContainer1.Panel2.Controls.Add(this.cboX);
this.splitContainer1.Panel2.Controls.Add(this.label2);
this.splitContainer1.Panel2.Controls.Add(this.cboY);
this.splitContainer1.Panel2.Controls.Add(this.cboZ);
this.splitContainer1.Size = new System.Drawing.Size(568, 514);
this.splitContainer1.SplitterDistance = 274;
this.splitContainer1.TabIndex = 10;
//
// txttNullValue
//
this.txttNullValue.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txttNullValue.Location = new System.Drawing.Point(74, 87);
this.txttNullValue.Name = "txttNullValue";
this.txttNullValue.Size = new System.Drawing.Size(87, 20);
this.txttNullValue.TabIndex = 10;
this.txttNullValue.Text = "-";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(13, 87);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(55, 13);
this.label4.TabIndex = 11;
this.label4.Text = "Null Value";
//
// chkSumValues
//
this.chkSumValues.AutoSize = true;
this.chkSumValues.Location = new System.Drawing.Point(74, 113);
this.chkSumValues.Name = "chkSumValues";
this.chkSumValues.Size = new System.Drawing.Size(82, 17);
this.chkSumValues.TabIndex = 13;
this.chkSumValues.Text = "Sum Values";
this.chkSumValues.UseVisualStyleBackColor = true;
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(3, 0);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(44, 13);
this.label5.TabIndex = 1;
this.label5.Text = "Source:";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(16, 137);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(40, 13);
this.label6.TabIndex = 14;
this.label6.Text = "Result:";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(592, 541);
this.Controls.Add(this.splitContainer1);
this.Name = "Form1";
this.Text = "Pivot Table";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).EndInit();
this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel1.PerformLayout();
this.splitContainer1.Panel2.ResumeLayout(false);
this.splitContainer1.Panel2.PerformLayout();
this.splitContainer1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.DataGridView dataGridView1;
private System.Windows.Forms.DataGridView dataGridView2;
private System.Windows.Forms.ComboBox cboX;
private System.Windows.Forms.ComboBox cboY;
private System.Windows.Forms.ComboBox cboZ;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.SplitContainer splitContainer1;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox txttNullValue;
private System.Windows.Forms.CheckBox chkSumValues;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
}
}
namespace PivotTable
{
public partial class Form1 : Form
{
DataTable dt = new DataTable();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
dt.Columns.Add("EmployeeID", Type.GetType("System.String"));
dt.Columns.Add("OrderID", Type.GetType("System.Int32"));
dt.Columns.Add("Amount", Type.GetType("System.Decimal"));
dt.Columns.Add("Cost", Type.GetType("System.Decimal"));
dt.Columns.Add("Date", Type.GetType("System.String"));
dt.Rows.Add(new object[] { "Sam", 1, 25.00, 13.00, "01/10/2007" });
dt.Rows.Add(new object[] { "Sam", 2, 512.00, 1.00, "02/10/2007" });
dt.Rows.Add(new object[] { "Sam", 3, 512.00, 1.00, "03/10/2007" });
dt.Rows.Add(new object[] { "Tom", 4, 50.00, 1.00, "04/10/2007" });
dt.Rows.Add(new object[] { "Tom", 5, 3.00, 7.00, "03/10/2007" });
dt.Rows.Add(new object[] { "Tom", 6, 78.75, 12.00, "02/10/2007" });
dt.Rows.Add(new object[] { "Sue", 7, 11.00, 7.00, "01/10/2007" });
dt.Rows.Add(new object[] { "Sue", 8, 2.50, 66.20, "02/10/2007" });
dt.Rows.Add(new object[] { "Sue", 9, 2.50, 22.00, "03/10/2007" });
dt.Rows.Add(new object[] { "Jack", 10, 6.00, 23.00, "02/10/2007" });
dt.Rows.Add(new object[] { "Jack", 11, 117.00, 199.00, "04/10/2007" });
dt.Rows.Add(new object[] { "Jack", 12, 13.00, 2.60, "01/10/2007" });
dt.Rows.Add(new object[] { "Jack", 13, 11.40, 99.80, "03/10/2007" });
dt.Rows.Add(new object[] { "Phill", 14, 37.00, 2.10, "02/10/2007" });
dt.Rows.Add(new object[] { "Phill", 15, 65.20, 99.30, "04/10/2007" });
dt.Rows.Add(new object[] { "Phill", 16, 34.10, 27.00, "02/10/2007" });
dt.Rows.Add(new object[] { "Phill", 17, 17.00, 959.00, "04/10/2007" });
dataGridView1.DataSource = dt;
foreach (DataColumn dc in dt.Columns)
cboX.Items.Add(dc.ColumnName);
foreach (DataColumn dc in dt.Columns)
cboY.Items.Add(dc.ColumnName);
foreach (DataColumn dc in dt.Columns)
cboZ.Items.Add(dc.ColumnName);
}
private void button1_Click_1(object sender, EventArgs e)
{
try
{
string x = "";
string y = "";
string z = "";
if (cboX.SelectedItem != null)
x = cboX.SelectedItem.ToString();
if (cboY.SelectedItem != null)
y = cboY.SelectedItem.ToString();
if (cboZ.SelectedItem != null)
z = cboZ.SelectedItem.ToString();
DataTable newDt = new DataTable();
if (y != "" && z != "")
newDt = PivotTable.GetInversedDataTable(dt, x, y, z, txttNullValue.Text, chkSumValues.Checked);
else
newDt = PivotTable.GetInversedDataTable(dt, x, y);
dataGridView2.DataSource = newDt;
}
catch(Exception err)
{
MessageBox.Show("Error: " + err.Message);
}
}
}
}
|
|
|
|
|
why dont you ask this question at the bottom of the CP Article you took this from - its a better way than asking a general question here, like you've done ... that way, (hopefully) the author of the article may be able to help you.
As it is, your question is a bit broad in scope - I can suggest on a cursory glance that a winforms GUI is being used, to display a 'hard loaded' datatable in a grid, and a pivot table operation is being performed when a button is clicked - the result of the pivot operation seems to be going to a different grid. But really, you need to find some good c# books and read lots if you're having trouble with this - download the article, play with it, search and read, modify, do it yourself - thats the only way to understand it
btw >> Quote: how this is cponnectipon tpo database? its not connected to a database - the data is being populated in the Quote: Form1_Load event handler
|
|
|
|
|