Esempio n. 1
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     ExcelInterface.SetTemplatePath(_templatePath);
     ExcelInterface.OpenExcelApplication();
     TemplateResetter.ResetEmployeeTableToWhite();
     TemplateResetter.FillInWeekdays();
     ExcelInterface.MakeVisible();
     ExcelInterface.CollectGarbage();
 }
Esempio n. 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        P = Server.MapPath(P);
        if (Request.Files.Count == 1)
        {
            if (File.Exists(P))
            {
                File.Delete(P);
            }
            Request.Files[0].SaveAs(P);

            if (File.Exists(P))
            {
                using (ExcelInterface EI = new ExcelInterface(P))
                {
                    Status = string.Empty;
                    foreach (string s in EI.Tables)
                    {
                        Status += string.Format("<h1>Table: {0}</h1>", Server.HtmlEncode(s));
                        SQLRow[] RR = EI.ExecReader("SELECT * FROM [" + s + "]");
                        if (RR.Length > 0)
                        {
                            Status += "<table><tr>";
                            for (int j = 0; j < RR[0].Names.Count; j++)
                            {
                                Status += string.Format("<th>{0}</th>", Server.HtmlEncode(RR[0].Names[j]));
                            }
                            Status += "</tr>";
                            foreach (SQLRow R in RR)
                            {
                                Status += "<tr>";
                                for (int i = 0; i < R.Values.Count; i++)
                                {
                                    Status += string.Format("<td>{0}</td>", R.Values[R.Names[i]] == null ? "" : Server.HtmlEncode(R.Values[R.Names[i]].ToString()));
                                }
                                Status += "</tr>";
                            }
                            Status += "</table>";
                        }
                        else
                        {
                            Status += "<i>Empty</i>";
                        }
                    }
                }
                File.Delete(P);
            }
            else
            {
                Status = "FILE ERROR";
            }
        }
    }
Esempio n. 3
0
    protected void ProcessExcel(string P)
    {
        ExcelInterface EI = new ExcelInterface(P);

        foreach (string s in EI.Tables)
        {
            TableInfo TI = new TableInfo();
            TI.TableName = s;
            TI.Fields    = EI.GetColumns(s);
            Tables.Add(TI);
            FieldCount += TI.Fields.Length;
        }
        EI.Dispose();
    }
Esempio n. 4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Base.IsAdmin(Session[Base.SESSION.ADMIN_LOGIN], Session[Base.SESSION.ADMIN_ID]))
        {
            Response.Redirect("./");
        }
        if (!string.IsNullOrEmpty(Request["ID"]) && Base.GetGuid(Request["ID"]) != Guid.Empty)
        {
            string       P  = "/temp/" + Guid.NewGuid().ToString() + ".xls";
            SQLInterface SI = new SQLInterface(Base.DSN.ADMIN);

            Base.Anlass  A  = Base.GetAnlass(Base.GetGuid(Request["ID"]), SI);
            Base.Frage[] FF = Base.GetFragen(SI);
            A.Soldaten = Base.GetAnswers(Base.GetSoldaten(A.AnlassID, SI), SI);

            string         insertFormat = string.Join(",", string.Empty.PadLeft(FF.Length, '?').ToCharArray());
            ExcelInterface EI           = new ExcelInterface(Server.MapPath(P));
            Response.Clear();
            EI.Exec(string.Format("CREATE TABLE [Export](SVNummer varchar(255),Vorname varchar(255),Nachname varchar(255),Problematic varchar(255),{0})", Fragen2Cols(FF)));
            EI.Exec(string.Format("INSERT INTO [Export] VALUES(NULL,NULL,NULL,NULL,{0})", insertFormat), Fragen2Insert(FF));
            foreach (Base.Soldat S in A.Soldaten)
            {
                EI.Exec(string.Format("INSERT INTO [Export] VALUES(?,?,?,?,{0})", insertFormat), S.SVNummer, S.Vorname, S.Nachname, S.Problematic?"Ja":"Nein", Poll2Values(S.Antworten));
            }
            EI.Dispose();
            SI.Dispose();
            Response.ContentType = "application/vnd.ms-excel";
            Response.AddHeader("Content-Disposition", string.Format("attachment; name=\"{0}.xls\"", A.Name.Replace('"', '\'')));
            Response.WriteFile(Server.MapPath(P), true);
            Response.Flush();
            try
            {
                Base.DelExcel(Server.MapPath("/temp/"));
            }
            catch
            {
            }
        }
    }
