Esempio n. 1
0
        private void mnu_ImportUser_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                MessageBoxResult result = MessageBox.Show("Do you want to update the PROJECT MATERIALS based on the DEFAULT USER MATERIALS?" + Environment.NewLine +
                                                          "Materials with IDENTICAL names will be OVERWRITTEN, NON-EXISTING  materials will be ADDED", "Warning", MessageBoxButton.YesNo);

                if (result == MessageBoxResult.Yes)
                {
                    string        name   = "db\\UserMaterials";
                    CarboDatabase buffer = UserMaterials.DeSerializeXML(name);

                    bool syncResult = UserMaterials.SyncMaterials(buffer);

                    if (syncResult == true)
                    {
                        buffer.SerializeXML(name);
                        Utils.WriteToLog("Database saved to: " + name);
                        MessageBox.Show("Dataset saved");
                    }
                }
                else
                {
                    MessageBox.Show("Dataset not saved");
                    Utils.WriteToLog("Database not saved");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Utils.WriteToLog(ex.Message);
            }
            RefreshTable();
        }
        private void Mnu_UpdateUserMaterials(object sender, RoutedEventArgs e)
        {
            string name = "";

            //Get the profile from a cvs:
            try
            {
                MessageBoxResult result = MessageBox.Show("Do you want to update the base set of usermaterials based on these project settings ?" + Environment.NewLine +
                                                          "Materials with excact same names will be overwritten", "Warning", MessageBoxButton.YesNo);

                if (result == MessageBoxResult.Yes)
                {
                    OpenFileDialog openFileDialog = new OpenFileDialog();
                    openFileDialog.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*";

                    var      path  = openFileDialog.ShowDialog();
                    FileInfo finfo = new FileInfo(openFileDialog.FileName);
                    if (openFileDialog.FileName != "")
                    {
                        name = openFileDialog.FileName;

                        CarboDatabase buffer = UserMaterials.DeSerializeXML(name);

                        bool syncResult = UserMaterials.SyncMaterials(buffer);

                        if (syncResult == true)
                        {
                            buffer.SerializeXML(name);
                            Utils.WriteToLog("Database saved to: " + name);
                            MessageBox.Show("Dataset saved");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        private void btn_SyncFrom_Click(object sender, RoutedEventArgs e)
        {
            if (liv_TemplateMaterials.SelectedItems.Count > 0)
            {
                try
                {
                    MessageBoxResult result = System.Windows.MessageBox.Show("Do you want to update the project materials  with the selected materials from the template?" + Environment.NewLine +
                                                                             "Materials with excact same name will be overwritten, others will be added to the project", "Warning", MessageBoxButton.YesNo);

                    if (result == MessageBoxResult.Yes)
                    {
                        CarboDatabase buffer = new CarboDatabase();

                        foreach (object item in liv_TemplateMaterials.SelectedItems)
                        {
                            CarboMaterial cm = item as CarboMaterial;
                            if (cm != null)
                            {
                                buffer.AddMaterial(cm);
                            }
                        }
                        projectDatabase.SyncMaterials(buffer);
                    }
                }
                catch (Exception ex)
                {
                    System.Windows.MessageBox.Show(ex.ToString());
                }
            }
            else
            {
                MessageBoxResult result = System.Windows.MessageBox.Show("Please select a material to syncronise", "Computer says no", MessageBoxButton.YesNo);
            }

            refreshTemplateMaterials();
            refreshProjectMaterials();
        }