交款功能代碼

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;
using WeifenLuo.WinFormsUI.Docking;
using System.Drawing.Printing;
using System.IO;

namespace DBzd
{
    public partial class FeesFrm : DockContent
    {
        private MainFrm mf;
        //交款方式
        private string jkfs;
        //圖片信息
        private byte[] byteZhiPiaoA = null;
        private byte[] byteZhiPiaoB = null;
        private byte[] byteHuiKuanA = null;
        private byte[] byteHuiKuanB = null;
        private byte[] byteQianTiaoA = null;
        private double trueprice;
        public FeesFrm()
        {
            InitializeComponent();
        }
        public FeesFrm(MainFrm f)
        {
            InitializeComponent();
            mf = f;

        }

        private void FeesFrm_Load(object sender, EventArgs e)
        {
            #region 年度列表

            toolStripComboBox1.Items.Clear();
            var q = from p in mf.DS.UnitPaperTask
                    orderby p.year descending
                    group p by p.year into g
                    select new
                    {
                        year = g.Key,
                        g
                    };

            foreach (var it in q)
            {
                toolStripComboBox1.Items.Add(it.year);                
            }
            toolStripComboBox1.SelectedIndex = 0;
            #endregion

            #region 加載單位類別
            toolStripComboBox3.Items.Clear();
            var q1 = from k in mf.DS.Unit
                   //  orderby k.kind descending
                     group k by k.kind into g
                     select new
                     {
                         kind = g.Key,
                         g
                     };
            foreach (var i in q1)
            {
                toolStripComboBox3.Items.Add(i.kind);
              
            }
            toolStripComboBox3.SelectedIndex = 0;
            #endregion

            combSKFS.SelectedIndex = 0;
            btnSave.Enabled = false;
        }

        #region 工具欄
        //工具欄 單位類別 下拉列表變換
        private void toolStripComboBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            combJKDW.Items.Clear();
            var q5 = from p in mf.DS.Unit.AsEnumerable()
                     where p.kind == toolStripComboBox3.SelectedItem.ToString().Trim() && p.Istake == ""
                     select p;
            foreach (var i in q5)
            {
                Unit un = new Unit();
                un.unitid = i.unitid;
                un.shortname = i.shortname;
                un.tel = i.Tel;
                un.allname = i.allname;
                combJKDW.Items.Add(un);

            }
            combJKDW.DisplayMember = "shortname";
            if (combJKDW.Items.Count > 0)
            {
                combJKDW.SelectedIndex = 0;
            }


        }
        //搜索單位
        private void tsTxtSearch_TextChanged(object sender, EventArgs e)
        {
            combJKDW.Items.Clear();
            string upper = tsTxtSearch.Text.ToUpper();
            var q5 = from p in mf.DS.Unit.AsEnumerable()
                     where p.Istake == ""
                     select p;
            foreach (var i in q5)
            {

                string namecode = PinYin.GetCodstring(i.shortname);
                if (namecode.StartsWith(upper))
                {
                    Unit un = new Unit();
                    un.unitid = i.unitid;
                    un.allname = i.allname;
                    un.shortname = i.shortname;
                    un.tel = i.Tel;
                    combJKDW.Items.Add(un);

                }

            }
            combJKDW.DisplayMember = "shortname";
            if (combJKDW.Items.Count > 0)
            {
                combJKDW.SelectedIndex = 0;
            }

        }

        #endregion

        
        //顯示計劃金額及企業任務
        private void PlantMoney()
        {
            //txtTruePrice.Text = "";
            txtPlantMoeny.Text = "";
            Unit un = combJKDW.SelectedItem as Unit;

            List<string> qflag = (from p in mf.DS.Fees.AsEnumerable() where p.unitid == un.unitid && p.year == toolStripComboBox1.SelectedItem.ToString().Trim() select p.flag).ToList<string>();
            if (qflag.Count > 0)
            {
                var qplantprices = from p in mf.DS.UnitMoneyTask.AsEnumerable()
                                   where p.unitid == un.unitid
                                   select p;
                foreach (var i in qplantprices)
                {

                    txtPlantMoeny.Text = i.totalMoney.ToString();
                    //  txtCompTask.Text = i.compprices.ToString();
                    txtUnitTel.Text = un.tel;


                }
                //查詢計劃金額表,是否有該單位的計劃金額?有:無
                if (qplantprices.Count() > 0)
                {
                    if (txtCompTask.Text != "0")
                    {
                        txtTruePrice.Text = txtTotalMoney.Text = (double.Parse(txtPlantMoeny.Text) + double.Parse(txtCompTask.Text) + double.Parse(txtZiDingMoney.Text.Trim())).ToString();
                    }
                    else
                    {
                        txtTruePrice.Text = txtTotalMoney.Text = (double.Parse(txtPlantMoeny.Text) + double.Parse(txtZiDingMoney.Text.Trim())).ToString();
                    }
                }
                else
                {
                    txtPlantMoeny.Text = labTal.Text;
                }

                var q = from p in mf.DS.Fees.AsEnumerable() where p.unitid == un.unitid select p;
                foreach (var i in q)
                {
                    txtDrawee.Text = i.drawee;
                    txtDraweeTel.Text = i.draweetel;
                    txtTruePrice.Text = i.tureprice.ToString();
                    combSKR.Text = i.payee;
                    dateTimePicker1.Value = i.paytime;
                    switch (i.flag)
                    {
                        case "完成":
                            rabOver.Checked = true;
                            break;
                        case "部分":
                            rabPat.Checked = true;
                            break;
                        case "未交":
                            rabNot.Checked = true;

                            break;
                    }
                    txtbz.Text = i.bz;
                }
                txtDrawee.Enabled = txtDraweeTel.Enabled = txtTruePrice.Enabled = combSKR.Enabled = btnSave.Enabled = dateTimePicker1.Enabled = btnEdit.Enabled = false;
            }
            else
            {

                txtDrawee.Enabled = txtDraweeTel.Enabled = txtTruePrice.Enabled = combSKR.Enabled = btnSave.Enabled = dateTimePicker1.Enabled = btnEdit.Enabled = true;
                txtDrawee.Text = txtDraweeTel.Text = "";

                txtPlantMoeny.Text = labTal.Text;
                if (txtPlantMoeny.Text == "")
                {
                    txtPlantMoeny.Text = "0";
                }

                if (txtCompTask.Text != "0")
                {
                    txtTruePrice.Text = txtTotalMoney.Text = (double.Parse(txtPlantMoeny.Text.Trim()) + double.Parse(txtCompTask.Text.Trim()) + double.Parse(txtZiDingMoney.Text.Trim())).ToString();
                }
                else
                {
                    txtTruePrice.Text = txtTotalMoney.Text = (double.Parse(txtPlantMoeny.Text.Trim()) + double.Parse(txtZiDingMoney.Text.Trim())).ToString();
                }
                rabNot.Checked = true;
                btnSave.Text = "保存";
            }

        }

