i have two class..One class with get,set
and the other with commands to read and copy certain files from a folder. the location for the files needed was inputted.
how can i inherit both of these classes?
i have two class..One class with get,set
and the other with commands to read and copy certain files from a folder. the location for the files needed was inputted.
how can i inherit both of these classes?
try with override.
An example for login form:
namespace LoginForm.cs
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string strUserName = textBoxUserName.Text.Trim();
string strPassword = textBoxPassword.Text.Trim();
DAL setting = new DAL();
setting.UserName = strUserName;
setting.Password = strPassword;
if (!String.IsNullOrEmpty(strUserName) && !String.IsNullOrEmpty(strPassword))
{
bool UserValidated = setting.UserAuthorization();
if (UserValidated)
this.DialogResult = DialogResult.OK;
else
this.DialogResult = DialogResult.Cancel;
}
}
}
}
namespace LoginForm.cs
{
abstract class GetSet
{
protected string userName;
public string UserName
{
get { return userName; }
set { userName = value; }
}
protected string password;
public string Password
{
get { return password; }
set { password = value; }
}
public abstract bool UserAuthorization();
}
}
namespace LoginForm.cs
{
class DAL : GetSet
{
static string p = ConfigurationManager.ConnectionStrings["povezava"].ConnectionString;
public override bool UserAuthorization()
{
using (SqlConnection povezava = new SqlConnection(p))
{
using (SqlCommand cmd = new SqlCommand("Login_Search", povezava))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@strUsername", SqlDbType.VarChar, 50).Value = UserName;
cmd.Parameters.Add("@strPasswordInsert", SqlDbType.VarChar, 50).Value = Password;
try
{
string strPassword = null;
cmd.Connection.Open();
object objPassword = cmd.ExecuteScalar();
if (objPassword != null)
{
strPassword = Convert.ToString(objPassword);
return true;
}
else return false;
}
catch
{
return false;
}
finally
{
if (povezava.State == ConnectionState.Open)
cmd.Connection.Close();
}
}
}
}
}
}
POst ur code
this is cCopy.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BACKUPEXEFILES
{
public class cCOPY
{
private string _directorypath;
private string _filename;
public string directorypath
{
get { return _directorypath; }
set { _directorypath = value; }
}
public string filename
{
get { return _filename; }
set { _filename = value; }
}
}
}
and this is program.cs
using System;
using System.IO;
using System.Collections;
namespace BACKUPEXEFILES
{
class test
{
public static void Main()
{
string sourceFile = @"C:\";
string destinationFile = @"C:\";
TextReader ts = new StreamReader(@"C:\");
string input = null;
string strfilepath = null;
while ((input = ts.ReadLine()) != null)
{
if (input != "")
{
if (input.Length > 18)
{
if (input.Substring(3, 7) == "New Dir")
{
strfilepath = input.Substring(22);
}
if (input.Substring(5, 8) == "New File")
{
try
{
sourceFile = @strfilepath + input.Substring(26);
destinationFile = @"C:\" + input.Substring(26);
File.Copy(sourceFile, destinationFile);
Console.WriteLine("Copy Completed");
}
catch (Exception exc)
{
Console.WriteLine(exc.Message);
}
Console.WriteLine();
}
}
}
}
ts.Close();
Console.WriteLine("\nPress Enter to Continue:");
Console.Read();
}
}
}
my problem is that the program is ready like it is but i would like to include classes...i think a foreach statemnet is needed right?
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.