main form
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using class_library;
namespace oil_business
{
public partial class Main_Form : Form
{
File_Access_Object access_object;
public Main_Form()
{
InitializeComponent();
access_object = new File_Access_Object();
//display message if serialization file not found
access_object.show_message += Access_object_show_message;
}
private void Access_object_show_message(object sender, EventArgs e)
{
MessageBox.Show("specified serialization file not found");
}
private void addWellPadToolStripMenuItem_Click(object sender, EventArgs e)
{
open_form<Add_Well_Pad> new_form = new open_form<Add_Well_Pad>(this);
}
private void explorerToolStripMenuItem_Click(object sender, EventArgs e)
{
open_form<Explorer> new_form = new open_form<Explorer>(this);
}
private void addProductionWellToolStripMenuItem_Click(object sender, EventArgs e)
{
open_form<Add_Production_Well> new_form = new open_form<Add_Production_Well>(this);
}
private void addInjectionWellToolStripMenuItem_Click(object sender, EventArgs e)
{
open_form<Add_Injection_well> new_form = new open_form<Add_Injection_well>(this);
}
private void wellProductionToolStripMenuItem_Click(object sender, EventArgs e)
{
open_form<Well_Production> new_form = new open_form<Well_Production>(this);
}
private class open_form<T> where T: Form, new()
{
private static T _form = null;
public open_form(Form main_form)
{
if(_form == null || _form.IsDisposed)
{
_form = new T();
_form.MdiParent = main_form;
_form.Show();
_form.Location = new Point(0, 0);
}
else
{
_form.BringToFront();
}
}
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
File_Access_Object.Save();
MessageBox.Show("Binary Serialization File Saved");
}
private void loadcsvToolStripMenuItem_Click(object sender, EventArgs e)
{
//load facilities from .csv files
Facility_Manager.add_well_pads(File_Access_Object.get_well_pads());
MessageBox.Show(".csv file loaded");
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
//File_Access_Object.Load();
access_object.Load();
MessageBox.Show("serialization file loaded");
}
private void savecsvToolStripMenuItem_Click(object sender, EventArgs e)
{
File_Access_Object.write_csv();
MessageBox.Show("csv file saved");
}
}
}
-----------------------------------------------------------------------------
//my_interface
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace class_library
{
public interface IWellPad
{
int Id { get; set; }
string Province { get; set; }
string Location { get; set; }
List<IWell> Wells { get; set; }
}
public interface IWell
{
int Id { get; set; }
DateTime SpudDate { get; set; }
}
public interface IProductionWell : IWell
{
List<IOilProduction> DailyProduction { get; set; }
}
public interface IInjectionWell : IWell
{
WaterType WaterType { get; set; }
}
public interface IOilProduction
{
DateTime ProductionDate { get; set; }
int BarrelsProduced { get; set; }
}
public enum WaterType { Brackish, Brine, Fresh, Saline }
}
-----------------------------------------------------------------------------
//well_pad
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace class_library
{
[Serializable]
public class well_pad : IWellPad
{
private int _Id;
private string _Location, _Province;
private List<IWell> _Wells;
public int Id
{
get
{
return _Id;
}
set
{
_Id = value;
}
}
public string Location
{
get
{
return _Location;
}
set
{
_Location = value;
}
}
public string Province
{
get
{
return _Province;
}
set
{
_Province = value;
}
}
public List<IWell> Wells
{
get
{
return _Wells;
}
set
{
_Wells = value;
}
}
}
}
----------------------------------------------------------------------------
//production_well
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace class_library
{
[Serializable]
public class production_well : IProductionWell
{
private List<IOilProduction> _DailyProduction;
private int _Id;
private DateTime _SpudDate;
public List<IOilProduction> DailyProduction
{
get
{
return _DailyProduction;
}
set
{
_DailyProduction = value;
}
}
public int Id
{
get
{
return _Id;
}
set
{
_Id = value;
}
}
public DateTime SpudDate
{
get
{
return _SpudDate;
}
set
{
_SpudDate = value;
}
}
}
}
----------------------------------------------------------------------------
//file_access_object
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace class_library
{
public class File_Access_Object
{
public delegate void message_delegate(object sender, EventArgs e);
public event message_delegate show_message;
//used for .csv loading
public static List<IWellPad> get_well_pads()
{
var well_pads = new List<IWellPad>();
IWellPad single_well_pad = null;
using (var reader = new StreamReader(new FileStream("well_pads.csv", FileMode.Open, FileAccess.Read)))
{
string line = reader.ReadLine();
while (line != null)
{
string[] items = line.Split(',');
single_well_pad = new well_pad { Id = int.Parse(items[0]), Province = items[1], Location =items[2] };
get_wells(single_well_pad);
well_pads.Add(single_well_pad);
line = reader.ReadLine();
}
}
return well_pads;
}
private static void get_wells(IWellPad single_well_pad)
{
var wells = new List<IWell>();
IWell single_well = null;
using (var reader = new StreamReader(new FileStream("wells.csv", FileMode.Open, FileAccess.Read)))
{
string line = reader.ReadLine();
while (line != null)
{
string[] items = line.Split(',');
int well_pad_id = int.Parse(items[3]);
if (well_pad_id == single_well_pad.Id)
{
if(items[1]=="production")
{
List<IOilProduction> oil_productions = new List<IOilProduction>();
IOilProduction oil_production = new oil_production { BarrelsProduced = 100, ProductionDate = new DateTime(2016,1,30) };
oil_productions.Add(oil_production);
oil_production = new oil_production { BarrelsProduced = 200, ProductionDate = new DateTime(2016, 2, 1) };
oil_productions.Add(oil_production);
//construct production well
Iwell_factory well_from_factory = new Iwell_factory(int.Parse(items[0]), Convert.ToDateTime(items[2]), items[1], oil_productions);
single_well = well_from_factory.factory_well(items[1]);
}
else
{
//construct injection well
Iwell_factory well_from_factory = new Iwell_factory(int.Parse(items[0]), Convert.ToDateTime(items[2]), items[1], WaterType.Saline);
single_well = well_from_factory.factory_well(items[1]);
}
wells.Add(single_well);
}
line = reader.ReadLine();
}
}
single_well_pad.Wells = wells;
}
public static void Save()
{
var formatter = new BinaryFormatter();
using (var stream = new FileStream("facilities.dat", FileMode.Create, FileAccess.Write))
{
formatter.Serialize(stream, Facility_Manager.get_facilities());
}
}
public void Load()
{
var formatter = new BinaryFormatter();
if (!File.Exists("facilities.dat"))
{
//System.Windows.Forms.MessageBox.Show("file not found");
//without add reference to windows form, use event to trigger messagebox dispaly on main form
if (show_message != null)
{
show_message.Invoke(this, new EventArgs { });
}
return;
}
using (var stream = new FileStream("facilities.dat", FileMode.Open, FileAccess.Read))
{
Facility_Manager.add_well_pads((List<IWellPad>)formatter.Deserialize(stream));
}
}
public static void write_csv()
{
List<IWellPad> well_pads = Facility_Manager.get_facilities();
using (var writer = new StreamWriter(new FileStream("saved_wells.csv", FileMode.Create, FileAccess.Write)))
{
foreach(IWellPad well_pad in well_pads)
{
if (well_pad.Wells!=null && well_pad.Wells.Count !=0)
{
foreach (IWell well in well_pad.Wells)
{
try
{
IProductionWell P_well = (IProductionWell)well;
if (P_well.DailyProduction.Count != 0)
{
foreach (IOilProduction daily_production in P_well.DailyProduction)
{
writer.WriteLine(well_pad.Id + "," + well_pad.Province + "," + well_pad.Location
+ "," + well.Id + "," + well.SpudDate.ToShortDateString() + ","
+ daily_production.BarrelsProduced + "," + daily_production.ProductionDate.ToShortDateString());
}
}
else
{
writer.WriteLine(well_pad.Id + "," + well_pad.Province + "," + well_pad.Location
+ "," + well.Id + "," + well.SpudDate.ToShortDateString());
}
}
catch (Exception e1)
{
IInjectionWell I_well = (IInjectionWell)well;
writer.WriteLine(well_pad.Id + "," + well_pad.Province + "," + well_pad.Location
+ "," + well.Id + "," + well.SpudDate.ToShortDateString() + ","
+ I_well.WaterType);
}
}
}
else
{
writer.WriteLine(well_pad.Id + "," + well_pad.Province + "," + well_pad.Location);
}
}
}
}
}
}
----------------------------------------------------------------------------
//facility_manager
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace class_library
{
public class Facility_Manager
{
private static List<IWellPad> facilities;
private Facility_Manager(){}
public static List<IWellPad> get_facilities()
{
if(facilities == null)
{
facilities = new List<IWellPad>();
}
return facilities;
}
public static void add_well_pads(List<IWellPad> well_pads)
{
facilities = well_pads;
}
public static void add_well_pad(IWellPad well_pad, int ID)
{
IWellPad _well_pad = facilities.Find(x => x.Id == ID);
//if well pad id exists, choose enter new ID or update existing pad
if(_well_pad!=null)
{
DialogResult yes_no = MessageBox.Show("Update existing well/Y \nEnter new ID/N", "well ID exists, what to do?", MessageBoxButtons.YesNo);
if (yes_no == DialogResult.Yes)
{
_well_pad.Province = well_pad.Province;
_well_pad.Location = well_pad.Location;
MessageBox.Show("updated");
}
return;
}
facilities.Add(well_pad);
MessageBox.Show("well pad added");
}
public static void add_well(IWell well, int well_pad_id, int well_id)
{
IWellPad well_pad = facilities.Find(x => x.Id == well_pad_id);
IWell _well = well_pad.Wells.Find(x => x.Id == well_id);
//if well ID exists in well pad, choose enter new ID or update existing well
if (_well!=null)
{
DialogResult yes_no = MessageBox.Show("Update existing well/Y \nEnter new ID/N", "well ID exists, what to do?", MessageBoxButtons.YesNo);
if (yes_no == DialogResult.Yes)
{
try
{
IProductionWell I_well = (IProductionWell)_well;
IProductionWell I_well_pameter = (IProductionWell)well;
I_well.SpudDate = I_well_pameter.SpudDate;
MessageBox.Show("updated");
}
catch (Exception e1)
{
IInjectionWell I_well = (IInjectionWell)_well;
IInjectionWell I_well_pameter = (IInjectionWell)well;
I_well.SpudDate = I_well_pameter.SpudDate;
I_well.WaterType = I_well_pameter.WaterType;
MessageBox.Show("updated");
}
}
return;
}
well_pad.Wells.Add(well);
MessageBox.Show("new well added");
}
public static void add_daily_production(IOilProduction daily_production,string location,int _id, string date)
{
IWellPad well_pad = facilities.Find(x => x.Location==location);
IWell well = well_pad.Wells.Find(x => x.Id == _id);
IProductionWell P_well = (IProductionWell)well;
IOilProduction P = P_well.DailyProduction.Find(x => x.ProductionDate.ToShortDateString() == date);
//if production date exists, choose enter new date or update existing
if (P != null)
{
DialogResult yes_no = MessageBox.Show("Update existing date/Y \nEnter new date/N", "Date exists, what to do?", MessageBoxButtons.YesNo);
if (yes_no == DialogResult.Yes)
{
P.BarrelsProduced = daily_production.BarrelsProduced;
MessageBox.Show("updated");
}
return;
}
P_well.DailyProduction.Add(daily_production);
MessageBox.Show("daily production added to selected well");
}
}
}
//my_interface
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace class_library
{
public interface IWellPad
{
int Id { get; set; }
string Province { get; set; }
string Location { get; set; }
List<IWell> Wells { get; set; }
}
public interface IWell
{
int Id { get; set; }
DateTime SpudDate { get; set; }
}
public interface IProductionWell : IWell
{
List<IOilProduction> DailyProduction { get; set; }
}
public interface IInjectionWell : IWell
{
WaterType WaterType { get; set; }
}
public interface IOilProduction
{
DateTime ProductionDate { get; set; }
int BarrelsProduced { get; set; }
}
public enum WaterType { Brackish, Brine, Fresh, Saline }
}
-----------------------------------------------------------------------------
//well_pad
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace class_library
{
[Serializable]
public class well_pad : IWellPad
{
private int _Id;
private string _Location, _Province;
private List<IWell> _Wells;
public int Id
{
get
{
return _Id;
}
set
{
_Id = value;
}
}
public string Location
{
get
{
return _Location;
}
set
{
_Location = value;
}
}
public string Province
{
get
{
return _Province;
}
set
{
_Province = value;
}
}
public List<IWell> Wells
{
get
{
return _Wells;
}
set
{
_Wells = value;
}
}
}
}
----------------------------------------------------------------------------
//production_well
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace class_library
{
[Serializable]
public class production_well : IProductionWell
{
private List<IOilProduction> _DailyProduction;
private int _Id;
private DateTime _SpudDate;
public List<IOilProduction> DailyProduction
{
get
{
return _DailyProduction;
}
set
{
_DailyProduction = value;
}
}
public int Id
{
get
{
return _Id;
}
set
{
_Id = value;
}
}
public DateTime SpudDate
{
get
{
return _SpudDate;
}
set
{
_SpudDate = value;
}
}
}
}
----------------------------------------------------------------------------
//iwell_factory
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace class_library
{
public class Iwell_factory
{
private int _id;
private List<IOilProduction> _oil_production;
private DateTime _spud_date;
private string _type;
private WaterType _water_type;
public Iwell_factory()
{ }
public Iwell_factory(int ID, DateTime Spud_date,string type,List<IOilProduction> oil_production)
{
_id = ID;
_spud_date = Spud_date;
_type = type;
_oil_production = oil_production;
}
public Iwell_factory(int ID, DateTime Spud_date, string type, WaterType water_type)
{
_id = ID;
_spud_date = Spud_date;
_type = type;
_water_type = water_type;
}
public IWell factory_well(string type )
{
if(type == "production")
{
IProductionWell production_well = new production_well {Id =_id,SpudDate=_spud_date,DailyProduction=_oil_production };
return production_well;
}
else
{
IInjectionWell injection_well = new injection_well { Id = _id, SpudDate = _spud_date, WaterType = _water_type };
return injection_well;
}
}
}
}
//file_access_object
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace class_library
{
public class File_Access_Object
{
public delegate void message_delegate(object sender, EventArgs e);
public event message_delegate show_message;
//used for .csv loading
public static List<IWellPad> get_well_pads()
{
var well_pads = new List<IWellPad>();
IWellPad single_well_pad = null;
using (var reader = new StreamReader(new FileStream("well_pads.csv", FileMode.Open, FileAccess.Read)))
{
string line = reader.ReadLine();
while (line != null)
{
string[] items = line.Split(',');
single_well_pad = new well_pad { Id = int.Parse(items[0]), Province = items[1], Location =items[2] };
get_wells(single_well_pad);
well_pads.Add(single_well_pad);
line = reader.ReadLine();
}
}
return well_pads;
}
private static void get_wells(IWellPad single_well_pad)
{
var wells = new List<IWell>();
IWell single_well = null;
using (var reader = new StreamReader(new FileStream("wells.csv", FileMode.Open, FileAccess.Read)))
{
string line = reader.ReadLine();
while (line != null)
{
string[] items = line.Split(',');
int well_pad_id = int.Parse(items[3]);
if (well_pad_id == single_well_pad.Id)
{
if(items[1]=="production")
{
List<IOilProduction> oil_productions = new List<IOilProduction>();
IOilProduction oil_production = new oil_production { BarrelsProduced = 100, ProductionDate = new DateTime(2016,1,30) };
oil_productions.Add(oil_production);
oil_production = new oil_production { BarrelsProduced = 200, ProductionDate = new DateTime(2016, 2, 1) };
oil_productions.Add(oil_production);
//construct production well
Iwell_factory well_from_factory = new Iwell_factory(int.Parse(items[0]), Convert.ToDateTime(items[2]), items[1], oil_productions);
single_well = well_from_factory.factory_well(items[1]);
}
else
{
//construct injection well
Iwell_factory well_from_factory = new Iwell_factory(int.Parse(items[0]), Convert.ToDateTime(items[2]), items[1], WaterType.Saline);
single_well = well_from_factory.factory_well(items[1]);
}
wells.Add(single_well);
}
line = reader.ReadLine();
}
}
single_well_pad.Wells = wells;
}
public static void Save()
{
var formatter = new BinaryFormatter();
using (var stream = new FileStream("facilities.dat", FileMode.Create, FileAccess.Write))
{
formatter.Serialize(stream, Facility_Manager.get_facilities());
}
}
public void Load()
{
var formatter = new BinaryFormatter();
if (!File.Exists("facilities.dat"))
{
//System.Windows.Forms.MessageBox.Show("file not found");
//without add reference to windows form, use event to trigger messagebox dispaly on main form
if (show_message != null)
{
show_message.Invoke(this, new EventArgs { });
}
return;
}
using (var stream = new FileStream("facilities.dat", FileMode.Open, FileAccess.Read))
{
Facility_Manager.add_well_pads((List<IWellPad>)formatter.Deserialize(stream));
}
}
public static void write_csv()
{
List<IWellPad> well_pads = Facility_Manager.get_facilities();
using (var writer = new StreamWriter(new FileStream("saved_wells.csv", FileMode.Create, FileAccess.Write)))
{
foreach(IWellPad well_pad in well_pads)
{
if (well_pad.Wells!=null && well_pad.Wells.Count !=0)
{
foreach (IWell well in well_pad.Wells)
{
try
{
IProductionWell P_well = (IProductionWell)well;
if (P_well.DailyProduction.Count != 0)
{
foreach (IOilProduction daily_production in P_well.DailyProduction)
{
writer.WriteLine(well_pad.Id + "," + well_pad.Province + "," + well_pad.Location
+ "," + well.Id + "," + well.SpudDate.ToShortDateString() + ","
+ daily_production.BarrelsProduced + "," + daily_production.ProductionDate.ToShortDateString());
}
}
else
{
writer.WriteLine(well_pad.Id + "," + well_pad.Province + "," + well_pad.Location
+ "," + well.Id + "," + well.SpudDate.ToShortDateString());
}
}
catch (Exception e1)
{
IInjectionWell I_well = (IInjectionWell)well;
writer.WriteLine(well_pad.Id + "," + well_pad.Province + "," + well_pad.Location
+ "," + well.Id + "," + well.SpudDate.ToShortDateString() + ","
+ I_well.WaterType);
}
}
}
else
{
writer.WriteLine(well_pad.Id + "," + well_pad.Province + "," + well_pad.Location);
}
}
}
}
}
}
//facility_manager
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace class_library
{
public class Facility_Manager
{
private static List<IWellPad> facilities;
private Facility_Manager(){}
public static List<IWellPad> get_facilities()
{
if(facilities == null)
{
facilities = new List<IWellPad>();
}
return facilities;
}
public static void add_well_pads(List<IWellPad> well_pads)
{
facilities = well_pads;
}
public static void add_well_pad(IWellPad well_pad, int ID)
{
IWellPad _well_pad = facilities.Find(x => x.Id == ID);
//if well pad id exists, choose enter new ID or update existing pad
if(_well_pad!=null)
{
DialogResult yes_no = MessageBox.Show("Update existing well/Y \nEnter new ID/N", "well ID exists, what to do?", MessageBoxButtons.YesNo);
if (yes_no == DialogResult.Yes)
{
_well_pad.Province = well_pad.Province;
_well_pad.Location = well_pad.Location;
MessageBox.Show("updated");
}
return;
}
facilities.Add(well_pad);
MessageBox.Show("well pad added");
}
public static void add_well(IWell well, int well_pad_id, int well_id)
{
IWellPad well_pad = facilities.Find(x => x.Id == well_pad_id);
IWell _well = well_pad.Wells.Find(x => x.Id == well_id);
//if well ID exists in well pad, choose enter new ID or update existing well
if (_well!=null)
{
DialogResult yes_no = MessageBox.Show("Update existing well/Y \nEnter new ID/N", "well ID exists, what to do?", MessageBoxButtons.YesNo);
if (yes_no == DialogResult.Yes)
{
try
{
IProductionWell I_well = (IProductionWell)_well;
IProductionWell I_well_pameter = (IProductionWell)well;
I_well.SpudDate = I_well_pameter.SpudDate;
MessageBox.Show("updated");
}
catch (Exception e1)
{
IInjectionWell I_well = (IInjectionWell)_well;
IInjectionWell I_well_pameter = (IInjectionWell)well;
I_well.SpudDate = I_well_pameter.SpudDate;
I_well.WaterType = I_well_pameter.WaterType;
MessageBox.Show("updated");
}
}
return;
}
well_pad.Wells.Add(well);
MessageBox.Show("new well added");
}
public static void add_daily_production(IOilProduction daily_production,string location,int _id, string date)
{
IWellPad well_pad = facilities.Find(x => x.Location==location);
IWell well = well_pad.Wells.Find(x => x.Id == _id);
IProductionWell P_well = (IProductionWell)well;
IOilProduction P = P_well.DailyProduction.Find(x => x.ProductionDate.ToShortDateString() == date);
//if production date exists, choose enter new date or update existing
if (P != null)
{
DialogResult yes_no = MessageBox.Show("Update existing date/Y \nEnter new date/N", "Date exists, what to do?", MessageBoxButtons.YesNo);
if (yes_no == DialogResult.Yes)
{
P.BarrelsProduced = daily_production.BarrelsProduced;
MessageBox.Show("updated");
}
return;
}
P_well.DailyProduction.Add(daily_production);
MessageBox.Show("daily production added to selected well");
}
}
}
----------------------------------------------------------------------------------------------
//explorer
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using class_library;
namespace oil_business
{
public partial class Explorer : Form
{
public Explorer()
{
InitializeComponent();
Tree();
}
private void Tree()
{
TreeNode Facilities_node = new TreeNode("Facilitites");
TreeNode well_pads_node = null;
TreeNode Well_pad_node = null;
TreeNode Wells_node = null;
UX_Tree.Nodes.Add(Facilities_node);
List<IWellPad> well_pads = Facility_Manager.get_facilities(); ;
Facilities_node.Tag = well_pads;
foreach (IWellPad single_well_pad in well_pads)
{
bool node_exist = false;
//check if province exists in facilities
foreach(TreeNode x in Facilities_node.Nodes)
{
if(x.Text == single_well_pad.Province)
{
node_exist = true;
//add city to province
Well_pad_node = new TreeNode(single_well_pad.Location);
Well_pad_node.Tag = single_well_pad;
x.Nodes.Add(Well_pad_node);
}
}
//province doesn't exist, add province
if(!node_exist)
{
//add province to facilities
well_pads_node = new TreeNode(single_well_pad.Province);
well_pads_node.Tag = well_pads;
Facilities_node.Nodes.Add(well_pads_node);
//add city to province
Well_pad_node = new TreeNode(single_well_pad.Location);
Well_pad_node.Tag = single_well_pad;
well_pads_node.Nodes.Add(Well_pad_node);
}
if (single_well_pad.Wells != null)
{
foreach (IWell well in single_well_pad.Wells)
{
Wells_node = new TreeNode(well.SpudDate.ToShortDateString());
Wells_node.Tag = well;
Well_pad_node.Nodes.Add(Wells_node);
}
}
}
}
private void UX_Tree_AfterSelect(object sender, TreeViewEventArgs e)
{
switch (e.Node.Level)
{
case 0:
display_facilities(e.Node.Tag, e.Node);
break;
case 1:
display_well_pads(e.Node.Tag,e.Node.Text);
break;
case 2:
display_single_well_pad(e.Node.Tag);
break;
case 3:
display_single_well(e.Node.Tag);
break;
}
}
private void display_facilities(object tag, TreeNode facilities)
{
List<IWellPad> well_pads = (List<IWellPad>)tag;
UX_Listview.Columns.Clear();
UX_Listview.Items.Clear();
UX_Listview.Columns.Add("Province", 100);
UX_Listview.Columns.Add("Well Pad Count", 100);
UX_Listview.Columns.Add("Producing Wells Count", 100);
UX_Listview.Columns.Add("Injection Wells Count", 100);
foreach(TreeNode provice_node in facilities.Nodes)
{
ListViewItem item = new ListViewItem();
item.Text = provice_node.Text;
int well_pad_count = 0;
//count citites in province
foreach (TreeNode city_node in provice_node.Nodes)
{
well_pad_count++;
}
item.SubItems.Add(new ListViewItem.ListViewSubItem { Text = well_pad_count.ToString() });
int production_well = 0, injection_well = 0;
//count different wells in province
foreach(IWellPad well_pad in well_pads)
{
if(well_pad.Province == provice_node.Text)
{
if (well_pad.Wells != null)
{
foreach (IWell well in well_pad.Wells)
{
try
{
IProductionWell P_well = (IProductionWell)well;
production_well++;
}
catch (Exception e1)
{
injection_well++;
}
}
}
}
}
item.SubItems.Add(new ListViewItem.ListViewSubItem { Text = production_well.ToString() });
item.SubItems.Add(new ListViewItem.ListViewSubItem { Text = injection_well.ToString() });
UX_Listview.Items.Add(item);
}
}
private void display_well_pads(object tag,string province)
{
List<IWellPad> well_pads = (List<IWellPad>)tag;
UX_Listview.Columns.Clear();
UX_Listview.Items.Clear();
UX_Listview.Columns.Add("Location", 100);
UX_Listview.Columns.Add("Producing Wells Count", 100);
UX_Listview.Columns.Add("Injection Wells Count", 100);
foreach(IWellPad well_pad in well_pads)
{
if(well_pad.Province == province)
{
ListViewItem item = new ListViewItem();
item.Text = well_pad.Location;
int production_well = 0, injection_well = 0;
//find number of different wells in province
foreach (IWell well in well_pad.Wells)
{
try
{
IProductionWell P_well = (IProductionWell)well;
production_well++;
}
catch (Exception e1)
{
injection_well++;
}
}
item.SubItems.Add(new ListViewItem.ListViewSubItem { Text = production_well.ToString() });
item.SubItems.Add(new ListViewItem.ListViewSubItem { Text = injection_well.ToString() });
UX_Listview.Items.Add(item);
}
}
}
private void display_single_well_pad(object tag)
{
IWellPad well_pad = (IWellPad)tag;
UX_Listview.Columns.Clear();
UX_Listview.Items.Clear();
UX_Listview.Columns.Add("Spud Date", 200);
UX_Listview.Columns.Add("Barrels Produced in history", 300);
if (well_pad.Wells != null)
{
foreach (IWell well in well_pad.Wells)
{
ListViewItem item = new ListViewItem();
item.Text = well.SpudDate.ToShortDateString();
//find historical barrels produces by single production well
try
{
IProductionWell P_well = (IProductionWell)well;
long history_production = 0;
foreach (IOilProduction daily_production in P_well.DailyProduction)
{
history_production += daily_production.BarrelsProduced;
}
item.SubItems.Add(new ListViewItem.ListViewSubItem { Text = history_production.ToString() });
}
catch (Exception e1)
{
}
UX_Listview.Items.Add(item);
}
}
}
private void display_single_well(object tag)
{
IWell well = (IWell)tag;
UX_Listview.Columns.Clear();
UX_Listview.Items.Clear();
//2 types of wells display different property
try
{
IProductionWell P_well = (IProductionWell)well;
UX_Listview.Columns.Add("Production Date", 200);
UX_Listview.Columns.Add("Barrels Produced for the day", 300);
if (P_well.DailyProduction == null) { return; }
//sort the production date for well dailyproduction
P_well.DailyProduction.Sort((y, x) => x.ProductionDate.CompareTo(y.ProductionDate));
foreach (IOilProduction oil_production in P_well.DailyProduction)
{
ListViewItem item = new ListViewItem();
item.Text = oil_production.ProductionDate.ToShortDateString();
item.SubItems.Add(new ListViewItem.ListViewSubItem { Text = oil_production.BarrelsProduced.ToString() });
UX_Listview.Items.Add(item);
}
}
catch (Exception e1)
{
IInjectionWell I_well = (IInjectionWell)well;
UX_Listview.Columns.Add("Water type", 200);
ListViewItem item = new ListViewItem();
item.Text = I_well.WaterType.ToString();
UX_Listview.Items.Add(item);
}
}
private void expandToolStripMenuItem_Click(object sender, EventArgs e)
{
UX_Tree.ExpandAll();
}
private void collapseToolStripMenuItem_Click(object sender, EventArgs e)
{
UX_Tree.CollapseAll();
}
private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
{
UX_Tree.Nodes.Clear();
Tree();
}
}
}
//add_well_pad
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using class_library;
namespace oil_business
{
public partial class Add_Well_Pad : Form
{
public Add_Well_Pad()
{
InitializeComponent();
refresh();
}
IWellPad well_pad;
private void button1_Click(object sender, EventArgs e)
{
try
{
well_pad = new well_pad
{
Id = Convert.ToInt32(UX_ID.Text),
Province = UX_Province.Text,
Location = UX_Location.Text,
Wells = new List<IWell>()
};
Facility_Manager.add_well_pad(well_pad, Convert.ToInt32(UX_ID.Text));
}
catch (Exception e1)
{
MessageBox.Show(e1.ToString());
}
}
private void refresh()
{
listView1.Columns.Clear();
listView1.Items.Clear();
listView1.Columns.Add("Existing Well Pads", 300);
foreach(IWellPad well_pad in Facility_Manager.get_facilities())
{
ListViewItem item = new ListViewItem();
item.Text = well_pad.Id + " " + well_pad.Location;
listView1.Items.Add(item);
}
}
private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
{
refresh();
}
}
}
---------------------------------------------------------------------------------------------
//add_production_well
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using class_library;
namespace oil_business
{
public partial class Add_Production_Well : Form
{
public Add_Production_Well()
{
InitializeComponent();
refresh();
}
protected virtual void button1_Click(object sender, EventArgs e)
{
if (UX_ListBox.SelectedItem != null)
{
try
{
int well_pad_id = Convert.ToInt32(UX_ListBox.SelectedItem.ToString().Split(' ')[0]);
IProductionWell _well = new production_well
{
Id = Convert.ToInt32(UX_ID.Text),
SpudDate = dateTimePicker1.Value,
DailyProduction = new List<IOilProduction>()
};
Facility_Manager.add_well(_well, well_pad_id, Convert.ToInt32(UX_ID.Text));
}
catch (Exception e1)
{
MessageBox.Show(e1.ToString() + "\n please select existing well pad ID from list");
}
}
else
{
MessageBox.Show("please select a well pad first");
}
}
private void refresh()
{
UX_ListBox.Items.Clear();
foreach (IWellPad well_pad in Facility_Manager.get_facilities())
{
UX_ListBox.Items.Add(well_pad.Id + " " + well_pad.Location);
}
}
private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
{
refresh();
}
protected virtual void UX_ListBox_SelectedValueChanged(object sender, EventArgs e)
{
listView1.Columns.Clear();
listView1.Items.Clear();
listView1.Columns.Add("Existing production well", 300);
if (UX_ListBox.SelectedItem != null)
{
int well_pad_id = Convert.ToInt32(UX_ListBox.SelectedItem.ToString().Split(' ')[0]);
IWellPad well_pad = Facility_Manager.get_facilities().Find(x => x.Id == well_pad_id);
foreach (IWell well in well_pad.Wells)
{
try
{
IProductionWell P_well = (IProductionWell)well;
ListViewItem item = new ListViewItem();
item.Text = P_well.Id.ToString() + " " + P_well.SpudDate.ToShortDateString();
listView1.Items.Add(item);
}
catch (Exception e1)
{ }
}
}
}
}
}
-------------------------------------------------------------------------------------------------------
//add_injection_well
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using class_library;
namespace oil_business
{
public partial class Add_Injection_well : oil_business.Add_Production_Well
{
public Add_Injection_well()
{
InitializeComponent();
foreach (string name in Enum.GetNames(typeof(WaterType)))
{
UX_Water_type.Items.Add(name);
}
}
protected override void button1_Click(object sender, EventArgs e)
{
//base.button1_Click(sender, e);
if (UX_ListBox.SelectedItem != null && UX_Water_type.SelectedItem!=null)
{
try
{
int well_pad_id = Convert.ToInt32(UX_ListBox.SelectedItem.ToString().Split(' ')[0]);
IInjectionWell _well = new injection_well
{
Id = Convert.ToInt32(UX_ID.Text),
SpudDate = dateTimePicker1.Value,
WaterType = get_water_type(UX_Water_type.SelectedItem.ToString())
};
Facility_Manager.add_well(_well, well_pad_id, Convert.ToInt32(UX_ID.Text));
}
catch (Exception e1)
{
MessageBox.Show(e1.ToString());
}
}
else
{
MessageBox.Show("please select a well pad and watertype first");
}
}
private WaterType get_water_type(string name)
{
switch(name)
{
case "Brackish":
return WaterType.Brackish;
case "Brine":
return WaterType.Brine;
case "Fresh":
return WaterType.Brine;
default:
return WaterType.Saline;
}
}
protected override void UX_ListBox_SelectedValueChanged(object sender, EventArgs e)
{
listView1.Columns.Clear();
listView1.Items.Clear();
listView1.Columns.Add("Existing injection well", 300);
if (UX_ListBox.SelectedItem != null)
{
int well_pad_id = Convert.ToInt32(UX_ListBox.SelectedItem.ToString().Split(' ')[0]);
IWellPad well_pad = Facility_Manager.get_facilities().Find(x => x.Id == well_pad_id);
foreach (IWell well in well_pad.Wells)
{
try
{
IInjectionWell I_well = (IInjectionWell)well;
ListViewItem item = new ListViewItem();
item.Text = I_well.Id.ToString() + " " + I_well.SpudDate.ToShortDateString();
listView1.Items.Add(item);
}
catch (Exception e1)
{ }
}
}
}
}
}
------------------------------------------------------------------------------------------------
//well_production
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using class_library;
namespace oil_business
{
public partial class Well_Production : Form
{
public Well_Production()
{
InitializeComponent();
refresh();
}
private void button1_Click(object sender, EventArgs e)
{
if(UX_Select_Well_pad.SelectedItem == null || UX_Select_Production_well.SelectedItem==null)
{
MessageBox.Show("please select Well Pad and production well first");
}
else
{
try
{
IOilProduction daily_production = new oil_production();
daily_production.ProductionDate = UX_date.Value;
daily_production.BarrelsProduced = Convert.ToInt32(UX_barrels.Text);
int well_ID = Convert.ToInt32(UX_Select_Production_well.SelectedItem.ToString().Split(' ')[0]);
Facility_Manager.add_daily_production(daily_production, UX_Select_Well_pad.SelectedItem.ToString(), well_ID, UX_date.Value.ToShortDateString());
}
catch(Exception e1)
{
MessageBox.Show(e1.ToString());
}
}
}
private void refresh()
{
UX_Select_Well_pad.Items.Clear();
UX_Select_Production_well.Items.Clear();
foreach (IWellPad well_pad in Facility_Manager.get_facilities())
{
UX_Select_Well_pad.Items.Add(well_pad.Location);
}
}
private void UX_Select_Well_pad_SelectedValueChanged(object sender, EventArgs e)
{
UX_Select_Production_well.Items.Clear();
if (UX_Select_Well_pad.SelectedItem != null)
{
IWellPad well_pad = Facility_Manager.get_facilities().Find(x => x.Location == UX_Select_Well_pad.SelectedItem.ToString());
foreach (IWell well in well_pad.Wells)
{
try
{
IProductionWell P_well = (IProductionWell)well;
UX_Select_Production_well.Items.Add(P_well.Id + " " + P_well.SpudDate.ToShortDateString());
}
catch (Exception e1)
{
}
}
}
}
}
}
--------------------------------------------------------------------
//well_pads.csv
1,BC,Kelowna
2,BC,Vancouver
3,AB,Calgary
4,AB,Edmonton
5,SK,Saskatoon
6,SK,Regina
//well_pads.csv
1,BC,Kelowna
2,BC,Vancouver
3,AB,Calgary
4,AB,Edmonton
5,SK,Saskatoon
6,SK,Regina
//wells.csv
1,injection,01/01/2006,1
2,production,02/02/2007,1
3,injection,03/03/2008,1
4,production,04/04/2009,2
5,injection,05/05/2010,2
6,production,06/06/2011,2
7,production,07/07/2012,3
8,production,08/08/2013,3
9,production,09/09/2014,3
10,injection,10/10/2013,4
11,injection,11/11/2014,4
12,injection,12/12/2015,4
No comments:
Post a Comment