Business Logic Controller for General Purpose Data Capturingsearch for big amount of data in SQL server

How do you voice extended chords?

False written accusations not made public - is there law to cover this?

Is there a verb that means to inject with poison?

Does the US government have any planning in place to ensure there's no shortages of food, fuel, steel and other commodities?

What's the oldest plausible frozen specimen for a Jurassic Park style story-line?

How to deal with possible delayed baggage?

What game did these black and yellow dice come from?

Cat is tipping over bed-side lamps during the night

Is a new boolean field better than null reference when a value can be meaningfully absent?

How would an AI self awareness kill switch work?

Am I correct in stating that the study of topology is purely theoretical?

Is there a file that always exists and a 'normal' user can't lstat it?

Not a Long-Winded Riddle

Calculate of total length of edges in Voronoi diagram

Potential client has a problematic employee I can't work with

Does a paladin have to announce that they're using Divine Smite before attacking?

Website seeing my Facebook data?

I have trouble understanding this fallacy: "If A, then B. Therefore if not-B, then not-A."

Has any human ever had the choice to leave Earth permanently?

When obtaining gender reassignment/plastic surgery overseas, is an emergency travel document required to return home?

If angels and devils are the same species, why would their mortal offspring appear physically different?

Why is a temp table a more efficient solution to the Halloween Problem than an eager spool?

Do authors have to be politically correct in article-writing?

Book where a space ship journeys to the center of the galaxy to find all the stars had gone supernova



Business Logic Controller for General Purpose Data Capturing


search for big amount of data in SQL server













0















Good day,



I have the following BLL (Business Logic Layer) class. It is the first class I have created that takes away all responsibility from the UI (where this class is instantiated/created/called) in terms of checking against business rules. My aim for this code is to be reusable and flexible in instances where I need to add a control or field and insert into the database.



I hope this is clear enough, thanks for taking the time to review it!



