c#满一年每个月增加4天,不满一年每个月增加2天
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
namespace CalculationOfLeave
{
//封装BPMU_USER表
public class BPMU_USERModel
{
public string Account { get; set; }
public string Pwd { get; set; }
public string LDAPDomain { get; set; }
public string DspName { get; set; }
public string CatalogId { get; set; }
public string HRID { get; set; }
public string Email { get; set; }
public string Tel { get; set; }
public string MbTel { get; set; }
public string Supervisor { get; set; }
public DateTime JoinDate { get; set; }
public string CostCenter { get; set; }
public string LocationCode { get; set; }
public bool IsEnable { get; set; }
public string DeptCode { get; set; }
public string DeptName { get; set; }
public string ChineseName { get; set; }
public string PinYin { get; set; }
public string remark { get; set; }
public string BRANCHCODE { get; set; }
public string BRANCHNAME { get; set; }
public string MEMO1 { get; set; }
public string MEMO2 { get; set; }
public int SEX { get; set; }
public int WorkId { get; set; }
}
//封装LeaveSystem_BaseNum表
public class LeaveSystem_BaseNumModel
{
public string ID { get; set; }
public string Account { get; set; }
public string HolidayType { get; set; }
public int Year { get; set; }
public float BaseNum { get; set; }
public DateTime Valid_Date { get; set; }
public DateTime Invalid_Date { get; set; }
public bool IsEnable { get; set; }
public string Remark { get; set; }
public string Remark2 { get; set; }
public int IsRemain { get; set; }
public string Recorder { get; set; }
public DateTime RecordDate { get; set; }
}
public static class LeaveSystem_BaseNumDAL
{
//修改天数
public static int Update(float basenum, string account)
{
string sql = string.Format("UPDATE LeaveSystem_BaseNum SET BaseNum = {0} where Account='{1}'", basenum, account);
return DBHelper.ExecuteSql(sql);
}public static int Add(string ID, string Account)
{
string sql = string.Format("INSERT INTO LeaveSystem_BaseNum (ID,Account,HolidayType,Year,IsEnable,IsRemain)VALUES('{0}', '{1}', '4', '2020', 1, 0)", ID, Account);
return DBHelper.ExecuteSql(sql);
}
public static List<LeaveSystem_BaseNumModel> Select()
{
string sql = "select * from LeaveSystem_BaseNum";
DataSet ds = DBHelper.SelectData(sql);
List<LeaveSystem_BaseNumModel> list = new List<LeaveSystem_BaseNumModel>();
foreach (DataRow item in ds.Tables[0].Rows)
{
LeaveSystem_BaseNumModel ml = new LeaveSystem_BaseNumModel();
ml.ID = item["ID"].ToString();
ml.Account = item["Account"].ToString();
list.Add(ml);
}
return list;
}
}
public static class BPMU_USERDAL
{
public static List<BPMU_USERModel> BPMU_USERDAL_Select(string account)
{
string sql = string.Format("select JoinDate from BPMU_USER where Account='{0}'", account);
DataSet ds = DBHelper.SelectData(sql);
List<BPMU_USERModel> list = new List<BPMU_USERModel>();
foreach (DataRow item in ds.Tables[0].Rows)
{
BPMU_USERModel ml = new BPMU_USERModel();
ml.Account = item["Account"].ToString();
list.Add(ml);
}
return list;
}
public static List<BPMU_USERModel> BPMU_USERDAL_Select1()
{
string sql = "select * from BPMU_USER";
DataSet ds = DBHelper.SelectData(sql);
List<BPMU_USERModel> list = new List<BPMU_USERModel>();
foreach (DataRow item in ds.Tables[0].Rows)
{
BPMU_USERModel ml = new BPMU_USERModel();
ml.Account = item["Account"].ToString();
ml.Pwd = item["Pwd"].ToString();
ml.LDAPDomain = item["LDAPDomain"].ToString();
ml.DspName = item["DspName"].ToString();
ml.CatalogId = item["CatalogId"].ToString();
ml.HRID = item["HRID"].ToString();
ml.Email = item["Email"].ToString();
ml.Tel = item["Tel"].ToString();
ml.MbTel = item["MbTel"].ToString();
ml.Supervisor = item["Supervisor"].ToString();
ml.JoinDate = DateTime.Parse(item["JoinDate"].ToString());
ml.CostCenter = item["CostCenter"].ToString();
ml.LocationCode = item["LocationCode"].ToString();
ml.IsEnable = bool.Parse(item["IsEnable"].ToString());
ml.DeptCode = item["DeptCode"].ToString();
ml.DeptName = item["DeptName"].ToString();
ml.ChineseName = item["ChineseName"].ToString();
ml.PinYin = item["PinYin"].ToString();
ml.remark = item["remark"].ToString();
ml.BRANCHCODE = item["BRANCHCODE"].ToString();
ml.BRANCHNAME = item["BRANCHNAME"].ToString();
ml.MEMO1 = item["MEMO1"].ToString();
ml.MEMO2 = item["MEMO2"].ToString();
ml.SEX = int.Parse(item["SEX"].ToString());
ml.WorkId = int.Parse(item["WorkId"].ToString());
list.Add(ml);
}
return list;
}
}
public static class LeaveSystem_BaseNumBLL
{
//返回修改天数
public static bool Update(float basenum, string account)
{
return LeaveSystem_BaseNumDAL.Update(basenum, account) > 0;
}
public static bool Add(string ID, string account)
{
return LeaveSystem_BaseNumDAL.Add(ID, account) > 0;
}
public static List<LeaveSystem_BaseNumModel> Select()
{
return LeaveSystem_BaseNumDAL.Select();
}
}
public static class BPMU_USERBLL
{
public static List<BPMU_USERModel> BPMU_USERSelect(string account)
{
return BPMU_USERDAL.BPMU_USERDAL_Select(account);
}
//返回入职名称
public static List<BPMU_USERModel> BPMU_USERSelect1()
{
return BPMU_USERDAL.BPMU_USERDAL_Select1();
}
}
public static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
public static void Main()
{
var employee_Name = LeaveSystem_BaseNumBLL.Select();
var employee = BPMU_USERBLL.BPMU_USERSelect1();
foreach (var item in employee)
{
var name = item.Account;
var dateTimeNow = DateTime.Now.Date;
TimeSpan span = new TimeSpan();
var basenum = 0;
span = dateTimeNow - item.JoinDate;
//大于28天可能大于1个月
if (span.TotalDays > 28)
{
//是否月份确实有变化差1个月以上
if (item.JoinDate.Month < dateTimeNow.Month)
{
//判断需要补加几个月的
int OneYearMonth = 0;
int OverOneYearMonth = 0;
//判断入职时间到不到1年
if (span.Days > 365)
{
var a = span.Days - 365;
if (a>28)
{
}
//for (int OverOneYearMonth)
//{
// Func(adddays, 4);
//}
foreach (var items in employee_Name)
{
//获取LeaveSystem表的员工名
var names = items.Account;
//判断BPMU_USER表的员工名与LeaveSystem表的员工名是否相同
if (names == name)
{
//如果相同直接修改天数
LeaveSystem_BaseNumBLL.Update(basenum, names);
}
else
{
//给ID获取值
string t = Guid.NewGuid().ToString("N");
//转换类型
string id = t.Substring(0, 32);
//如果不相同把BPMU_USER表的员工名添加到与LeaveSystem表中
LeaveSystem_BaseNumBLL.Add(id, name);
//修改天数
LeaveSystem_BaseNumBLL.Update(basenum, name);
}
}
//for (int OverOneYearMonth)
//{
// Func(adddays, 4)
//}
//加4天
}
else
{
//for (int OneYearMonth)
//{
// Func(adddays, 2);
//}
foreach (var items in employee_Name)
{
//获取LeaveSystem表的员工名
var names = items.Account;
//判断BPMU_USER表的员工名与LeaveSystem表的员工名是否相同
if (names == name)
{
//如果相同直接修改天数
LeaveSystem_BaseNumBLL.Update(basenum, names);
}
else
{
//给ID获取值
string t = Guid.NewGuid().ToString("N");
//转换类型
string id = t.Substring(0, 32);
//如果不相同把BPMU_USER表的员工名添加到与LeaveSystem表中
LeaveSystem_BaseNumBLL.Add(id, name);
//修改天数
LeaveSystem_BaseNumBLL.Update(basenum, name);
}
}
//for (int OneYearMonth)
// Func(adddays, 2)
//加2天
}
}
}
}
}
}
}
回答
这代码写的。。有耐性没人性啊。先把if else优化下吧,修改DBHelper.SelectData ,DataTable不要,直接返回LIST,这BLL就不要了,换个Dapper或EF。
以上是 c#满一年每个月增加4天,不满一年每个月增加2天 的全部内容, 来源链接: utcz.com/a/41205.html