private void btnRestore_Click(object sender, EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
try
{
if (File.Exists(txtPath.Text + txtDireccion.Text + ".bak"))
{
if (MessageBox.Show("¿Está seguro de restaurar?", "Respaldo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
if (Program.laconexion.State != System.Data.ConnectionState.Open)
Program.laconexion.Open();
SqlCommand command = new SqlCommand("use master", Program.laconexion);
command.ExecuteNonQuery();
command = new SqlCommand(@"restore database FABRINOX from disk ='"+txtPath.Text + txtDireccion.Text + ".bak'", Program.laconexion);
command.ExecuteNonQuery();
Program.laconexion.Close();
MessageBox.Show("Se ha restaurado la base de datos", "Restauración", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
}
else
MessageBox.Show(@"No haz hecho ningun respaldo anteriormente (o no está en la ruta correcta)", "Restauracion", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
Monday, April 19, 2010
Back up a Data Base from C#
private void btnGuardar_Click(object sender, EventArgs e)
{
bool desea_respaldar = true;
Cursor.Current = Cursors.WaitCursor;
if (Directory.Exists(txtPath.Text))
{
if (File.Exists(txtPath.Text + txtDireccion.Text+ ".bak"))
{
if (MessageBox.Show(@"Archivo existe ¿desea remplazarlo?", "Respaldo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
File.Delete(txtPath.Text + txtDireccion.Text + ".bak");
}
else
desea_respaldar = false;
}
}
else
Directory.CreateDirectory(txtPath.Text);
if (desea_respaldar)
{
if (Program.laconexion.State != System.Data.ConnectionState.Open)
Program.laconexion.Open();
SqlCommand command;
command = new SqlCommand(@"backup database FABRINOX to disk ='" + txtPath.Text + txtDireccion.Text + ".bak" + "' with init,stats=10", Program.laconexion);
command.ExecuteNonQuery();
Program.laconexion.Close();
MessageBox.Show("Respaldo Exitoso");
this.Close();
}
}
{
bool desea_respaldar = true;
Cursor.Current = Cursors.WaitCursor;
if (Directory.Exists(txtPath.Text))
{
if (File.Exists(txtPath.Text + txtDireccion.Text+ ".bak"))
{
if (MessageBox.Show(@"Archivo existe ¿desea remplazarlo?", "Respaldo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
File.Delete(txtPath.Text + txtDireccion.Text + ".bak");
}
else
desea_respaldar = false;
}
}
else
Directory.CreateDirectory(txtPath.Text);
if (desea_respaldar)
{
if (Program.laconexion.State != System.Data.ConnectionState.Open)
Program.laconexion.Open();
SqlCommand command;
command = new SqlCommand(@"backup database FABRINOX to disk ='" + txtPath.Text + txtDireccion.Text + ".bak" + "' with init,stats=10", Program.laconexion);
command.ExecuteNonQuery();
Program.laconexion.Close();
MessageBox.Show("Respaldo Exitoso");
this.Close();
}
}
Monday, March 29, 2010
Clear all Textboxes on a Form or Group control
//On a Form
foreach(Control ctl in this.Controls)
{
if (ctl is TextBox)
(ctl as TextBox).Text = "";
} //On Group Control
foreach (Control ctrls in gcGeneralInfo.Controls)
{
if (ctrls is TextBox)
ctrls.Text = string.Empty;
}
Thursday, February 25, 2010
Constructors in C#
Constructors are class methods that are executed when an object of a given type is created. Constructors have the same name as the class, and usually initialize the data members of the new object.
In the following example, a class called Taxi is defined with a simple constructor. This class is then instantiated with the new operator. The Taxi constructor is invoked by the new operator immediately after memory is allocated for the new object.
public class Taxi
{
public bool isInitialized;
public Taxi()
{
isInitialized = true;
}
}
class TestTaxi
{
static void Main()
{
Taxi t = new Taxi();
System.Console.WriteLine(t.isInitialized);
}
} A constructor that takes no parameters is called a default constructor.Default constructors are invoked whenever an object is instantiated using the new operator and no arguments are provided to new Passing Arguments to Constructors Constructors may also be used to pass in initial values for an object's attributesat the time that an object is being instantiated. Instead of creating an object whoseattributes are all initialized to zero-equivalent values, and then utilizing the accessorsprovided by that class to initialize attribute values one-by-one, as illustratedby the next snippet: //Create a bare boones Student onject Student s = new Student(); //Initialize the atributes one-by-one s.name = "Ivan Osorio"; s.ssn = "06210056"; s.major = "English"; the initial values for selected attibutes can all passed in as a single step whenthe constructor is called, if desired:
Student s = new Student("Ivan Osorio", "06210056", "English");
In order to accommodate this, we'd have to define a Student constructor with anappropriate header, as shown here:
public class Student { //Atributes private string name; private string ssn; private straing major; /* We've programmed a constructor with three parameters to accommodate passing in argument values. */
public Student (string s, string n, string m) { name = n; ssn = s; major = m; } }
Wednesday, February 24, 2010
Subversion AnkhSVN
AnkhSVN is a Subversion SourceControl Provider for Visual Studio. The software allows you to perform the most common version control operations directly from inside the Microsoft Visual Studio IDE. With AnkhSVN you no longer need to leave your IDE to perform tasks like viewing the status of your source code, updating your Subversion working copy and committin
"look at this just to get an idea about subversion"
- Install AnkhSVN
- Enable AnkhSVN for source control
- Connect a project to AnkhSVN
- Add a solution to a repository
- Explore a repository
- Add your working copy to the Working Copy Explorer
- Check out a solution
- Update your working copy
- Perform a Subversion operation from Pending Changes
- Commit your changes
- Get and release locks
- Undo changes
- Revert an item to a specific revision
- Find out who made what changes to a line
- Branch, tag and merge changes
- Compare differences
- View revision history
- Create and apply patches
- Add an item to a changelist
- Add a Subversion property
- Clean up the working copy
- Integrate an issue tracker
Saturday, January 16, 2010
Configure SQL Server Authentication
In order to use SQL Server authentication you must first configure your server by login with windows authentication.
Right-click on the server node and select 'Properties'.

On the new window select 'Security' from the left menu, select the 'SQL Server and Windows Authentication mode option, click 'OK' to close the dialog.

Right-click on the server node and select 'Properties'.

On the new window select 'Security' from the left menu, select the 'SQL Server and Windows Authentication mode option, click 'OK' to close the dialog.

In the server node expand 'Security' and 'Logins', right click on the login name and select 'Properties'.
Under the new window enter a password and confirm the password. Select 'Status' from the left menu, set the 'Login' option to 'Enabled' and click 'OK' to close the dialog.

Now right click on the server node and choose 'Restart' for the changes to take affect and connect with SQL Server Authentication, user 'sa' and you new password.
If you can't connect, you may need restart the service.
Go to Start => All Programs => Micrsoft SQL Server 2005 => Configuration Tools => SQL Server Configuration Manager.
From the left menu, select 'SQL Server 2005 Services', in the right menu right click on 'SQL Server(SQLEXPRESS) and restart it.
Under the new window enter a password and confirm the password. Select 'Status' from the left menu, set the 'Login' option to 'Enabled' and click 'OK' to close the dialog.

Now right click on the server node and choose 'Restart' for the changes to take affect and connect with SQL Server Authentication, user 'sa' and you new password.
If you can't connect, you may need restart the service.
Go to Start => All Programs => Micrsoft SQL Server 2005 => Configuration Tools => SQL Server Configuration Manager.
From the left menu, select 'SQL Server 2005 Services', in the right menu right click on 'SQL Server(SQLEXPRESS) and restart it.
Monday, January 11, 2010
Use lambda
Lambda expressions use the lambda operator =>, which is read as "goes to".
(input parameters) => expression
The => operator has the same precedence as assignment (=) and is right-associative.
Example
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
int oddNumbers = numbers.Count(n => n % 2 == 1);
Lamda Expressions are a simpler syntax for anonymous delegates and can be used everywhere an anonymous delegate can be used. However, the opposite is not true;
lambda expressions can be converted to expression trees which allows
for a lot of the magic that LINQ to SQL.
The following is an example using anonymous delegates then lambda expressions.
==Delegate==
delegate(int x)
{
return (x % 2) == 0;
}
==Lambda==(x => (x % 2) == 0)
Subscribe to:
Posts (Atom)
