当前位置:Gxlcms > asp.net > .NET实现工资管理系统

.NET实现工资管理系统

时间:2021-07-01 10:21:17 帮助过:117人阅读

本文实例为大家分享了.NET实现工资管理系统的具体代码,供大家参考,具体内容如下

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace gongzi
{
  class Program
  {
    static bool flag = true;
    //工人数
    const int NUM = 3;
    //定义二维数组
    static string[,] gong = new string[NUM, 5];
    static void Main(string[] args)
    {
      Console.Title = "工资管理系统";
      jiemian();  //菜单界面
      login();   //登录界面
      while (flag)
      {
        caidan(); //菜单界面
      }
    }
    static void jiemian()
    {
      Console.Clear();
      Console.WriteLine("------工资管理系统------");
      Console.WriteLine("-----@lijia---2018-4-4-----------");
      Console.ReadKey();
    }
    static void login() //登录界面
    {
      Console.WriteLine("请输入用户名:");
      String username = Console.ReadLine();
      Console.WriteLine("请输入密码:");
      String password = Console.ReadLine();
      if (username == "lijia" && password == "123456")
      {
        flag = true;//进入菜单界面
      }
      else
      {
        Console.WriteLine("对不起,你输入的用户名或者密码错误!请重新输入!");
        flag = false;
      }
    }
    static void caidan()
    {
      Console.Clear();
      Console.WriteLine("工资管理系统");
      Console.WriteLine("1.工资录入");
      Console.WriteLine("2.工资查询");
      Console.WriteLine("3.工资修改");
      Console.WriteLine("4.工资统计");
      Console.WriteLine("0.退出系统");
      Console.WriteLine("请输入0-3数字:");
      String choice = Console.ReadLine();
      switch (choice)
      {
        case "1":
          Console.WriteLine("工资录入");
          Inputgongzi(gong,NUM);
          Console.ReadKey();
          break;
        case "2":
          Console.WriteLine("工资查询");
          Outputgongzi(gong, NUM);
          Console.ReadKey();
          break;
        case "3":
          Console.WriteLine("请输入你需要选择的哪种工资的修改:(1基本工资2奖金)");
          string temp = string.Empty;
          int t = Convert.ToInt32(Console.ReadLine());
          switch (t)
          {
            case 1:
              Console.WriteLine("输入您要修改基本工资在二维数组中所在行数(0-2):");
              int t1 = Convert.ToInt32(Console.ReadLine());
              temp = gong[t1, 2];
              gong[t1, 2] = Console.ReadLine();
              sfgz();
              break;
            case 2:
              Console.WriteLine("输入您要修改的奖金在二维数组中所在行数(0-2):");
              int t2 = Convert.ToInt32(Console.ReadLine());
              temp = gong[t2, 3];
              gong[t2, 3] = Console.ReadLine();
              sfgz();
              break;
          }
          break;
        case "4":
          double a = Convert.ToDouble(gong[0, 4]);
          double b = Convert.ToDouble(gong[1, 4]);
          double c = Convert.ToDouble(gong[2, 4]);
          if (a > b)
          {
            if (a > c)
            {
              Console.WriteLine("最高工资:{0}", a);
              if (b > c)
              {
                Console.WriteLine("最低工资:{0}", c);
              }
              else
              {
                Console.WriteLine("最低工资:{0}", b);
              }
            }
            else
            {
              Console.WriteLine("最高工资:{0}", c);
            }
          }
          else
          {//a<b
            if (b > c)
            {
              Console.WriteLine("最高工资:{0}", b);
              if (a > c)
              {
                Console.WriteLine("最低工资:{0}", c);
              }
              else
              {
                Console.WriteLine("最低工资:{0}", a);
              }
            }
            else//b<c
            {
              Console.WriteLine("最高工资:{0}", c);
              Console.WriteLine("最低工资:{0}", a);
 
            }
          }
          double pjzhi = (a + b + c) / 3;
          Console.WriteLine("工资平均值:{0}", pjzhi);
          Console.ReadKey();
          break;
        case "0":
          flag = false;
          break;
      }
 
    }
 
    static void Inputgongzi(string[,] gong,int NUM)
    {
      string yuangong = string.Empty;
      string[] tmp;
      for (int i = 0; i < NUM; i++)
      {
        Console.WriteLine("请输入第{0}个工人的工号、姓名、基本工资、奖金(以空格分割):", i + 1);
        yuangong = Console.ReadLine();
        //分割工人信息
        tmp = yuangong.Split(' ');
        for (int j = 0; j < tmp.Length; j++)
        {
          gong[i, j] = tmp[j];          
        }
        //计算实发工资
        double sodeshui = 0;
        double sfgz;
        double jbgz = Convert.ToDouble(gong[i, 2]);
        double jj = Convert.ToDouble(gong[i, 3]);
        if ((jbgz + jj) < 5000)
        {
          sfgz = jbgz + jj - sodeshui;
          gong[i, 4] = Convert.ToString(sfgz);
        }
        else if ((jbgz + jj) < 8000)
        {
          sodeshui = jbgz * 0.03;
        }
        else if ((jbgz + jj) < 20000)
        {
          sodeshui = 3000 * 0.03 + (jbgz - 8000) * 0.15;
        }
        else if ((jbgz + jj) > 20000)
        {
          sodeshui = 3000 * 0.03 + 2000 * 0.15 + (jbgz - 20000) * 0.25;
        }
        //计算实发工资
        sfgz = jbgz + jj - sodeshui;
        gong[i, 4] = Convert.ToString(sfgz);
      }
    }
 
    static void sfgz()
    {
      double sodeshui = 0;
      double sfgz;
      int i = 0;
      double jbgz = Convert.ToDouble(gong[i, 2]);
      double jiangjin = Convert.ToDouble(gong[i, 3]);
      if ((jbgz + jiangjin) < 5000)
      {
        sfgz = jbgz + jiangjin - sodeshui;
        gong[i, 4] = Convert.ToString(sfgz);
      }
      else if ((jbgz + jiangjin) < 8000)
      {
        sodeshui = jbgz * 0.03;
      }
      else if ((jbgz + jiangjin) < 20000)
      {
        sodeshui = 3000 * 0.03 + (jbgz - 8000) * 0.15;
      }
      else if ((jbgz + jiangjin) > 20000)
      {
        sodeshui = 3000 * 0.03 + 2000 * 0.15 + (jbgz - 20000) * 0.25;
      }
      //计算实发工资
      sfgz = jbgz + jiangjin - sodeshui;
      gong[i, 4] = Convert.ToString(sfgz);
    }
    static void Outputgongzi(string[,] gong, int NUM)
    {
      Console.WriteLine("-----------工人工资单-------------");
      Console.WriteLine("|----------------------------------|");
      Console.WriteLine("|工 号|姓  名|基本工资|奖  金|实发工资|");
      Console.WriteLine("-----------------------------------|");
      for (int i = 0; i < NUM; i++)
      {
        Console.WriteLine("|{0,5}|{1,8}|{2,8:f2}|{3,8:f2}|{4:8,f2}|", gong[i, 0], gong[i, 1], gong[i, 2], gong[i, 3], gong[i, 4]);
        Console.WriteLine("|---------------------------------------------|");
      }     
    }
  }
}

运行结果:






以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

人气教程排行