using System; using RetireUtility; namespace ConsoleApp1 { internal class Program { public static void Main(string[] args) { //参照 https://mp.weixin.qq.com/s/wqFAOhfNhfwMJKaQEE5lYQ 进行测试 var r1 = Retire.CalcNewRetireDate("AAABBB19760503CC1C", employee_type.male_all); Console.WriteLine(); Retire.CalcNewRetireDate("1976-05-03", gender.female, employee_type.female_manage); Console.WriteLine(); Retire.CalcNewRetireDate(1976, 5, 3, gender.female, employee_type.female_operation); Console.ReadLine(); } } }
using System; namespace RetireUtility { public enum gender { male, female } public enum employee_type { male_all, female_manage, female_operation } public struct retire_result { public DateTime birthday { get; set; } public gender gender { get; set; } public employee_type employee_type { get; set; } public string retire_age { get; set; } public DateTime retire_date { get; set; } public int delay_months { get; set; } public string least_pay_months { get; set; } } public class Retire { public static retire_result CalcNewRetireDate(string birthday, gender gender, employee_type employee_type) { int gender_flag = gender == gender.male ? 1 : 0; string birthday_str = Convert.ToDateTime(birthday).ToString("yyyyMMdd"); string sfz = $"AAABBB{birthday_str}CC{gender_flag}D"; return CalcNewRetireDate(sfz, employee_type); } public static retire_result CalcNewRetireDate(int year, int month, int day, gender gender, employee_type employee_type) { int gender_flag = gender == gender.male ? 1 : 0; string birthday_str = new DateTime(year, month, day).ToString("yyyyMMdd"); string sfz = $"AAABBB{birthday_str}CC{gender_flag}D"; return CalcNewRetireDate(sfz, employee_type); } public static retire_result CalcNewRetireDate(string sfz, employee_type employee_type) { int year = int.Parse(sfz.Substring(6, 4)); int month = int.Parse(sfz.Substring(10, 2)); int day = int.Parse(sfz.Substring(12, 2)); gender gender = int.Parse(sfz.Substring(16, 1)) % 2 == 0 ? gender.female : gender.male; DateTime birthday = new DateTime(year, month, day); int retire_delay_months = 0; int retire_original_months = 0; if (gender == gender.male) //男 60 { retire_original_months = 12 * 60; if (year >= 1965) { int over_months = 12 * (year - 1965) + (month - 0); retire_delay_months = 1 * (((over_months - 1) / 4) + 1); retire_delay_months = retire_delay_months > 36 ? 36 : retire_delay_months; } } else if (gender == gender.female && employee_type == employee_type.female_manage) //女 管理 55 { retire_original_months = 12 * 55; if (year >= 1970) { int over_months = 12 * (year - 1970) + (month - 0); retire_delay_months = 1 * (((over_months - 1) / 4) + 1); retire_delay_months = retire_delay_months > 36 ? 36 : retire_delay_months; } } else if (gender == gender.female && employee_type == employee_type.female_operation) //女 操作 50 { retire_original_months = 12 * 50; if (year >= 1975) { int over_months = 12 * (year - 1975) + (month - 0); retire_delay_months = 1 * (((over_months - 1) / 2) + 1); retire_delay_months = retire_delay_months > 60 ? 60 : retire_delay_months; } } int total_work_months = retire_original_months + retire_delay_months; DateTime retire_date = birthday.AddMonths(total_work_months); //计算“当年最低缴费年限” int least_pay_months = 12 * 15; int retire_year = retire_date.Year; if (retire_year >= 2030 && retire_year <= 2039) { least_pay_months += 6 * ((retire_year - 2030) + 1); } else if (retire_year > 2039) { least_pay_months = 12 * 20; } string retire_age = $"{total_work_months / 12}岁{total_work_months % 12}个月"; string least_pay_months_str = $"{least_pay_months / 12}年{least_pay_months % 12}个月"; Console.WriteLine($"性别\t\t\t{gender.ToString()}\r\n" + $"类别\t\t\t{employee_type.ToString()}\r\n" + $"出生时间\t\t{year}年{month}月\r\n" + $"改革后法定退休年龄\t{retire_age}\r\n" + $"改革后退休时间\t\t{retire_date.ToString("yyyy年M月")}\r\n" + $"延迟月数\t\t{retire_delay_months}\r\n" + $"当年最低缴费年限\t{least_pay_months_str}"); var result = new retire_result { birthday = birthday, gender = gender, employee_type = employee_type, delay_months = retire_delay_months, retire_age = retire_age, retire_date = retire_date, least_pay_months = least_pay_months_str }; return result; } } }
标签:core,months,C#,gender,retire,2025,int,employee,type From: https://www.cnblogs.com/laozuan/p/18435232