        //顯示計劃任務列表
        private void ShowPlantTask()
        {
            listView1.Items.Clear();
            //實現了視圖功能
            Unit un = combJKDW.SelectedItem as Unit;
            var pt = from p in mf.DS.Paper.AsEnumerable()
                     from ut in mf.DS.UnitPaperTask.AsEnumerable()
                     where ut.unitid == un.unitid && ut.paperid == p.paperid && ut.year == toolStripComboBox1.SelectedItem.ToString().Trim()
                     select new
                     {
                         id = ut.id,
                         paperid = p.paperid,
                         bk = p.name,
                         nm = ut.plantnum,
                         // tnm = ut.truenum,
                         price = p.price,
                         bt = p.subsidy,
                         ye = ut.year
                     };
            foreach (var i in pt)
            {

                //ListViewItem lv = new ListViewItem(new string[] { i.bk, i.nm.ToString(), i.tnm.ToString(), (i.price - i.bt).ToString(), i.ye });
                ListViewItem lv = new ListViewItem(new string[] { i.bk, i.nm.ToString(), (i.price - i.bt).ToString(), i.ye });
                lv.Tag = i.id;
                listView1.Items.Add(lv);
            }

        }
        //計算、顯示總金額
        private void CalListViewMoney()
        {
            double money = 0;
            foreach (ListViewItem item in listView1.Items)
            {
                int fensu = Int32.Parse(item.SubItems[2].Text.Trim());
                double danjia = double.Parse(item.SubItems[3].Text.Trim());
                money += fensu * danjia;
            }
            labTal.Text = money.ToString();

        }
        //選擇單位
        private void combJKDW_SelectedIndexChanged(object sender, EventArgs e)
        {
            //顯示自訂報刊金額
            getZidinbBaoKan();
            //顯示計劃金額
            PlantMoney();
            //顯示實際訂刊數
            ShowPlantTask();
            //計算實際金額
            CalListViewMoney();
            //顯示不一樣交款方式
            ShowJiaoKuanFanShi();
            //顯示不一樣交款方式頁
            //  showTabControlPt();
            //顯示批覆
            getPiFu();
            txtbaokan.Text = txtNumber.Text = "";
            combJKDW.Focus();
        }
        //todo:是否要從新設計?有了計劃任務的單位,單位計劃金額應即時程序算出來,不該從庫取;
        //而只有計劃金額無任務的單位才從,庫在取(只包括幾個鄉鎮!他們是爲完成總任務作備份金用的)
        private void ShowJiaoKuanFanShi()
        {
            Unit un = combJKDW.SelectedItem as Unit;
            var q = from p in mf.DS.Fees.AsEnumerable()
                    where p.unitid == un.unitid
                    select p;
            foreach (var i in q)
            {
                switch (i.paykind)
                {
                    case "現金":
                        combSKFS.SelectedIndex = 0;
                        //tabControl1.SelectedIndex = 0;
                        break;
                    case "支票":
                        combSKFS.SelectedIndex = 1;
                        combBank.Text = i.bank;
                        txtSbgetMoeny.Text = i.getpaysb;
                        rabMoney.Checked = (i.checkkind == "現金支票") ? true : false;
                        rabZhip.Checked = (i.checkkind == "轉帳支票") ? true : false;
                        dateTimePickerMoney.Value = i.getpaytime;
                        //  tabControl1.SelectedIndex = 1;
                        break;
                    case "匯款":
                        combSKFS.SelectedIndex = 2;
                        txtPayAccount.Text = i.getpayaccount;
                        dateTimePicker5.Value = i.getpaytime;
                        //   tabControl1.SelectedIndex = 2;
                        break;
                    case "欠條":
                        combSKFS.SelectedIndex = 3;
                        //txtPayAccount.Text = i.getpayaccount;
                        //dateTimePicker5.Value = i.getpaytime;
                        // tabControl1.SelectedIndex = 3;
                        break;

                }
            }
        }
        //顯示自訂報刊金額
        private void getZidinbBaoKan()
        {
            //獲得單位ID
            Unit u = combJKDW.SelectedItem as Unit;
            //獲得非黨刊id;
            List<string> Arid = (from p in mf.DS.UnitPaperTask.AsEnumerable() where p.unitid == u.unitid select p.paperid).ToList<string>();
            List<string> dkid = (from p in mf.DS.Paper.AsEnumerable() where p.IsDanKan == "" select p.paperid).ToList<string>();
            int caljg = 0;
            txtZiDingMoney.Text = "0";
            foreach (var i in dkid)
            {

                if (Arid.Contains(i))
                {
                    int m = 0;
                    var q = from p in mf.DS.Paper.AsEnumerable()
                            from upt in mf.DS.UnitPaperTask.AsEnumerable()
                            where upt.unitid == u.unitid && p.paperid == i
                            select new
                            {
                                price = p.price,
                                subprice = p.subsidy,
                                numb = upt.plantnum
                            };
                    foreach (var im in q)
                    {
                        m = Convert.ToInt32(im.price - im.subprice) * im.numb;
                    }
                    caljg += m;
                }
            }
            txtZiDingMoney.Text = caljg.ToString();
        }