EDIT: This could be a complete miss or partial hit, IMO



    public class MillInsController
{
private MillInspectionTableAdapter _millDt = null;

protected MillInspectionTableAdapter Adapter
{
get
{
if (_millDt == null)

_millDt = new MillInspectionTableAdapter();
_millDt.ConnectionString = Login.LoginController.UserConnString;
return _millDt;
}
}

public static void InitMillForm(Form millform)
{
switch (DateTime.Now.Year)
{
case 2016:
millform.Controls["txtPrefEnd"].Text = "ES";
millform.Controls["txtPrefStart"].Text = "ES";
break;
case 2017:
millform.Controls["txtPrefEnd"].Text = "ET";
millform.Controls["txtPrefStart"].Text = "ET";
break;
case 2018:
millform.Controls["txtPrefEnd"].Text = "EU";
millform.Controls["txtPrefStart"].Text = "EU";
break;
case 2019:
millform.Controls["txtPrefEnd"].Text = "EV";
millform.Controls["txtPrefStart"].Text = "EV";
break;
case 2020:
millform.Controls["txtPrefEnd"].Text = "EW";
millform.Controls["txtPrefStart"].Text = "EW";
break;
case 2021:
millform.Controls["txtPrefEnd"].Text = "EX";
millform.Controls["txtPrefStart"].Text = "EX";
break;
case 2022:
millform.Controls["txtPrefEnd"].Text = "EY";
millform.Controls["txtPrefStart"].Text = "EY";
break;
case 2023:
millform.Controls["txtPrefEnd"].Text = "EZ";
millform.Controls["txtPrefStart"].Text = "EZ";
break;

}

}

public DialogResult InsertMillData(Form form)
{
string inValue = "";
bool TransactionStat = true;
ComboBox cbCoil = form.Controls["cbCoilNumber"] as ComboBox;
ComboBox cbShift = form.Controls["cbShift"] as ComboBox;

string JobNumber = form.Controls["txtJobNumber"].Text;
string PipeSize = form.Controls["txtDiameter"].Text + "X" + form.Controls["txtThickness"].Text + "X" + form.Controls["txtLength"].Text;
string HeatNumber = form.Controls["txtHeatNumber"].Text;
string CoilNumber = cbCoil.SelectedItem.ToString();
string pipePrefix = form.Controls["txtPrefStart"].Text;
string PipeNumberStart = form.Controls["txtPipeNumberStart"].Text;
string PipeNumberEnd = form.Controls["txtPipeNumberEnd"].Text;
string Length = form.Controls["txtLength"].Text;
string Thickness = form.Controls["txtThickness"].Text;
string Diameter = form.Controls["txtDiameter"].Text;
string Mass = form.Controls["txtMass"].Text;
string SNo = form.Controls["txtSNo"].Text;
string SheetNumber = form.Controls["txtSheetNumber"].Text;
string SteelGrade = form.Controls["txtSteelGrade"].Text;
string Operator = form.Controls["txtOperator"].Text;

InputBox("Coil Number", "Enter Coil Number used for Sheet:" + form.Controls["txtSheetNumber"].Text, ref inValue);
if (inValue != cbCoil.SelectedItem.ToString().Trim())
{
TransactionStat = false;
return MessageBox.Show("ERROR! Please check Coil Number entered for Sheet.");

}
else
{
if ((pipePrefix + PipeNumberStart).Length < 8 || (pipePrefix + PipeNumberEnd).Length < 8)
{
TransactionStat = false;
return MessageBox.Show("Pipe Number range incorrect format.");
}

foreach (Control controls in form.Controls)
{
if (controls is TextBox)
{
if (String.IsNullOrWhiteSpace(controls.Text))
{
controls.BackColor = Color.Red;
TransactionStat = false;
}
else
{
controls.BackColor = Color.White;
}
}
if (controls is ComboBox)
{
var cb = controls as ComboBox;
if (String.IsNullOrWhiteSpace(cb.SelectedItem.ToString()))
{
cb.BackColor = Color.Red;
TransactionStat = false;
}
}
}

if (TransactionStat == false)
{
return MessageBox.Show("PLEASE PROVIDE ALL REQUIRED FIELDS, CHECK HIGHLIGHTED (RED) FIELDS TO CORRECT THE ERROR. CAPTURE ABORTED.", "ERROR OCCURED");
}
else
{
List<string> pipes = new List<string>();

int start = Int32.Parse(PipeNumberStart);
int end = Int32.Parse(PipeNumberEnd);
int endlen = end.ToString().Length;

while (start <= end)
{
int startlen = start.ToString().Length;
pipes.Add(pipePrefix.PadRight(8 - startlen, '0') + start);
start++;
}
MillInsController millinsctrl;
millinsctrl = new MillInsController();
//INSERT MILL
foreach (var pipe in pipes)
{
Adapter.Insert(
Mass, Diameter, Thickness, SNo, JobNumber,
SheetNumber, SteelGrade, cbShift.SelectedItem.ToString(),
Operator, HeatNumber, cbCoil.SelectedItem.ToString(), pipe, Length);
}
return MessageBox.Show("INSERT SUCCESSFULL");
}
}
}

public static DialogResult InputBox(string title, string promptText, ref string value)
{
Form form = new Form();
Label label = new Label();
TextBox textBox = new TextBox();
Button buttonOk = new Button();
Button buttonCancel = new Button();

form.Text = title;
label.Text = promptText;
textBox.Text = value;

buttonOk.Text = "OK";
buttonCancel.Text = "Cancel";
buttonOk.DialogResult = DialogResult.OK;
buttonCancel.DialogResult = DialogResult.Cancel;

label.SetBounds(9, 20, 372, 13);
textBox.SetBounds(12, 36, 372, 20);
buttonOk.SetBounds(228, 72, 75, 23);
buttonCancel.SetBounds(309, 72, 75, 23);

label.AutoSize = true;
textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;

form.ClientSize = new Size(396, 107);
form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
form.FormBorderStyle = FormBorderStyle.FixedDialog;
form.StartPosition = FormStartPosition.CenterScreen;
form.MinimizeBox = false;
form.MaximizeBox = false;
form.AcceptButton = buttonOk;
form.CancelButton = buttonCancel;

DialogResult dialogResult = form.ShowDialog();
value = textBox.Text;
return dialogResult;
}


public bool updateMill(string stat, string scrapl, string length, string pipenum)
{
ds_Mill.MillInspectionDataTable mill = Adapter.GetDataByPipe(pipenum);
if (mill.Count == 0)
{
return false;
}

ds_Mill.MillInspectionRow millrw = mill[0];

_millDt.Update(stat, scrapl, length, pipenum);

int rowsAffected = Adapter.Update(millrw);

// Return true if precisely one row was updated,
// otherwise false
return rowsAffected == 1;

}

public ds_Mill.MillInspectionDataTable getSheet(string sheet)
{
return Adapter.GetDataBySheetNum(sheet);
}

public System.Data.DataTable fillDataGridMillIns(string sheetnum)
{
try
{
MillInsController millIns = new MillInsController();
return millIns.getSheet(sheetnum);

}
catch (SqlException ex)
{
MessageBox.Show(ex.ToString());
return null;
}
catch (InvalidOperationException exOp)
{
MessageBox.Show(exOp.ToString());
return null;
}
}
}








