lab2
This commit is contained in:
parent
9c27b69e17
commit
78e2098513
25
CheckedListBoxLibrary/Components/testComponent.cs
Normal file
25
CheckedListBoxLibrary/Components/testComponent.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyUserControls.Components
|
||||
{
|
||||
public partial class testComponent : Component
|
||||
{
|
||||
public testComponent()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public testComponent(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyUserControls
|
||||
namespace MyUserControls.VisualComponents
|
||||
{
|
||||
public class ValueOutOfRangeException : Exception
|
||||
{
|
@ -1,65 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyUserControls.Components
|
||||
{
|
||||
public partial class testComponent : Component
|
||||
{
|
||||
public testComponent()
|
||||
{
|
||||
InitializeComponent();
|
||||
_fileName = string.Empty;
|
||||
}
|
||||
|
||||
public testComponent(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
InitializeComponent();
|
||||
_fileName = string.Empty;
|
||||
}
|
||||
|
||||
private string _fileName;
|
||||
public string FileName
|
||||
{
|
||||
set
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!value.EndsWith(".txt"))
|
||||
{
|
||||
throw new ArgumentException("No txt file");
|
||||
}
|
||||
_fileName = value;
|
||||
}
|
||||
}
|
||||
public bool SaveToFile(string[] texts)
|
||||
{
|
||||
CheckFileExsists();
|
||||
using var writer = new StreamWriter(_fileName, true);
|
||||
foreach (var text in texts)
|
||||
{
|
||||
writer.WriteLine(text);
|
||||
}
|
||||
writer.Flush();
|
||||
return true;
|
||||
}
|
||||
private void CheckFileExsists()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_fileName))
|
||||
{
|
||||
throw new ArgumentNullException(_fileName);
|
||||
}
|
||||
if (!File.Exists(_fileName))
|
||||
{
|
||||
throw new FileNotFoundException(_fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user