using System;
using System.Data;
using System.Configuration;
using System.Drawing;
using System.IO;
using System.Collections.Generic;
///
/// 畫薪資條
///
public class SalaryStrip
{
public string 公司名稱 = "";
public string 薪資別 = "";
public string 發薪年月 = "";
public string 部門 = "";
public string 員工代號 = "";
public string 姓名 = "";
public string 職務 = "";
public int 公司提繳 = 0;
public int 津貼合計 = 0;
public int 課稅金額 = 0;
public int 應發金額 = 0;
public int 員工累計 = 0;
public int 扣款合計 = 0;
public int 所得稅 = 0;
public int 實發金額 = 0;
public int 公司累計 = 0;
public string 帳號 = "";
public int 薪資條樣板 = 0;
public bool 列印公司提繳 = true;
public bool 列印津貼合計 = true;
public bool 列印課稅金額 = true;
public bool 列印應發金額 = true;
public bool 列印員工累計 = true;
public bool 列印扣款合計 = true;
public bool 列印所得稅 = true;
public bool 列印實發金額 = true;
public bool 列印公司累計 = true;
public bool 列印帳號 = true;
#region 私用變數
private Font companyFont = new Font("細明體", 18, FontStyle.Bold);
private Font titleFont = new Font("細明體", 11, FontStyle.Regular);
private Font detailFont = new Font("細明體", 10, FontStyle.Regular);
// 定義各點位置
private PointF pt公司名稱 = new PointF(379, 35);
private PointF pt薪資別 = new PointF(100, 76);
private PointF pt發薪年月 = new PointF(633, 76);
private PointF pt部門 = new PointF(100, 98);
private PointF pt員工代號 = new PointF(290, 98);
private PointF pt姓名 = new PointF(442, 98);
private PointF pt職務 = new PointF(633, 98);
private PointF pt加項1 = new PointF(40, 180);
private PointF pt減項1 = new PointF(267, 180);
private PointF pt出勤1 = new PointF(494, 180);
private PointF pt加項2 = new PointF(126, 180);
private PointF pt減項2 = new PointF(352, 180);
private PointF pt出勤2 = new PointF(668, 180);
private PointF pt公司提繳 = new PointF(192, 404);
private PointF pt津貼合計 = new PointF(343, 404);
private PointF pt課稅金額 = new PointF(494, 404);
private PointF pt應發金額 = new PointF(645, 404);
private PointF pt員工累計 = new PointF(192, 424);
private PointF pt扣款合計 = new PointF(343, 424);
private PointF pt所得稅 = new PointF(494, 424);
private PointF pt實發金額 = new PointF(645, 424);
private PointF pt公司累計 = new PointF(192, 443);
private PointF pt帳號 = new PointF(343, 443);
// 定義加項名稱
private List PlusNames = new List();
private List PlusAmounts = new List();
// 定義減項名稱
private List MinusNames = new List();
private List MinusAmounts = new List();
// 定義出勤名稱
private List PresentNames = new List();
private List PresentAmounts = new List();
#endregion
#region 私用方法
private string[] 薪資條樣板檔案 = { @"picture\SalaryStrip.dib", @"picture\SalaryStrip_Bonus.dib" };
private void DrawTitle(Graphics g)
{
DrawString(g, 公司名稱, companyFont, pt公司名稱, "C");
DrawString(g, 薪資別, titleFont, pt薪資別, "L");
DrawString(g, 發薪年月, titleFont, pt發薪年月, "L");
DrawString(g, 部門, titleFont, pt部門, "L");
DrawString(g, 員工代號, titleFont, pt員工代號, "L");
DrawString(g, 姓名, titleFont, pt姓名, "L");
DrawString(g, 職務, titleFont, pt職務, "L");
if (列印公司提繳)
DrawString(g, String.Format("{0,9:#,###,##0}", 公司提繳), titleFont, pt公司提繳, "L");
if (列印津貼合計)
DrawString(g, String.Format("{0,9:#,###,##0}", 津貼合計), titleFont, pt津貼合計, "L");
if (列印課稅金額)
DrawString(g, String.Format("{0,9:#,###,##0}", 課稅金額), titleFont, pt課稅金額, "L");
if (列印應發金額)
DrawString(g, String.Format("{0,9:#,###,##0}", 應發金額), titleFont, pt應發金額, "L");
if (列印員工累計)
DrawString(g, String.Format("{0,9:#,###,##0}", 員工累計), titleFont, pt員工累計, "L");
if (列印扣款合計)
DrawString(g, String.Format("{0,9:#,###,##0}", 扣款合計), titleFont, pt扣款合計, "L");
if (列印所得稅)
DrawString(g, String.Format("{0,9:#,###,##0}", 所得稅), titleFont, pt所得稅, "L");
if (列印實發金額)
DrawString(g, String.Format("{0,9:#,###,##0}", 實發金額), titleFont, pt實發金額, "L");
if (列印公司累計)
DrawString(g, String.Format("{0,9:#,###,##0}", 公司累計), titleFont, pt公司累計, "L");
if (列印帳號)
DrawString(g, 帳號, titleFont, pt帳號, "L");
}
private void DrawItems(Graphics g)
{
for (int i = 0; i < PlusNames.Count; i++)
g.DrawString(PlusNames[i], detailFont, Brushes.Black, pt加項1.X, pt加項1.Y + (i * 18));
for (int i = 0; i < PlusAmounts.Count; i++)
g.DrawString(String.Format("{0,9:#,###,##0}", PlusAmounts[i]), detailFont, Brushes.Black, pt加項2.X, pt加項2.Y + (i * 18));
for (int i = 0; i < MinusNames.Count; i++)
g.DrawString(MinusNames[i], detailFont, Brushes.Black, pt減項1.X, pt減項1.Y + (i * 18));
for (int i = 0; i < MinusAmounts.Count; i++)
g.DrawString(String.Format("{0,9:#,###,##0}", MinusAmounts[i]), detailFont, Brushes.Black, pt減項2.X, pt減項2.Y + (i * 18));
for (int i = 0; i < PresentNames.Count; i++)
g.DrawString(PresentNames[i], detailFont, Brushes.Black, pt出勤1.X, pt出勤1.Y + (i * 18));
for (int i = 0; i < PresentAmounts.Count; i++)
g.DrawString(String.Format("{0,6:c}", PresentAmounts[i]), detailFont, Brushes.Black, pt出勤2.X, pt出勤2.Y + (i * 18));
}
private void DrawString(Graphics g, string s, Font f, PointF pt, string align)
{
PointF pt1 = new PointF() { X = pt.X, Y = pt.Y };
SizeF size = g.MeasureString(s, f);
if (align == "R")
pt1.X -= size.Width;
else if (align == "C")
pt1.X -= size.Width / 2;
g.DrawString(s, f, Brushes.Black, pt1);
}
#endregion
public void AddPlus(string name, int amount)
{
PlusNames.Add(name);
PlusAmounts.Add(amount);
}
public void AddMinus(string name, int amount)
{
MinusNames.Add(name);
MinusAmounts.Add(amount);
}
public void AddPresent(string name, string amount)
{
PresentNames.Add(name);
PresentAmounts.Add(amount);
}
public MemoryStream Draw(string rootpath)
{
Image img = Image.FromFile(rootpath + 薪資條樣板檔案[薪資條樣板]);
Graphics g = Graphics.FromImage(img);
DrawTitle(g);
DrawItems(g);
MemoryStream result = new MemoryStream();
img.Save(result, System.Drawing.Imaging.ImageFormat.Gif);
img.Dispose();
g.Dispose();
return result;
}
public void Clear()
{
PlusNames.Clear();
PlusAmounts.Clear();
MinusNames.Clear();
MinusAmounts.Clear();
PresentNames.Clear();
PresentAmounts.Clear();
公司名稱 = "";
薪資別 = "";
發薪年月 = "";
部門 = "";
員工代號 = "";
姓名 = "";
職務 = "";
公司提繳 = 0;
津貼合計 = 0;
課稅金額 = 0;
應發金額 = 0;
員工累計 = 0;
扣款合計 = 0;
所得稅 = 0;
實發金額 = 0;
公司累計 = 0;
帳號 = "";
}
}