share







New contributor




Brendan Jacobs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Should be moved to stackoverflow.com

    – spikey_richie
    5 mins ago











  • What is your exact question? Are you sure it's on-topic?

    – Kamil Maciorowski
    5 mins ago
















0















Good day,



I have the following BLL (Business Logic Layer) class. It is the first class I have created that takes away all responsibility from the UI (where this class is instantiated/created/called) in terms of checking against business rules. My aim for this code is to be reusable and flexible in instances where I need to add a control or field and insert into the database.



I hope this is clear enough, thanks for taking the time to review it!



EDIT: This could be a complete miss or partial hit, IMO



    public class MillInsController
{
private MillInspectionTableAdapter _millDt = null;

protected MillInspectionTableAdapter Adapter
{
get
{
if (_millDt == null)

_millDt = new MillInspectionTableAdapter();
_millDt.ConnectionString = Login.LoginController.UserConnString;
return _millDt;
}
}

public static void InitMillForm(Form millform)
{
switch (DateTime.Now.Year)
{
case 2016:
millform.Controls["txtPrefEnd"].Text = "ES";
millform.Controls["txtPrefStart"].Text = "ES";
break;
case 2017:
millform.Controls["txtPrefEnd"].Text = "ET";
millform.Controls["txtPrefStart"].Text = "ET";
break;
case 2018:
millform.Controls["txtPrefEnd"].Text = "EU";
millform.Controls["txtPrefStart"].Text = "EU";
break;
case 2019:
millform.Controls["txtPrefEnd"].Text = "EV";
millform.Controls["txtPrefStart"].Text = "EV";
break;
case 2020:
millform.Controls["txtPrefEnd"].Text = "EW";
millform.Controls["txtPrefStart"].Text = "EW";
break;
case 2021:
millform.Controls["txtPrefEnd"].Text = "EX";
millform.Controls["txtPrefStart"].Text = "EX";
break;
case 2022:
millform.Controls["txtPrefEnd"].Text = "EY";
millform.Controls["txtPrefStart"].Text = "EY";
break;
case 2023:
millform.Controls["txtPrefEnd"].Text = "EZ";
millform.Controls["txtPrefStart"].Text = "EZ";
break;

}

}

public DialogResult InsertMillData(Form form)
{
string inValue = "";
bool TransactionStat = true;
ComboBox cbCoil = form.Controls["cbCoilNumber"] as ComboBox;
ComboBox cbShift = form.Controls["cbShift"] as ComboBox;

string JobNumber = form.Controls["txtJobNumber"].Text;
string PipeSize = form.Controls["txtDiameter"].Text + "X" + form.Controls["txtThickness"].Text + "X" + form.Controls["txtLength"].Text;
string HeatNumber = form.Controls["txtHeatNumber"].Text;
string CoilNumber = cbCoil.SelectedItem.ToString();
string pipePrefix = form.Controls["txtPrefStart"].Text;
string PipeNumberStart = form.Controls["txtPipeNumberStart"].Text;
string PipeNumberEnd = form.Controls["txtPipeNumberEnd"].Text;
string Length = form.Controls["txtLength"].Text;
string Thickness = form.Controls["txtThickness"].Text;
string Diameter = form.Controls["txtDiameter"].Text;
string Mass = form.Controls["txtMass"].Text;
string SNo = form.Controls["txtSNo"].Text;
string SheetNumber = form.Controls["txtSheetNumber"].Text;
string SteelGrade = form.Controls["txtSteelGrade"].Text;
string Operator = form.Controls["txtOperator"].Text;

InputBox("Coil Number", "Enter Coil Number used for Sheet:" + form.Controls["txtSheetNumber"].Text, ref inValue);
if (inValue != cbCoil.SelectedItem.ToString().Trim())
{
TransactionStat = false;
return MessageBox.Show("ERROR! Please check Coil Number entered for Sheet.");

}
else
{
if ((pipePrefix + PipeNumberStart).Length < 8 || (pipePrefix + PipeNumberEnd).Length < 8)
{
TransactionStat = false;
return MessageBox.Show("Pipe Number range incorrect format.");
}

foreach (Control controls in form.Controls)
{
if (controls is TextBox)
{
if (String.IsNullOrWhiteSpace(controls.Text))
{
controls.BackColor = Color.Red;
TransactionStat = false;
}
else
{
controls.BackColor = Color.White;
}
}
if (controls is ComboBox)
{
var cb = controls as ComboBox;
if (String.IsNullOrWhiteSpace(cb.SelectedItem.ToString()))
{
cb.BackColor = Color.Red;
TransactionStat = false;
}
}
}

if (TransactionStat == false)
{
return MessageBox.Show("PLEASE PROVIDE ALL REQUIRED FIELDS, CHECK HIGHLIGHTED (RED) FIELDS TO CORRECT THE ERROR. CAPTURE ABORTED.", "ERROR OCCURED");
}
else
{
List<string> pipes = new List<string>();

int start = Int32.Parse(PipeNumberStart);
int end = Int32.Parse(PipeNumberEnd);
int endlen = end.ToString().Length;

while (start <= end)
{
int startlen = start.ToString().Length;
pipes.Add(pipePrefix.PadRight(8 - startlen, '0') + start);
start++;
}
MillInsController millinsctrl;
millinsctrl = new MillInsController();
//INSERT MILL
foreach (var pipe in pipes)
{
Adapter.Insert(
Mass, Diameter, Thickness, SNo, JobNumber,
SheetNumber, SteelGrade, cbShift.SelectedItem.ToString(),
Operator, HeatNumber, cbCoil.SelectedItem.ToString(), pipe, Length);
}
return MessageBox.Show("INSERT SUCCESSFULL");
}
}
}

public static DialogResult InputBox(string title, string promptText, ref string value)
{
Form form = new Form();
Label label = new Label();
TextBox textBox = new TextBox();
Button buttonOk = new Button();
Button buttonCancel = new Button();

form.Text = title;
label.Text = promptText;
textBox.Text = value;

buttonOk.Text = "OK";
buttonCancel.Text = "Cancel";
buttonOk.DialogResult = DialogResult.OK;
buttonCancel.DialogResult = DialogResult.Cancel;

label.SetBounds(9, 20, 372, 13);
textBox.SetBounds(12, 36, 372, 20);
buttonOk.SetBounds(228, 72, 75, 23);
buttonCancel.SetBounds(309, 72, 75, 23);

label.AutoSize = true;
textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;

form.ClientSize = new Size(396, 107);
form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
form.FormBorderStyle = FormBorderStyle.FixedDialog;
form.StartPosition = FormStartPosition.CenterScreen;
form.MinimizeBox = false;
form.MaximizeBox = false;
form.AcceptButton = buttonOk;
form.CancelButton = buttonCancel;

DialogResult dialogResult = form.ShowDialog();
value = textBox.Text;
return dialogResult;
}


public bool updateMill(string stat, string scrapl, string length, string pipenum)
{
ds_Mill.MillInspectionDataTable mill = Adapter.GetDataByPipe(pipenum);
if (mill.Count == 0)
{
return false;
}

ds_Mill.MillInspectionRow millrw = mill[0];

_millDt.Update(stat, scrapl, length, pipenum);

int rowsAffected = Adapter.Update(millrw);

// Return true if precisely one row was updated,
// otherwise false
return rowsAffected == 1;

}

public ds_Mill.MillInspectionDataTable getSheet(string sheet)
{
return Adapter.GetDataBySheetNum(sheet);
}

public System.Data.DataTable fillDataGridMillIns(string sheetnum)
{
try
{
MillInsController millIns = new MillInsController();
return millIns.getSheet(sheetnum);

}
catch (SqlException ex)
{
MessageBox.Show(ex.ToString());
return null;
}
catch (InvalidOperationException exOp)
{
MessageBox.Show(exOp.ToString());
return null;
}
}
}








