Esempio n. 1
0
        private string GenerateIdString()
        {
            if (!(_idString is null))
            {
                return(_idString);
            }
            var sb = new StringBuilder();

            var bits = DataPath.Split(Strings.Separator) ?? Array.Empty <string>();

            if (bits.Length < 1)
            {
                _idString = Name; return(_idString);
            }

            sb.Append(Root);
            for (var i = 1; i < bits.Length; i++)
            {
                sb.Append('-');
                sb.Append(HtmlIdSafe(bits[i]));
            }

            _idString = sb.ToString();
            return(_idString);
        }
Esempio n. 2
0
        /// <summary>
        /// Copy view model values into an existing index file (to perform an update)
        /// </summary>
        public void CopyTo(TemplateProject targetTemplateProject)
        {
            if (BoxKey is null)
            {
                return;
            }
            if (PageIndex < 0 || PageIndex >= targetTemplateProject.Pages.Count)
            {
                return;
            }

            var thePage = targetTemplateProject.Pages[PageIndex];
            var theBox  = thePage.Boxes[BoxKey];

            // First, handle renaming of box key
            if (string.IsNullOrWhiteSpace(BoxName))
            {
                BoxName = BoxKey;
            }
            else
            {
                BoxName = Strings.CleanKeyName(BoxName);
            }
            if (BoxKey != BoxName)
            {
                BoxKey = RenameOperations.RenamePageBox(thePage, BoxKey, BoxName);
            }

            // Handle depends-on links
            if (string.IsNullOrWhiteSpace(DependsOn))
            {
                theBox.DependsOn = null;
            }
            else if (EditChecks.NotCircular(thePage, DependsOn, BoxKey))
            {
                theBox.DependsOn = DependsOn;
            }

            // Handle the display properties
            if (string.IsNullOrWhiteSpace(DisplayFormatJsonStruct))
            {
                theBox.DisplayFormat = null;
            }
            else
            {
                theBox.DisplayFormat = SkinnyJson.Json.Defrost <DisplayFormatFilter>(DisplayFormatJsonStruct);
            }

            // Now copy across the regular values
            theBox.Alignment   = TextAlign;
            theBox.BoxOrder    = ParseIntOrDefault(ProcessingOrder, null);
            theBox.MappingPath = string.IsNullOrWhiteSpace(DataPath) ? null : DataPath?.Split('.');
            theBox.WrapText    = WrapText;
            theBox.ShrinkToFit = ShrinkToFit;
            theBox.IsRequired  = IsRequired;
            theBox.BoxFontSize = ParseIntOrDefault(FontSize, theBox.BoxFontSize);
            theBox.Notes       = Notes;
        }
        public bool DataRestore(string BackupFile, bool Data = true, bool TransactionLog = false)
        {
            string DataName, LogName, DataPath, LogPath, DBName;

            try
            {
                DataName = LogPath = LogName = DataPath = string.Empty;
                using (SqlConnection conn = new SqlConnection(GlobalClass.DataConnectionString))
                {
                    conn.Open();
                    DBName = conn.Database;
                    conn.ChangeDatabase("Master");

                    using (SqlCommand cmd = conn.CreateCommand())
                    {
                        IEnumerable <string> pids = conn.Query <string>("SELECT CAST(SPID AS VARCHAR(3)) FROM SYSPROCESSES S JOIN SYSDATABASES D ON S.dbid = D.dbid WHERE D.name = '" + DBName + "'");
                        foreach (string spid in pids)
                        {
                            conn.Execute("KILL " + spid);
                        }
                        if (Data)
                        {
                            cmd.CommandText = "RESTORE FILELISTONLY FROM Disk='" + BackupFile + "'";
                            SqlDataReader dr = cmd.ExecuteReader();
                            while (dr.Read())
                            {
                                if (dr["Type"].ToString() == "D")
                                {
                                    DataName = dr["LogicalName"].ToString();
                                    DataPath = dr["PhysicalName"].ToString();
                                    DataPath = DataPath.Replace(DataPath.Split('\\').Last(), string.Empty);
                                }
                                else
                                {
                                    LogName = dr["LogicalName"].ToString();
                                    LogPath = dr["PhysicalName"].ToString();
                                    LogPath = LogPath.Replace(LogPath.Split('\\').Last(), string.Empty);
                                }
                            }
                            dr.Close();

                            cmd.CommandText = @"RESTORE DATABASE " + DBName + " FROM Disk='" + BackupFile + @"' WITH REPLACE,
                                                     MOVE '" + DataName + "' TO '" + DataPath + DBName + @".mdf',
                                                    MOVE '" + LogName + "' TO '" + LogPath + DBName + ".ldf';";
                            cmd.ExecuteNonQuery();
                        }
                        else
                        {
                            cmd.CommandText = "RESTORE LOG " + DBName + " FROM DISK = '" + BackupFile + "' WITH REPLACE";
                            cmd.ExecuteNonQuery();
                        }
                    }
                }
                MessageBox.Show("Database restore successfully completed.", "Data Restore", MessageBoxButton.OK, MessageBoxImage.Information);
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(GlobalClass.GetRootException(ex).Message, "Data Restore", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
        }