using MapoDb; using SteamWare; using System; using System.Configuration; using System.Data; namespace MoonPro_site.WebUserControls { public partial class mod_caricaOperatoriCSV : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { checkAuth(); } private void checkAuth() { // se in session è auth alora mostro pannello caricamento.. if (Convert.ToBoolean(Session["isAuthUpdForced"])) { pnlUpload.Visible = true; pnlPasswd.Visible = false; } else { pnlUpload.Visible = false; pnlPasswd.Visible = true; } } protected void Button1_Click(object sender, EventArgs e) { // controllo se c'è il file if (FileUpload1.HasFile) { // salvo file in locale... string _dirPath = System.Web.HttpContext.Current.Server.MapPath("./upload/"); string _logPath = System.Web.HttpContext.Current.Server.MapPath("./logs/"); FileUpload1.PostedFile.SaveAs(string.Format("{0}importOpr.csv", _dirPath)); // leggo il file locale in una tabella fileMover fm = new fileMover(_dirPath, _dirPath); DataTable tabIn = CsvParser.Parse(fm.scaricaFileString("importOpr.csv"), CheckBox1.Checked); // svuoto vecchia tab inserting... DataLayer.obj.taOp2ins.DeleteAll(); int _errori = 0; logger lg = new logger(_logPath); foreach (DataRow riga in tabIn.Rows) { try { DataLayer.obj.taOp2ins.Insert(Convert.ToInt32(riga[0]), riga[1].ToString(), riga[2].ToString()); } catch { _errori++; lg.scriviLog(string.Format("Importazione dati operatore: errore nell'inserimento dell'operatore con matricola {0}", riga[0])); } } DataLayer.obj.taOp2ins.UpdateOperatori(); lblWarning.Text = "Dati operatore caricati!"; if (_errori > 0) lblWarning.Text = lblWarning.Text + string.Format(" - riscontrati {0} errori, vedere log!", _errori); } else { lblWarning.Text = "Indicare il file da caricare!"; } } protected void txtPwd_TextChanged(object sender, EventArgs e) { string _pwdOk = ConfigurationManager.AppSettings.Get("_pdwUpdateForzato"); // verifico la password ed eventualmente mostro pannello caricamento.. if (txtPwd.Text != "" && txtPwd.Text == _pwdOk) { Session["isAuthUpdForced"] = true; checkAuth(); } else { Session["isAuthUpdForced"] = false; checkAuth(); } } } }