share







New contributor




Brendan Jacobs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Should be moved to stackoverflow.com

    – spikey_richie
    5 mins ago











  • What is your exact question? Are you sure it's on-topic?

    – Kamil Maciorowski
    5 mins ago














0












0








0








Good day,



I have the following BLL (Business Logic Layer) class. It is the first class I have created that takes away all responsibility from the UI (where this class is instantiated/created/called) in terms of checking against business rules. My aim for this code is to be reusable and flexible in instances where I need to add a control or field and insert into the database.



I hope this is clear enough, thanks for taking the time to review it!



EDIT: This could be a complete miss or partial hit, IMO



    public class MillInsController
{
private MillInspectionTableAdapter _millDt = null;

protected MillInspectionTableAdapter Adapter
{
get
{
if (_millDt == null)

_millDt = new MillInspectionTableAdapter();
_millDt.ConnectionString = Login.LoginController.UserConnString;
return _millDt;
}
}

public static void InitMillForm(Form millform)
{
switch (DateTime.Now.Year)
{
case 2016:
millform.Controls["txtPrefEnd"].Text = "ES";
millform.Controls["txtPrefStart"].Text = "ES";
break;
case 2017:
millform.Controls["txtPrefEnd"].Text = "ET";
millform.Controls["txtPrefStart"].Text = "ET";
break;
case 2018:
millform.Controls["txtPrefEnd"].Text = "EU";
millform.Controls["txtPrefStart"].Text = "EU";
break;
case 2019:
millform.Controls["txtPrefEnd"].Text = "EV";
millform.Controls["txtPrefStart"].Text = "EV";
break;
case 2020:
millform.Controls["txtPrefEnd"].Text = "EW";
millform.Controls["txtPrefStart"].Text = "EW";
break;
case 2021:
millform.Controls["txtPrefEnd"].Text = "EX";
millform.Controls["txtPrefStart"].Text = "EX";
break;
case 2022:
millform.Controls["txtPrefEnd"].Text = "EY";
millform.Controls["txtPrefStart"].Text = "EY";
break;
case 2023:
millform.Controls["txtPrefEnd"].Text = "EZ";
millform.Controls["txtPrefStart"].Text = "EZ";
break;

}

}

public DialogResult InsertMillData(Form form)
{
string inValue = "";
bool TransactionStat = true;
ComboBox cbCoil = form.Controls["cbCoilNumber"] as ComboBox;
ComboBox cbShift = form.Controls["cbShift"] as ComboBox;

string JobNumber = form.Controls["txtJobNumber"].Text;
string PipeSize = form.Controls["txtDiameter"].Text + "X" + form.Controls["txtThickness"].Text + "X" + form.Controls["txtLength"].Text;
string HeatNumber = form.Controls["txtHeatNumber"].Text;
string CoilNumber = cbCoil.SelectedItem.ToString();
string pipePrefix = form.Controls["txtPrefStart"].Text;
string PipeNumberStart = form.Controls["txtPipeNumberStart"].Text;
string PipeNumberEnd = form.Controls["txtPipeNumberEnd"].Text;
string Length = form.Controls["txtLength"].Text;
string Thickness = form.Controls["txtThickness"].Text;
string Diameter = form.Controls["txtDiameter"].Text;
string Mass = form.Controls["txtMass"].Text;
string SNo = form.Controls["txtSNo"].Text;
string SheetNumber = form.Controls["txtSheetNumber"].Text;
string SteelGrade = form.Controls["txtSteelGrade"].Text;
string Operator = form.Controls["txtOperator"].Text;

InputBox("Coil Number", "Enter Coil Number used for Sheet:" + form.Controls["txtSheetNumber"].Text, ref inValue);
if (inValue != cbCoil.SelectedItem.ToString().Trim())
{
TransactionStat = false;
return MessageBox.Show("ERROR! Please check Coil Number entered for Sheet.");

}
else
{
if ((pipePrefix + PipeNumberStart).Length < 8 || (pipePrefix + PipeNumberEnd).Length < 8)
{
TransactionStat = false;
return MessageBox.Show("Pipe Number range incorrect format.");
}

foreach (Control controls in form.Controls)
{
if (controls is TextBox)
{
if (String.IsNullOrWhiteSpace(controls.Text))
{
controls.BackColor = Color.Red;
TransactionStat = false;
}
else
{
controls.BackColor = Color.White;
}
}
if (controls is ComboBox)
{
var cb = controls as ComboBox;
if (String.IsNullOrWhiteSpace(cb.SelectedItem.ToString()))
{
cb.BackColor = Color.Red;
TransactionStat = false;
}
}
}

if (TransactionStat == false)
{
return MessageBox.Show("PLEASE PROVIDE ALL REQUIRED FIELDS, CHECK HIGHLIGHTED (RED) FIELDS TO CORRECT THE ERROR. CAPTURE ABORTED.", "ERROR OCCURED");
}
else
{
List<string> pipes = new List<string>();

int start = Int32.Parse(PipeNumberStart);
int end = Int32.Parse(PipeNumberEnd);
int endlen = end.ToString().Length;

while (start <= end)
{
int startlen = start.ToString().Length;
pipes.Add(pipePrefix.PadRight(8 - startlen, '0') + start);
start++;
}
MillInsController millinsctrl;
millinsctrl = new MillInsController();
//INSERT MILL
foreach (var pipe in pipes)
{
Adapter.Insert(
Mass, Diameter, Thickness, SNo, JobNumber,
SheetNumber, SteelGrade, cbShift.SelectedItem.ToString(),
Operator, HeatNumber, cbCoil.SelectedItem.ToString(), pipe, Length);
}
return MessageBox.Show("INSERT SUCCESSFULL");
}
}
}

public static DialogResult InputBox(string title, string promptText, ref string value)
{
Form form = new Form();
Label label = new Label();
TextBox textBox = new TextBox();
Button buttonOk = new Button();
Button buttonCancel = new Button();

form.Text = title;
label.Text = promptText;
textBox.Text = value;

buttonOk.Text = "OK";
buttonCancel.Text = "Cancel";
buttonOk.DialogResult = DialogResult.OK;
buttonCancel.DialogResult = DialogResult.Cancel;

label.SetBounds(9, 20, 372, 13);
textBox.SetBounds(12, 36, 372, 20);
buttonOk.SetBounds(228, 72, 75, 23);
buttonCancel.SetBounds(309, 72, 75, 23);

label.AutoSize = true;
textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;

form.ClientSize = new Size(396, 107);
form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
form.FormBorderStyle = FormBorderStyle.FixedDialog;
form.StartPosition = FormStartPosition.CenterScreen;
form.MinimizeBox = false;
form.MaximizeBox = false;
form.AcceptButton = buttonOk;
form.CancelButton = buttonCancel;

DialogResult dialogResult = form.ShowDialog();
value = textBox.Text;
return dialogResult;
}


public bool updateMill(string stat, string scrapl, string length, string pipenum)
{
ds_Mill.MillInspectionDataTable mill = Adapter.GetDataByPipe(pipenum);
if (mill.Count == 0)
{
return false;
}

ds_Mill.MillInspectionRow millrw = mill[0];

_millDt.Update(stat, scrapl, length, pipenum);

int rowsAffected = Adapter.Update(millrw);

// Return true if precisely one row was updated,
// otherwise false
return rowsAffected == 1;

}

public ds_Mill.MillInspectionDataTable getSheet(string sheet)
{
return Adapter.GetDataBySheetNum(sheet);
}

public System.Data.DataTable fillDataGridMillIns(string sheetnum)
{
try
{
MillInsController millIns = new MillInsController();
return millIns.getSheet(sheetnum);

}
catch (SqlException ex)
{
MessageBox.Show(ex.ToString());
return null;
}
catch (InvalidOperationException exOp)
{
MessageBox.Show(exOp.ToString());
return null;
}
}
}








