Hello guys am trying to implement Info Cards using the IInfoCard and IInfoCardFactory and IInfocards interfaces. If you know how to complete the methods of these interfaces to make a program show the forms for the respective categories, then you might just be the guy to help me. I have the interface code as below.
using System;
using System.Windows.Forms;
public interface IInfoCard
{
string Name { get; set; }
string Category { get; }
string GetDataAsString();
void DisplayData(Panel displayPanel);
void CloseDisplay();
bool EditData();
}
and then the interface for IInfoCardFactory
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public interface IInfoCardFactory
{
IInfoCard CreateNewInfoCard(string category);
IInfoCard CreateInfoCard(string initialDetails);
string[] CategoriesSupported { get; }
string GetDescription(string category);
}
How do I complete the methods in the class below to make them create the needed info cards and save data to a file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace Assignment
{
internal class CreditCardInfo : IInfoCardFactory,IInfoCard
{
private string[] categories = new string[] { "Credit Card" };
private string name;
public string[] CategoriesSupported
{
get { return categories; }
set { categories = value; }
}
public string Name { get
{
return this.name;
}
set { this.name = value; }
}
public string Category
{
get
{
return this.Name;
}
set
{
this.Name = value;
}
}
public void CloseDisplay()
{
return;
}
public IInfoCard CreateInfoCard(string initialDetails)
{
string[] stringToSplit = initialDetails.Split(new char[] { '|' });
string category = stringToSplit[0];
string description = stringToSplit[1];
CreditCardInfo info = new CreditCardInfo();
info.CategoriesSupported=categories;
return info;
}
public IInfoCard CreateNewInfoCard(string category)
{
CreditCardInfo info= new CreditCardInfo();
info.Category = category;
return info;
}
public void DisplayData(Panel displayPanel)
{
//get the string[] categories and display
string text = this.GetDataAsString();
string[] info=text.Split(new char[] { '|' });
CreditCardDetails form=new CreditCardDetails();
for(int i=0;i<form.Controls.Count;i++)
{
if (form.Controls[i].Name == "label7")
{
form.Controls[i].Text = info[0];
}
}
form.Show();
}
public bool EditData()
{
new CreditCardForm().ShowDialog();
return true;
}
public string GetDataAsString()
{
string data = this.Name;
if(categories.Length > 0)
{
data+=categories[0].ToString();
}
return data;
}
public string GetDescription(string category)
{
if (category == "Credit Card")
return "Save personal info about your credit card";
else
return "";
}
}
}