Code cleanup con CodeMaid
This commit is contained in:
@@ -7,311 +7,317 @@ using System.Web.UI.WebControls;
|
||||
|
||||
namespace MP_ADM.WebUserControls
|
||||
{
|
||||
public partial class mod_planCreate : SteamWare.UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Oggetto datalayer specifico
|
||||
/// </summary>
|
||||
private DataLayer DataLayerObj = new DataLayer();
|
||||
|
||||
public partial class mod_planCreate : SteamWare.UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Oggetto datalayer specifico
|
||||
/// </summary>
|
||||
DataLayer DataLayerObj = new DataLayer();
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!Page.IsPostBack)
|
||||
{
|
||||
// di default NASCONDE...
|
||||
//toggleVisibility();
|
||||
calcTotali();
|
||||
}
|
||||
}
|
||||
public string CodGruppo
|
||||
{
|
||||
get
|
||||
{
|
||||
return hfCodGruppo.Value;
|
||||
}
|
||||
set
|
||||
{
|
||||
hfCodGruppo.Value = value;
|
||||
}
|
||||
}
|
||||
public string CodArticolo
|
||||
{
|
||||
get
|
||||
{
|
||||
return hfCodArticolo.Value;
|
||||
}
|
||||
set
|
||||
{
|
||||
hfCodArticolo.Value = value;
|
||||
}
|
||||
}
|
||||
public string IdxMacchina
|
||||
{
|
||||
get
|
||||
{
|
||||
return hfIdxMacchina.Value;
|
||||
}
|
||||
set
|
||||
{
|
||||
hfIdxMacchina.Value = value;
|
||||
}
|
||||
}
|
||||
public void doUpdate()
|
||||
{
|
||||
grView.DataBind();
|
||||
calcTotali();
|
||||
}
|
||||
/// <summary>
|
||||
/// seleziona/deseleziona le righe indicate...
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void btnSelAll_Click(object sender, EventArgs e)
|
||||
{
|
||||
// seleziono tutti i valori visibili nel datagrid
|
||||
CheckBox chkbox = ((CheckBox)sender);
|
||||
bool isChecked = chkbox.Checked;
|
||||
if (!isChecked)
|
||||
{
|
||||
chkbox.ToolTip = traduci("btnSelAll");
|
||||
}
|
||||
else
|
||||
{
|
||||
chkbox.ToolTip = traduci("btnDeselAll");
|
||||
}
|
||||
foreach (GridViewRow riga in grView.Rows)
|
||||
{
|
||||
((CheckBox)riga.FindControl("chkSelect")).Checked = isChecked;
|
||||
}
|
||||
calcTotali();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// comando reset
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void lbtReset_Click(object sender, EventArgs e)
|
||||
{
|
||||
doReset();
|
||||
}
|
||||
private void doReset()
|
||||
{
|
||||
grView.SelectedIndex = -1;
|
||||
grView.DataBind();
|
||||
raiseEvent(SteamWare.ucEvType.Reset);
|
||||
}
|
||||
|
||||
protected void lbtToggle_Click(object sender, EventArgs e)
|
||||
{
|
||||
toggleVisibility();
|
||||
}
|
||||
|
||||
private void toggleVisibility()
|
||||
{
|
||||
divDetail.Visible = !divDetail.Visible;
|
||||
tgIcon.Attributes["class"] = divDetail.Visible ? "fa fa-chevron-up" : "fa fa-chevron-down";
|
||||
}
|
||||
|
||||
protected void chkSelect_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
calcTotali();
|
||||
}
|
||||
|
||||
private void calcTotali()
|
||||
{
|
||||
// update valori calcolati in base a selezione...
|
||||
int numOrd = 0;
|
||||
int numPzOrd = 0;
|
||||
decimal tempoMinOrd = 0;
|
||||
decimal tc50p = 0;
|
||||
int numPzTot = 0;
|
||||
decimal tempoMinTot = 0;
|
||||
Dictionary<string, int> ElArticoli = new Dictionary<string, int>();
|
||||
string CodArt = "";
|
||||
foreach (GridViewRow riga in grView.Rows)
|
||||
{
|
||||
numPzOrd = 0;
|
||||
tempoMinOrd = 0;
|
||||
DateTime DataRif = DateTime.Now.Date;
|
||||
if (((CheckBox)riga.FindControl("chkSelect")).Checked && ((CheckBox)riga.FindControl("chkSelect")).Visible)
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
int.TryParse(((TextBox)riga.FindControl("txtNumPezzi")).Text, out numPzOrd);
|
||||
decimal.TryParse(((Label)riga.FindControl("lblTC50p")).Text, out tc50p);
|
||||
tempoMinOrd = tc50p * numPzOrd;
|
||||
CodArt = ((Label)riga.FindControl("lblCodArticolo")).Text;
|
||||
if (numPzOrd > 0) numOrd++;
|
||||
// salvo dictionary articoli...
|
||||
if (ElArticoli.ContainsKey(CodArt))
|
||||
if (!Page.IsPostBack)
|
||||
{
|
||||
ElArticoli[CodArt]++;
|
||||
// di default NASCONDE...
|
||||
//toggleVisibility();
|
||||
calcTotali();
|
||||
}
|
||||
}
|
||||
|
||||
public string CodGruppo
|
||||
{
|
||||
get
|
||||
{
|
||||
return hfCodGruppo.Value;
|
||||
}
|
||||
set
|
||||
{
|
||||
hfCodGruppo.Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string CodArticolo
|
||||
{
|
||||
get
|
||||
{
|
||||
return hfCodArticolo.Value;
|
||||
}
|
||||
set
|
||||
{
|
||||
hfCodArticolo.Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string IdxMacchina
|
||||
{
|
||||
get
|
||||
{
|
||||
return hfIdxMacchina.Value;
|
||||
}
|
||||
set
|
||||
{
|
||||
hfIdxMacchina.Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void doUpdate()
|
||||
{
|
||||
grView.DataBind();
|
||||
calcTotali();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// seleziona/deseleziona le righe indicate...
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void btnSelAll_Click(object sender, EventArgs e)
|
||||
{
|
||||
// seleziono tutti i valori visibili nel datagrid
|
||||
CheckBox chkbox = ((CheckBox)sender);
|
||||
bool isChecked = chkbox.Checked;
|
||||
if (!isChecked)
|
||||
{
|
||||
chkbox.ToolTip = traduci("btnSelAll");
|
||||
}
|
||||
else
|
||||
{
|
||||
ElArticoli[CodArt] = 1;
|
||||
chkbox.ToolTip = traduci("btnDeselAll");
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
numPzTot += numPzOrd;
|
||||
tempoMinTot += tempoMinOrd;
|
||||
}
|
||||
}
|
||||
//lblNumPzTot.Text = $"{numPzTot:N0}";
|
||||
numPzCalc = numPzTot;
|
||||
lblOreTot.Text = $"{tempoMinTot / 60:N2}";
|
||||
// controllo SE abilitare il crea gruppo o split...
|
||||
divSplitOdl.Visible = numOrd == 1;
|
||||
divConfirm.Visible = numOrd > 0;
|
||||
divCreaGrp.Visible = (numOrd > 1) && (ElArticoli.Count == 1) && CodGruppo != "";
|
||||
ddlMacc.DataBind();
|
||||
}
|
||||
/// <summary>
|
||||
/// Num pz totali calcolati
|
||||
/// </summary>
|
||||
protected int numPzCalc
|
||||
{
|
||||
get
|
||||
{
|
||||
int answ = 0;
|
||||
int.TryParse(hfNumPzTot.Value, out answ);
|
||||
return answ;
|
||||
}
|
||||
set
|
||||
{
|
||||
lblNumPzTot.Text = $"{value:N0}";
|
||||
hfNumPzTot.Value = value.ToString();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Approva e pianifica richeiste...
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void lbtDoPlan_Click(object sender, EventArgs e)
|
||||
{
|
||||
int IdxPromessa = 0;
|
||||
foreach (GridViewRow riga in grView.Rows)
|
||||
{
|
||||
DateTime DataRif = DateTime.Now.Date;
|
||||
if (((CheckBox)riga.FindControl("chkSelect")).Checked && ((CheckBox)riga.FindControl("chkSelect")).Visible)
|
||||
{
|
||||
try
|
||||
{
|
||||
int.TryParse(((Label)riga.FindControl("lblIdxPromessa")).Text, out IdxPromessa);
|
||||
// approvo la promessa COPIANDOLA
|
||||
DataLayerObj.taPlanRichieste.approvaRich(IdxPromessa, SteamWare.user_std.UtSn.utente);
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
}
|
||||
// update!
|
||||
reportUpdate();
|
||||
}
|
||||
|
||||
private void reportUpdate()
|
||||
{
|
||||
// aggiorno grView...
|
||||
grView.SelectedIndex = -1;
|
||||
grView.DataBind();
|
||||
// segnalo update
|
||||
raiseEvent(SteamWare.ucEvType.ReqUpdateParent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Chiama stored per creare NUOVO PODL, chiudere i selezionati, registrare associazione,...
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void lbtCreaGrp_Click(object sender, EventArgs e)
|
||||
{
|
||||
int IdxPromessa = 0;
|
||||
int IdxPromessaOUT = 0;
|
||||
int QtyEv = 0;
|
||||
if (numPzCalc > 0)
|
||||
{
|
||||
// in primis CREA la richiesta raggruppata
|
||||
foreach (GridViewRow riga in grView.Rows)
|
||||
{
|
||||
DateTime DataRif = DateTime.Now.Date;
|
||||
if (((CheckBox)riga.FindControl("chkSelect")).Checked && ((CheckBox)riga.FindControl("chkSelect")).Visible)
|
||||
{
|
||||
try
|
||||
foreach (GridViewRow riga in grView.Rows)
|
||||
{
|
||||
int.TryParse(((Label)riga.FindControl("lblIdxPromessa")).Text, out IdxPromessa);
|
||||
break;
|
||||
((CheckBox)riga.FindControl("chkSelect")).Checked = isChecked;
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
calcTotali();
|
||||
}
|
||||
var resultIdxOut = DataLayerObj.taPlanRichieste.creaGrp(IdxPromessa, SteamWare.user_std.UtSn.utente, ddlMacc.SelectedValue, CodGruppo, numPzCalc);
|
||||
// se ho trovato una promessaOUT...
|
||||
int.TryParse(resultIdxOut.ToString(), out IdxPromessaOUT);
|
||||
if (IdxPromessaOUT > 0)
|
||||
|
||||
/// <summary>
|
||||
/// comando reset
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void lbtReset_Click(object sender, EventArgs e)
|
||||
{
|
||||
// poi alloca tutte le istanze alla richiesta....
|
||||
foreach (GridViewRow riga in grView.Rows)
|
||||
{
|
||||
DateTime DataRif = DateTime.Now.Date;
|
||||
if (((CheckBox)riga.FindControl("chkSelect")).Checked && ((CheckBox)riga.FindControl("chkSelect")).Visible)
|
||||
{
|
||||
try
|
||||
{
|
||||
int.TryParse(((Label)riga.FindControl("lblIdxPromessa")).Text, out IdxPromessa);
|
||||
int.TryParse(((TextBox)riga.FindControl("txtNumPezzi")).Text, out QtyEv);
|
||||
// approvo la promessa COPIANDOLA
|
||||
DataLayerObj.taPlanRichieste.allocaIst(IdxPromessa, IdxPromessaOUT, QtyEv, SteamWare.user_std.UtSn.utente, "GRP");
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
logger.lg.scriviLog($"Eccezione in CreaGrp:{Environment.NewLine}{exc}", tipoLog.EXCEPTION);
|
||||
}
|
||||
}
|
||||
}
|
||||
doReset();
|
||||
}
|
||||
}
|
||||
// update!
|
||||
reportUpdate();
|
||||
}
|
||||
|
||||
protected void txtNumPezzi_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
calcTotali();
|
||||
}
|
||||
private void doReset()
|
||||
{
|
||||
grView.SelectedIndex = -1;
|
||||
grView.DataBind();
|
||||
raiseEvent(SteamWare.ucEvType.Reset);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// cambia il colore del campo secondo la due date indicata
|
||||
/// rosso: in ritardo (scaduta)
|
||||
/// verde: > 2 week
|
||||
/// giallo: altrimenti
|
||||
/// </summary>
|
||||
/// <param name="dueDate"></param>
|
||||
/// <returns></returns>
|
||||
public string cssDueDate(object dueDate)
|
||||
{
|
||||
DateTime oggi = DateTime.Today;
|
||||
DateTime dataRif = oggi.AddDays(-1);
|
||||
DateTime.TryParse(dueDate.ToString(), out dataRif);
|
||||
string answ = "text-secondary";
|
||||
if (dataRif < oggi)
|
||||
{
|
||||
answ = "text-danger";
|
||||
}
|
||||
else if (dataRif < oggi.AddDays(14))
|
||||
{
|
||||
answ = "text-warning";
|
||||
}
|
||||
else
|
||||
{
|
||||
answ = "text-success";
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
protected void lbtToggle_Click(object sender, EventArgs e)
|
||||
{
|
||||
toggleVisibility();
|
||||
}
|
||||
|
||||
}
|
||||
private void toggleVisibility()
|
||||
{
|
||||
divDetail.Visible = !divDetail.Visible;
|
||||
tgIcon.Attributes["class"] = divDetail.Visible ? "fa fa-chevron-up" : "fa fa-chevron-down";
|
||||
}
|
||||
|
||||
protected void chkSelect_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
calcTotali();
|
||||
}
|
||||
|
||||
private void calcTotali()
|
||||
{
|
||||
// update valori calcolati in base a selezione...
|
||||
int numOrd = 0;
|
||||
int numPzOrd = 0;
|
||||
decimal tempoMinOrd = 0;
|
||||
decimal tc50p = 0;
|
||||
int numPzTot = 0;
|
||||
decimal tempoMinTot = 0;
|
||||
Dictionary<string, int> ElArticoli = new Dictionary<string, int>();
|
||||
string CodArt = "";
|
||||
foreach (GridViewRow riga in grView.Rows)
|
||||
{
|
||||
numPzOrd = 0;
|
||||
tempoMinOrd = 0;
|
||||
DateTime DataRif = DateTime.Now.Date;
|
||||
if (((CheckBox)riga.FindControl("chkSelect")).Checked && ((CheckBox)riga.FindControl("chkSelect")).Visible)
|
||||
{
|
||||
try
|
||||
{
|
||||
int.TryParse(((TextBox)riga.FindControl("txtNumPezzi")).Text, out numPzOrd);
|
||||
decimal.TryParse(((Label)riga.FindControl("lblTC50p")).Text, out tc50p);
|
||||
tempoMinOrd = tc50p * numPzOrd;
|
||||
CodArt = ((Label)riga.FindControl("lblCodArticolo")).Text;
|
||||
if (numPzOrd > 0) numOrd++;
|
||||
// salvo dictionary articoli...
|
||||
if (ElArticoli.ContainsKey(CodArt))
|
||||
{
|
||||
ElArticoli[CodArt]++;
|
||||
}
|
||||
else
|
||||
{
|
||||
ElArticoli[CodArt] = 1;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
numPzTot += numPzOrd;
|
||||
tempoMinTot += tempoMinOrd;
|
||||
}
|
||||
}
|
||||
//lblNumPzTot.Text = $"{numPzTot:N0}";
|
||||
numPzCalc = numPzTot;
|
||||
lblOreTot.Text = $"{tempoMinTot / 60:N2}";
|
||||
// controllo SE abilitare il crea gruppo o split...
|
||||
divSplitOdl.Visible = numOrd == 1;
|
||||
divConfirm.Visible = numOrd > 0;
|
||||
divCreaGrp.Visible = (numOrd > 1) && (ElArticoli.Count == 1) && CodGruppo != "";
|
||||
ddlMacc.DataBind();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Num pz totali calcolati
|
||||
/// </summary>
|
||||
protected int numPzCalc
|
||||
{
|
||||
get
|
||||
{
|
||||
int answ = 0;
|
||||
int.TryParse(hfNumPzTot.Value, out answ);
|
||||
return answ;
|
||||
}
|
||||
set
|
||||
{
|
||||
lblNumPzTot.Text = $"{value:N0}";
|
||||
hfNumPzTot.Value = value.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Approva e pianifica richeiste...
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void lbtDoPlan_Click(object sender, EventArgs e)
|
||||
{
|
||||
int IdxPromessa = 0;
|
||||
foreach (GridViewRow riga in grView.Rows)
|
||||
{
|
||||
DateTime DataRif = DateTime.Now.Date;
|
||||
if (((CheckBox)riga.FindControl("chkSelect")).Checked && ((CheckBox)riga.FindControl("chkSelect")).Visible)
|
||||
{
|
||||
try
|
||||
{
|
||||
int.TryParse(((Label)riga.FindControl("lblIdxPromessa")).Text, out IdxPromessa);
|
||||
// approvo la promessa COPIANDOLA
|
||||
DataLayerObj.taPlanRichieste.approvaRich(IdxPromessa, SteamWare.user_std.UtSn.utente);
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
}
|
||||
// update!
|
||||
reportUpdate();
|
||||
}
|
||||
|
||||
private void reportUpdate()
|
||||
{
|
||||
// aggiorno grView...
|
||||
grView.SelectedIndex = -1;
|
||||
grView.DataBind();
|
||||
// segnalo update
|
||||
raiseEvent(SteamWare.ucEvType.ReqUpdateParent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Chiama stored per creare NUOVO PODL, chiudere i selezionati, registrare associazione,...
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void lbtCreaGrp_Click(object sender, EventArgs e)
|
||||
{
|
||||
int IdxPromessa = 0;
|
||||
int IdxPromessaOUT = 0;
|
||||
int QtyEv = 0;
|
||||
if (numPzCalc > 0)
|
||||
{
|
||||
// in primis CREA la richiesta raggruppata
|
||||
foreach (GridViewRow riga in grView.Rows)
|
||||
{
|
||||
DateTime DataRif = DateTime.Now.Date;
|
||||
if (((CheckBox)riga.FindControl("chkSelect")).Checked && ((CheckBox)riga.FindControl("chkSelect")).Visible)
|
||||
{
|
||||
try
|
||||
{
|
||||
int.TryParse(((Label)riga.FindControl("lblIdxPromessa")).Text, out IdxPromessa);
|
||||
break;
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
}
|
||||
var resultIdxOut = DataLayerObj.taPlanRichieste.creaGrp(IdxPromessa, SteamWare.user_std.UtSn.utente, ddlMacc.SelectedValue, CodGruppo, numPzCalc);
|
||||
// se ho trovato una promessaOUT...
|
||||
int.TryParse(resultIdxOut.ToString(), out IdxPromessaOUT);
|
||||
if (IdxPromessaOUT > 0)
|
||||
{
|
||||
// poi alloca tutte le istanze alla richiesta....
|
||||
foreach (GridViewRow riga in grView.Rows)
|
||||
{
|
||||
DateTime DataRif = DateTime.Now.Date;
|
||||
if (((CheckBox)riga.FindControl("chkSelect")).Checked && ((CheckBox)riga.FindControl("chkSelect")).Visible)
|
||||
{
|
||||
try
|
||||
{
|
||||
int.TryParse(((Label)riga.FindControl("lblIdxPromessa")).Text, out IdxPromessa);
|
||||
int.TryParse(((TextBox)riga.FindControl("txtNumPezzi")).Text, out QtyEv);
|
||||
// approvo la promessa COPIANDOLA
|
||||
DataLayerObj.taPlanRichieste.allocaIst(IdxPromessa, IdxPromessaOUT, QtyEv, SteamWare.user_std.UtSn.utente, "GRP");
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
logger.lg.scriviLog($"Eccezione in CreaGrp:{Environment.NewLine}{exc}", tipoLog.EXCEPTION);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// update!
|
||||
reportUpdate();
|
||||
}
|
||||
|
||||
protected void txtNumPezzi_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
calcTotali();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// cambia il colore del campo secondo la due date indicata
|
||||
/// rosso: in ritardo (scaduta)
|
||||
/// verde: > 2 week
|
||||
/// giallo: altrimenti
|
||||
/// </summary>
|
||||
/// <param name="dueDate"></param>
|
||||
/// <returns></returns>
|
||||
public string cssDueDate(object dueDate)
|
||||
{
|
||||
DateTime oggi = DateTime.Today;
|
||||
DateTime dataRif = oggi.AddDays(-1);
|
||||
DateTime.TryParse(dueDate.ToString(), out dataRif);
|
||||
string answ = "text-secondary";
|
||||
if (dataRif < oggi)
|
||||
{
|
||||
answ = "text-danger";
|
||||
}
|
||||
else if (dataRif < oggi.AddDays(14))
|
||||
{
|
||||
answ = "text-warning";
|
||||
}
|
||||
else
|
||||
{
|
||||
answ = "text-success";
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user