share







New contributor




Brendan Jacobs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












Good day,



I have the following BLL (Business Logic Layer) class. It is the first class I have created that takes away all responsibility from the UI (where this class is instantiated/created/called) in terms of checking against business rules. My aim for this code is to be reusable and flexible in instances where I need to add a control or field and insert into the database.



I hope this is clear enough, thanks for taking the time to review it!



EDIT: This could be a complete miss or partial hit, IMO



    public class MillInsController
{
private MillInspectionTableAdapter _millDt = null;

protected MillInspectionTableAdapter Adapter
{
get
{
if (_millDt == null)

_millDt = new MillInspectionTableAdapter();
_millDt.ConnectionString = Login.LoginController.UserConnString;
return _millDt;
}
}

public static void InitMillForm(Form millform)
{
switch (DateTime.Now.Year)
{
case 2016:
millform.Controls["txtPrefEnd"].Text = "ES";
millform.Controls["txtPrefStart"].Text = "ES";
break;
case 2017:
millform.Controls["txtPrefEnd"].Text = "ET";
millform.Controls["txtPrefStart"].Text = "ET";
break;
case 2018:
millform.Controls["txtPrefEnd"].Text = "EU";
millform.Controls["txtPrefStart"].Text = "EU";
break;
case 2019:
millform.Controls["txtPrefEnd"].Text = "EV";
millform.Controls["txtPrefStart"].Text = "EV";
break;
case 2020:
millform.Controls["txtPrefEnd"].Text = "EW";
millform.Controls["txtPrefStart"].Text = "EW";
break;
case 2021:
millform.Controls["txtPrefEnd"].Text = "EX";
millform.Controls["txtPrefStart"].Text = "EX";
break;
case 2022:
millform.Controls["txtPrefEnd"].Text = "EY";
millform.Controls["txtPrefStart"].Text = "EY";
break;
case 2023:
millform.Controls["txtPrefEnd"].Text = "EZ";
millform.Controls["txtPrefStart"].Text = "EZ";
break;

}

}

public DialogResult InsertMillData(Form form)
{
string inValue = "";
bool TransactionStat = true;
ComboBox cbCoil = form.Controls["cbCoilNumber"] as ComboBox;
ComboBox cbShift = form.Controls["cbShift"] as ComboBox;

string JobNumber = form.Controls["txtJobNumber"].Text;
string PipeSize = form.Controls["txtDiameter"].Text + "X" + form.Controls["txtThickness"].Text + "X" + form.Controls["txtLength"].Text;
string HeatNumber = form.Controls["txtHeatNumber"].Text;
string CoilNumber = cbCoil.SelectedItem.ToString();
string pipePrefix = form.Controls["txtPrefStart"].Text;
string PipeNumberStart = form.Controls["txtPipeNumberStart"].Text;
string PipeNumberEnd = form.Controls["txtPipeNumberEnd"].Text;
string Length = form.Controls["txtLength"].Text;
string Thickness = form.Controls["txtThickness"].Text;
string Diameter = form.Controls["txtDiameter"].Text;
string Mass = form.Controls["txtMass"].Text;
string SNo = form.Controls["txtSNo"].Text;
string SheetNumber = form.Controls["txtSheetNumber"].Text;
string SteelGrade = form.Controls["txtSteelGrade"].Text;
string Operator = form.Controls["txtOperator"].Text;

InputBox("Coil Number", "Enter Coil Number used for Sheet:" + form.Controls["txtSheetNumber"].Text, ref inValue);
if (inValue != cbCoil.SelectedItem.ToString().Trim())
{
TransactionStat = false;
return MessageBox.Show("ERROR! Please check Coil Number entered for Sheet.");

}
else
{
if ((pipePrefix + PipeNumberStart).Length < 8 || (pipePrefix + PipeNumberEnd).Length < 8)
{
TransactionStat = false;
return MessageBox.Show("Pipe Number range incorrect format.");
}

foreach (Control controls in form.Controls)
{
if (controls is TextBox)
{
if (String.IsNullOrWhiteSpace(controls.Text))
{
controls.BackColor = Color.Red;
TransactionStat = false;
}
else
{
controls.BackColor = Color.White;
}
}
if (controls is ComboBox)
{
var cb = controls as ComboBox;
if (String.IsNullOrWhiteSpace(cb.SelectedItem.ToString()))
{
cb.BackColor = Color.Red;
TransactionStat = false;
}
}
}

if (TransactionStat == false)
{
return MessageBox.Show("PLEASE PROVIDE ALL REQUIRED FIELDS, CHECK HIGHLIGHTED (RED) FIELDS TO CORRECT THE ERROR. CAPTURE ABORTED.", "ERROR OCCURED");
}
else
{
List<string> pipes = new List<string>();

int start = Int32.Parse(PipeNumberStart);
int end = Int32.Parse(PipeNumberEnd);
int endlen = end.ToString().Length;

while (start <= end)
{
int startlen = start.ToString().Length;
pipes.Add(pipePrefix.PadRight(8 - startlen, '0') + start);
start++;
}
MillInsController millinsctrl;
millinsctrl = new MillInsController();
//INSERT MILL
foreach (var pipe in pipes)
{
Adapter.Insert(
Mass, Diameter, Thickness, SNo, JobNumber,
SheetNumber, SteelGrade, cbShift.SelectedItem.ToString(),
Operator, HeatNumber, cbCoil.SelectedItem.ToString(), pipe, Length);
}
return MessageBox.Show("INSERT SUCCESSFULL");
}
}
}

public static DialogResult InputBox(string title, string promptText, ref string value)
{
Form form = new Form();
Label label = new Label();
TextBox textBox = new TextBox();
Button buttonOk = new Button();
Button buttonCancel = new Button();

form.Text = title;
label.Text = promptText;
textBox.Text = value;

buttonOk.Text = "OK";
buttonCancel.Text = "Cancel";
buttonOk.DialogResult = DialogResult.OK;
buttonCancel.DialogResult = DialogResult.Cancel;

label.SetBounds(9, 20, 372, 13);
textBox.SetBounds(12, 36, 372, 20);
buttonOk.SetBounds(228, 72, 75, 23);
buttonCancel.SetBounds(309, 72, 75, 23);

label.AutoSize = true;
textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;

form.ClientSize = new Size(396, 107);
form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
form.FormBorderStyle = FormBorderStyle.FixedDialog;
form.StartPosition = FormStartPosition.CenterScreen;
form.MinimizeBox = false;
form.MaximizeBox = false;
form.AcceptButton = buttonOk;
form.CancelButton = buttonCancel;

DialogResult dialogResult = form.ShowDialog();
value = textBox.Text;
return dialogResult;
}


public bool updateMill(string stat, string scrapl, string length, string pipenum)
{
ds_Mill.MillInspectionDataTable mill = Adapter.GetDataByPipe(pipenum);
if (mill.Count == 0)
{
return false;
}

ds_Mill.MillInspectionRow millrw = mill[0];

_millDt.Update(stat, scrapl, length, pipenum);

int rowsAffected = Adapter.Update(millrw);

// Return true if precisely one row was updated,
// otherwise false
return rowsAffected == 1;

}

public ds_Mill.MillInspectionDataTable getSheet(string sheet)
{
return Adapter.GetDataBySheetNum(sheet);
}

public System.Data.DataTable fillDataGridMillIns(string sheetnum)
{
try
{
MillInsController millIns = new MillInsController();
return millIns.getSheet(sheetnum);

}
catch (SqlException ex)
{
MessageBox.Show(ex.ToString());
return null;
}
catch (InvalidOperationException exOp)
{
MessageBox.Show(exOp.ToString());
return null;
}
}
}






