Files
2023-11-13 18:46:55 +01:00

625 lines
18 KiB
C#

using MapoDb;
using SteamWare;
using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MP_ADM.WebUserControls
{
public partial class mod_gestPromODL : BaseUserControl
{
/// <summary>
/// Determina se sia solo readonly il controllo...
/// </summary>
public bool readOnly;
/// <summary>
/// Chiave PRE selezione tipo richiesta ordine
/// </summary>
public string codOrdPre
{
get
{
return hfCodPre.Value.Trim();
}
set
{
hfCodPre.Value = value;
}
}
/// <summary>
/// dimensione pagina
/// </summary>
public int pageSize
{
get
{
int answ = 10;
try
{
answ = Convert.ToInt32(txtPageSize.Text);
}
catch
{ }
return answ;
}
set
{
txtPageSize.Text = value.ToString();
}
}
/// <summary>
/// Abilitazione modifica selettore fase
/// </summary>
public bool enableSelFase
{
get
{
return ddlCodGruppo.Enabled;
}
set
{
ddlCodGruppo.Enabled = value;
}
}
/// <summary>
/// Gruppo selezionato
/// </summary>
public string CodGruppo
{
get
{
return ddlCodGruppo.SelectedValue;
}
set
{
ddlCodGruppo.SelectedValue = value;
}
}
#region area da NON modificare
#region area protected
protected string _idxGridView;
/// <summary>
/// reset della selezione
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnReset_Click(object sender, EventArgs e)
{
resetSelezione();
}
/// <summary>
/// salvo comando
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lbt_Command(object sender, CommandEventArgs e)
{
memLayer.ML.setSessionVal("nextObjCommand", ((LinkButton)sender).CommandArgument);
}
/// <summary>
/// gestione cambio selezione valore
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void grView_SelectedIndexChanged(object sender, EventArgs e)
{
// salvo in session il valore selezionato...
memLayer.ML.setSessionVal(string.Format("{0}_sel", _idxGridView), grView.SelectedValue, false);
bool doClone = false;
bool doEdit = false;
// gestione buttons richieste
string _comando = "";
if (memLayer.ML.isInSessionObject("nextObjCommand"))
{
_comando = memLayer.ML.StringSessionObj("nextObjCommand");
memLayer.ML.emptySessionVal("nextObjCommand");
}
switch (_comando)
{
case "Clona":
doClone = true;
break;
case "Edit":
doEdit = true;
break;
default:
break;
}
if (doClone)
{
memLayer.ML.setSessionVal("idxProm2Clone", grView.SelectedValue, false);
showAddNewPODL();
mod_newPromessaODL.doSelPODL();
}
else if (doEdit)
{
memLayer.ML.setSessionVal("idxProm2Edit", grView.SelectedValue, false);
showAddNewPODL();
mod_newPromessaODL.doSelPODL();
}
else
{
// mostro edit quantità...
divEditQta.Visible = true;
lbtNewPODL.Visible = true;
mod_newPromessaODL.Visible = false;
var riga = DataLayerObj.taPODL.getByKey(idxPOdlSel)[0];
numPz = riga.NumPezzi;
pzPallet = riga.PzPallet;
}
}
/// <summary>
/// traduce gli header delle colonne
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void grView_DataBound(object sender, EventArgs e)
{
if (grView.Rows.Count > 0)
{
LinkButton lb;
// aggiorno gli headers
foreach (TableCell cella in grView.HeaderRow.Cells)
{
try
{
lb = (LinkButton)cella.Controls[0];
lb.Text = traduci(lb.Text);
}
catch
{ }
}
int totRecord = grView.Rows.Count + grView.PageSize * (grView.PageCount - 1);
lblNumRec.Text = string.Format("{0} records of ~ {1}", grView.Rows.Count, totRecord);
}
else
{
lblNumRec.Text = "";
}
}
/// <summary>
/// recupera i dati di un nuovo record contenuti nel footer di un gridView;
/// questi devono esses opportunamente nominati (es: txt{0}, dl{0}, ...)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void recuperaFooter(object sender, ObjectDataSourceMethodEventArgs e)
{
//recupero la riga footer...
DataColumnCollection colonne = colonneObj();
string nomeCol;
string tipoColonna = "";
foreach (DataColumn colonna in colonne)
{
nomeCol = colonna.ColumnName;
// cerco un textbox o quello che sia...
if (grView.FooterRow.FindControl(string.Format("txt{0}", nomeCol)) != null)
{
tipoColonna = "textBox";
}
else if (grView.FooterRow.FindControl(string.Format("dl{0}", nomeCol)) != null)
{
tipoColonna = "dropDownList";
}
else if (grView.FooterRow.FindControl(string.Format("chk{0}", nomeCol)) != null)
{
tipoColonna = "checkBox";
}
else if (grView.FooterRow.FindControl(string.Format("selAjax_{0}", nomeCol)) != null)
{
tipoColonna = "selAjax";
}
// in base al tipo salvo negli inputparameters dell'ODS
switch (tipoColonna)
{
case "textBox":
e.InputParameters[nomeCol] = ((TextBox)grView.FooterRow.FindControl(string.Format("txt{0}", nomeCol))).Text;
break;
case "dropDownList":
e.InputParameters[nomeCol] = ((DropDownList)grView.FooterRow.FindControl(string.Format("dl{0}", nomeCol))).SelectedValue;
break;
case "checkBox":
e.InputParameters[nomeCol] = ((CheckBox)grView.FooterRow.FindControl(string.Format("chk{0}", nomeCol))).Checked;
break;
//case "selAjax":
// e.InputParameters[nomeCol] = ((mod_selettore_ajax)grView.FooterRow.FindControl(string.Format("selAjax_{0}", nomeCol))).valore;
// break;
default:
break;
}
tipoColonna = "";
}
}
/// <summary>
/// svuoto da cache post update
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ods_Updated(object sender, ObjectDataSourceStatusEventArgs e)
{
raiseNewVal();
}
#endregion area protected
#region are public
/// <summary>
/// resetta la selezione dei valori in caso di modifiche su altri controlli
/// </summary>
public void resetSelezione()
{
memLayer.ML.emptySessionVal(string.Format("{0}_sel", _idxGridView));
grView.SelectedIndex = -1;
grView.DataBind();
divEditQta.Visible = false;
mod_newPromessaODL.Visible = false;
lbtNewPODL.Visible = true;
lblWarning.Visible = false;
raiseReset();
}
#endregion are public
#endregion area da NON modificare
#region area da modificare
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (!Page.IsPostBack)
{
mod_newPromessaODL.Visible = false;
grView.PageSize = pageSize;
// se ho in sessione selezione la recupero...
if (memLayer.ML.isInSessionObject("selFaseBCode") && enableSelFase)
{
ddlCodGruppo.SelectedValue = memLayer.ML.StringSessionObj("selFaseBCode");
}
}
mod_newPromessaODL.eh_nuovoValore += new EventHandler(mod_newOdl1_eh_nuovoValore);
}
/// inizializzazione valori di default
/// </summary>
/// <param name="e"></param>
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
_idxGridView = "IdxODL";
}
/// <summary>
/// nuovo valore creato...
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void mod_newOdl1_eh_nuovoValore(object sender, EventArgs e)
{
// nascondo controllo e mostro button
mod_newPromessaODL.Visible = false;
lbtNewPODL.Visible = true;
// aggiorno!
resetSelezione();
}
/// <summary>
/// elenco colonne del datagrid
/// </summary>
/// <returns></returns>
protected DataColumnCollection colonneObj()
{
DS_ProdTempi.ODLDataTable tabella = new DS_ProdTempi.ODLDataTable();
DataColumnCollection colonne = tabella.Columns;
return colonne;
}
public bool delEnabled(object _idxOdl)
{
bool answ = false;
int idxOdl = 0;
// controllo non sia già stata iniziata la produzione sennò non posso cancellare...
try
{
idxOdl = Convert.ToInt32(_idxOdl);
answ = (DataLayerObj.taODL.getByIdx(idxOdl, true).Count > 0);
}
catch
{ }
return answ;
}
/// <summary>
/// mostra creazione nuovo ODL
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lbtNewPODL_Click(object sender, EventArgs e)
{
showAddNewPODL();
}
private void showAddNewPODL()
{
// mostro controllo creazione ODL
mod_newPromessaODL.Visible = true;
divEditQta.Visible = false;
lbtNewPODL.Visible = false;
//grView.SelectedIndex = -1;
grView.DataBind();
}
/// <summary>
/// formatot url x stampa ODL
/// </summary>
/// <param name="idx"></param>
/// <returns></returns>
public string formattaUrlOdl(object idx)
{
string answ = String.Format(memLayer.ML.CRS("exportFormat1"), Convert.ToInt32(reportRichiesto.SchedaODL), idx);
return answ;
}
/// <summary>
/// cambio dim pagina
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void txtPageSize_TextChanged(object sender, EventArgs e)
{
grView.PageSize = pageSize;
}
/// <summary>
/// elimina commento
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lbtDel_Click(object sender, EventArgs e)
{
LinkButton imgBtn = (LinkButton)sender;
int IdxProm = 0;
int.TryParse(imgBtn.CommandArgument, out IdxProm);
DataLayerObj.taPODL.deleteQuery(IdxProm);
doUpdate();
}
private void doUpdate()
{
grView.DataBind();
}
#endregion area da modificare
protected void btnOk_Click(object sender, EventArgs e)
{
if (idxPOdlSel > 0)
{
DataLayerObj.taPODL.updateQta(numPz, pzPallet, idxPOdlSel);
}
updateCtrl();
}
private void updateCtrl()
{
divEditQta.Visible = false;
grView.SelectedIndex = -1;
grView.DataBind();
}
/// <summary>
/// idxOdl selezionato
/// </summary>
protected int idxPOdlSel
{
get
{
int answ = 0;
try
{
answ = Convert.ToInt32(grView.SelectedValue);
}
catch
{ }
return answ;
}
}
/// <summary>
/// Nuovo num pz
/// </summary>
protected int numPz
{
get
{
int answ = 0;
try
{
answ = Convert.ToInt32(txtNewQta.Text.Trim());
}
catch
{ }
return answ;
}
set
{
txtNewQta.Text = value.ToString();
}
}
/// <summary>
/// Nuovo num pz per pallet
/// </summary>
protected int pzPallet
{
get
{
int answ = 1;
try
{
answ = Convert.ToInt32(txtNewPzPallet.Text.Trim());
}
catch
{ }
// controllo sia > 0...
if (answ < 1)
{
answ = 1;
}
return answ;
}
set
{
txtNewPzPallet.Text = value.ToString();
}
}
protected void btnCancel_Click(object sender, EventArgs e)
{
updateCtrl();
}
protected void chkUnassigned_CheckedChanged(object sender, EventArgs e)
{
updateGrView();
}
/// <summary>
/// Aggiorno Gridview
/// </summary>
private void updateGrView()
{
grView.DataBind();
}
/// <summary>
/// IdxMacchina filtrata
/// </summary>
protected string idxMacc
{
get
{
return lblIdxMacc.Text;
}
set
{
lblIdxMacc.Text = value;
}
}
/// <summary>
/// Nome filtrata
/// </summary>
protected string NomeMacc
{
get
{
return lblNomeMacc.Text;
}
set
{
lblNomeMacc.Text = value;
}
}
/// <summary>
/// CodArt filtrato
/// </summary>
protected string CodArt
{
get
{
return lblCodArt.Text;
}
set
{
lblCodArt.Text = value;
}
}
/// <summary>
/// CodArt filtrato
/// </summary>
protected string DescArt
{
get
{
return lblDescArt.Text;
}
set
{
lblDescArt.Text = value;
}
}
/// <summary>
/// Selezionato un condominio --> riporto selezione
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lbtSelArt_Click(object sender, EventArgs e)
{
LinkButton lb = (LinkButton)sender;
// imposto articolo, splittando
string[] artData = lb.CommandArgument.Split('|');
CodArt = artData[0];
DescArt = artData[1];
updateGrView();
}
/// <summary>
/// Selezionato un condominio --> riporto selezione
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lbtSelMacc_Click(object sender, EventArgs e)
{
LinkButton lb = (LinkButton)sender;
// imposto articolo, splittando
string[] maccData = lb.CommandArgument.Split('|');
idxMacc = maccData[0];
NomeMacc = maccData[1];
updateGrView();
}
protected void lbtResArt_Click(object sender, EventArgs e)
{
CodArt = "";
DescArt = "";
updateGrView();
}
protected void lbtResMacc_Click(object sender, EventArgs e)
{
idxMacc = "";
NomeMacc = "";
updateGrView();
}
protected void ddlCodGruppo_SelectedIndexChanged(object sender, EventArgs e)
{
// salvo in sessione selezione...
memLayer.ML.setSessionVal("selFaseBCode", ddlCodGruppo.SelectedValue);
}
}
}