frmyingshoumoney.cs
来自「关于医院进销存的系统」· CS 代码 · 共 103 行
CS
103 行
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace YYJXC
{
public partial class frmYingShouMoney : Form
{
public frmYingShouMoney()
{
InitializeComponent();
}
private SqlDataAdapter da = null;
private DataSet ds = new DataSet();
private void frmYingShouMoney_Load(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Maximized;
SqlConnection Conn = new SqlConnection("server=" + CLoad.ReadServer() + ";pwd=" + CLoad.ReadPwd() + ";uid=sa;database=YYJXC");
Conn.Open();
SqlCommand Comm = new SqlCommand("select 客户名称,客户编号 from tb_client", Conn);
SqlDataReader dr = Comm.ExecuteReader();
while (dr.Read())
{
comboBox1.Items.Add(dr.GetString(0));
comboBox2.Items.Add(dr.GetInt32(1).ToString());
}
Conn.Close();
da = new SqlDataAdapter("select * from tb_client_arrerage",Conn);
SqlCommandBuilder cb = new SqlCommandBuilder(da);
da.Fill(ds);
button1.Enabled = false;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox2.SelectedIndex = comboBox1.SelectedIndex;
DataView dv = new DataView(ds.Tables[0]);
dv.RowFilter = "客户名称 ='" + comboBox1.Text.Trim() + "'";
dv.Sort = "日期,时间";
dataGridView1.DataSource = dv;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (comboBox1.Text.Trim() != "")
{
if (textBox1.Text.Trim()!="" && long.Parse(textBox1.Text.Trim()) > 0)
button1.Enabled = true;
else
button1.Enabled = false;
}
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
try
{
if ((Keys)e.KeyChar == Keys.Back) return;
int.Parse(e.KeyChar.ToString());
}
catch { e.Handled = true; }
}
private void button1_Click(object sender, EventArgs e)
{
DataView dv = new DataView(ds.Tables[0]);
dv.RowFilter = "客户名称 ='" + comboBox1.Text + "'";
float LeiJi = 0;
if (dv.Count > 0 && dv[dv.Count - 1]["累计余额"].ToString()!="")
{
if (Math.Abs(float.Parse(dv[dv.Count - 1]["累计余额"].ToString())) > 0)
{
LeiJi = float.Parse(dv[dv.Count - 1]["累计余额"].ToString());
}
}
DataRow newRow = ds.Tables[0].NewRow();
newRow["日期"] = DateTime.Now.ToShortDateString();
newRow["时间"] = DateTime.Now.ToShortTimeString();
newRow["客户名称"] = comboBox1.Text;
newRow["客户编号"] = comboBox2.Text;
newRow["摘要"] = "收款:收【" + comboBox1.Text + "】" + textBox1.Text + "元";
newRow["收款合计"] = textBox1.Text;
newRow["累计余额"] = (LeiJi - float.Parse(textBox1.Text)).ToString();
ds.Tables[0].Rows.Add(newRow);
da.Update(ds.Tables[0]);
ds.Tables[0].AcceptChanges();
MessageBox.Show("收款成功!","信息提示");
textBox1.Clear();
comboBox1.Focus();
}
private void button2_Click(object sender, EventArgs e)
{
Close();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?