private void BtnDelete_Clicked(object sender, EventArgs e)
        {
            if (bIsRemote)
            {

            }
            else
            {
                string szProjectName = (sender as Button).CommandParameter.ToString();

                Overlay overlay = new Overlay(grdOverlay);
                overlay.ShowQuestion("Soll das Projekt " + szProjectName + " gelöscht werden?", () => {
                    ProjectSql tmpProject = new ProjectSql(szProjectName);
                    if(tmpProject.GetBilderChanged().Count > 0 )
                    {
                        overlay.ShowQuestion("Das Projekt " + szProjectName + " wurde nicht nicht gesichert." + Environment.NewLine +"Soll es trotzdem gelöscht werden?", () =>
                        {
                            DeleteProject(false,szProjectName);
                        });
                    }
                    else
                    {
                        DeleteProject(false,szProjectName);
                    }
                });
            }
        }
        private void LstProjects_ItemTapped(object sender, ItemTappedEventArgs e)
        {
            if (lstProjects.SelectedItem != null)
            {
                string szProjectName = lstProjects.SelectedItem.ToString();
                if (bIsRemote && !FlagToBoolean.bIsConnectedToSend)
                {
                    if (  ProjectSql.DbExists(szProjectName) )
                    {
                        ProjectSql tmpProject = new ProjectSql(szProjectName);
                        if(tmpProject.IsDirty())
                        {
                            Overlay overlay = new Overlay(grdOverlay);
                            overlay.ShowMessage("Das Projekt enthält geänderte Daten, die noch nicht gesichert wurden.");
                        }
                        else
                        {
                            DownloadProject(szProjectName);
                        }
                    }
                    else
                    {
                        DownloadProject(szProjectName);
                    }
                }
                else if( bIsRemote && FlagToBoolean.bIsConnectedToSend)
                {
                    Overlay overlay = new Overlay(grdOverlay);
                    overlay.ShowRunMessage("Versuche das Projekt " + szProjectName + " an den Server " + Config.current.szIP + " zu senden ...");

                    Task.Run(async () =>
                    {
                        SetStatusLine("");
                        await SendProjectAsync(szProjectName, (bFinished, bError, szStr) =>
                        {
                            /* bFinished == true the sending is completed
                             * bError == true an error occured
                             * szStr   the message or error text
                             */
                            if (bFinished)
                            {
                                // the overlay does not have the cancel X, so we have to close it here
                                Device.BeginInvokeOnMainThread(() =>
                                {
                                    overlay.Close();
                                });
                            }
                            AddStatusLine(szStr);
                        });
                    });

                }
                else if( !bIsRemote )
                {
                    XCamera.Util.Config.current.szCurProject = lstProjects.SelectedItem.ToString();
                    Navigation.PushAsync(new MainPage());
                }
            }
        }
        private void BtnOk_Click(object sender, RoutedEventArgs e)
        {
            if (tbNewDbSuffix.Text == tbOldDbSuffix.Text && tbNewPicSuffix.Text == tbOldPicSuffix.Text)
            {
                MessageBox.Show("Eingebene Suffixe sind identisch!");
            }
            else
            {
                Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;

                var projekte = ProjectUtil.GetProjectList();
                foreach (var projekt in projekte)
                {
                    ((MainWindow)Application.Current.MainWindow).ToLog("moving " + projekt);
                    string oldDbPath = Path.Combine(ProjectUtil.szBasePath, projekt, tbOldDbSuffix.Text);
                    string newDbPath = Path.Combine(ProjectUtil.szBasePath, projekt, tbNewDbSuffix.Text);
                    if (File.Exists(Path.Combine(oldDbPath, projekt + ".db")))
                    {
                        if (!(tbNewDbSuffix.Text == tbOldDbSuffix.Text))
                        {
                            MoveFile(projekt + ".db", oldDbPath, newDbPath);
                        }
                        ProjectSql tmpProject = new ProjectSql(projekt, tbNewDbSuffix.Text);
                        if (!(tbNewPicSuffix.Text == tbOldPicSuffix.Text))
                        {
                            List <Bild> bildListe = tmpProject.GetBilder(null, null);
                            foreach (var bild in bildListe)
                            {
                                string oldPath = Path.Combine(Config.current.szBasedir, projekt, tbOldPicSuffix.Text);
                                string newPath = Path.Combine(Config.current.szBasedir, projekt, tbNewPicSuffix.Text);
                                MoveFile(bild.Name, oldPath, newPath);
                            }
                        }
                    }
                    else
                    {
                        ((MainWindow)Application.Current.MainWindow).ToLog("Database " + Path.Combine(oldDbPath, projekt + ".db") + " existiert nicht");
                    }
                }

                if (Config.current.szDbSuffix != tbNewDbSuffix.Text)
                {
                    Config.current.szDbSuffix = tbNewDbSuffix.Text;
                }
                if (Config.current.szPicSuffix != tbNewPicSuffix.Text)
                {
                    Config.current.szPicSuffix = tbNewPicSuffix.Text;
                }

                Mouse.OverrideCursor = null;
                if (MessageBox.Show("Daten erfolgreich verschoben.") == MessageBoxResult.OK)
                {
                    Close();
                }
            }
        }
 public ManageWindow(ProjectSql projectSql)
 {
     InitializeComponent();
     cmbTable.Items.Clear();
     cmbTable.Items.Add("Gebäude");
     cmbTable.Items.Add("Wohnung");
     cmbTable.Items.Add("Etage");
     cmbTable.Items.Add("Zimmer");
     cmbTable.Items.Add("Kommentar");
     this.projectSql = projectSql;
 }
