|
Installing the certificate of that site on your computer might help.
|
|
|
|
|
Hi All,
I'm new to TDD. I need to return a DTO containing the the details of the Customers referenced by CustomerID in C# as given below.
The Output DTO should contain the following properties:
int CustomerID
String CustomerName
String[] Addresses
Given below are the data repository classes with properties:
Customer class
{
public int CustomerID {get; set;}
public string CustomerName {get; set;}
public int[] AddressId {get; set;}
}
Address class
{
public int AddressId {get; set;}
public string Street {get; set;}
public string City {get; set;}
}
Note: Should be a TDD approach
Please help me with sample code
Thanks in advance,
Ram
|
|
|
|
|
hi
how to restore a sql database programmatically in c#?
|
|
|
|
|
Use the RESTORE command and connect to the database server with an user that has access to do restores. (e.g. server admin)
You can just use the normal SqlConnection and SqlCommands to do that
Important Note: The path to the backup you provide are relative to the SqlServer. If it is not the same server as your application you need to copy the files to the server (or a network share?) first where the database server can restore the backup from.
|
|
|
|
|
Try this: Backing up an SQL Database in C#[^] - it includes code for backup and restore.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
The following namespaces can be used to access SQL Server 2005 programmatically:
Microsoft.SqlServer.management
Microsoft.SqlServer.Management.NotificationServices
Microsoft.SqlServer.Management.Smo
Microsoft.SqlServer.Management.Smo.Agent
Microsoft.SqlServer.Management.Smo.Broker
Microsoft.SqlServer.Management.Smo.Mail
Microsoft.SqlServer.Management.Smo.RegisteredServers
Microsoft.SqlServer.Management.Smo.Wmi
Microsoft.SqlServer.Management.Trace
Backup bkpDBFull = new Backup();
bkpDBFull.Action = BackupActionType.Database;
bkpDBFull.Database = myDatabase.Name;
bkpDBFull.Devices.AddDevice(@"D:\AdventureWorksFull.bak", DeviceType.File);
bkpDBFull.BackupSetName = "Adventureworks database Backup";
bkpDBFull.BackupSetDescription = "Adventureworks database - Full Backup";
bkpDBFull.ExpirationDate = DateTime.Today.AddDays(10);
bkpDBFull.Initialize = false;
bkpDBFull.PercentComplete += CompletionStatusInPercent;
bkpDBFull.Complete += Backup_Completed;
bkpDBFull.SqlBackup(myServer);
Mouli
|
|
|
|
|
The following namespaces can be used to access SQL Server 2005 programmatically:
Microsoft.SqlServer.management
Microsoft.SqlServer.Management.NotificationServices
Microsoft.SqlServer.Management.Smo
Microsoft.SqlServer.Management.Smo.Agent
Microsoft.SqlServer.Management.Smo.Broker
Microsoft.SqlServer.Management.Smo.Mail
Microsoft.SqlServer.Management.Smo.RegisteredServers
Microsoft.SqlServer.Management.Smo.Wmi
Microsoft.SqlServer.Management.Trace
Backup bkpDBFull = new Backup();
bkpDBFull.Action = BackupActionType.Database;
bkpDBFull.Database = myDatabase.Name;
bkpDBFull.Devices.AddDevice(@"D:\AdventureWorksFull.bak", DeviceType.File);
bkpDBFull.BackupSetName = "Adventureworks database Backup";
bkpDBFull.BackupSetDescription = "Adventureworks database - Full Backup";
bkpDBFull.ExpirationDate = DateTime.Today.AddDays(10);
bkpDBFull.Initialize = false;
bkpDBFull.PercentComplete += CompletionStatusInPercent;
bkpDBFull.Complete += Backup_Completed;
bkpDBFull.SqlBackup(myServer);
for more info - http://www.mssqltips.com/sqlservertip/1849/backup-and-restore-sql-server-databases-programmatically-with-smo/[^]
Mouli
|
|
|
|
|
Sir, kind you help me with code to read and send sms through the internet and gsm modem.
Thank you.
|
|
|
|
|
|
Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...
A very quick search using your subject as the search term gave three quarters of a million hits: SerialComm Port to send and receive sms[^]
In future, please try to do at least basic research yourself, and not waste your time or ours.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
hi every body, i use dynamically toolstripmenu to generate menu, i don't know how to prevent form open twice, please help.
this is my code :
ToolStripMenuItem SubMenu = new ToolStripMenuItem(sdr1["description"].ToString(), null, new EventHandler(klikMenu));
private void klikMenu(object sender, EventArgs e)
{
string sFormName = "AIO_System." + ((ToolStripMenuItem)sender).Tag.ToString();
System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
Form frm = (Form)asm.CreateInstance(sFormName); <======
if(!IsFormOpen(frm.GetType()))
{
frm.Owner = this;
frm.Show();
}
else
frm.Focus();
}
}
private bool IsFormOpen(Type formType)
{
foreach (Form form in Application.OpenForms)
if (form.GetType().Name == form.Name)
return true;
return false;
}
|
|
|
|
|
If it's always the same Form, just cache it, and hide/reshow/bring to front as apropiate. The problem is you are creating always a new Form (via reflection), this is also not very "fast" so caching the "frm" variable has another advantage (just make it a member and initialize if null).
|
|
|
|
|
johannesnestler wrote: The problem is you are creating always a new Form (via reflection), this is also not very "fast" so caching the "frm" variable has another advantage I'd like to point out that reflection is not "slow". Creating a form is always an expensive operation, even if you call the constructor directly.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
yes, that's a good and valid point, in this case the "impact" by reflecting the type is neglectible. Thank you for pointing that out.
But what luck for me, that my advice isn't totally wrong - and in general it's always a good habit to do "maximum caching of type information" when reflecting...
|
|
|
|
|
You can do this without using Reflection; you can use Activator.CreateInstance:
Form newForm = (Form) Activator.CreateInstance(Type.GetType(YourNameSpace + "." + YourNewFormName)); Keep in mind that when you create a new Form of some specific Type, like a new "Form4," and cast it to the generic Type 'Form: the new Form has an empty string for its 'Name property. So, you can't test if the new Form exists in the Application.OpenForms collection by using its Name. To fix that: give the new Form a Name when you create it:
Form newForm = (Form) Activator.CreateInstance(Type.GetType(YourNameSpace + "." + YourNewFormName));
newForm.Owner = this;
newForm.Name = YourNewFormName;
newForm.Show(); I'd like to suggest you define your own List<string> of currently opened secondary Form names; it will simplify testing for an instance being already opened. You can also pre-define a string with your NameSpace plus "." to make creating a new Form simpler.
“The best hope is that one of these days the Ground will get disgusted enough just to walk away ~ leaving people with nothing more to stand ON than what they have so bloody well stood FOR up to now.” Kenneth Patchen, Poet
modified 24-Feb-14 12:51pm.
|
|
|
|
|
Looking at your code, the problem appears to be with the frm.Focus(); line:
- You create a new instance of the form type;
- You check to see if there is an open form of the same type;
- If there is, you call the
Focus method on the new form instance;
I suspect that calling Focus on an invisible form causes it to be shown.
Try something like this instead:
private Form FindOpenFormOfType(Type formType)
{
foreach (Form form in Application.OpenForms)
{
if (form.GetType() == formType)
{
return form;
}
}
return null;
}
private void klikMenu(object sender, EventArgs e)
{
string sFormName = "AIO_System." + ((ToolStripMenuItem)sender).Tag.ToString();
System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
Type formType = asm.GetType(sFormName);
Form frm = FindOpenFormOfType(formType);
if (frm == null)
{
frm = (Form)Activator.CreateInstance(formType);
frm.Owner = this;
frm.Show();
}
else
{
frm.Focus();
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: I suspect that calling Focus on an invisible form causes it to be shown. In Windows Forms calling 'Focus on an instantiated, but hidden, Form will not cause it become visible.
Your code would work "as is" if you removed the modifier ".Tag" in the line where 'sFormName is constructed ... but, we can't know, from the information the OP presented, what they've done to create a 'Tag property for the ToolStripMenuItems ... that's not shown in the code posted here.
“The best hope is that one of these days the Ground will get disgusted enough just to walk away ~ leaving people with nothing more to stand ON than what they have so bloody well stood FOR up to now.” Kenneth Patchen, Poet
|
|
|
|
|
if(frm != null)
{
MessageBox.Show("already running");
}
|
|
|
|
|
I have added a new column to my database table. When I have added this new columnm, the first chance exception start appearing. When I debugged it, it stated the code line
MLongListSelector.ItemsSource = c.ToDoList.ToList(); is the next statement to execute that causes the problem. What have I done wrong there?
using (DatabaseContext c = new DatabaseContext(DatabaseContext.ConnectionString))
{
c.CreateIfNotExists();
c.LogDebug = true;
//output todolist data from database
MLongListSelector.ItemsSource = c.ToDoList.ToList();
}
|
|
|
|
|
Check the column name and connection to database
|
|
|
|
|
I have finally solved it . There was a problem in creating the database. instead of CreateIfNotExist() i used If(!DatabaseExist()){CreateDatabase();}
This solved it. It doesn't really make sense to me as it is actually the same thing. But it works.
|
|
|
|
|
Hi Guys,
Ive just finished my admin panel that uses an SQL source and fills a list view with all clients and allows admins to update, edit Customer details..
Im trying to do the same thing for my User Panel (after user logs in and wants to edit their information)
Im using Context.User.Identity.Name(page_Load) in a label to welcome the user (can I SELECT the value from here??)
I don't want all the customer details coming up, just the ones for that particular user.
Is it possible to display only the customer information for the Current user? and again just in a simple listview
Any help is appreciated,
any questions, just ask.
|
|
|
|
|
Unless I'm misunderstanding, would a simple WHERE clause allow you to limit the returned Customer details for just that customer whose username is Context.User.Identity.Name ?
/ravi
|
|
|
|
|
I'v inherited ComboBox in C#.net winform , and I'v drew a rectangle's diagonal(like 'X') behind the content of each item in the override method OnDrawItem . Now I want to implement a function, when mouse click the area of rectangle can delete current item , rather than to select the current item.
Anyone can help, Thank y:confusedou very much!
Denny Xue
|
|
|
|
|