Files
MoonPro.net/MP-Tablet/WebUserControls/mod_ODL.ascx.cs
T
2018-02-28 09:18:39 +01:00

567 lines
18 KiB
C#

using MapoDb;
using SteamWare;
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MoonProTablet.WebUserControls
{
public partial class mod_ODL : System.Web.UI.UserControl
{
/// <summary>
/// stringa UID univoca
/// </summary>
public string uid
{
get
{
return this.UniqueID.Replace("$", "_").Replace("-", "_");
}
}
/// <summary>
/// idx macchina selezionata
/// </summary>
public string idxMacchina
{
get
{
string answ = "";
try
{
answ = memLayer.ML.StringSessionObj(string.Format("idxMacchina-{0}", uid));
}
catch
{ }
return answ;
}
set
{
memLayer.ML.setSessionVal(string.Format("idxMacchina-{0}", uid), value);
}
}
/// <summary>
/// classe MapoDB x uso locale
/// </summary>
protected MapoDb.MapoDb controllerMapo = new MapoDb.MapoDb();
/// <summary>
/// Determina se sia abilitato il controllo x editing
/// </summary>
public bool isEnabled
{
get
{
bool answ = false;
try
{
answ = memLayer.ML.BoolSessionObj(string.Format("isEnabled-{0}", uid));
}
catch
{ }
return answ;
}
set
{
memLayer.ML.setSessionVal(string.Format("isEnabled-{0}", uid), value);
}
}
/// <summary>
/// codice odl selezionato
/// </summary>
public int idxODLSel
{
get
{
int answ = 0;
try
{
answ = Convert.ToInt32(ddlODL.SelectedValue);
}
catch
{ }
return answ;
}
}
/// <summary>
/// Cod articolo dell'ODL selezionato
/// </summary>
public string CodArtSel
{
get
{
string CodArticolo = "";
try
{
CodArticolo = DataLayer.obj.taODL.getByIdx(idxODLSel, false)[0].CodArticolo;
}
catch
{ }
return CodArticolo;
}
}
/// <summary>
/// avvio pagina
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
checkAll();
}
}
public void checkAll()
{
lblOut.Text = "";
checkBtnStatus();
chkCloseOdl.Checked = memLayer.ML.cdvb("chkCloseOdl");
chkCloseOdl.Visible = memLayer.ML.cdvb("showChkCloseOdl");
}
/// <summary>
/// Sistema CSS x status enabled/disabled
/// </summary>
/// <param name="lbtn"></param>
protected void fixWCtrStatus(object lbtn)
{
// tolgo (eventuale) classe
try
{
((WebControl)lbtn).CssClass = ((WebControl)lbtn).CssClass.Replace("disabled", "");
// se richiesto metto disabled...
if (!((WebControl)lbtn).Enabled) ((WebControl)lbtn).CssClass += " disabled";
}
catch
{ }
}
/// <summary>
/// controlla stato bottoni abilitato
/// </summary>
private void checkBtnStatus()
{
// di default rendo abilitato / disabilitato tutto in base al valore "isEnabled"
lbtShowSplitODL.Enabled = isEnabled;
lbtSplitODL.Enabled = isEnabled;
chkCloseOdl.Enabled = isEnabled;
fixWCtrStatus(lbtShowSplitODL);
fixWCtrStatus(lbtSplitODL);
fixWCtrStatus(chkCloseOdl);
// condizioni booleane
bool inAttr = false;
bool currHasOdl = false;
// controllo se la macchina è in attrezzaggio...
DS_applicazione.StatoMacchineRow rigaStato = null;
try
{
rigaStato = DataLayer.obj.taStatoMacchine.GetDataByIdxMacchina(idxMacchina)[0];
inAttr = (rigaStato.IdxStato == 2);
}
catch (Exception exc)
{
logger.lg.scriviLog(string.Format("Eccezione in recupero dati rigaStato! {0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
}
try
{
currHasOdl = DataLayer.obj.taODL.getByMacchina(idxMacchina)[0].IdxODL != 0;
}
catch (Exception exc)
{
logger.lg.scriviLog(string.Format("Eccezione in recupero dati currHasOdl! {0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
}
bool hasNewOdl = DataLayer.obj.taSelOdlFree.getUnused().Rows.Count > 1;
// sistemo buttons!
lbtStartAttr.Enabled = (isEnabled && (!inAttr && hasNewOdl));
lbtStartProd.Enabled = (isEnabled && inAttr);
lbtEndProd.Enabled = (isEnabled && (!inAttr && currHasOdl));
ddlODL.Enabled = (isEnabled && (!inAttr && hasNewOdl));
odsODL.DataBind();
// sistemo anche come css..
fixWCtrStatus(lbtStartAttr);
fixWCtrStatus(lbtStartProd);
fixWCtrStatus(lbtEndProd);
fixWCtrStatus(ddlODL);
// sistemo show tempo/note attrezzaggio..
if (inAttr)
{
showNoteTC(true);
// sistemo SOLO se non si trtta di un postback...
if (!Page.IsPostBack)
{
int idxOdl = 0;
try
{
idxOdl = DataLayer.obj.taODL.getByMacchina(idxMacchina)[0].IdxODL;
updateTempoTc(idxOdl);
updateNoteTC(idxOdl);
}
catch (Exception exc)
{
logger.lg.scriviLog(string.Format("Eccezione in recupero dati ODL! {0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
}
}
}
// verifico se l'articolo corrente sia in revisione x mostrare conferma modifica revisione...
if (CodArtSel != "")
{
bool showWarn = false;
try
{
showWarn = DataLayer.obj.taAnagArt.getByCod(CodArtSel)[0].FlagIsNew;
}
catch (Exception exc)
{
logger.lg.scriviLog(string.Format("Eccezione in recupero dati showWarn! {0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
}
divWarningArt.Visible = showWarn;
}
}
/// <summary>
/// processa evento richiesto
/// </summary>
/// <param name="idxEvento"></param>
/// <param name="userMsg"></param>
/// <param name="idxODL"></param>
private void processaEvento(int idxEvento, string userMsg, int idxODL)
{
MapoDb.inputComando inCmd;
MapoDb.inputComando inCmd2;
bool needStRefresh = false;
DS_applicazione.StatoMacchineRow rigaStato = DataLayer.obj.taStatoMacchine.GetDataByIdxMacchina(idxMacchina)[0];
// ricavo codice articolo...
string CodArticolo = DataLayer.obj.taODL.getByIdx(idxODL, false)[0].CodArticolo;
// processo evento...
inCmd = controllerMapo.scriviRigaEventoBarcode(idxMacchina, idxEvento, CodArticolo, "", rigaStato.MatrOpr, rigaStato.pallet);
// verifico se serva refresh
if (inCmd.needStatusRefresh) needStRefresh = true;
// se la macchina è MULTI (cod#tavola) e sonoa INIZIO/FINE attrezzaggio (idxEv <=2) processo ANCHE per la macchina madre...
if (idxMacchina.IndexOf('#') > 0 && idxEvento <= 2)
{
string idxMacchinaParent = idxMacchina.Substring(0, idxMacchina.IndexOf('#'));
inCmd2 = controllerMapo.scriviRigaEventoBarcode(idxMacchinaParent, idxEvento, CodArticolo, "", rigaStato.MatrOpr, rigaStato.pallet);
if (inCmd2.needStatusRefresh) needStRefresh = true;
}
if (needStRefresh)
{
// chiamo refresh MSE
DataLayer.obj.taMSE.getByRefreshData(memLayer.ML.confReadInt("refrMSE_0"));
}
lblOut.Text = userMsg;
// loggo USR MSG
logger.lg.scriviLog(userMsg, tipoLog.INFO);
checkBtnStatus();
}
/// <summary>
/// valore decimal del TC richiesto...
/// </summary>
protected decimal TCRichAttr
{
get
{
decimal answ = 0;
try
{
answ = mod_tempoMSMC.tempoMC;
}
catch
{ }
return answ;
}
set
{
mod_tempoMSMC.tempoMC = value;
}
}
/// <summary>
/// valore decimal del TC ASSEGNATO...
/// </summary>
protected decimal TCAssegnato(int idxODL)
{
decimal answ = 0;
// leggo idxOdl da ultimo odl attivo x macchina
DS_ProdTempi.ODLRow rigaOdl = DataLayer.obj.taODL.getByIdx(idxODL, false)[0];
answ = rigaOdl.TCAssegnato;
return answ;
}
/// <summary>
/// dichiara inizio attrezzaggio ODL indicato..
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lbtStartAttr_Click(object sender, EventArgs e)
{
confermaProdOdl(false);
if (idxODLSel > 0)
{
// se vedesse TCRich a zero lo reimposta a quello assegnato...
if (TCRichAttr == 0)
{
TCRichAttr = TCAssegnato(idxODLSel);
}
// splitto VECCHIO ODL (se è rimasto qualcosa da produrre e se ce ne è rimasto uno.......)
int idxODL = 0;
try
{
idxODL = DataLayer.obj.taODL.getByMacchina(idxMacchina)[0].IdxODL;
DataLayer.obj.taODL.splitODL(idxODL, idxMacchina, TCAssegnato(idxODL), string.Format("inizio attrezzaggio, Sospensione ODL {0}, generato residuo con pari TCiclo: {1}", idxODL, TCAssegnato(idxODL)), false);
}
catch
{ }
// avvio NUOVO ODL
DataLayer.obj.taODL.inizioSetup(idxODLSel, idxMacchina, TCRichAttr, txtNote.Text);
int idxEvento = 2; // !!!HARD CODED
processaEvento(idxEvento, String.Format("Registrata inizio attrezzaggio per ODL {0}", idxODLSel), idxODLSel);
// ricarico...
Response.Redirect("~/ODL.aspx");
}
else
{
lblOut.Text = "Selezionare un ODL valido!";
}
}
/// <summary>
/// inizio prod
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lbtStartProd_Click(object sender, EventArgs e)
{
confermaProdOdl(true);
// se vedesse TCRich a zero lo reimposta a quello assegnato...
if (TCRichAttr == 0)
{
TCRichAttr = TCAssegnato(idxODLSel);
}
// leggo idxOdl da ultimo odl attivo x macchina
int idxODL = DataLayer.obj.taODL.getByMacchina(idxMacchina)[0].IdxODL;
int idxEvento = 1; // !!!HARD CODED
// aggiorno (se necessario) note e tempo setup
DataLayer.obj.taODL.updateSetup(idxODL, TCRichAttr, txtNote.Text);
// controllo se TC Assegnato != TCRichiesto allora invio email x verifiche...
DS_ProdTempi.ODLRow rigaOdl = DataLayer.obj.taODL.getByIdx(idxODL, false)[0];
if (rigaOdl.TCAssegnato != TCRichAttr)
{
// invio email!
DataLayer.obj.sendWarnTcChangeReq(memLayer.ML.confReadString("_adminEmail"));
}
// processo chiusura setup
processaEvento(idxEvento, String.Format("Registrata inizio produzione per ODL {0}", idxODL), idxODL);
// nascondo note!
showNoteTC(false);
}
/// <summary>
/// fine prod
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lbtEndProd_Click(object sender, EventArgs e)
{
// leggo idxOdl da ultimo odl attivo x macchina
int idxODL = DataLayer.obj.taODL.getByMacchina(idxMacchina)[0].IdxODL;
int idxEvento = 7; // !!!HARD CODED
// confermo prod vecchio ODL
confermaProdOdl(false);
// se chk flaggato ovvero richiesta di chiudere ODL procedo come prima (chiudendo ODL senza averne altri...)
if (chkCloseOdl.Checked)
{
// aggiungo try/catch x capire se sia qui che si "impasta" in chiusura ODL
try
{
// processo
DataLayer.obj.taODL.fineProd(idxODL, idxMacchina);
processaEvento(idxEvento, String.Format("Registrata fine produzione per ODL {0}", idxODL), idxODL);
}
catch (Exception exc)
{
logger.lg.scriviLog(string.Format("Eccezione in operazione chiusura ODL! {0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
Response.Redirect("~/DettaglioMacchina.aspx");
}
}
// altrimenti split ODL x completare IN FUTURO la produzione...
else
{
try
{
// effettuo split su nuovo ODL
DataLayer.obj.taODL.splitODL(idxODL, idxMacchina, TCAssegnato(idxODL), string.Format("Fine Produzione, Sospensione ODL {0}, generato residuo con pari TCiclo: {1}", idxODL, TCAssegnato(idxODL)), false);
// processo chiusura setup
processaEvento(idxEvento, String.Format("Registrata fine produzione per ODL {0}, nuovo ODL per quantità residua", idxODL), idxODL);
// sistemo buttons!
bool splitOdl = false;
fixSplitBtn(splitOdl);
}
catch (Exception exc)
{
logger.lg.scriviLog(string.Format("Eccezione in operazione Chiusura + Split ODL su nuovo! {0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
Response.Redirect("~/DettaglioMacchina.aspx");
}
}
// ricarico...
Response.Redirect("~/ODL.aspx");
}
/// <summary>
/// verifica se sia necessario confermare la prod dell'ODL precedente prima di chiudere e lo fa in automatico...
/// </summary>
/// <param name="confZero">boolean, true = deve confermare 0 pezzi (es. in setup)</param>
private void confermaProdOdl(bool confZero)
{
// 2016.11.17 NOTA: introdotti scarti, li confermiamo SEMPRE a zero se ins etup, però da valutare SE a FINE ATTREZZAGGIO chiedere num pezzi e num scarti (saldo zero buoni) da inserire...
if (confZero)
{
// confermo produzione ZERO pezzi (in setup)
DataLayer.obj.confermaProdMacchina(idxMacchina, memLayer.ML.confReadInt("modoConfProd"), 0, 0);
}
else // se NON sono in setup verifico se ho pz da confermare
{
// recupero pz da confermare
DS_ProdTempi.stp_PzProd_getByMacchinaRow rigaProd = DataLayer.obj.taPzProd2conf.GetData(idxMacchina)[0];
if (rigaProd.pezziNonConfermati > 0)
{
DataLayer.obj.confermaProdMacchina(idxMacchina, memLayer.ML.confReadInt("modoConfProd"), rigaProd.pezziNonConfermati, 0);
}
}
}
/// <summary>
/// mostra dati ed opzione x split ODL
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lbtShowSplitODL_Click(object sender, EventArgs e)
{
bool splitOdl = true;
fixSplitBtn(splitOdl);
// recupero current idx
int currODL = DataLayer.obj.taODL.getByMacchina(idxMacchina)[0].IdxODL;
updateTempoTc(currODL);
updateNoteTC(currODL);
}
/// <summary>
/// sistema buttons split
/// </summary>
/// <param name="splitOdl"></param>
private void fixSplitBtn(bool splitOdl)
{
lbtShowSplitODL.Visible = !splitOdl;
chkCloseOdl.Visible = !splitOdl;
lbtSplitODL.Visible = splitOdl;
showNoteTC(splitOdl);
ddlODL.Visible = !splitOdl;
lbtStartAttr.Visible = !splitOdl;
lbtStartProd.Visible = !splitOdl;
lbtEndProd.Visible = !splitOdl;
}
/// <summary>
/// split ODL con creazione nuovo ODL
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lbtSplitODL_Click(object sender, EventArgs e)
{
// chiamo stored che genera nuovo ODL, mette note e tempo, chiude vecchi e assegna nuovo...
int currODL = DataLayer.obj.taODL.getByMacchina(idxMacchina)[0].IdxODL;
int idxEvento = 1; // !!!HARD CODED
// controllo se TC è valorizzato..
if (TCRichAttr == 0)
{
mod_tempoMSMC.checkTC();
}
// confermo prod vecchio ODL
confermaProdOdl(false);
// effettuo split su nuovo ODL
DataLayer.obj.taODL.splitODL(currODL, idxMacchina, TCRichAttr, txtNote.Text, true);
// invio email!
DataLayer.obj.sendWarnTcChangeReq(memLayer.ML.confReadString("_adminEmail"));
// processo chiusura setup
processaEvento(idxEvento, String.Format("Registrato Riattrezzaggio ODL (old: {0})", currODL), currODL);
// sistemo buttons!
bool splitOdl = false;
fixSplitBtn(splitOdl);
}
/// <summary>
/// selezionato un ODL mostro note/tempo da validare
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlODL_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlODL.SelectedIndex > 0)
{
showNoteTC(true);
updateTempoTc(idxODLSel);
updateNoteTC(idxODLSel);
}
else
{
showNoteTC(false);
}
}
/// <summary>
/// mostra/nasconde note
/// </summary>
private void showNoteTC(bool show)
{
// mostra/nasconde note da compilare
divTempo.Visible = show;
divNote.Visible = show;
}
/// <summary>
/// aggiorna note ODL
/// </summary>
/// <param name="idxOdl"></param>
private void updateNoteTC(int idxOdl)
{
string testo = "";
if (idxOdl > 0)
{
try
{
testo = DataLayer.obj.taODL.getByIdx(idxOdl, false)[0].Note;
}
catch
{ }
}
txtNote.Text = testo;
}
/// <summary>
/// update TC mostrato
/// </summary>
/// <param name="idxOdl"></param>
private void updateTempoTc(int idxOdl)
{
// riporta TC
DS_ProdTempi.ODLRow rigaOdl = DataLayer.obj.taODL.getByIdx(idxOdl, false)[0];
decimal TCRichAttr = 0;
if (rigaOdl.TCRichAttr > 0)
{
TCRichAttr = rigaOdl.TCRichAttr;
}
else
{
TCRichAttr = rigaOdl.TCAssegnato;
}
// mostro!
mod_tempoMSMC.tempoMC = TCRichAttr;
}
protected void lbtConfNewRevProd_Click(object sender, EventArgs e)
{
// chiamo stored x allineare revProd a revUT
string CodArticolo = DataLayer.obj.taODL.getByIdx(idxODLSel, false)[0].CodArticolo;
DataLayer.obj.taAnagArt.setNewRev(CodArticolo);
checkBtnStatus();
}
}
}