您好,登錄后才能下訂單哦!
本篇文章為大家展示了使用.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("|---------------------------------------------|"); } } } }
上述內容就是使用.NET編寫一個工資管理系統,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。