        //雙擊列表要修改數量
        private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (listView1.SelectedItems.Count > 0)
            {
                txtNumber.Text = "";
                txtbaokan.Text = listView1.SelectedItems[0].Text;
                txtNumber.Text = listView1.SelectedItems[0].SubItems[2].Text;
            }
        }
        //編輯數量
        private void btnEdit_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem item in listView1.Items)
            {
                if (item.Text == txtbaokan.Text)
                {
                    item.SubItems[2].Text = txtNumber.Text.Trim();
                }
            }
            txtbaokan.Text = "";
            txtNumber.Text = "";
            CalListViewMoney();
            //保存實際訂刊數
            SaveTruePaperNumb();
        }

        //todo:計劃金額列表中,無單位計劃金額,須要新查詢計算。一、單位,二、分任務或分金額。若有任務無金額?有金額無任務?
        //保存按鍵
        private void btnSave_Click(object sender, EventArgs e)
        {
            Fees fees = new Fees();
            Unit un = combJKDW.SelectedItem as Unit;
            fees.unitid = un.unitid;//單位代碼
            fees.paykind = jkfs;//交款方式
            fees.plantprrice = double.Parse(txtTotalMoney.Text.Trim());//計劃總額
            fees.tureprice = double.Parse(txtTruePrice.Text.Trim());//實收金額
            fees.drawee = txtDrawee.Text;//交款人
            fees.draweetel = txtDraweeTel.Text;//交款人電話
            fees.payee = combSKR.SelectedItem.ToString();//收款人
            fees.paytime = dateTimePicker1.Value;//交款時間
            string flag = "";
            foreach (RadioButton rb in gBoxFlag.Controls)
            {
                if (rb.Checked == true)
                {
                    flag = rb.Text;
                }
            }
            fees.flay = flag;//進度標註(完成,部分,未交
            fees.bz = txtbz.Text;
            //todo:系統的配置年度設置
            fees.year = toolStripComboBox1.SelectedItem.ToString().Trim();

            //判斷

            switch (jkfs)
            {
                case "現金":
                    //判斷是新增仍是修改
                    if (btnSave.Text == "保存")
                    {
                        BKDataSet.FeesRow fr = mf.DS.Fees.AddFeesRow(fees.unitid, fees.paykind, fees.plantprrice, fees.tureprice, fees.drawee, fees.draweetel, fees.payee, fees.paytime, fees.flay, fees.bz, fees.year, "", "", "", DateTime.Now, null, null, "");
                        int zed = mf.feesTap.Update(mf.DS.Fees);
                        if (zed > 0)
                        {
                            MessageBox.Show("已保存!");
                        }
                        if (combJKDW.SelectedIndex < combJKDW.Items.Count - 1)
                        {
                            combJKDW.SelectedIndex = combJKDW.SelectedIndex + 1;
                        }

                    }
                    if (btnSave.Text == "修改")
                    {
                        int id = (from p in mf.DS.Fees.AsEnumerable() orderby p.id descending where p.unitid == un.unitid && p.flag == "完成" && p.year == toolStripComboBox1.SelectedItem.ToString().Trim() select p.id).SingleOrDefault();
                        BKDataSet.FeesRow fr = mf.DS.Fees.FindByid(id);
                        fr.tureprice = double.Parse(txtTruePrice.Text.Trim()); fr.drawee = txtDrawee.Text;
                        fr.draweetel = txtDraweeTel.Text; fr.paykind = jkfs; fr.payee = combSKR.SelectedItem.ToString();
                        fr.year = toolStripComboBox1.SelectedItem.ToString().Trim();
                        fr.flag = flag; fr.bz = txtbz.Text; fr.paytime = dateTimePicker1.Value;

                        int zed = mf.feesTap.Update(mf.DS.Fees);
                        if (zed > 0)
                        {
                            MessageBox.Show("已修改!");
                        }
                        if (combJKDW.SelectedIndex < combJKDW.Items.Count - 1)
                        {
                            combJKDW.SelectedIndex = combJKDW.SelectedIndex + 1;
                        }


                    }
                    break;
                case "支票":
                    //判斷是新增仍是修改
                    if (btnSave.Text == "保存")
                    {
                        string checkkind = (rabMoney.Checked == true) ? "現金支票" : "轉帳支票";

                        BKDataSet.FeesRow fr = mf.DS.Fees.AddFeesRow(fees.unitid, fees.paykind, fees.plantprrice, fees.tureprice, fees.drawee, fees.draweetel, fees.payee, fees.paytime, fees.flay, fees.bz, fees.year, checkkind, combBank.Text, txtSbgetMoeny.Text, DateTime.Now, byteZhiPiaoA, byteZhiPiaoB, "");
                        int zed = mf.feesTap.Update(mf.DS.Fees);
                        if (zed > 0)
                        {
                            MessageBox.Show("已保存!");
                        }
                        if (combJKDW.SelectedIndex < combJKDW.Items.Count - 1)
                        {
                            combJKDW.SelectedIndex = combJKDW.SelectedIndex + 1;
                        }

                    }
                    if (btnSave.Text == "修改")
                    {
                        int id = (from p in mf.DS.Fees.AsEnumerable() orderby p.id descending where p.unitid == un.unitid && p.flag == "完成" && p.year == toolStripComboBox1.SelectedItem.ToString().Trim() select p.id).SingleOrDefault();
                        BKDataSet.FeesRow fr = mf.DS.Fees.FindByid(id);
                        fr.tureprice = double.Parse(txtTruePrice.Text.Trim()); fr.drawee = txtDrawee.Text;
                        fr.draweetel = txtDraweeTel.Text; fr.paykind = jkfs; fr.payee = combSKR.SelectedItem.ToString();
                        fr.year = toolStripComboBox1.SelectedItem.ToString().Trim();
                        fr.flag = flag; fr.bz = txtbz.Text; fr.getpaytime = dateTimePickerMoney.Value; fr.getpaysb = txtSbgetMoeny.Text; fr.bank = combBank.Text;

                        int zed = mf.feesTap.Update(mf.DS.Fees);
                        if (zed > 0)
                        {
                            MessageBox.Show("已修改!");
                        }
                        if (combJKDW.SelectedIndex < combJKDW.Items.Count - 1)
                        {
                            combJKDW.SelectedIndex = combJKDW.SelectedIndex + 1;
                        }


                    }
                    break;
                case "匯款":
                    //判斷是新增仍是修改
                    if (btnSave.Text == "保存")
                    {

                        BKDataSet.FeesRow fr = mf.DS.Fees.AddFeesRow(fees.unitid, fees.paykind, fees.plantprrice, fees.tureprice, fees.drawee, fees.draweetel, fees.payee, fees.paytime, fees.flay, fees.bz, fees.year, "", "", "", DateTime.Now, byteHuiKuanA, byteHuiKuanB, txtPayAccount.Text);
                        int zed = mf.feesTap.Update(mf.DS.Fees);
                        if (zed > 0)
                        {
                            MessageBox.Show("已保存!");
                        }
                        if (combJKDW.SelectedIndex < combJKDW.Items.Count - 1)
                        {
                            combJKDW.SelectedIndex = combJKDW.SelectedIndex + 1;
                        }

                    }
                    if (btnSave.Text == "修改")
                    {
                        int id = (from p in mf.DS.Fees.AsEnumerable() orderby p.id descending where p.unitid == un.unitid && p.flag == "完成" && p.year == toolStripComboBox1.SelectedItem.ToString().Trim() select p.id).SingleOrDefault();
                        BKDataSet.FeesRow fr = mf.DS.Fees.FindByid(id);
                        fr.tureprice = double.Parse(txtTruePrice.Text.Trim()); fr.drawee = txtDrawee.Text;
                        fr.draweetel = txtDraweeTel.Text; fr.paykind = jkfs; fr.payee = combSKR.SelectedItem.ToString();
                        fr.year = toolStripComboBox1.SelectedItem.ToString().Trim();
                        fr.flag = flag; fr.bz = txtbz.Text; fr.paytime = dateTimePicker1.Value; fr.getpaytime = dateTimePicker5.Value; fr.getpayaccount = txtPayAccount.Text;

                        int zed = mf.feesTap.Update(mf.DS.Fees);
                        if (zed > 0)
                        {
                            MessageBox.Show("已修改!");
                        }
                        if (combJKDW.SelectedIndex < combJKDW.Items.Count - 1)
                        {
                            combJKDW.SelectedIndex = combJKDW.SelectedIndex + 1;
                        }


                    }
                    break;
                case "欠條":
                    //判斷是新增仍是修改
                    if (btnSave.Text == "保存")
                    {
                        BKDataSet.FeesRow fr = mf.DS.Fees.AddFeesRow(fees.unitid, fees.paykind, fees.plantprrice, fees.tureprice, fees.drawee, fees.draweetel, fees.payee, fees.paytime, fees.flay, fees.bz, fees.year, "", "", "", DateTime.Now, null, null, "");
                        int zed = mf.feesTap.Update(mf.DS.Fees);
                        if (zed > 0)
                        {
                            MessageBox.Show("已保存!");
                        }
                        if (combJKDW.SelectedIndex < combJKDW.Items.Count - 1)
                        {
                            combJKDW.SelectedIndex = combJKDW.SelectedIndex + 1;
                        }

                    }
                    if (btnSave.Text == "修改")
                    {
                        int id = (from p in mf.DS.Fees.AsEnumerable() orderby p.id descending where p.unitid == un.unitid && p.year == toolStripComboBox1.SelectedItem.ToString().Trim() select p.id).SingleOrDefault();
                        BKDataSet.FeesRow fr = mf.DS.Fees.FindByid(id);
                        fr.tureprice = double.Parse(txtTruePrice.Text.Trim()); fr.drawee = txtDrawee.Text;
                        fr.draweetel = txtDraweeTel.Text; fr.paykind = jkfs; fr.payee = combSKR.SelectedItem.ToString();
                        fr.year = toolStripComboBox1.SelectedItem.ToString().Trim();
                        fr.flag = flag; fr.bz = txtbz.Text; fr.paytime = dateTimePicker1.Value;

                        int zed = mf.feesTap.Update(mf.DS.Fees);
                        if (zed > 0)
                        {
                            MessageBox.Show("已修改!");
                        }
                        if (combJKDW.SelectedIndex < combJKDW.Items.Count - 1)
                        {
                            combJKDW.SelectedIndex = combJKDW.SelectedIndex + 1;
                        }


                    }

                    break;



            }


        }
        //保存實際訂刊數
        private void SaveTruePaperNumb()
        {
            for (int i = 0; i < listView1.Items.Count; i++)
            {
                int u = Int32.Parse(listView1.Items[i].Tag.ToString());
                BKDataSet.UnitPaperTaskRow rw = mf.DS.UnitPaperTask.FindByid(u);
                string j = listView1.Items[i].SubItems[2].Text.Trim();
                // rw.truenum = Int32.Parse(j);
            }
            mf.unitpapertaskTap.Update(mf.DS.UnitPaperTask);
        }
        //大寫金額
        private void txtTotalMoney_TextChanged(object sender, EventArgs e)
        {
            labRMB.Text = "人民幣(大寫):";
            if (txtTruePrice.Text != "")
            {
                labRMB.Text += RMBCapitalization.RMBAmount(double.Parse(txtTruePrice.Text));
            }

        }
       
        //清除文本
        private static void clearTXT(BKDataSet.FeesRow fr)
        {
            fr.unitid = "";
            fr.plantprice = 0;
            fr.tureprice = 0;
            fr.drawee = "";
            fr.draweetel = "";
            fr.paykind = "";
            fr.paytime = DateTime.Now;
            fr.payee = "";
            fr.bank = "";
            fr.getpayaccount = "";
            fr.getpaysb = "";
            fr.getpaytime = DateTime.Now;
            fr.year = "";
            fr.flag = "";
            fr.bz = "";
        }
        //交款實際金額變更
        private void txtTruePrice_TextChanged(object sender, EventArgs e)
        {
            if (!System.Text.RegularExpressions.Regex.IsMatch(txtTruePrice.Text, @"^([0-9]*)\.?[0-9]*$"))
            {
                MessageBox.Show("請輸入正確的金額!");
                return;
            }
            //  double caizhi = Convert.ToDouble(txtTotalMoney.Text.Trim()) - Convert.ToDouble(txtTruePrice.Text.Trim());
            //if (caizhi > 0)
            //{
            //    labCaZhi.Text = "少收金額:";
            //    txtChazhi.Text = caizhi.ToString("0.00");
            //}
            //else
            //{
            //    labCaZhi.Text = "多收金額:";
            //    txtChazhi.Text = (-caizhi).ToString("0.00");
            //}

            loadPrintText();
        }
        //交款方式
        private void combSKFS_SelectedIndexChanged(object sender, EventArgs e)
        {
            jkfs = combSKFS.SelectedItem.ToString().Trim();
            for (int i = 0; i < tabControl1.TabPages.Count; i++)
            {
                if (tabControl1.TabPages[i].Text == jkfs)
                {
                    tabControl1.SelectedTab = tabControl1.TabPages[i];
                    if (tabControl1.SelectedTab.Text == "欠條")
                    {
                        loadPrintText();
                    }
                }

            }

        }

        //支票正面圖片
        private void pictureBox1_DoubleClick(object sender, EventArgs e)
        {

            if (DialogResult.OK == openFileDialog1.ShowDialog())
            {

                try
                {
                    // 讀成二進制
                    byteZhiPiaoA = File.ReadAllBytes(openFileDialog1.FileName);
                    // 直接返這個存儲到數據就好了 cmd.Parameters.Add("@image", SqlDbType.Image).Value = bytes;

                    // 輸出二進制 在這裏把數據中取到的值放在這裏byte[] bytes=(byte[])model.image;
                    pictureBox1.Image = System.Drawing.Image.FromStream(new MemoryStream(byteZhiPiaoA));
                    this.pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;

                    // 若是保存成文件:File.WriteAllBytes(@"d:\text.jpg", bytes);
                }
                catch { }
            }
        }

        //支票反面圖片
        private void pictureBox2_DoubleClick(object sender, EventArgs e)
        {
            //通過實踐,咱們能夠經過FileStream 來打開文件,這樣就能夠實現不鎖定Image文件,到時可讓多用戶同時訪問Image文件。具體文件實現以下:
            //FileStream fs = File.OpenRead(Path); //OpenRead
            //int filelength = 0;
            //filelength = (int)fs.Length; //得到文件長度 
            //Byte[] image = new Byte[filelength]; //創建一個字節數組 
            //fs.Read(image, 0, filelength); //按字節流讀取 
            //System.Drawing.Image result = System.Drawing.Image.FromStream(fs);
            //fs.Close();
            if (DialogResult.OK == openFileDialog1.ShowDialog())
            {

                try
                {
                    // 讀成二進制
                    byteZhiPiaoB = File.ReadAllBytes(openFileDialog1.FileName);
                    // 直接返這個存儲到數據就好了 cmd.Parameters.Add("@image", SqlDbType.Image).Value = bytes;

                    // 輸出二進制 在這裏把數據中取到的值放在這裏byte[] bytes=(byte[])model.image;
                    pictureBox2.Image = System.Drawing.Image.FromStream(new MemoryStream(byteZhiPiaoB));
                    this.pictureBox2.SizeMode = PictureBoxSizeMode.Zoom;

                    // 若是保存成文件:File.WriteAllBytes(@"d:\text.jpg", bytes);
                }
                catch { }
            }

        }
        //欠條圖片
        private void pictureBox3_DoubleClick(object sender, EventArgs e)
        {
            if (DialogResult.OK == openFileDialog1.ShowDialog())
            {

                try
                {
                    // 讀成二進制
                    byteQianTiaoA = File.ReadAllBytes(openFileDialog1.FileName);
                    // 直接返這個存儲到數據就好了 cmd.Parameters.Add("@image", SqlDbType.Image).Value = bytes;

                    // 輸出二進制 在這裏把數據中取到的值放在這裏byte[] bytes=(byte[])model.image;
                    pictureBox3.Image = System.Drawing.Image.FromStream(new MemoryStream(byteQianTiaoA));
                    this.pictureBox3.SizeMode = PictureBoxSizeMode.Zoom;

                    // 若是保存成文件:File.WriteAllBytes(@"d:\text.jpg", bytes);
                }
                catch { }
            }

        }
        //匯款正面
        private void pictureBox5_DoubleClick(object sender, EventArgs e)
        {
            if (DialogResult.OK == openFileDialog1.ShowDialog())
            {

                try
                {
                    // 讀成二進制
                    byteHuiKuanA = File.ReadAllBytes(openFileDialog1.FileName);
                    // 直接返這個存儲到數據就好了 cmd.Parameters.Add("@image", SqlDbType.Image).Value = bytes;

                    // 輸出二進制 在這裏把數據中取到的值放在這裏byte[] bytes=(byte[])model.image;
                    pictureBox5.Image = System.Drawing.Image.FromStream(new MemoryStream(byteHuiKuanA));
                    this.pictureBox5.SizeMode = PictureBoxSizeMode.Zoom;

                    // 若是保存成文件:File.WriteAllBytes(@"d:\text.jpg", bytes);
                }
                catch { }
            }
        }
        //匯款反面
        private void pictureBox6_DoubleClick(object sender, EventArgs e)
        {
            if (DialogResult.OK == openFileDialog1.ShowDialog())
            {

                try
                {
                    // 讀成二進制
                    byteHuiKuanB = File.ReadAllBytes(openFileDialog1.FileName);
                    // 直接返這個存儲到數據就好了 cmd.Parameters.Add("@image", SqlDbType.Image).Value = bytes;

                    // 輸出二進制 在這裏把數據中取到的值放在這裏byte[] bytes=(byte[])model.image;
                    pictureBox6.Image = System.Drawing.Image.FromStream(new MemoryStream(byteHuiKuanB));
                    this.pictureBox6.SizeMode = PictureBoxSizeMode.Zoom;



                    // 若是保存成文件:File.WriteAllBytes(@"d:\text.jpg", bytes);
                }
                catch { }
            }
        }


        private void tsbEdit_Click(object sender, EventArgs e)
        {
            if (txtDrawee.Enabled == txtDraweeTel.Enabled == txtTruePrice.Enabled == combSKR.Enabled == btnSave.Enabled == dateTimePicker1.Enabled == btnEdit.Enabled == false)
            {
                txtDrawee.Enabled = txtDraweeTel.Enabled = txtTruePrice.Enabled = combSKR.Enabled = btnSave.Enabled = dateTimePicker1.Enabled = btnEdit.Enabled = true;
                btnSave.Text = "修改";
            }
            else
            {
                txtDrawee.Enabled = txtDraweeTel.Enabled = txtTruePrice.Enabled = combSKR.Enabled = btnSave.Enabled = dateTimePicker1.Enabled = btnEdit.Enabled = false;
                btnSave.Text = "保存";
            }
        }

        private void rabOver_CheckedChanged(object sender, EventArgs e)
        {
            BtnSaveEnabled();
        }

        private void BtnSaveEnabled()
        {
            if (rabOver.Checked || rabPat.Checked)
            {
                btnSave.Enabled = true;
            }
            else
            {
                btnSave.Enabled = false;
            }

        }

        private void rabPat_CheckedChanged(object sender, EventArgs e)
        {
            BtnSaveEnabled();
        }

        private void btnUp_Click(object sender, EventArgs e)
        {

            if (txtTruePrice.Text != "")
            {

                if (btnUp.Text == "")
                {
                    trueprice = double.Parse(txtTotalMoney.Text.Trim());
                    txtTruePrice.Text = Math.Ceiling(trueprice).ToString("0");
                    btnUp.Text = "";
                }
                else
                {
                    trueprice = double.Parse(txtTotalMoney.Text.Trim());
                    txtTruePrice.Text = Math.Floor(trueprice).ToString("0");
                    btnUp.Text = "";
                }

            }
        }


        #region 功能區

        #region 打印內容設置
        #region 欠條
        private void loadPrintText()
        {
            Unit u = combJKDW.SelectedItem as Unit;
            rtbDoc.Font = new Font("仿宋", 16, FontStyle.Regular);

            rtbDoc.Text = "                         欠   條" + "\n";
            rtbDoc.Text += "\n";
            //rtbDoc.Text += "    今欠宣傳部" + mf.configbk.YEAR + "年度,黨報黨刊款(小寫):¥" + txtTruePrice.Text + "元。\n" + "大寫人民幣:" + RMBCapitalization.RMBAmount(double.Parse(txtTruePrice.Text)) + "。";
            rtbDoc.Text += "\n\n";
            rtbDoc.Text += "\n                         欠款單位:" + u.allname;
            rtbDoc.Text += "\n                         打欠條人:" + "               ";
            rtbDoc.Text += "\n                         電    話:" + txtDraweeTel.Text;
            rtbDoc.Text += "\n                         日    期:" + System.DateTime.Now.ToString("yyyy年MM月dd日");



        }
        #endregion
        #region 批覆
        private void getPiFu()
        {
            Unit u = combJKDW.SelectedItem as Unit;
            rtbDoc.Font = new Font("仿宋", 16, FontStyle.Regular);
            //todo:編號設置
            rtbDocPF.Font = new Font("仿宋", 16, FontStyle.Regular);
            rtbDocPF.Text = "第   號" + "\n";
            rtbDocPF.Text += "\n";
            //rtbDocPF.Text += "          關於提取" + mf.configbk.YEAR + "年度重點黨報黨刊徵訂獎金的批覆";
            rtbDocPF.Text += "\n";
            rtbDocPF.Text += "\n";
            rtbDocPF.Text += u.allname + ":";
            rtbDocPF.Text += "\n";
            rtbDocPF.Text += "\n";
            //rtbDocPF.Text += "    經研究贊成,對按時完成" + mf.configbk.YEAR + "年度重點黨報黨刊徵訂任務的單位給予獎勵,獎金爲報款總額的10%,資金自籌。\n";
            //rtbDocPF.Text += "    你單位按要求完成了任務,報款總額爲:¥" + txtTotalMoney.Text + "元,大寫:" + labRMB.Text.ToString() + ",獎金爲" + double.Parse(txtTotalMoney.Text) * .1 + "人民幣(大寫):" + RMBCapitalization.RMBAmount(double.Parse(txtTotalMoney.Text) * .1) + "。\n";
            rtbDocPF.Text += "\n";
            rtbDocPF.Text += "\n                              中共灤縣縣委宣傳部";
            rtbDocPF.Text += "\n";
            rtbDocPF.Text += "\n";
            rtbDocPF.Text += "                                 " + System.DateTime.Now.ToString("yyyy年MM月dd日");
            rtbDocPF.Text += "\n";
            rtbDocPF.Text += "…………………………………………………………………………";
            rtbDocPF.AppendText("\n");
            rtbDocPF.AppendText("第   號" + "\n");
            rtbDocPF.AppendText("\n");
            //rtbDocPF.AppendText("          關於提取" + mf.configbk.YEAR + "年度重點黨報黨刊徵訂獎金的批覆");
            rtbDocPF.AppendText("\n");
            rtbDocPF.AppendText("\n");
            rtbDocPF.AppendText(u.allname + ":");
            rtbDocPF.AppendText("\n");
            rtbDocPF.AppendText("\n");
            //rtbDocPF.AppendText("    經研究贊成,對按時完成" + mf.configbk.YEAR + "年度重點黨報黨刊徵訂任務的單位給予獎勵,獎金爲報款總額的10%,資金自籌。\n");
            //rtbDocPF.AppendText("    你單位按要求完成了任務,報款總額爲:¥" + txtTotalMoney.Text + "元,大寫:" + labRMB.Text.ToString() + ",獎金爲" + double.Parse(txtTotalMoney.Text) * .1 + "人民幣(大寫):" + RMBCapitalization.RMBAmount(double.Parse(txtTotalMoney.Text) * .1) + "。\n");
            rtbDocPF.AppendText("\n");
            rtbDocPF.AppendText("\n                              中共灤縣縣委宣傳部");
            rtbDocPF.AppendText("\n");
            rtbDocPF.AppendText("\n");
            rtbDocPF.AppendText("                                 " + System.DateTime.Now.ToString("yyyy年MM月dd日"));
            rtbDocPF.AppendText("\n");

        }
        #endregion
        #endregion

        #region Printing
        private int checkPrint;

        private void PrintDocument1_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {

            checkPrint = 0;

        }


        private void PrintDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            if (tabControl1.SelectedTab.Text == "欠條")
            {
                checkPrint = rtbDoc.Print(checkPrint, rtbDoc.TextLength, e);

                if (checkPrint < rtbDoc.TextLength)
                {
                    e.HasMorePages = true;
                }
                else
                {
                    e.HasMorePages = false;
                }
            }
            if (tabControl1.SelectedTab.Text == "批覆")
            {
                checkPrint = rtbDocPF.Print(checkPrint, rtbDocPF.TextLength, e);

                if (checkPrint < rtbDocPF.TextLength)
                {
                    e.HasMorePages = true;
                }
                else
                {
                    e.HasMorePages = false;
                }
            }

        }


        private void tsbtnPrintSetup_Click(object sender, EventArgs e)
        {
            this.pageSetupDialog1.ShowDialog();
        }

        private void tsbtnPrintView_Click(object sender, EventArgs e)
        {
            this.printPreviewDialog1.ShowDialog();
        }

        private void tsbtnPrint_Click(object sender, EventArgs e)
        {
            if (this.printDialog1.ShowDialog() == DialogResult.OK)
            {
                this.printDocument1.Print();
            }
        }

        #endregion

        #region 文字編輯設置
        private void tsbtnLeft_Click(object sender, EventArgs e)
        {
            if (tabControl1.SelectedTab.Text == "欠條")
            {
                if (this.rtbDoc.SelectionAlignment == HorizontalAlignment.Left)
                    this.rtbDoc.SelectionAlignment = HorizontalAlignment.Center;
                else
                    this.rtbDoc.SelectionAlignment = HorizontalAlignment.Left;
                this.rtbDoc.Focus();
            }
            if (tabControl1.SelectedTab.Text == "批覆")
            {
                if (this.rtbDocPF.SelectionAlignment == HorizontalAlignment.Left)
                    this.rtbDocPF.SelectionAlignment = HorizontalAlignment.Center;
                else
                    this.rtbDocPF.SelectionAlignment = HorizontalAlignment.Left;
                this.rtbDocPF.Focus();
            }
        }

        private void tsbtnCenter_Click(object sender, EventArgs e)
        {
            if (tabControl1.SelectedTab.Text == "欠條")
            {
                if (this.rtbDoc.SelectionAlignment == HorizontalAlignment.Center)
                    this.rtbDoc.SelectionAlignment = HorizontalAlignment.Left;
                else
                    this.rtbDoc.SelectionAlignment = HorizontalAlignment.Center;
                this.rtbDoc.Focus();
            }
            if (tabControl1.SelectedTab.Text == "批覆")
            {
                if (this.rtbDocPF.SelectionAlignment == HorizontalAlignment.Center)
                    this.rtbDocPF.SelectionAlignment = HorizontalAlignment.Left;
                else
                    this.rtbDocPF.SelectionAlignment = HorizontalAlignment.Center;
                this.rtbDocPF.Focus();
            }
        }

        private void tsbtnRight_Click(object sender, EventArgs e)
        {
            if (tabControl1.SelectedTab.Text == "欠條")
            {
                if (this.rtbDoc.SelectionAlignment == HorizontalAlignment.Right)
                    this.rtbDoc.SelectionAlignment = HorizontalAlignment.Left;
                else
                    this.rtbDoc.SelectionAlignment = HorizontalAlignment.Right;
                this.rtbDoc.Focus();
            }
            if (tabControl1.SelectedTab.Text == "批覆")
            {
                if (this.rtbDocPF.SelectionAlignment == HorizontalAlignment.Right)
                    this.rtbDocPF.SelectionAlignment = HorizontalAlignment.Left;
                else
                    this.rtbDocPF.SelectionAlignment = HorizontalAlignment.Right;
                this.rtbDocPF.Focus();
            }
        }

        private void tsbtnUnderline_Click(object sender, EventArgs e)
        {
            if (tabControl1.SelectedTab.Text == "欠條")
            {
                Font oldFont = this.rtbDoc.SelectionFont;
                Font newFont;
                if (oldFont.Underline)
                    newFont = new Font(oldFont, oldFont.Style & ~FontStyle.Underline);
                else
                    newFont = new Font(oldFont, oldFont.Style | FontStyle.Underline);
                this.rtbDoc.SelectionFont = newFont;
                this.rtbDoc.Focus();
            }
            if (tabControl1.SelectedTab.Text == "批覆")
            {
                Font oldFont = this.rtbDocPF.SelectionFont;
                Font newFont;
                if (oldFont.Underline)
                    newFont = new Font(oldFont, oldFont.Style & ~FontStyle.Underline);
                else
                    newFont = new Font(oldFont, oldFont.Style | FontStyle.Underline);
                this.rtbDocPF.SelectionFont = newFont;
                this.rtbDocPF.Focus();
            }
        }

        private void tsbtnBold_Click(object sender, EventArgs e)
        {
            if (tabControl1.SelectedTab.Text == "欠條")
            {
                Font oldFont = this.rtbDoc.SelectionFont;
                Font newFont;
                if (oldFont.Bold)
                    newFont = new Font(oldFont, oldFont.Style & ~FontStyle.Bold);
                else
                    newFont = new Font(oldFont, oldFont.Style | FontStyle.Bold);
                this.rtbDoc.SelectionFont = newFont;
                this.rtbDoc.Focus();
            }
            if (tabControl1.SelectedTab.Text == "批覆")
            {
                Font oldFont = this.rtbDocPF.SelectionFont;
                Font newFont;
                if (oldFont.Bold)
                    newFont = new Font(oldFont, oldFont.Style & ~FontStyle.Bold);
                else
                    newFont = new Font(oldFont, oldFont.Style | FontStyle.Bold);
                this.rtbDocPF.SelectionFont = newFont;
                this.rtbDocPF.Focus();
            }
        }

        private void tsbtnFont_Click(object sender, EventArgs e)
        {
            if (tabControl1.SelectedTab.Text == "欠條")
            {
                try
                {
                    if (!(rtbDoc.SelectionFont == null))
                    {
                        fontDialog1.Font = rtbDoc.SelectionFont;
                    }
                    else
                    {
                        fontDialog1.Font = null;
                    }
                    fontDialog1.ShowApply = true;
                    if (fontDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        rtbDoc.SelectionFont = fontDialog1.Font;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString(), "Error");
                }
            }
            if (tabControl1.SelectedTab.Text == "批覆")
            {
                try
                {
                    if (!(rtbDocPF.SelectionFont == null))
                    {
                        fontDialog1.Font = rtbDocPF.SelectionFont;
                    }
                    else
                    {
                        fontDialog1.Font = null;
                    }
                    fontDialog1.ShowApply = true;
                    if (fontDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        rtbDocPF.SelectionFont = fontDialog1.Font;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString(), "Error");
                }
            }
        }
        #endregion
        #endregion


    }
}
相關文章
相關標籤/搜索