<TextBox Name="Box_110" ...>
<TextBox Tag="Box_110" ...>
<Setter Property="CommandParameter" Value="{Binding Path=PlacementTarget.Tag, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}" />
public void ContextMenuClick(object param)
{
if (int.TryParse(Convert.ToString(param), out int v))
{
StampDictionary.TextBoxes[v.ToString()].BoxValue = Name;
StampDictionary.TextBoxes[(v + 10).ToString()].BoxValue = Signature;
}
}
var test = JArray.Parse(json);
var count = // count = 125
test
.Single(j => j.Value<string>("name") == "facebook")
.Value<int>("count");
e1 with { identifier = e2, ... }
e1.With(identifier2: e2, ...)
OnPropertyChanged(nameof(TextBoxes));
OnPropertyChanged();
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName]string prop = "")
{
// ...
}
public class SomeClass
{
public int M { get { return Data.GetLength(1); } }
public int N { get { return Data.GetLength(0); } }
public double[,] Data { get; }
public SomeClass(double[,] data)
{
Data = new double[data.GetLength(0), data.GetLength(1)];
Array.Copy(data, Data, data.Length);
}
public double Sum()
{
var s = 0.0;
foreach (var x in Data)
s += x;
return s;
}
}
public class Item
{
public string Title { get; }
public SomeClass Data { get; }
public Item(string title, SomeClass sc)
{
Title = title;
if (sc != null)
Data = new SomeClass(sc.Data);
}
public override string ToString() => Title;
}
public void Fill(Item item)
{
label1.Text = item.Title;
if (item.Data != null)
{
var n = item.Data.N;
var m = item.Data.M;
textBox1.Text = n.ToString();
textBox2.Text = m.ToString();
dataGridView1.ColumnCount = m;
dataGridView1.RowCount = n;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
dataGridView1[j, i].Value = item.Data.Data[i, j];
}
else
{
textBox1.Text = "";
textBox2.Text = "";
dataGridView1.ColumnCount = 0;
dataGridView1.RowCount = 0;
}
}
public Item Extract()
{
string title = label1.Text;
if (string.IsNullOrWhiteSpace(title))
return null;
var n = dataGridView1.RowCount;
var m = dataGridView1.ColumnCount;
if (n == 0 || m == 0)
return new Item(title, null);
var data = new double[n, m];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
data[i, j] = Convert.ToDouble(dataGridView1[j, i].Value);
return new Item(title, new SomeClass(data));
}
ItemView iview;
BindingSource bs = new BindingSource()
{ DataSource = typeof(Item) };
public Form1()
{
InitializeComponent();
listBox1.DataSource = bs;
bs.PositionChanged += PositionChanged;
}
private void SaveCurrent()
{
var pr = iview.Extract();
if (pr != null)
{
var old = bs.List.OfType<Item>().First(v => v.Title == pr.Title);
var ind = bs.List.IndexOf(old);
bs[ind] = pr;
}
}
private void PositionChanged(object sender, EventArgs e)
{
if (bs.Current is Item item && bs.Count > 1)
{
SaveCurrent();
iview.Fill(item);
}
}
SaveCurrent();
var items = bs.OfType<Item>().Select(item => item.Data?.Sum() ?? -1);
resLbl.Text = string.Join(";", items);
var ts = new TimeSpan(10, 10, 10);
var rnd = new Random((int)ts.TotalMilliseconds);
for (int i = 0; i < 1; i++)
Console.WriteLine("{0,4}", rnd.Next(50, 501)); // 265
x = int.Parse(Console.ReadLine());
y = int.Parse(Console.ReadLine());
//z = int.Parse(Console.ReadLine());
Console.WriteLine(x);
Console.WriteLine("X", x);
Console.WriteLine("X: {0}", x);
Console.WriteLine($"Y: {y}", y);
int x = int.Parse(Console.ReadLine());
int y = int.Parse(Console.ReadLine());
if (x > y)
Console.WriteLine("X: {0}", x);
else
Console.WriteLine($"Y: {y}", y);
using MathNet.Symbolics;
using Expr = MathNet.Symbolics.SymbolicExpression;
...
Expr.Parse("1/(a*b"); // выбросит исключение
Expr.Parse("1/(a*b)").ToString(); // вернет строку "1/(a*b)"
module Model
type Student = {
Name : string
Surname : string
LastName : string
Phone : string
Faculty : string
}
[<RequireQualifiedAccess>]
type AccountType =
| Student of Student
| Enrollee of Enrollee
| Teacher of Teacher
[<RequireQualifiedAccess>]
module Defaults =
let student:Student = {
Name = ""
Surname = ""
LastName = ""
Phone = ""
Faculty = ""
}
[<RequireQualifiedAccess>]
module PdfReport
open Model
open PdfSharp.Drawing
open SharpLayout
let private defaultSettings =
PageSettings(
TopMargin=Util.Cm(1.2),
BottomMargin=Util.Cm(1.0),
LeftMargin=Util.Cm(2.0),
RightMargin=Util.Cm(1.0))
let private createReportForTeacher teacher =
let document = Document()
let section = document.Add(Section(defaultSettings))
let font =
Font("Times New Roman", 10.0, XFontStyle.Regular, XPdfFontOptions.UnicodeDefault)
|> Option
section.Add(Paragraph().Add("Информация об преподователе", font.Value).Alignment(HorizontalAlign.Center.AsOption().ToNullable())) |> ignore
let table = section.AddTable().Font font
let c1 = table.AddColumn(Util.Px(600.0))
let c2 = table.AddColumn(Util.Px(600.0))
let r1 = table.AddRow()
let r2 = table.AddRow()
let r3 = table.AddRow()
let r4 = table.AddRow()
let r5 = table.AddRow()
r1.[c1].Add(Paragraph().Add("Имя:")) |> ignore
r1.[c2].Add(Paragraph().Add(teacher.Name)) |> ignore
r2.[c1].Add(Paragraph().Add("Фамилия:")) |> ignore
r2.[c2].Add(Paragraph().Add(teacher.LastName)) |> ignore
r3.[c1].Add(Paragraph().Add("Отчество:")) |> ignore
r3.[c2].Add(Paragraph().Add(teacher.Surname)) |> ignore
r4.[c1].Add(Paragraph().Add("Телефон:")) |> ignore
r4.[c2].Add(Paragraph().Add(teacher.Phone)) |> ignore
r5.[c1].Add(Paragraph().Add("Факультет:")) |> ignore
r5.[c2].Add(Paragraph().Add(teacher.Faculty)) |> ignore
document
[<RequireQualifiedAccess>]
type NavMessages =
| Student
| Teacher
| Enrollee
let appComp =
Component.create<AppModel, NavMessages, Messages> [
<@ ctx.Model.Student @> |> Bind.comp (fun m -> m.Student) studentComp fst
<@ ctx.Model.Enrollee @> |> Bind.comp (fun m -> m.Enrollee) enrolleeComp fst
<@ ctx.Model.Teacher @> |> Bind.comp (fun m -> m.Teacher) teacherComp fst
<@ ctx.Model.Menu @> |> Bind.comp (fun m -> m.Menu) menuComponent fst
<@ ctx.SendReport @> |> Bind.cmd
]
let upd (nav : Dispatcher<NavMessages>) message model =
match message with
| Messages.SendReport ->
let v, m =
match model.Menu.Current with
| NavMessages.Enrollee ->
AccountType.Enrollee model.Enrollee, { model with Enrollee = Defaults.enrollee }
| NavMessages.Student ->
AccountType.Student model.Student, { model with Student = Defaults.student }
| NavMessages.Teacher ->
AccountType.Teacher model.Teacher, { model with Teacher = Defaults.teacher }
v
|> PdfReport.createReport
|> PdfReport.saveReport "test.pdf"
|> PdfReport.sendReport
m
| Messages.SetCurrent current ->
current |> nav.Dispatch
{ model with Menu = { model.Menu with Current = current }}
| Messages.UpdateEnrollee msg ->
{ model with Enrollee = EnrolleeComponent.update model.Enrollee msg }
| Messages.UpdateStudent msg ->
{ model with Student = StudentComponent.update model.Student msg }
| Messages.UpdateTeacher msg ->
{ model with Teacher = TeacherComponent.update model.Teacher msg }
open Gjallarhorn.Bindable.Framework
let applicationCore nav =
let navigation = Dispatcher<NavMessages>()
Framework.application init (upd navigation) appComp nav
|> Framework.withNavigation navigation
public string ShortFormat()
{
return string.Format("{0,15} {1} {2}", Name, BirthDay.ToShortDateString(), GroupName);
}
public override string ToString()
{
StringBuilder sb = new StringBuilder(ShortFormat());
sb.AppendLine("\nОценки:");
foreach (var m in Marks)
sb.AppendFormat("{0} - {1}\n", m.Key, m.Value);
return sb.ToString();
}
public bool HasDebt => Marks.ContainsValue(2);
switch (menu)
{
case 1:
foreach (var student in students)
Console.WriteLine(student);
break;
case 2:
foreach (var student in students.Where(s => s.HasDebt))
Console.WriteLine(student.ShortFormat());
break;
}
Array.Copy(numbs, numbs2, numbs.Length);
for (int i = 0, z = 0; i < numbs2.GetLength(0); i++)
{
for (int j = 0; j < numbs2.GetLength(1); j++)
{
numbs2[i, j] = numbs[j, i];
Console.Write(numbs2[i, j] + " ");
}
Console.WriteLine();
}
Заданы три функции y1=x^3, y2=x^3+1, y3= 1/(1+x^2). Определить, являются ли эти функции четными или нечетными.
Определить четность функций.
Нечётными и чётными называются функции, обладающие симметрией относительно изменения знака аргумента.
public enum FuncType { Odd, Even, Unknown };
Func<double, FuncType> isEven = v =>
{
var y1 = func(v);
var y2 = func(-v);
if (y1 == y2)
return FuncType.Even;
if (y1 == -y2)
return FuncType.Odd;
return FuncType.Unknown;
};
Func<FuncType, FuncType, FuncType> add = (v1, v2) =>
{
if (v1 == v2) return v2;
return FuncType.Unknown;
};
var funcType = isEven(a);
if (funcType == FuncType.Unknown)
return FuncType.Unknown;
for (double x = a + step; x <= b; x += step)
{
var funcTypeNext = isEven(x);
funcType = add(funcType, funcTypeNext);
if (funcType == FuncType.Unknown)
return FuncType.Unknown;
}
public static FuncType IsEvenFunction(Func<double, double> func, double a, double b, double step)
{
Func<double, FuncType> isEven = v =>
{
var y1 = func(v);
var y2 = func(-v);
if (y1 == y2)
return FuncType.Even;
if (y1 == -y2)
return FuncType.Odd;
return FuncType.Unknown;
};
Func<FuncType, FuncType, FuncType> add = (v1, v2) =>
{
if (v1 == v2) return v2;
return FuncType.Unknown;
};
var funcType = isEven(a);
if (funcType == FuncType.Unknown)
return FuncType.Unknown;
for (double x = a + step; x <= b; x += step)
{
var funcTypeNext = isEven(x);
funcType = add(funcType, funcTypeNext);
if (funcType == FuncType.Unknown)
return FuncType.Unknown;
}
return funcType;
}
Func<double, double> fn1 = x => x * x * x;
Func<double, double> fn2 = x => x * x * x + 1;
Func<double, double> fn3 = x => 1 / (1 + x * x);
Console.WriteLine("Fn1: {0}", IsEvenFunction(fn1, 1, 10, 0.01));
Console.WriteLine("Fn2: {0}", IsEvenFunction(fn2, 1, 10, 0.01));
Console.WriteLine("Fn3: {0}", IsEvenFunction(fn3, 1, 10, 0.01));
public static void ClearPayment()
{
Console.Write("Введите код: ");
int C = int.Parse(Console.ReadLine());
if (payments.RemoveAll(p => p.Code == C) > 0)
Console.WriteLine("Указанный платеж удален ");
else
Console.WriteLine("Платежа с таким кодом не существует");
}
public static Payment ReadPayment()
{
Console.Write("Введите марку бензина: ");
int another_petrol = int.Parse(Console.ReadLine());
Console.Write("Введите количество бензина в литрах: ");
double another_count = double.Parse(Console.ReadLine());
Console.Write("Введите номер колонки: ");
byte another_column = byte.Parse(Console.ReadLine());
Console.Write("Введите дату: ");
byte another_code = byte.Parse(Console.ReadLine());
Console.Write("Введите код: ");
DateTime another_dt = DateTime.Parse(Console.ReadLine());
return
new Payment(another_column, another_dt, another_petrol, another_count, another_code);
}
case '3':
payments.Add(ReadPayment());
break;
struct Payment
{
public int Petrol;
public double Count;
public DateTime Dt;
public byte Column;
public byte Code;
public Payment(byte column, DateTime dt, int petrol, double count, byte code)
{
Column = column;
Petrol = petrol;
Count = count;
Dt = dt;
Code = code;
}
public String SString()
{
return String.Format("Колонка: {0} \n" +
"Дата: {1}.{2}.{3} {4}:{5}:{6} \n" +
"Марка бензина: {7} \n" +
"Количество: {8} \n" +
"Код платежа: {9}" +
"\n===============================", Column, Dt.Year, Dt.Month, Dt.Day, Dt.Hour, Dt.Minute, Dt.Second, Petrol, Count, Code);
}
}
class Program
{
public static Payment ReadPayment()
{
Console.Write("Введите марку бензина: ");
int another_petrol = int.Parse(Console.ReadLine());
Console.Write("Введите количество бензина в литрах: ");
double another_count = double.Parse(Console.ReadLine());
Console.Write("Введите номер колонки: ");
byte another_column = byte.Parse(Console.ReadLine());
Console.Write("Введите дату: ");
byte another_code = byte.Parse(Console.ReadLine());
Console.Write("Введите код: ");
DateTime another_dt = DateTime.Parse(Console.ReadLine());
return
new Payment(another_column, another_dt, another_petrol, another_count, another_code);
}
public static List<Payment> payments = new List<Payment>();
public static void Menu()
{
Console.WriteLine("1. История платежей");
Console.WriteLine("2. Редактировать историю платежей");
Console.WriteLine("3. Добавить новый платеж");
Console.WriteLine("4. Удалить платеж из списка");
Console.WriteLine("5. Поиск платежа по коду");
Console.WriteLine("6. Выход из программы");
Console.Write("\n \nВведите номер пункта меню: ");
char M = char.Parse(Console.ReadLine());
switch (M)
{
case '1': break; // вывод списка платежей
case '2': break;
case '3':
payments.Add(ReadPayment());
break;
case '4':
Console.WriteLine();
break;
case '5': break;
case '6': break;
}
}
public static void Main(string[] args)
{
Menu();
Payment np = new Payment(1, new DateTime(2000, 12, 13, 15, 12, 31), 92, 5.12, 001);
payments.Add(np);
payments.Add(new Payment(1, new DateTime(2012, 2, 12, 12, 42, 21), 92, 5.13, 001));
foreach (Payment n in payments)
Console.WriteLine(np.SString());
}
}
<DataGridTemplateColumn Header="Должность">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox
HorizontalContentAlignment="Center"
ItemsSource="{Binding DataContext.Titles, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"
SelectedItem="{Binding Title}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
")(:^^=!?"
if (q == Trim(baza[i], tr.ToCharArray()))