Esempio n. 5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Base.IsAdmin(Session[Base.SESSION.ADMIN_LOGIN], Session[Base.SESSION.ADMIN_ID]))
        {
            Response.Redirect("./");
        }

        if (Base.Verify(Request.Form, "Svorname", "Snachname", "Ssvnr", "Sdatum", "Sanlassname", "Sanlassdatum") &&
            !string.IsNullOrEmpty(Request["ID"]) &&
            IsGuid(Request["ID"]) &&
            Request.Form["anlassdatum"].Contains(" "))
        {
            Guid tmp = Guid.Parse(Request["ID"]);
            ExcelFile = tmp.ToString();
            string P = Server.MapPath(Base.ExcelPath(tmp));
            if (File.Exists(P))
            {
                ExcelInterface EI    = new ExcelInterface(P);
                string         Table = EI.Tables[0];
                List <string>  Cols  = new List <string>(EI.GetColumns(Table));

                if (Cols.Contains(Request.Form["vorname"]) &&
                    Cols.Contains(Request.Form["nachname"]) &&
                    Cols.Contains(Request.Form["svnr"]) &&
                    Cols.Contains(Request.Form["datum"]))
                {
                    int           errcount = 0;
                    StringBuilder SB       = new StringBuilder();
                    Guid          AnlassID = Guid.NewGuid();
                    string        Name;
                    DateTime      Datum;
                    string        Zeit;
                    Name  = Request.Form["anlassname"];
                    Datum = DateTime.Parse(Request.Form["anlassdatum"].Split(' ')[0]);
                    Zeit  = Request.Form["anlassdatum"].Split(' ')[1];

                    SQLInterface SI = new SQLInterface(Base.DSN.ADMIN);
                    SI.Exec(@"INSERT INTO [Anlass]
                        ([AnlassID],[Name],[Datum],[Zeit])
                        VALUES(?,?,?,?)",
                            AnlassID, Name, Datum, Zeit);
                    SQLRow[] RR = EI.ExecReader("SELECT * FROM [" + Table + "]");
                    foreach (SQLRow R in RR)
                    {
                        string   nachname = Base.ToString(R[Request.Form["nachname"]], string.Empty).Trim();
                        string   vorname  = Base.ToString(R[Request.Form["vorname"]], string.Empty).Trim();
                        string   svnr     = Base.ToString(R[Request.Form["svnr"]], string.Empty).Trim();
                        string   datum    = Base.ToString(R[Request.Form["datum"]], string.Empty).Trim();
                        DateTime gebdatum = DateTime.MinValue;

                        if (R[Request.Form["datum"]] is DateTime)
                        {
                            gebdatum = (DateTime)R[Request.Form["datum"]];
                        }
                        else
                        {
                            int tempdate = 0;
                            //excel date is sometimes in days
                            if (int.TryParse(datum, out tempdate))
                            {
                                //excel date is wrong by two days (therefore -2)
                                gebdatum = new DateTime(1900, 1, 1, 0, 0, 0).AddDays(tempdate - 2);
                                if (gebdatum.Ticks >= DateTime.Now.Ticks || tempdate == 0)
                                {
                                    ++errcount;
                                    SB.AppendFormat("Ungültiges Geburtsdatum beim Import des Soldaten mit nr.: {0}. Datum: {1}\r\n", svnr, datum);
                                    continue;
                                }
                            }
                            else if (!DateTime.TryParse(datum, out gebdatum) ||                         //ungültiges format
                                     gebdatum.Ticks >= DateTime.Now.Ticks ||                            //datum in der Zukunft
                                     gebdatum.Ticks == DateTime.MinValue.Ticks)                         //Datum nicht gesetzt
                            {
                                ++errcount;
                                SB.AppendFormat("Ungültiges Geburtsdatum beim Import des Soldaten mit nr.: {0}\r\n", svnr);
                                continue;
                            }
                        }
                        if (!IsValid(vorname, nachname, svnr))
                        {
                            ++errcount;
                            SB.AppendFormat("Ungültige Angaben beim Import des Soldaten mit nr.: {0}\r\n", svnr);
                            continue;
                        }


                        if (Base.SoldatExists((string)R[Request.Form["svnr"]], SI))
                        {
                            //Soldat auf neuen Anlass eintragen
                            Guid SoldatID = (Guid)SI.ExecReader("SELECT SoldatID FROM Soldat WHERE SVNummer=?", svnr)[0][0];
                            if (SI.Exec("UPDATE Soldat SET AnlassID=? WHERE SoldatID=?", AnlassID, SoldatID) < 0 ||
                                SI.Exec("UPDATE SoldatAntwort SET AnlassID=? WHERE SoldatID=?", AnlassID, SoldatID) < 0)
                            {
                                ++errcount;
                                SB.AppendFormat("Fehlerhafter Datensatz beim Import des Soldaten mit nr.: {0}\r\n", svnr);
                            }
                            else
                            {
                                SB.AppendFormat("Existierenden Soldat auf neuen Anlass eingetragen. Soldat: {0} {1}\r\n", vorname, nachname);
                            }
                        }
                        else
                        {
                            //Soldat erfassen
                            if (
                                SI.Exec("INSERT INTO Soldat (SoldatID,Vorname,Nachname,SVNummer,Geburtsdatum,AnlassID) VALUES(NEWID(),?,?,?,?,?)",
                                        vorname,
                                        nachname,
                                        svnr,
                                        gebdatum,
                                        AnlassID) < 1)
                            {
                                ++errcount;
                                SB.AppendFormat("Fehlerhafter Datensatz beim Import des Soldaten mit nr.: {0}\r\n", svnr);
                            }
                            else
                            {
                                SB.AppendFormat("Soldat erfasst: {0} {1}\r\n", vorname, nachname);
                            }
                        }
                    }
                    SB.AppendFormat("Anzahl Fehler: {0}", errcount);
                    Log = Server.HtmlEncode(SB.ToString());
                    SI.Dispose();
                    EI.Dispose();
                    try
                    {
                        Base.DelExcel(Server.MapPath("/temp/"));
                    }
                    catch
                    {
                    }
                }
                else
                {
                    Response.Redirect(string.Format("New2.aspx?err=2&ID={0}&anlass={1}&datum={2}",
                                                    Server.UrlEncode(Request.Form["ID"]),
                                                    Server.UrlEncode(Request.Form["anlassname"]),
                                                    Server.UrlEncode(Request.Form["anlassdatum"]))
                                      );
                }
            }
            else
            {
                Response.Redirect("New.aspx?err=2");
            }
        }
        else
        {
            Response.Redirect("New2.aspx?err=1&ID=" + Server.UrlEncode(Request.Form["ID"]));
        }
    }