frmsell.cs
来自「关于医院进销存的系统」· CS 代码 · 共 513 行 · 第 1/2 页
CS
513 行
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 frmSell : Form
{
public frmSell()
{
InitializeComponent();
}
private BindingSource client_bind = new BindingSource();
private DataView client_dv = null;
private SqlDataAdapter sell_da = null;
private SqlDataAdapter stock_da = null;
private BindingSource stock_bind = new BindingSource();
private DataView stock_dv = null;
private SqlDataAdapter client_arrerage_da = null;
private SqlDataAdapter sell_main_da = null;
private DataSet ds = new DataSet();
/// <summary>
/// 填充数据
/// </summary>
public void FillData()
{
SqlConnection Conn = new SqlConnection("server=" + CLoad.ReadServer() + ";pwd=" + CLoad.ReadPwd() + ";uid=sa;database=YYJXC");
SqlDataAdapter client_da = new SqlDataAdapter("select 客户名称,客户编号,拼音码,地址,所属地区,电话,联系人电话,欠款金额 from tb_client", Conn);
client_da.Fill(ds, "tb_client");
sell_da = new SqlDataAdapter("select * from tb_sell_detailed ", Conn);
SqlCommandBuilder sell_cb = new SqlCommandBuilder(sell_da);
sell_da.Fill(ds, "tb_sell_detailed");
stock_da = new SqlDataAdapter("select * from tb_stock", Conn);
SqlCommandBuilder stoce_cb = new SqlCommandBuilder(stock_da);
stock_da.Fill(ds, "tb_stock");
client_arrerage_da = new SqlDataAdapter("select * from tb_client_arrerage",Conn);
SqlCommandBuilder client_arrerage_cb = new SqlCommandBuilder(client_arrerage_da);
client_arrerage_da.Fill(ds, "tb_client_arrerage");
sell_main_da = new SqlDataAdapter("select * from tb_sell_main",Conn);
SqlCommandBuilder sell_main_cb = new SqlCommandBuilder(sell_main_da);
sell_main_da.Fill(ds, "tb_sell_main");
}
/// <summary>
/// 初始化
/// </summary>
public void init()
{
cbShouKuanFangChi.SelectedIndex = 0;
cbXiaoShouLeiXing.SelectedIndex = 0;
tbXiaoShaoDan.Clear();
tbLuDanTime.Clear();
tbKeHuName.Clear();
tbKeHuId.Clear();
tbJingShouRen.Clear();
listView1.Items.Clear();
tbYaoName.Clear();
tbShuLiang.Clear();
tbPingZhong.Text = "0";
tbHeJiShuLiang.Text = "0";
tbHeJiMoney.Text = "0";
tbZheKou.Text = "10";
tbShuiLv.Text = "0";
tbYingShouMoney.Text = "0";
tbShiShouMoney.Text = "0";
tbWeiShouMoney.Text = "0";
DataView dv = new DataView(ds.Tables["tb_sell_detailed"]);
dv.Sort = "销售单据号";
if (dv.Count < 1)
tbXiaoShaoDan.Text = "XS" + DateTime.Now.ToString("yyyyMMdd") + "0001";
else
{
string newStr = dv[dv.Count - 1]["销售单据号"].ToString().Substring(2);
tbXiaoShaoDan.Text = "XS" + (long.Parse(newStr) + 1).ToString();
}
tbLuDanTime.Text = DateTime.Now.ToShortDateString();
tbKeHuName.Focus();
}
private void frmSell_Load(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Maximized;
cbShouKuanFangChi.Items.Add("现金");
cbShouKuanFangChi.Items.Add("转帐支票");
cbShouKuanFangChi.Items.Add("汇票");
cbXiaoShouLeiXing.Items.Add("零售");
cbXiaoShouLeiXing.Items.Add("批发");
cbXiaoShouLeiXing.Items.Add("进贷");
FillData();
init();
}
private void tbKeHuName_TextChanged(object sender, EventArgs e)
{
try
{
tbKeHuId.Clear();
client_dv = new DataView(ds.Tables["tb_client"]);
client_dv.RowFilter = "客户名称 like '*" + tbKeHuName.Text.Trim() + "*' or 拼音码 like '*" + tbKeHuName.Text.Trim() + "*'";
client_bind.DataSource = client_dv;
dataGridView1.DataSource = null;
dataGridView1.DataSource = client_bind;
if (tbKeHuName.Text.Trim() != "" && client_bind.Count > 0)
{
dataGridView1.Columns[2].Visible = false;
dataGridView1.Visible = true;
}
else
dataGridView1.Visible = false;
}
catch { dataGridView1.Visible = false; }
}
private void tbKeHuName_KeyPress(object sender, KeyPressEventArgs e)
{
if (listView1.Items.Count > 0)
{
MessageBox.Show("登记正在进行不能更换客户!", "信息提示");
e.Handled = true;
tbYaoName.Focus();
tbYaoName.SelectAll();
return;
}
if ((Keys)e.KeyChar == Keys.Enter && dataGridView1.Visible)
{
tbKeHuName.Text = client_dv[client_bind.Position]["客户名称"].ToString();
tbKeHuId.Text = client_dv[client_bind.Position]["客户编号"].ToString();
dataGridView1.Visible = false;
tbJingShouRen.Focus();
e.Handled = true;
}
}
private void tbKeHuName_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Up && dataGridView1.Visible)
{
client_bind.Position -= 1;
e.Handled = true;
}
if (e.KeyCode == Keys.Down && dataGridView1.Visible)
{
client_bind.Position += 1;
e.Handled = true;
}
if (e.KeyCode == Keys.PageDown && dataGridView1.Visible)
{
client_dv.RowFilter = null;
client_bind.DataSource = client_dv;
}
}
private void tbKeHuName_Leave(object sender, EventArgs e)
{
dataGridView1.Visible = false;
}
private void tbYaoName_TextChanged(object sender, EventArgs e)
{
try
{
stock_dv = new DataView(ds.Tables["tb_stock"]);
stock_dv.RowFilter = "药品名称 like '*" + tbYaoName.Text.Trim() + "*' or 拼音码 like '*" + tbYaoName.Text.Trim() + "*' or 通用名 like '*" + tbYaoName.Text.Trim() + "*'";
stock_bind.DataSource = stock_dv;
dataGridView1.DataSource = null;
dataGridView1.DataSource = stock_bind;
if (tbYaoName.Text.Trim() != "" && stock_bind.Count > 0)
{
dataGridView1.Columns[0].Visible = false;
dataGridView1.Columns[2].Visible = false;
dataGridView1.Columns[3].Visible = false;
dataGridView1.Columns[4].Visible = false;
dataGridView1.Columns[6].Visible = false;
dataGridView1.Columns[7].Visible = false;
dataGridView1.Visible = true;
}
else
dataGridView1.Visible = false;
}
catch { dataGridView1.Visible = false; }
}
private void tbYaoName_KeyPress(object sender, KeyPressEventArgs e)
{
if (tbKeHuId.Text == "")
{
MessageBox.Show("该客户编号不存在!", "信息提示");
tbKeHuId.Clear();
tbKeHuName.Focus();
tbKeHuName.SelectAll();
e.Handled = true;
return;
}
if ((Keys)e.KeyChar == Keys.Enter && dataGridView1.Visible)
{
tbYaoName.Text = stock_dv[stock_bind.Position]["药品名称"].ToString();
dataGridView1.Visible = false;
tbShuLiang.Text = "1";
tbShuLiang.Focus();
tbShuLiang.SelectAll();
e.Handled = true;
}
}
private void tbYaoName_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Up && dataGridView1.Visible)
{
stock_bind.Position -= 1;
e.Handled = true;
}
if (e.KeyCode == Keys.Down && dataGridView1.Visible)
{
stock_bind.Position += 1;
e.Handled = true;
}
if (e.KeyCode == Keys.PageDown && dataGridView1.Visible)
{
stock_dv.RowFilter = null;
stock_bind.DataSource = stock_dv;
}
}
private void tbShuLiang_KeyPress(object sender, KeyPressEventArgs e)
{
try
{
if ((Keys)e.KeyChar == Keys.Enter)
cbXiaoShouLeiXing.Focus();
if ((Keys)e.KeyChar == Keys.Back) return;
int.Parse(e.KeyChar.ToString());
}
catch { e.Handled = true; }
}
private void tbZheKou_KeyPress(object sender, KeyPressEventArgs e)
{
try
{
if ((Keys)e.KeyChar == Keys.Back) return;
int shu = 0;
if (tbZheKou.Text != "")
shu = int.Parse(tbZheKou.Text);
if ((shu * 10 + int.Parse(e.KeyChar.ToString())) > 10 && tbZheKou.SelectionLength < tbZheKou.Text.Length)
e.Handled = true;
}
catch { e.Handled = true; }
}
private void tbShuiLv_KeyPress(object sender, KeyPressEventArgs e)
{
try
{
if (e.KeyChar == '.')
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?