c# winforms





share







New contributor




Brendan Jacobs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










share







New contributor




Brendan Jacobs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








share



share






New contributor




Brendan Jacobs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 9 mins ago









Brendan JacobsBrendan Jacobs

1




1




New contributor




Brendan Jacobs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Brendan Jacobs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Brendan Jacobs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • Should be moved to stackoverflow.com

    – spikey_richie
    5 mins ago











  • What is your exact question? Are you sure it's on-topic?

    – Kamil Maciorowski
    5 mins ago



















  • Should be moved to stackoverflow.com

    – spikey_richie
    5 mins ago











  • What is your exact question? Are you sure it's on-topic?

    – Kamil Maciorowski
    5 mins ago

















Should be moved to stackoverflow.com

– spikey_richie
5 mins ago





Should be moved to stackoverflow.com

– spikey_richie
5 mins ago













What is your exact question? Are you sure it's on-topic?

– Kamil Maciorowski
5 mins ago





What is your exact question? Are you sure it's on-topic?

– Kamil Maciorowski
5 mins ago










0






active

oldest

votes











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Brendan Jacobs is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1409547%2fbusiness-logic-controller-for-general-purpose-data-capturing%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes








Brendan Jacobs is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















Brendan Jacobs is a new contributor. Be nice, and check out our Code of Conduct.













Brendan Jacobs is a new contributor. Be nice, and check out our Code of Conduct.












Brendan Jacobs is a new contributor. Be nice, and check out our Code of Conduct.
















Thanks for contributing an answer to Super User!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1409547%2fbusiness-logic-controller-for-general-purpose-data-capturing%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Why not use the yoke to control yaw, as well as pitch and roll? Announcing the arrival of...

Couldn't open a raw socket. Error: Permission denied (13) (nmap)Is it possible to run networking commands...

VNC viewer RFB protocol error: bad desktop size 0x0I Cannot Type the Key 'd' (lowercase) in VNC Viewer...