Exemple #5
0
        public MainPage()
        {
            InitializeComponent();
            this.Resources.Add(StyleSheet.FromAssemblyResource(
                                   IntrospectionExtensions.GetTypeInfo(typeof(MainPage)).Assembly,
                                   "XCamera.Resources.styles.css"));

            curProjectSql = new ProjectSql(XCamera.Util.Config.current.szCurProject);

            btnTakePhoto.Clicked += btnTakePhoto_Clicked;
            btnPickPhoto.Clicked += btnPickPhoto_Clicked;
        }
        public ImageEditWindow(ProjectSql projectSql, BildMitKommentar bmk = null, bool newImage = false)
        {
            this.bmk        = bmk;
            this.projectSql = projectSql;
            this.newImage   = newImage;

            InitializeComponent();
            this.Closing += InputWindow_Closing;

            if (newImage == true)
            {
                this.Title = "Neues Bild hinzufügen";

                //imgNewImage.Source = new BitmapImage(new Uri(bmk.BildPath));

                image = new BitmapImage();
                image.BeginInit();
                image.CacheOption = BitmapCacheOption.OnLoad;
                image.UriSource   = new Uri(bmk.BildPath);
                image.EndInit();
                imgNewImage.Source = image;
            }
            else
            {
                this.Title = "Bilddaten editieren";
            }

            cmbGebaeude.ItemsSource = null;
            cmbGebaeude.ItemsSource = projectSql.sqlGebaeude.GetListe();

            cmbEtage.ItemsSource = null;
            cmbEtage.ItemsSource = projectSql.sqlEtage.GetListe();

            cmbWohnung.ItemsSource = null;
            cmbWohnung.ItemsSource = projectSql.sqlWohnung.GetListe();

            cmbZimmer.ItemsSource = null;
            cmbZimmer.ItemsSource = projectSql.sqlZimmer.GetListe();

            if (bmk != null && bmk.BildInfo != null) // && !newImage
            {
                cmbGebaeude.SelectedValue = bmk.BildInfo.GebaeudeId;
                cmbEtage.SelectedValue    = bmk.BildInfo.EtageId;
                cmbWohnung.SelectedValue  = bmk.BildInfo.WohnungId;
                cmbZimmer.SelectedValue   = bmk.BildInfo.ZimmerId;
                tbKommentar.Text          = bmk.BildInfo.KommentarBezeichnung;
                if (bmk.BildInfo.CaptureDate != DateTime.MinValue)
                {
                    dpCaptureDate.SelectedDate = bmk.BildInfo.CaptureDate;
                }
            }
        }
 private void DeleteProject(Boolean bForce,string szProjectName)
 {
         string szDelRet = ProjectSql.Delete(bForce, szProjectName);
         if (string.IsNullOrWhiteSpace(szDelRet))
         {
             lblStatus.Text = "";
             projects.Remove(szProjectName);
             lstProjects.ItemsSource = null;
             lstProjects.ItemsSource = projects;
         }
         else
         {
             lblStatus.Text = szDelRet;
         }
 }
        // private void DownloadProject
        private async Task SendProjectAsync(string szProjectName, Action<Boolean, Boolean, string> cb)
        {
            if (projects.Any(proj => { return proj.Equals(szProjectName); }))
            {
                // ToDo: open the overlay with the server settings
                // here we expect the current settings to be correct.
                cb(false, false, "sende Projekt " + szProjectName);
                ProjectSql tmpProject = new ProjectSql(szProjectName);
                List<Bild> bilder =  tmpProject.GetBilderChanged();
                Boolean bError = false;
                // send all changed images
                cb(false, false, "sende " + bilder.Count.ToString() + " Bilder");
                foreach (var bild in bilder)
                {
                    cb(false, false, "sende " + bild.Name);
                    bError = ! await ProjectUtil.SendFileAsync(szProjectName, Path.GetFileName(bild.Name));
                    if( bError)
                    {
                        break;
                    }
                }
                if (!bError)
                {
                    // send all changed data
                    foreach (var bild in bilder)
                    {
                        cb(false, false, "sende geänderte Daten für " + bild.Name);

                        BildInfo bi = tmpProject.GetBildInfo(bild.Name, DateTime.Now);

                        string szJson = Newtonsoft.Json.JsonConvert.SerializeObject(bi);
                        if (await ProjectUtil.SendJsonAsync(szProjectName, szJson))
                        {
                            tmpProject.ClearStatus(bild.ID, STATUS.CHANGED);
                        }

                    }
                }
                string szMessage = "";
                if( bError)
                {
                    szMessage = "Es gab einen internen Fehler.";
                }
                cb(true, bError, szMessage);

            }
        }
        public wsResponse SendResponse(HttpListenerRequest request)
        {
            Dictionary <string, string> postParams = new Dictionary <string, string>();
            wsResponse swRes = new wsResponse();

            string szProjectname = "";
            string szFilename    = "";
            string szHasJson     = "";

            if (request.QueryString["project"] != null)
            {
                szProjectname = request.QueryString["project"].ToString();
            }
            if (request.QueryString["file"] != null)
            {
                szFilename = request.QueryString["file"].ToString();
            }
            if (request.QueryString["json"] != null)
            {
                szHasJson = request.QueryString["json"].ToString();
            }

            swRes.ba = Encoding.UTF8.GetBytes("{}");
            if (request.HttpMethod.Equals("POST", StringComparison.InvariantCultureIgnoreCase))
            {
                if (string.IsNullOrEmpty(szProjectname))
                {
                    JsonError je = new JsonError {
                        szMessage = "POST requires a project "
                    };
                    ShowError(je.szMessage);

                    string szJson = Newtonsoft.Json.JsonConvert.SerializeObject(je);
                    swRes.ba         = Encoding.UTF8.GetBytes(szJson);
                    swRes.szMinetype = "text/json";
                }
                else if (string.IsNullOrEmpty(szHasJson) && string.IsNullOrEmpty(szFilename))
                {
                    JsonError je = new JsonError {
                        szMessage = "POST requires both project and file "
                    };
                    ShowError(je.szMessage);

                    string szJson = Newtonsoft.Json.JsonConvert.SerializeObject(je);
                    swRes.ba         = Encoding.UTF8.GetBytes(szJson);
                    swRes.szMinetype = "text/json";
                }
                else if (!string.IsNullOrEmpty(szHasJson))
                {
                    string szJson = "";
                    System.Text.Encoding encoding = request.ContentEncoding;
                    using (StreamReader sr = new StreamReader(request.InputStream, encoding))
                    {
                        szJson = sr.ReadToEnd();
                    }
                    request.InputStream.Close();
                    try
                    {
                        BildInfo bi = Newtonsoft.Json.JsonConvert.DeserializeObject <BildInfo>(szJson);
                        if (bi.CaptureDate == null)
                        {
                            bi.CaptureDate = DateTime.Now;
                        }
                        ProjectSql tmpProject = new ProjectSql(szProjectname, Config.current.szDbSuffix);
                        var        biResult   = tmpProject.GetBildId(bi.BildName, bi.CaptureDate);
                        tmpProject.SetCaptureDate(biResult.BildId, bi.CaptureDate);

                        Gebaeude gebauede = tmpProject.sqlGebaeude.Ensure(bi.GebaeudeBezeichnung) as Gebaeude;
                        Etage    etage    = tmpProject.sqlEtage.Ensure(bi.EtageBezeichnung) as Etage;
                        Wohnung  wohnung  = tmpProject.sqlWohnung.Ensure(bi.WohnungBezeichnung) as Wohnung;
                        Zimmer   zimmer   = tmpProject.sqlZimmer.Ensure(bi.ZimmerBezeichnung) as Zimmer;
                        if (gebauede != null)
                        {
                            tmpProject.sqlGebaeude.Set(biResult.BildId, gebauede.ID);
                        }
                        if (etage != null)
                        {
                            tmpProject.sqlEtage.Set(biResult.BildId, etage.ID);
                        }
                        if (wohnung != null)
                        {
                            tmpProject.sqlWohnung.Set(biResult.BildId, wohnung.ID);
                        }
                        if (zimmer != null)
                        {
                            tmpProject.sqlZimmer.Set(biResult.BildId, zimmer.ID);
                        }
                        tmpProject.SetComment(biResult.BildId, bi.KommentarBezeichnung);
                    }
                    catch (Exception ex)
                    {
                        JsonError je = new JsonError {
                            szMessage = "POST " + ex.ToString()
                        };
                        ShowError(je.szMessage);

                        string szErrJson = Newtonsoft.Json.JsonConvert.SerializeObject(je);
                        swRes.ba         = Encoding.UTF8.GetBytes(szErrJson);
                        swRes.szMinetype = "text/json";
                    }
                }
                else
                {
                    try
                    {
                        string szFullPath = System.IO.Path.Combine(XCamera.Util.Config.current.szBasedir, szProjectname, Config.current.szPicSuffix);
                        if (!Directory.Exists(szFullPath))
                        {
                            Directory.CreateDirectory(szFullPath);
                        }
                        string szFullFilename = System.IO.Path.Combine(szFullPath, szFilename);
                        ShowInfo("recieving " + szFullFilename);

                        using (FileStream fs = new FileStream(szFullFilename, FileMode.Create, FileAccess.Write))
                        {
                            request.InputStream.CopyTo(fs);
                        }
                        request.InputStream.Close();
                        ProjectSql tmpProject = new ProjectSql(szProjectname, Config.current.szDbSuffix);
                        tmpProject.AddBild(szFilename);
                    }
                    catch (Exception ex)
                    {
                        JsonError je = new JsonError {
                            szMessage = "POST " + ex.ToString()
                        };
                        ShowError(je.szMessage);

                        string szJson = Newtonsoft.Json.JsonConvert.SerializeObject(je);
                        swRes.ba         = Encoding.UTF8.GetBytes(szJson);
                        swRes.szMinetype = "text/json";
                    }
                }
            }
            else
            {
                if (string.IsNullOrEmpty(szProjectname))
                {
                    ShowInfo("sending project list");
                    string[]           szProjects = Directory.GetDirectories(XCamera.Util.Config.current.szBasedir, "*.", SearchOption.TopDirectoryOnly);
                    List <JsonProject> jProjects  = new List <JsonProject>();
                    foreach (var szProject in szProjects)
                    {
                        jProjects.Add(new JsonProject {
                            szProjectName = System.IO.Path.GetFileNameWithoutExtension(szProject),
                            lSize         = GetDirectorySize(0, System.IO.Path.Combine(XCamera.Util.Config.current.szBasedir, szProject))
                        });
                    }

                    string szJson = Newtonsoft.Json.JsonConvert.SerializeObject(jProjects);
                    swRes.ba         = Encoding.UTF8.GetBytes(szJson);
                    swRes.szMinetype = "text/json";
                }
                else if (!string.IsNullOrWhiteSpace(szFilename))
                {
                    string szFullFilename = System.IO.Path.Combine(XCamera.Util.Config.current.szBasedir, szProjectname, szFilename);
                    ShowInfo("sending  " + szFullFilename);
                    if (File.Exists(szFullFilename))
                    {
                        if (System.IO.Path.GetExtension(szFullFilename).Equals(".jpg", StringComparison.InvariantCultureIgnoreCase))
                        {
                            swRes.ba         = System.IO.File.ReadAllBytes(szFullFilename);
                            swRes.szMinetype = "image/jpeg";
                        }
                        else
                        {
                            // swRes.szMinetype = "Application/x-sqlite3";
                            ProjectSql tmpProject = new ProjectSql(szProjectname);
                            var        metaData   = tmpProject.GetMetaData();
                            string     szJson     = Newtonsoft.Json.JsonConvert.SerializeObject(metaData);
                            swRes.ba         = Encoding.UTF8.GetBytes(szJson);
                            swRes.szMinetype = "text/json";
                        }
                    }
                    else
                    {
                        JsonError je = new JsonError {
                            szMessage = "File not found " + szFullFilename
                        };
                        ShowError(je.szMessage);
                        string szJson = Newtonsoft.Json.JsonConvert.SerializeObject(je);
                        swRes.ba         = Encoding.UTF8.GetBytes(szJson);
                        swRes.szMinetype = "text/json";
                    }
                }
                else if (!string.IsNullOrEmpty(szProjectname))
                {
                    ShowInfo("sending project info " + szProjectname);
                    List <JsonProject> jProjects = new List <JsonProject>();

                    jProjects.Add(new JsonProject
                    {
                        szProjectName = System.IO.Path.GetFileNameWithoutExtension(szProjectname),
                        lSize         = GetDirectorySize(0, System.IO.Path.Combine(XCamera.Util.Config.current.szBasedir, szProjectname))
                    });


                    string szJson = Newtonsoft.Json.JsonConvert.SerializeObject(jProjects);
                    swRes.ba         = Encoding.UTF8.GetBytes(szJson);
                    swRes.szMinetype = "text/json";
                }
            }

            return(swRes);
        }