Just want to start out by saying three quick things to those of you who are trying to help me with this.
- All of you rock
- Thank you so much for your help with this. I really really appreciate it.
- Sorry for the novel below.
Now back to the customization issue. I tried to break it down to make it easier to follow. Please let me know if you have questions. (I should note, if it was not already obvious, I did not write any of this code)
First Customization is for the Part Status:
Status Field Code #1: (Only the âmasterâ can set the field)
private void epicmbStatus_Enter(object sender, System.EventArgs args)
{
EpiTextBox tbPart = (EpiTextBox)(csm.GetNativeControlReference("38e1671b-0c3f-4ab3-b8ab-95f26285f1d2"));
EpiCombo cmbStatus = (EpiCombo)(csm.GetNativeControlReference("a7e02cab-ea1f-42a8-aeae-8ea2ed60aded"));
string sStatus = Convert.ToString(cmbStatus.Text);
string userID = session.UserID;
string sMaster = ""; string sEngineer = "";
getStatusSecurity(userID, out sMaster, out sEngineer);
//if(sEngineer != userID && sMaster != userID)
//{
// MessageBox.Show("You are not authorized to update this field; you are not the manager and not an Engineer.");
// tbPart.Focus();
// cmbStatus.Enabled = false; //turn off for this user
//
if(sEngineer == userID)
{
if(sStatus == "D")
{
MessageBox.Show("Changing Status to 'P'.");
edvPart.dataView[0]["ShortChar08"] = "P"; cmbStatus.Text = "P";
edvPart.dataView[0]["StatusDate_c"] = DateTime.Today;
tbPart.Focus();
cmbStatus.Enabled = false; //turn off
}
else
{
MessageBox.Show("Engineers may only change a stat D to a P.");
tbPart.Focus();
cmbStatus.Enabled = false; //turn off
}
}
//if(sEngineer == userID && sStatus != "D")
//{
// MessageBox.Show("You are set up as an Engineer but may only update when the status = D");
// tbPart.Focus();
// cmbStatus.Enabled = false; // turn off as they should not have tried to change this status
//}
if(sMaster == userID)
{MessageBox.Show("You are the mananger of this system and can change anything.");}
Status Field Code #2: (The âassigned engineerâ can change field from D to P. Also generates query)
private void epicmbStatus_Leave(object sender, System.EventArgs args)
{
EpiTextBox tbPart = (EpiTextBox)(csm.GetNativeControlReference("38e1671b-0c3f-4ab3-b8ab-95f26285f1d2"));
EpiCombo cmbStatus = (EpiCombo)(csm.GetNativeControlReference("a7e02cab-ea1f-42a8-aeae-8ea2ed60aded"));
string sStatus = Convert.ToString(cmbStatus.Text);
string userID = session.UserID; string sMaster = ""; string sEngineer = "";
getStatusSecurity(userID, out sMaster, out sEngineer);
// if Engineer than can change to a P only
if(sEngineer == userID && sStatus != "P") // only the master is allowed to edit this field all others out
{
MessageBox.Show("You can only change the status to P."); // maybe force this?
cmbStatus.Enabled = false;
}
// if is master and change to N then use first routine
if(sMaster == userID && sStatus == "N")
{
//eval using query and throw up message box recommendation for Engineer.
MessageBox.Show("Place current BAQ for N D counts here.");
DynamicQueryAdapter dqa1 = new DynamicQueryAdapter(oTrans);
dqa1.BOConnect();
QueryExecutionDataSet qeds1 = dqa1.GetQueryExecutionParametersByID("PartStatusByEngineer");
qeds1.ExecutionParameter.Clear();
//qeds1.ExecutionParameter.AddExecutionParameterRow("MachineID", workstationID, "nvarchar", false, Guid.NewGuid(),"A"); //since we dont want any parms skip it
dqa1.ExecuteByID("PartStatusByEngineer",qeds1);
DataTable tblStatusByEngineer = dqa1.QueryResults.Tables["Results"];
//loop through populate the message box with data
string sMsg = ""; string sSaveEng = ""; int iSaveEng = 99999999;
for(int i=0; i < tblStatusByEngineer.Rows.Count; i++)
{
if(Convert.ToString(tblStatusByEngineer.Rows[i][0]) != "")
{
sMsg = sMsg + tblStatusByEngineer.Rows[i][0] + " N=" + tblStatusByEngineer.Rows[i][1] + " D=" + tblStatusByEngineer.Rows[i][2] + " total=" + tblStatusByEngineer.Rows[i][3];
if(Convert.ToString(tblStatusByEngineer.Rows[i][0]) != "" && Convert.ToInt32(tblStatusByEngineer.Rows[i][3]) < iSaveEng)
{ sSaveEng = Convert.ToString(tblStatusByEngineer.Rows[i][0]);
iSaveEng = Convert.ToInt32(tblStatusByEngineer.Rows[i][3]);}
if(Convert.ToString(tblStatusByEngineer.Rows[i][0]) != "")
{ sMsg = sMsg + Environment.NewLine;}
}
}
MessageBox.Show(sMsg + Environment.NewLine + Environment.NewLine + "Assign this part to " + sSaveEng);
//edvPart.dataView[0]["AssignedEngineer_c"] = sSaveEng;
}
}
Second Customization is for the Part Engineer:
Engineer Field Code: (Only the âmasterâ can assign the engineer)
private void epicmbAssignedEngineer_Enter(object sender, System.EventArgs args)
{
EpiTextBox tbPart = (EpiTextBox)(csm.GetNativeControlReference(â38e1671b-0c3f-4ab3-b8ab-95f26285f1d2â));
EpiCombo cmbStatus = (EpiCombo)(csm.GetNativeControlReference(âa7e02cab-ea1f-42a8-aeae-8ea2ed60adedâ));
string sStatus = Convert.ToString(cmbStatus.Text);
EpiCombo cmbEngineer = (EpiCombo)(csm.GetNativeControlReference(â9c770db2-e8ac-4397-991d-0aa79c6199c5â));
string userID = session.UserID; string sMaster = ââ; string sEngineer = ââ;
getStatusSecurity(userID, out sMaster, out sEngineer);
//MessageBox.Show(âsMaster:â + sMaster + " userID:" + userID);
if(sMaster != userID) // only the master is allowed to edit this field all others out
{
tbPart.Focus();
cmbEngineer.Enabled = false; //turn off the field they should not be here
}
}
My Assumption:
I noticed that there is this âgetStatusSecurity(userID, out sMaster, out sEngineer)â line of code in all of the scripts shown above. I assume this line of code is to run another script that checks the users ID. I provided that script below. Now, I believe the âgetStatusSecurityâ is the code that I want to modify to accept the âCodeID = âmasterââ and âCodeID = âlgistââ (that is the other user). I am not sure if it is just as easy as adding "String exp = "CodeID = âmasterâ " || âCodeID = âlgistâ " ;â. However, I think by doing something like that, it should solve the issue for both the Status and Engineer. What do you think? Is this the route I need to go?
Status Security Code:
private void getStatusSecurity(string userID, out string sMaster,out string sEngineer)
{
sMaster = ""; sEngineer = "";
try
{
bool morePages = false;
UserCodesAdapter userCodesBO = new UserCodesAdapter(this.oTrans);
userCodesBO.BOConnect();
int iPageSize = 0; int iAbsolutePageSize = 1; bool bMorePages = false;
SearchOptions opts = new SearchOptions(SearchMode.AutoSearch);
opts.NamedSearch.WhereClauses.Add("UDCodes", "CodeTypeID = 'AssEng'"); //get everything later filter
System.Data.DataSet dsMC = userCodesBO.GetRows(opts, out bMorePages);
string exp = "CodeID = 'master'";
DataRow[] drMaster = dsMC.Tables["UDCodes"].Select(exp, "CodeID ASC");
sMaster = Convert.ToString(drMaster[0]["CodeDesc"]); //this is the master user id
string exp2 = "CodeID = '" + userID + "'";
DataRow[] drEngineer = dsMC.Tables["UDCodes"].Select(exp2, "CodeID ASC");
sEngineer = "Not Authorized";
if(drEngineer.Length > 0)
{sEngineer = Convert.ToString(drEngineer[0]["CodeID"]);} //this is the master user id
userCodesBO.Dispose();
} catch (System.Exception ex)
{
ExceptionBox.Show(ex);
}