• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >C#教程 > C# 实现计算生辰八字

C# 实现计算生辰八字

作者: 字体:[增加 减小] 来源:互联网 时间:2017-05-28

通过本文主要向大家介绍了c#实现接口,c#实现计算器,c#实现登陆界面,c#实现增删改查,c#实现动画效果等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace BrithdayEigth
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }
    public static string[] date = {
     "甲子", "乙丑", "丙寅", "丁卯", "戊辰", "己巳", "庚午", "辛未", "壬申", "癸酉",
     "甲戊", "乙亥", "丙子", "丁丑", "戊寅", "乙卯", "庚辰", "辛巳", "壬午", "癸未",     "甲申", "乙酉", "丙戌", "丁亥", "戊子", "己丑", "庚寅", "辛卯", "壬辰", "癸巳",     "甲午", "乙未", "丙申", "丁酉", "戊戌", "己亥", "庚子", "辛丑", "壬寅", "癸卯",     "甲辰", "乙巳", "丙午", "丁未", "戊申", "乙酉", "庚戌", "辛亥", "壬子", "癸丑",     "甲寅", "乙卯", "丙辰", "丁巳", "戊午", "己未", "庚申", "辛酉", "壬戌", "癸亥"
                   
                   };
 
    public int yearZi=0;
    private void btnOk_Click(object sender, EventArgs e)
    {
      DateTime dt=Day.Value;
      int year=dt.Year;
      int moon = dt.Month;
      int date = dt.DayOfYear;
       
      MessageBox.Show("Test:"+(year%60-3)+":"+moon+":"+date);
      //调用获得年生辰的方法
      String yearZi = yearZ(year);
      string moonZi = moonZ(moon,year);
      string dayZi = dayei(year, date);
      int hour = int.Parse(hourDate.Text);
     string hourZi= Hours(hour, date, year);
      txtBrithday.Text = yearZi+" "+moonZi+" "+dayZi+" "+hourZi;
    }
 
    private void Form1_Load(object sender, EventArgs e)
    {
       
    }
    //获得年生辰的方法
    public string yearZ(int y) {
      int yearZie = yearNum(y);
      return date[yearZie-1];
    }
    public string moonZ(int m,int year) {
 
      int yearZie = yearNum(year);
      if (yearZie >= 12)
      {
        if (yearZie % 10 == 6 || yearZie % 10 == 1)
        {
          return date[2+m-1];
        }
        else if (yearZie % 10 == 2 || yearZie % 10 == 7) {
          return date[14 + m - 1];
        }
        else if (yearZie % 10 == 3 || yearZie % 10 == 8)
        {
          return date[26 + m - 1];
        }
        else if (yearZi % 10 == 4 || yearZi % 10 == 9)
        {
          return date[38 + m - 1];
        }
        else if (yearZie % 10 == 5 || yearZie % 10 == 0)
        {
          return date[50 + m - 1 > 60 ? (m - 11) : 49 + m];
        }
      }
      else
      {
        if (yearZie == 6 || yearZie == 1)
        {
          return date[2 + m - 1];
        }
        else if (yearZie == 2 || yearZie == 7)
        {
          return date[14 + m - 1];
        }
        else if (yearZie == 3 || yearZie == 8)
        {
          return date[26 + m - 1];
        }
        else if (yearZi == 4 || yearZi == 9)
        {
          return date[38 + m - 1];
        }
        else if (yearZie== 5 || yearZie == 10)
        {
          return date[50 + m - 1>60?(m-11):49+m];
        }
      }
      return date[1];
    }
 
    public string dayei(int year,int day) {
 
      int yearZie = yearNum(year);
      return date[(yearZie + day)%60-1];
    }
    public string Hours(int hour,int day,int year) {
      int yearZie=yearNum(year);
      string strH = "";
      int datey=(yearZie+day)%60-1;
      int dateZi=datey%10;
      if (dateZi == 1 || dateZi == 5)
      {
        strH += "甲";
      }
      else if (dateZi == 2 || dateZi == 6)
      {
        strH += "丙";
      }
      else if (dateZi == 3 || dateZi == 7)
      {
        strH += "戊";
      }
      else if (dateZi == 4 || dateZi == 8)
      {
        strH += "庚";
      }
      else if (dateZi == 5 || dateZi == 0)
      {
        strH += "壬";
      }
 
 
      if (hour > 0 && hour <= 1) 
      { 
         strH+="子";
      }
      else if (hour > 1 && hour <= 3)
      {
        strH += "丑";
      }
      else if (hour > 3 && hour <= 5)
      {
        strH += "寅";
      }
      else if (hour > 5 && hour <= 7)
      {
        strH += "卯";
      }
      else if (hour > 7 && hour <= 9)
      {
        strH += "辰";
      }
      else if (hour > 9 && hour <= 11)
      {
        strH += "巳";
      }
      else if (hour > 11 && hour <= 13)
      {
        strH += "午";
      }
      else if (hour > 13 && hour <= 15)
      {
        strH += "未";
      }
      else if (hour > 15 && hour <= 17)
      {
        strH += "申";
      }
      else if (hour > 17 && hour <= 19)
      {
        strH += "子";
      }
      else if (hour > 19 && hour <= 21)
      {
        strH += "酉";
      }
      else if (hour > 21 && hour <= 23)
      {
        strH += "戊";
      }
      else if (hour > 0 && hour <= 1) 
      {
        strH += "亥";
      }
      return strH;
    }
 
    public int yearNum(int year) {
      int yearZie = year % 60 - 3;
 
      if (yearZie <= 0)
      {
        yearZie += 60;
      }
      return yearZie;
 
    }
  }
}
</div>

以上就是本文的全部内容了,希望大家能够喜欢。

</div>
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • C#中实现判断某个类是否实现了某个接口
  • C#实现控制Windows系统关机、重启和注销的方法
  • C#实现简单播放mp3的方法
  • C# 实现计算生辰八字
  • C#实现图片上传与浏览切换的方法
  • 使用C#实现在word中插入页眉页脚的方法
  • C#实现快捷键的几种常用方法汇总
  • C#实现将PPT转换成HTML的方法
  • 基于C#实现的仿windows左侧伸缩菜单效果
  • C#实现修改系统时间的方法

相关文章

  • 2017-05-28C#图像透明度调整的方法
  • 2017-05-28c#读取文件详谈
  • 2017-05-28C#获取文件相关信息的方法
  • 2017-05-28C#实现根据指定容器和控件名字获得控件的方法
  • 2017-05-28C#实现简单播放mp3的方法
  • 2017-05-28解析C#中@符号的几种使用方法详解
  • 2017-05-28C#词法分析器之转换DFA详解
  • 2017-05-28C#函数式编程中的标准高阶函数详解
  • 2017-05-28c# Graphics使用方法(画圆写字代码)
  • 2017-05-28C#调用WinRar执行rar、zip压缩的方法

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • C#实现简单聊天程序的方法
    • 使用淘宝ip地址库查ip的示例
    • 谈谈C# replace在正则表达式中的意义
    • c#使用nsoup解析html乱码解决方法分享 nsoup教程
    • C#与SQL连接:GridView控件对数据库的操作
    • C#实现从windows剪贴板获取内容的方法
    • C# 通过 inline-asm 解决嵌入x86汇编
    • winform 实现控制输入法
    • c#实现的操作oracle通用类
    • npoi2.0将datatable对象转换为excel2007示例

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有