基本信息
源码名称:简单汽车修理厂收费系统源码(含access数据库)
源码大小:5.83M
文件格式:.rar
开发语言:C#
更新时间:2018-04-17
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 1 元 
   源码介绍
简单汽车修理厂收费系统



using CYQ.Data;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WXPayer
{
    public partial class frmMain : CCWin.CCSkinMain
    {
        public frmMain()
        {
            InitializeComponent();
            this.Icon = Resource1.bitbug_favicon;
        }

        private void frmMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            //Application.Exit();
        }

        List<Model.ChargePartsItem> _partslist = null;
        List<Model.ChargeServerItem> _serverlist = null;


        private void frmMain_Load(object sender, EventArgs e)
        {
            dgvServer.AutoGenerateColumns = true;
            string payerprinter = Common.Setting.Get("payerprinter", "Printer", "");
            if (string.IsNullOrEmpty(payerprinter))
            {
                MessageBox.Show("未设置打印机");
            }

            txtYouhui.KeyPress  = new KeyPressEventHandler(control_KeyPress);
            txtYouhui.Leave  = new EventHandler(control_Leave);
            txtYouhui.TextChanged  = new EventHandler(control_TextChanged);
            Reset();
        }

        private void Reset()
        {
            _partslist = new List<Model.ChargePartsItem>();
            _serverlist = new List<Model.ChargeServerItem>();
            dgvServer.Rows.Clear();
            dgvPart.Rows.Clear();
            skinTabControl1.SelectedIndex = 0;
            txtCarNo.Text = txtCustomName.Text = txtJiedai.Text = txtPhone.Text = "";
            txtRealPrice.Text = txtTotal.Text = txtYouhui.Text = "0.00";
        }

        TextBox control;
        private void control_KeyPress(object sender, KeyPressEventArgs e)
        {
            //限制只能输入-9的数字,退格键,小数点和回车
            if (((int)e.KeyChar >= 48 && (int)e.KeyChar <= 57) || e.KeyChar == 13 || e.KeyChar == 8 || e.KeyChar == 46)
            {
                e.Handled = false;
            }
            else
            {
                e.Handled = true;
            }
        }

        private void control_Leave(object sender, EventArgs e)
        {
            TextBox txt = (TextBox)sender;
            if (txt.Text == "")
            {
                txt.Text = "0.00";
            }
            CountCost();
        }

        public DataGridViewTextBoxEditingControl CellEdit = null;
        private void dgvServer_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            DataGridView dgv = (DataGridView)sender;
            if (dgv.CurrentCellAddress.X == 1 || dgv.CurrentCellAddress.X == 2)//获取当前处于活动状态的单元格索引
            {
                CellEdit = (DataGridViewTextBoxEditingControl)e.Control;
                CellEdit.SelectAll();
                CellEdit.KeyPress  = control_KeyPress;
            }
            //if (dgv.CurrentCell.ColumnIndex == 1 || dgv.CurrentCell.ColumnIndex == 2)
            //{
            //    control = new TextBox();
            //    control = (TextBox)e.Control;
            //    //if (control.Text == "0")    //需要限制输入数字的单元格               
            //    //{
            //    control.KeyPress  = new KeyPressEventHandler(control_KeyPress);
            //    control.TextChanged  = new EventHandler(control_TextChanged);
            //    //}
            //    //else
            //    //{
            //    //    //非数字类型单元格
            //    //    control.Leave  = new EventHandler(control_Leave);
            //    //}
            //}
        }

        private void dgvServer_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1)
            {
                return;
            }
            if (e.ColumnIndex == 0)
            {
                var ss = new frmServerList();
                if (ss.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    string ServerName = ss.model.ServerName;
                    bool IshasEmptyRow = false;
                    int level = -1;
                    foreach (DataGridViewRow row in dgvServer.Rows)
                    {
                        level  ;
                        if (row.Cells[0].Value != null && row.Cells[0].Value.ToString() == ServerName)
                        {
                            MessageBox.Show("服务项目重复");
                            return;
                        }
                        if (e.RowIndex != level && (row.Cells[0].Value == null || row.Cells[0].Value.ToString() == ""))
                        {
                            IshasEmptyRow = true;
                        }
                    }

                    if (!IshasEmptyRow)
                    {
                        DataGridViewRow dr = new DataGridViewRow();
                        dr.CreateCells(dgvServer);
                        dr.Cells[0].Value = ServerName;
                        dr.Cells[1].Value = ss.model.Cost;
                        int quantity = 1;
                        if (dgvServer.Rows[e.RowIndex].Cells[2].Value != null)
                        {
                            int.TryParse(dgvServer.Rows[e.RowIndex].Cells[2].Value.ToString(), out quantity);
                        }
                        dr.Cells[3].Value = ss.model.Cost * quantity;
                        dgvServer.Rows.Insert(dgvServer.Rows.Count - 1, dr);
                    }
                    else
                    {
                        dgvServer.CurrentCell.Value = ServerName;
                        dgvServer.Rows[e.RowIndex].Cells[1].Value = ss.model.Cost;
                        int quantity = 1;
                        if (dgvServer.Rows[e.RowIndex].Cells[2].Value != null)
                        {
                            int.TryParse(dgvServer.Rows[e.RowIndex].Cells[2].Value.ToString(), out quantity);
                        }
                        dgvServer.Rows[e.RowIndex].Cells[3].Value = ss.model.Cost * quantity;
                    }
                    CountCost();
                }
            }
        }

        private void btnClear_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (MessageBox.Show("确定要清空吗?", "温馨提示", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK)
            {
                if (skinTabControl1.SelectedIndex == 0)
                {
                    dgvServer.Rows.Clear();
                }
                else
                {
                    dgvPart.Rows.Clear();
                }
            }
        }

        /// <summary>
        /// 计算金额
        /// </summary>
        private void CountCost()
        {
            decimal total = 0;
            foreach (DataGridViewRow dr in dgvServer.Rows)
            {
                if (dr.Cells[1].Value == null)
                {
                    break;
                }
                decimal price = decimal.Parse(dr.Cells[1].Value.ToString());
                string a = "1";
                if (dr.Cells[2].Value != null)
                {
                    a = dr.Cells[2].Value.ToString();
                }

                decimal quantity = decimal.Parse(a);
                total  = (price * quantity);
            }
            foreach (DataGridViewRow dr in dgvPart.Rows)
            {
                if (dr.Cells[1].Value == null)
                {
                    break;
                }
                decimal price = decimal.Parse(dr.Cells[1].Value.ToString());
                string a = "1";
                if (dr.Cells[2].Value != null)
                {
                    a = dr.Cells[2].Value.ToString();
                }
                decimal quantity = decimal.Parse(a);
                total  = (price * quantity);
            }
            txtTotal.Text = total.ToString("#0.00");

            txtRealPrice.Text = "0.00";
            if (!string.IsNullOrEmpty(txtYouhui.Text.Trim()))
            {
                decimal youhui = decimal.Parse(txtYouhui.Text.Trim());
                decimal realprice = total - youhui;
                txtRealPrice.Text = realprice.ToString("#0.00");
            }

        }

        private void control_TextChanged(object sender, EventArgs e)
        {
            CountCost();
        }

        private void dgvServer_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0 || e.ColumnIndex < 0)
            {
                return;
            }
            if (e.ColumnIndex == 0)
            {

            }
            DataGridView dgv = (DataGridView)sender;
            int quantity = 1;
            if (dgv.Rows[e.RowIndex].Cells[2].Value != null)
            {
                int.TryParse(dgv.Rows[e.RowIndex].Cells[2].Value.ToString(), out quantity);
            }
            decimal cost = 0;
            if (dgv.Rows[e.RowIndex].Cells[1].Value != null)
            {
                decimal.TryParse(dgv.Rows[e.RowIndex].Cells[1].Value.ToString(), out cost);
            }
            dgv.Rows[e.RowIndex].Cells[3].Value = cost * quantity;

            CountCost();
        }

        private void dgvPart_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1)
            {
                return;
            }
            if (e.ColumnIndex == 0)
            {
                var ss = new frmPartList();
                if (ss.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    string PartName = ss.model.PartName;
                    bool IshasEmptyRow = false;
                    int level = -1;
                    foreach (DataGridViewRow row in dgvServer.Rows)
                    {
                        level  ;
                        if (row.Cells[0].Value != null && row.Cells[0].Value.ToString() == PartName)
                        {
                            MessageBox.Show("配件重复");
                            return;
                        }
                        if (e.RowIndex != level && (row.Cells[0].Value == null || row.Cells[0].Value.ToString() == ""))
                        {
                            IshasEmptyRow = true;
                        }
                    }

                    if (!IshasEmptyRow)
                    {
                        DataGridViewRow dr = new DataGridViewRow();
                        dr.CreateCells(dgvServer);
                        dr.Cells[0].Value = ServerName;
                        dr.Cells[1].Value = ss.model.Cost;
                        int quantity = 1;
                        if (dgvPart.Rows[e.RowIndex].Cells[2].Value != null)
                        {
                            int.TryParse(dgvPart.Rows[e.RowIndex].Cells[2].Value.ToString(), out quantity);
                        }
                        dr.Cells[3].Value = ss.model.Cost * quantity;
                        dgvPart.Rows.Insert(dgvPart.Rows.Count - 1, dr);
                    }
                    else
                    {
                        dgvPart.CurrentCell.Value = ServerName;
                        dgvPart.Rows[e.RowIndex].Cells[1].Value = ss.model.Cost;
                        int quantity = 1;
                        if (dgvPart.Rows[e.RowIndex].Cells[2].Value != null)
                        {
                            int.TryParse(dgvPart.Rows[e.RowIndex].Cells[2].Value.ToString(), out quantity);
                        }
                        dgvPart.Rows[e.RowIndex].Cells[3].Value = ss.model.Cost * quantity;
                    }
                    CountCost();
                }
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            btnSave.Enabled = false;
            btnSave.Text = "提交中...";
            Model.Charges charge = new Model.Charges();
            charge.CustomName = txtCustomName.Text.Trim();
            charge.Phone = txtPhone.Text.Trim();
            charge.CarNo = txtCarNo.Text.Trim();
            charge.JieDaiName = txtJiedai.Text.Trim();
            charge.JieDaiTime = txtJiedaiDate.Text   txtJiedaiTime.Text;
            charge.RealPrice = decimal.Parse(txtRealPrice.Text);
            charge.Total = decimal.Parse(txtTotal.Text);
            charge.Youhui = decimal.Parse(txtYouhui.Text);
            charge.Remark = txtRemark.Text;

            if (string.IsNullOrEmpty(charge.CustomName))
            {
                MessageBox.Show("客户名称不能为空");
                btnSave.Text = "提 交";
                btnSave.Enabled = true;
                return;
            }

            if (dgvServer.Rows.Count == 0 && dgvPart.Rows.Count == 0)
            {
                MessageBox.Show("请添加服务或配件");
                btnSave.Text = "提 交";
                btnSave.Enabled = true;
                return;
            }
            using (MAction action = new MAction("Charges", Model.Conn.Access))
            {
                bool result = false;
                action.SetTransLevel(IsolationLevel.ReadCommitted);//可设置的事务级别,一般可以不用设置
                action.BeginTransation();//设置开启事务标识

                action.Set("CustomName", charge.CustomName);
                action.Set("Phone", charge.Phone);
                action.Set("CarNo", charge.CarNo);
                action.Set("JieDaiName", charge.JieDaiName);
                action.Set("JieDaiTime", charge.JieDaiTime);
                action.Set("RealPrice", charge.RealPrice);
                action.Set("Total", charge.Total);
                action.Set("Youhui", charge.Youhui);
                action.Set("Remark", charge.Remark);
                action.Set("CreateTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm"));
                int id = 0;
                if (action.Insert())//第一个执行时,事务才被加载
                {
                    id = action.Get<int>("ID");
                    action.ResetTable("ChargeServerItem");
                    foreach (DataGridViewRow dr in dgvServer.Rows)
                    {
                        if (dr.Cells[0].Value == null)
                        {
                            break;
                        }
                        action.Set("ChargeID", id);
                        action.Set("ServerName", dr.Cells[0].Value.ToString());
                        action.Set("Cost", dr.Cells[1].Value);
                        string quantity = "0";
                        if (dr.Cells[2].Value != null)
                        {
                            quantity = dr.Cells[2].Value.ToString();
                        }
                        action.Set("Quantity", (quantity == "0" ? "1" : quantity));
                        result = action.Insert(InsertOp.None);
                    }
                    action.ResetTable("ChargePartsItem");
                    foreach (DataGridViewRow dr in dgvPart.Rows)
                    {
                        if (dr.Cells[0].Value == null)
                        {
                            break;
                        }
                        action.Set("ChargeID", id);
                        action.Set("PartName", dr.Cells[0].Value.ToString());
                        action.Set("Cost", dr.Cells[1].Value);
                        string quantity = "0";
                        if (dr.Cells[2].Value != null)
                        {
                            quantity = dr.Cells[2].Value.ToString();
                        }
                        action.Set("Quantity", (quantity == "0" ? "1" : quantity));
                        result = action.Insert(InsertOp.None);
                    }
                }
                else
                {
                    action.RollBack();//手工回滚
                    MessageBox.Show("操作失败", "温馨提示");
                    btnSave.Text = "提 交";
                    btnSave.Enabled = true;
                    return;
                }
                action.EndTransation();
                var dialogresult = MessageBox.Show("操作成功!\n是:打印收费单\n否:不打印", "温馨提示", MessageBoxButtons.YesNo);
                if (dialogresult == System.Windows.Forms.DialogResult.Yes)
                {
                    //打印
                    Common.PrintOrder order = new Common.PrintOrder(id);
                    if (order.Printer())
                    {
                        MessageBox.Show("打印任务已发出");
                    }
                    else
                    {
                        MessageBox.Show(order.outmessage);
                    }
                }
                btnSave.Text = "提 交";
                btnSave.Enabled = true;
                Reset();
            }
        }

        private void txtCarNo_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtCarNo.Text.Trim()))
            {
                txtCarNo.Text = "粤A";
                txtCarNo.ScrollToCaret();
            }
        }
    }
}