|
|
I'm currently revisiting C# and oop after a few years programming PLCs. I'm looking at delegates and events. I was wondering what is the difference between a non-generic event handler and a generic one. Why would you use the generic one over the non-generic one. I've searched on the internet and can't find a satisfactory explanation.
Thanks in advance
|
|
|
|
|
|
My application is for Leave Module. now in that i used, employee can apply leave normally Seek Leave, Casual Leave and Paid leave. but Now i have to put condition like if total leave days(Count) is less than or equal to 2 then it will automatically goes in CL n PL will be invisible in drop down list. so what can i do for that?
|
|
|
|
|
Filter the underlying collection based on the number of days asked/available. To do this you trap the change event on the requesting control and then filter the collection accordingly.
More specific help will require more detail on the UI you are using.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Ok. I can understood. now i have change event on no of days calculation button. but what can i put a condition for that. can u help me in coding.
|
|
|
|
|
Member 11221185 wrote: can u help me in coding Coding what! I have no idea of your data structure, the technology you are using. For all I know you may be coding for an iPhone.
We don't do the coding for you, you will get help if you show the code YOU have written and have a problem with.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Need a simple 2D graph library for C# console app. Thanks for any ideas.
sundownr
|
|
|
|
|
And?
Google not working today?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Google works fine and after trying a few libraries I did not find what I wanted... thus I asked for any ideas. I am trying SharpDX now but prefer something simpler. All I need to do is graph a series of voltages.
sundownr
|
|
|
|
|
Are you looking to manipulate a Charting library from a Console App: I mean what else could you do in the Console but read a file into some data structure(s), manipulate the data, call the library's facilities for creating a chart passing in the data, save the resulting output chart/graphic to a file ?
Why not create a WinForms app where you can preview the chart/image you create ?
«At the still point of the turning world. Neither flesh nor fleshless;
Neither from nor towards; at the still point, there the dance is
...
Neither ascent nor decline. Except for the point, the still point,
There would be no dance, and there is only the dance»
T.S. Elliot, The Four Quartets: "Burnt Norton"/xml>
modified 14-Nov-14 13:12pm.
|
|
|
|
|
Good description of graphing with the console. I asked this question myself and then posted my question. Unless the magic answer appears I guess I am stuck with Windows forms using DirectX. It sure would be nice to draw a simple graph with minimal code. Thanks for the thought... it clarified the issue. Note... I tried the "A simple C# library for graph plotting," here on the Code Project, but was unable to find the sample code the author referred to.
sundownr
|
|
|
|
|
Well, I can't see a downside to using a WinForm app, but what you want is what you want
Check this example out: [^]. It uses System.Windows.Forms.DataVisualization.Charting; from within a Console App.
I am under the impression there are many articles on Charting/Graphing in WinForms here on CP.
cheers, Bill
«The greater the social and cultural distances between people, the more magical the light can spring from their contact» Milan Kundera, "Testaments Trahis"
|
|
|
|
|
Thanks... I will give it a try.
sundownr
|
|
|
|
|
using System;
using System.Collections.Generic;
class Program {
static void Main( string[] args ) {
List<int> voltages = new List<int>() { 10, 4, 15, 7, 20 };
int n = 0;
foreach ( int voltage in voltages ) {
Console.WriteLine( "Voltage {0}: {1}", ++n, "".PadRight( voltage, '*' ) );
}
}
}
|
|
|
|
|
Thanks Gerry... I can use this. This is as simple as it can get.
sundownr
|
|
|
|
|
Hi All,
I am using Visual Studio 2008 to design windows form Application.
I created one form, that will Browse and select excel file and by clicking on Export button, all data will transfer to sql database.
But while debugging, it stop at code
using (OleDbConnection connection = new OleDbConnection(excelConnectionString))
For your review i am giving full code below:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Data.Common;
namespace CHD_CALL_REGISTER
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection();
protected void Page_Load(object sender, EventArgs e)
{
string str = "Data Source=INLGM84MV1;Initial Catalog=CHD;Integrated Security=True";
SqlConnection con = new SqlConnection(str);
}
public Form1()
{
InitializeComponent();
}
private void buttonBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "C:\\";
openFileDialog1.Title = "Browse Excel Files";
openFileDialog1.CheckFileExists = true;
openFileDialog1.CheckPathExists = true;
openFileDialog1.DefaultExt = "xls";
openFileDialog1.Filter = "Excel file (*.xls)|*.xls";
openFileDialog1.RestoreDirectory = true;
openFileDialog1.ReadOnlyChecked = true;
openFileDialog1.ShowReadOnly = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.Text = openFileDialog1.SafeFileName;
buttonexport.Enabled = true;
}
}
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
Close();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBox1.Text))
{
buttonexport.Enabled = false;
}
}
private void buttonexport_Click(object sender, EventArgs e)
{
string excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source" + textBox1.Text + ";Extended Properties\"Excel 8.0;HDR=YES\"";
using (OleDbConnection connection = new OleDbConnection(excelConnectionString))
{
OleDbCommand command = new OleDbCommand("Select * FROM [Sheet1$]", connection);
connection.Open();
using (DbDataReader dr = command.ExecuteReader())
{
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(con))
{
bulkCopy.DestinationTableName = "EMP_TABLE";
bulkCopy.ColumnMappings.Add("EMPCODE", "EMPCODE");
bulkCopy.ColumnMappings.Add("EMP_NAME", "EMP_NAME");
bulkCopy.ColumnMappings.Add("BUSINESS_CODE", "BUSINESS_CODE");
bulkCopy.ColumnMappings.Add("JOIN_DT", "JOIN_DT");
bulkCopy.ColumnMappings.Add("HQ_NAME", "HQ_NAME");
bulkCopy.ColumnMappings.Add("ZONE_ID", "ZONE_ID");
bulkCopy.ColumnMappings.Add("DESIG", "DESIG");
bulkCopy.ColumnMappings.Add("BAND", "BAND");
bulkCopy.ColumnMappings.Add("DEPT_NAME", "DEPT_NAME");
bulkCopy.ColumnMappings.Add("EMP_STATUS", "EMP_STATUS");
bulkCopy.ColumnMappings.Add("SUP1", "SUP1");
bulkCopy.ColumnMappings.Add("SUP1NAME", "SUP1NAME");
bulkCopy.ColumnMappings.Add("SUP1HQ", "SUP1HQ");
bulkCopy.ColumnMappings.Add("SUP2", "SUP2");
bulkCopy.ColumnMappings.Add("SUP2NAME", "SUP2NAME");
bulkCopy.ColumnMappings.Add("SUP2HQ", "SUP2HQ");
bulkCopy.ColumnMappings.Add("SUP3", "SUP3");
bulkCopy.ColumnMappings.Add("SUP3NAME", "SUP3NAME");
bulkCopy.ColumnMappings.Add("SUP3HQ", "SUP3HQ");
bulkCopy.WriteToServer(dr);
MessageBox.Show("Data Exported To Sql Server Successfully");
}
}
}
}
}
}
Please help me...thanks in advance...
Vishal
|
|
|
|
|
Member 11134954 wrote: But while debugging, it stop at code After which point it will throw an exception with some valuable information.
Your connection-string is broken. It should read DataSource= . It'd be cleaner if you use a string.format to get your variable in there.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
Its get stop debug at below line.
// Create Connection to Excel Workbook
using (OleDbConnection connection = new OleDbConnection(excelConnectionString))
|
|
|
|
|
And what does the exception say?
|
|
|
|
|
Yes, but that line is correct. Copy/paste below line, should at least give a new error.
string excelConnectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties\"Excel 8.0;HDR=YES\"", textBox1.Text);
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
After using your line/code. it still give same error but after i changed the line as below it proceed ahead.
string excelConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + textBox1.Text + ";Extended Properties=\"Excel 8.0;HDR=Yes;\"";
Now it got stuck at line:
// Create DbDataReader to Data Worksheet
using (DbDataReader dr = command.ExecuteReader())
Exception message says:
The Microsoft Jet database engine could not find the object 'Sheet1$'. Make sure the object exists and that you spell its name and the path name correctly.
|
|
|
|
|
That line again does not cause the problem; it is the SQL statement that is being executed that generates the error. Did you put the sheetname in brackets?
Find the code that says "SELECT .. FROM [Sheet1$]", that's where the problem is.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I am using this line:
OleDbCommand command = new OleDbCommand("Select * FROM [Sheet1$]", connection);
Does it seem to be invaline code?
|
|
|
|
|
Nope, looks correct. Same as the example here[^].
Is there a sheet with that name inside the workbook?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|