| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 | namespace PRSDesktop{}//class CoreAttributeGrid<T> : DynamicEnclosedListGrid<T,CoreAttribute> where T : Entity, IRemotable, IPersistent, new()//{//    public CoreTable Schedules { get; set; }//    public CoreAttributeGrid(PropertyInfo prop) : base(prop)//    {//        Options = new DynamicGridOptions[] { DynamicGridOptions.RecordCount, DynamicGridOptions.AddRows, DynamicGridOptions.EditRows, DynamicGridOptions.DeleteRows, DynamicGridOptions.SelectColumns, DynamicGridOptions.MultiSelect };//        HiddenColumns.Add(x => x.Name);//        HiddenColumns.Add(x => x.Value);//        AddButton("Export", PRSDesktop.Resources.download.AsBitmapImage(), SaveAttributes);//        AddButton("Import", PRSDesktop.Resources.upload.AsBitmapImage(), LoadAttributes);//    }//    private bool LoadAttributes(Button sender, CoreRow[] rows)//    {//        var dlg = new Microsoft.Win32.OpenFileDialog();//        dlg.Filter = "PRS Attribute Files (*.attributes)|*.attributes";//        if (dlg.ShowDialog() == true)//        {//            Items.Clear();//            Progress.Show("");//            String json = File.ReadAllText(dlg.FileName);//            List<CoreAttribute> attributes = new List<CoreAttribute> { };//            try//            {//                attributes = Serialization.Deserialize<List<CoreAttribute>>(json);//            }//            catch (Exception e)//            {//                Progress.Close();//                MessageBox.Show("[" + Path.GetFileName(dlg.FileName) + "] is not a valid attributes file!");//                return false;//            }//            if (!attributes.Any())//            {//                Progress.Close();//                MessageBox.Show("[" + Path.GetFileName(dlg.FileName) + "] does not contain any attributes!");//                return false;//            }//            Items.AddRange(attributes);//            Progress.Close();//            MessageBox.Show(String.Format("{0} attributes loaded from [{1}]", attributes.Count, Path.GetFileName(dlg.FileName)));//        }//        return true;//    }//    /// <summary>//    /// Strip illegal chars and reserved words from a candidate filename (should not include the directory path)//    /// </summary>//    /// <remarks>//    /// http://stackoverflow.com/questions/309485/c-sharp-sanitize-file-name//    /// </remarks>//    private string CoerceValidFileName(string filename)//    {//        var invalidChars = Regex.Escape(new string(Path.GetInvalidFileNameChars()));//        var invalidReStr = string.Format(@"[{0}]+", invalidChars);//        var reservedWords = new[]//        {//            "CON", "PRN", "AUX", "CLOCK$", "NUL", "COM0", "COM1", "COM2", "COM3", "COM4",//            "COM5", "COM6", "COM7", "COM8", "COM9", "LPT0", "LPT1", "LPT2", "LPT3", "LPT4",//            "LPT5", "LPT6", "LPT7", "LPT8", "LPT9"//        };//        var sanitisedNamePart = Regex.Replace(filename, invalidReStr, "_");//        foreach (var reservedWord in reservedWords)//        {//            var reservedWordPattern = string.Format("^{0}\\.", reservedWord);//            sanitisedNamePart = Regex.Replace(sanitisedNamePart, reservedWordPattern, "_reservedWord_.", RegexOptions.IgnoreCase);//        }//        return sanitisedNamePart;//    }//    private bool SaveAttributes(Button sender, CoreRow[] rows)//    {            //        String filename = CoerceValidFileName(String.Format("{0} ({1})",typeof(T).EntityName().Split('.').Last(),Entity.ToString()));//        var dlg = new Microsoft.Win32.SaveFileDialog();//        dlg.Filter = "PRS Schedule Files (*.attributes)|*.attributes";//        dlg.FileName = filename + ".attributes";//        dlg.AddExtension = false;//        if (dlg.ShowDialog() == true)//        {//            string json = Serialization.Serialize(Items);//            File.WriteAllText(dlg.FileName, json);//            MessageBox.Show(String.Format("{0} attributes saved to [{1}]", Items.Count, Path.GetFileName(dlg.FileName)));//        }//        return false;//    }//}
 |