First of all, I'd like to thank all persons who read and try to help me.
I've been working on a simple -obsolete- Mobile Company to add a line and save the information of a client in a Data Grid, so I've written the following:
I've defined an line and defined the fields, constructors, and properties, with useful methods:
line.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MobileCompany
{
public abstract class line
{
protected int Id;
protected string mobilenumber;
protected string customername;
static int tmp = 0 ;
public int Identity
{
get { return Id; }
}
public string MobileNumber
{
set
{
if (value != null)
{ mobilenumber = value; }
}
get
{
return mobilenumber;
}
}
public string CustomerName
{
set
{
if (value != null)
{
customername = value;
}
}
get
{
return customername;
}
}
public line()
{
tmp++;
Id = tmp;
}
public line (string customername,string mobilenumber)
{
tmp++;
Id = tmp;
this.customername = customername;
this.mobilenumber = mobilenumber;
}
public override string ToString()
{
return "Identity :\t"+Id+"\nCustomer Name :\t"+customername+"\nMoblie Number :\t"+mobilenumber;
}
public abstract decimal BillAmount();
}
}
Then, I've added -as requested- a subscribed line that inherits from line.cs :
SubscriberLine.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MobileCompany
{
class SubcriberLine : line
{
int mm;
int mf;
public int MoblietoMobile
{
set
{
if (value > 0)
mm = value;
}
get
{ return mm; }
}
public int Mobiletofixed
{
set
{
if (value > 0)
mf = value;
}
get
{ return mf; }
}
public SubcriberLine(string name , string number,int mm, int mf): base( name, number )
{
this.mm = mm;
this.mf = mf;
}
public SubcriberLine()
{
}
public override string ToString()
{
return "Identity :\t" + base.Id + "\nCustomer Name :\t" + base.customername + "\nMoblie Number :\t" + base.mobilenumber +
"Totall Calling minutes :\nPhone Calls to Mobile:\t" + mm + "\tMobile Calls Charge:\t" + mobilecalls_cost()
+ "\nPhone Calls to Landlines:\t" + mf + "\tland Calls Charge:\t" + landcalls_cost() + "\nTotal Tax :\t" + BillAmount();
}
public decimal mobilecalls_cost()
{
return mm * 4;
}
public decimal landcalls_cost()
{
return mm * 6;
}
public override decimal BillAmount()
{
return mobilecalls_cost() + landcalls_cost();
}
}
}
Last, but not least, I've encoded the Company:
Company.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace MobileCompany
{
public class Company
{
ArrayList data = new ArrayList();
public void Addline(line l)
{
data.Add(l);
}
public Company()
{
}
public line getLine(int index)
{
return data[index] as line;
}
public line this[int index]
{
get
{
return data[index] as line;
}
}
public int Count()
{
return data.Count;
}
}
}
Here I've finished writing the important coding for my application.
I've headed next to the windows form application; it consists of two forms only.
The first form is simple, asks for client's name, number, mobile calls, and land calls; by Pressing buttom1 "Add line", a new line object is created.
It's simplified as follows:
Form1.cs
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.Collections;
namespace MobileCompany
{
public partial class Form1 : Form
{
public static Company MTN = new Company();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SubcriberLine s = new SubcriberLine(txtName.Text,txtNumber.Text,Convert.ToInt32(txtMobile.Text),Convert.ToInt32(txtFixed.Text));
MTN.Addline(s);
MessageBox.Show("new CellPhone Line has been created !");
}
private void button2_Click(object sender, EventArgs e)
{
Form2 f = new Form2();
f.Show();
}
}
}
Now, if you noticed, the functionality of buttom2 "Show All Lines" is Making another instance of Form called Form2, and simply showing it.
Here, I've Placed Only a DataGridView in Form2, wrote some code to ensure the DataGridView shows what is written, by retrieving data from the object :
Form2.cs
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;
namespace MobileCompany
{
public partial class Form2 :Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
for (int i = 0; i < Form1.MTN.Count(); i++)
{
dataGridView1.Rows.Add(Form1.MTN.getLine(i).Identity,Form1.MTN.getLine(i).CustomerName,Form1.MTN.getLine(i).MobileNumber,Form1.MTN.getLine(i).BillAmount());
}
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
}
}
Now, I've finished a pile of coding, unfortunately, the data about an added client won't be shown on the DataGridView.
Can you please Help me find a solution?
I'd be pleased to hear comments about how my code is too.
Appreciate any contributor's help, as long as we're under the same Coding roof.