Console.WriteLine(new DateTime(2023, 3, 1).GetSeason());
Console.WriteLine(new DateTime(2023, 6, 1).GetSeason());
Console.WriteLine(new DateTime(2023, 9, 1).GetSeason());
Console.WriteLine(new DateTime(2023, 12, 1).GetSeason());
Console.WriteLine(new DateTime(2023, 12, 2).GetSeasonDay());
public enum Season
{
Spring,
Summer,
Autumn,
Winter
}
public static class SeasonTools
{
public static Season GetSeason(this DateTime date)
{
int month = date.Month;
if (month >= 3 && month <= 5) return Season.Spring;
else if (month >= 6 && month <= 8) return Season.Summer;
else if (month >= 9 && month <= 11) return Season.Autumn;
else return Season.Winter;
}
public static int GetSeasonDay(this DateTime date)
{
int month = date.Month;
if (month >= 3 && month <= 5) return GetDay(date,Season.Spring);
else if (month >= 6 && month <= 8) return GetDay(date,Season.Summer);
else if (month >= 9 && month <= 11) return GetDay(date,Season.Autumn);
else return GetDay(date, Season.Winter);
}
private static int GetDay(DateTime date, Season season)
{
if (season == Season.Spring) return (int) (date - new DateTime(date.Year, 3, 1) ).TotalDays ;
else if (season == Season.Summer) return (int)(date - new DateTime(date.Year, 6, 1)).TotalDays;
else if (season == Season.Autumn) return (int)(date - new DateTime(date.Year, 9, 1)).TotalDays;
else return (int)(date - new DateTime(date.Year, 12, 1)).TotalDays;
}
}
private void Select(object sender, RoutedEventArgs e)
{
var ff = new FolderBrowserDialog();
if (ff.ShowDialog() == DialogResult.OK)
{
foreach (var file in Directory.EnumerateFiles(ff.SelectedPath, "*.dbf"))
{
var sqlFileName = file.Remove(file.IndexOf('.')) + "_asd_34.sql";
// тут вызываете конвертор
DbfToSql(file, sqlFileName);
}
}
}
switch (type)
{
case "Double":
return Type_.int_; // если пришел Double отправляем int
case "String":
// но как узнать длину строк? Возможно нужно пробежаться по всем данным и вычислить максимальную?
return "VARCHAR2(42)"; // если пришел String отправляем varchar(255)
case "DateTime":
return Type_.Datetime_; // если пришел DateTime, отправляем datetime
}
public interface ISqlGenerator
{
string Generate();
}
public class Parent
{
}
public class new_table : Parent, ISqlGenerator
{
public string Generate()
{
return "insert ....";
}
}
public class tb : Parent, ISqlGenerator
{
private string _id;
private string _name;
public string Id { get => _id; set => _id = value; }
public string Name { get => _name; set => _name = value; }
public tb(string id, string name)
{
Id = id;
Name = name;
}
public string Generate()
{
return "insert ....";
}
}
public class Crud {
public static bool Add(Parent instance, string tableName)
{
if (instance is tb)
{
var t = instance as tb;
}
else if (instance is new_table)
{
var t = instance as new_table;
}
return false;
}
public static bool AddInterface(ISqlGenerator instance, string tableName) {
var sql = instance.Generate();
return false;
}
}
var options = new DefaultFilesOptions();
options.DefaultFileNames.Clear();
options.DefaultFileNames.Add("mydefault.html");
app.UseDefaultFiles(options);
app.UseStaticFiles();
var imagefile = document.getElementById("upload_files") as HTMLInputElement;
if (imagefile == null) return;
if (imagefile.files == null) return;
const files = imagefile.files;
for (let i = 0; i < files.length; i++) {
formData.append("files", files[i]);
}
using System;
public class Program
{
public static void Main()
{
try{
GetImage(2);
}
catch(ArgumentException e){
Console.WriteLine( int.Parse(e.Message));
}
}
public static string GetImage(int index){
if(index == 1){ return "/img/1";}
throw new ArgumentException("5");
}
}
using System;
public class Program
{
public static void Main()
{
Object r = GetImage(1);
Check(r);
r = GetImage(2);
Check(r);
}
public static void Check(Object o){
if(o is String) Console.WriteLine("string");
if(o is int) Console.WriteLine("int");
else
Console.WriteLine(o.GetType());
}
public static Object GetImage(int index){
if(index == 1){ return "/img/1";}
return 5;
}
}