447 lines
17 KiB
C#
447 lines
17 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using MapoDb;
|
|
using SteamWare;
|
|
|
|
namespace MoonProTablet.WebUserControls
|
|
{
|
|
public partial class mod_ODL : System.Web.UI.UserControl
|
|
{
|
|
/// <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
|
|
{
|
|
return memLayer.ML.BoolSessionObj(string.Format("OdlEnab_{0}", idxMacchina));
|
|
}
|
|
set
|
|
{
|
|
memLayer.ML.setSessionVal(string.Format("OdlEnab_{0}", idxMacchina), value);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// idx macchina selezionata
|
|
/// </summary>
|
|
public int idxMacchina
|
|
{
|
|
get
|
|
{
|
|
return memLayer.ML.IntSessionObj("IdxMacchina");
|
|
}
|
|
set
|
|
{
|
|
memLayer.ML.setSessionVal("IdxMacchina", value);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// codice odl selezionato
|
|
/// </summary>
|
|
public int idxODLSel
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
try
|
|
{
|
|
answ = Convert.ToInt32(ddlODL.SelectedValue);
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// avvio pagina
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
checkBtnStatus();
|
|
if (!Page.IsPostBack)
|
|
{
|
|
lblOut.Text = "";
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// controlla stato bottoni abilitato
|
|
/// </summary>
|
|
private void checkBtnStatus()
|
|
{
|
|
// di default rendo abilitato / disabilitato tutto in base al valore "isEnabled"
|
|
btnShowSplitODL.Enabled = isEnabled;
|
|
btnSplitODL.Enabled = isEnabled;
|
|
chkCloseOdl.Enabled = isEnabled;
|
|
|
|
|
|
// controllo se la macchina è in attrezzaggio...
|
|
DS_applicazione.StatoMacchineRow rigaStato = DataLayer.obj.taStatoMacchine.GetDataByIdxMacchina(idxMacchina.ToString())[0];
|
|
// condizioni booleane
|
|
bool inAttr = (rigaStato.IdxStato == 2);
|
|
bool currHasOdl = false;
|
|
try
|
|
{
|
|
currHasOdl = DataLayer.obj.taMSE.getByIdxMacchina(idxMacchina.ToString())[0].idxODL != 0;
|
|
}
|
|
catch
|
|
{ }
|
|
bool hasNewOdl = DataLayer.obj.taSelOdlFree.getUnused().Rows.Count > 1;
|
|
// sistemo buttons!
|
|
btnStartAttr.Enabled = (isEnabled && (!inAttr && hasNewOdl));
|
|
btnStartProd.Enabled = (isEnabled && inAttr);
|
|
btnEndProd.Enabled = (isEnabled && (!inAttr && currHasOdl));
|
|
ddlODL.Enabled = (isEnabled && (!inAttr && hasNewOdl));
|
|
odsODL.DataBind();
|
|
// sistemo show tempo/note attrezzaggio..
|
|
if (inAttr)
|
|
{
|
|
showNoteTC(true);
|
|
// sistemo SOLO se non si trtta di un postback...
|
|
if (!Page.IsPostBack)
|
|
{
|
|
int idxOdl = DataLayer.obj.taMSE.getByIdxMacchina(idxMacchina.ToString())[0].idxODL;
|
|
try
|
|
{
|
|
updateTempoTc(idxOdl);
|
|
updateNoteTC(idxOdl);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
logger.lg.scriviLog(string.Format("Eccezione in recupero dati ODL! {0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <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)
|
|
{
|
|
DS_applicazione.StatoMacchineRow rigaStato = DataLayer.obj.taStatoMacchine.GetDataByIdxMacchina(idxMacchina.ToString())[0];
|
|
// ricavo codice articolo + kanban...
|
|
string CodArticolo = DataLayer.obj.taODL.getByIdx(idxODL, false)[0].CodArticolo;
|
|
string MatrKanban = DataLayer.obj.taKanban.getByCodArt(CodArticolo)[0].MatricolaKanban;
|
|
// processo evento...
|
|
MapoDb.inputComando inCmd = controllerMapo.scriviRigaEventoBarcode(idxMacchina.ToString(), idxEvento, MatrKanban, "", rigaStato.MatrOpr, rigaStato.pallet);
|
|
if (inCmd.needStatusRefresh)
|
|
{
|
|
// chiamo refresh MSE
|
|
DataLayer.obj.taMSE.getByRefreshData(memLayer.ML.confReadInt("refrMSE_0"));
|
|
}
|
|
lblOut.Text = userMsg;
|
|
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 btnStartAttr_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.ToString())[0].IdxODL;
|
|
DataLayer.obj.taODL.splitODL(idxODL, idxMacchina.ToString(), TCAssegnato(idxODL), string.Format("Sospensione ODL {0}, generato residuo con pari TCiclo: {1}", idxODL, TCAssegnato(idxODL)), false);
|
|
}
|
|
catch
|
|
{ }
|
|
// avvio NUOVO ODL
|
|
DataLayer.obj.taODL.inizioSetup(idxODLSel, idxMacchina.ToString(), 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 btnStartProd_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.ToString())[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 btnEndProd_Click(object sender, EventArgs e)
|
|
{
|
|
// leggo idxOdl da ultimo odl attivo x macchina
|
|
int idxODL = DataLayer.obj.taODL.getByMacchina(idxMacchina.ToString())[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.ToString());
|
|
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.ToString(), TCAssegnato(idxODL), string.Format("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)
|
|
{
|
|
if (confZero)
|
|
{
|
|
// confermo produzione ZERO pezzi (in setup)
|
|
DataLayer.obj.confermaProdMacchina(idxMacchina.ToString(), memLayer.ML.confReadInt("modoConfProd"), 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.ToString())[0];
|
|
if (rigaProd.pezziNonConfermati > 0)
|
|
{
|
|
DataLayer.obj.confermaProdMacchina(idxMacchina.ToString(), memLayer.ML.confReadInt("modoConfProd"), rigaProd.pezziNonConfermati);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// mostra dati ed opzione x split ODL
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnShowSplitODL_Click(object sender, EventArgs e)
|
|
{
|
|
bool splitOdl = true;
|
|
fixSplitBtn(splitOdl);
|
|
// recupero current idx
|
|
int currODL = DataLayer.obj.taODL.getByMacchina(idxMacchina.ToString())[0].IdxODL;
|
|
updateTempoTc(currODL);
|
|
updateNoteTC(currODL);
|
|
}
|
|
/// <summary>
|
|
/// sistema buttons split
|
|
/// </summary>
|
|
/// <param name="splitOdl"></param>
|
|
private void fixSplitBtn(bool splitOdl)
|
|
{
|
|
btnShowSplitODL.Visible = !splitOdl;
|
|
chkCloseOdl.Visible = !splitOdl;
|
|
btnSplitODL.Visible = splitOdl;
|
|
showNoteTC(splitOdl);
|
|
ddlODL.Visible = !splitOdl;
|
|
btnStartAttr.Visible = !splitOdl;
|
|
btnStartProd.Visible = !splitOdl;
|
|
btnEndProd.Visible = !splitOdl;
|
|
}
|
|
/// <summary>
|
|
/// split ODL con creazione nuovo ODL
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnSplitODL_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.ToString())[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.ToString(), 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;
|
|
}
|
|
}
|
|
} |