frmsell.cs

来自「关于医院进销存的系统」· CS 代码 · 共 513 行 · 第 1/2 页

CS
513
字号
                {
                    if (((TextBox)sender).Text.IndexOf('.') >= 0)
                    {
                        e.Handled = true;
                    }
                    return;
                }
                if ((Keys)e.KeyChar == Keys.Back) return;
                int.Parse(e.KeyChar.ToString());
            }
            catch
            {
                e.Handled = true;
            }
        }

        private void tbShuiLv_Leave(object sender, EventArgs e)
        {
            if (tbShuiLv.Text == "" || tbShuiLv.Text==".")
                tbShuiLv.Text = "0";
        }

        private void tbJingShouRen_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((Keys)e.KeyChar == Keys.Enter)
            {
                tbYaoName.Focus();
                e.Handled = true;
            }
        }

        public string MdiStr(string str)
        {
            string returnStr = str;
            if (str.IndexOf('.') > -1 && (str.Length - str.IndexOf('.') - 1) > 2)
            {
                returnStr = str.Substring(0, str.IndexOf('.') + 3);
            }
            return returnStr;
        }
        private void tbShiShouMoney_Leave(object sender, EventArgs e)
        {
            if (tbShiShouMoney.Text.Trim() == "" || tbShiShouMoney.Text==".")
                tbShiShouMoney.Text = "0";
        }

        private void tbYingShouMoney_TextChanged(object sender, EventArgs e)
        {
            ((TextBox)sender).Text = MdiStr(((TextBox)sender).Text);
        }

        private void cbXiaoShouLeiXing_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((Keys)e.KeyChar == Keys.Enter)
            {
                if (stock_bind.Count > 0 && tbYaoName.Text.Trim() != "")
                {
                    if (tbShuLiang.Text.Trim() == "" || tbShuLiang.Text.Trim() == "0")
                    {
                        MessageBox.Show("请输入数量!", "信息提示");
                        tbShuLiang.Focus();
                        return;
                    }
                    for (int i = 0; i < listView1.Items.Count; i++)
                    {
                        if (listView1.Items[i].SubItems[2].Text == stock_dv[stock_bind.Position]["药品编号"].ToString())
                        {
                            MessageBox.Show("上面已经有该药品的记录,不能再次添加!","信息提示");
                            tbYaoName.Clear();
                            tbYaoName.Focus();
                            return;
                        }
                    }
                    if (stock_dv[stock_bind.Position]["库存数量"].ToString().Trim() == "" || int.Parse(stock_dv[stock_bind.Position]["库存数量"].ToString().Trim()) < int.Parse(tbShuLiang.Text))
                    {
                        MessageBox.Show("该药品已的数量已经不够这次销售!", "信息提示");
                        tbYaoName.Clear();
                        tbYaoName.Focus();
                        return;
                    }
                    ListViewItem newItem = new ListViewItem((listView1.Items.Count + 1).ToString());
                    newItem.SubItems.Add(stock_dv[stock_bind.Position]["药品名称"].ToString());
                    newItem.SubItems.Add(stock_dv[stock_bind.Position]["药品编号"].ToString());
                    newItem.SubItems.Add(stock_dv[stock_bind.Position]["批号"].ToString());
                    newItem.SubItems.Add(stock_dv[stock_bind.Position]["规格"].ToString());
                    newItem.SubItems.Add(stock_dv[stock_bind.Position]["产地"].ToString());
                    newItem.SubItems.Add(stock_dv[stock_bind.Position]["单位"].ToString());
                    newItem.SubItems.Add(stock_dv[stock_bind.Position][cbXiaoShouLeiXing.Text + "价"].ToString());
                    newItem.SubItems.Add(tbShuLiang.Text.Trim());
                    string HeJiMoney = (int.Parse(tbShuLiang.Text.Trim()) * float.Parse(stock_dv[stock_bind.Position][cbXiaoShouLeiXing.Text + "价"].ToString())).ToString();
                    int ShuLiang = int.Parse(tbShuLiang.Text);
                    newItem.SubItems.Add(HeJiMoney);
                    newItem.SubItems.Add(cbXiaoShouLeiXing.Text);
                    listView1.Items.Add(newItem);
                    tbShuLiang.Clear();
                    tbYaoName.Clear();
                    tbYaoName.Focus();
                    tbPingZhong.Text = listView1.Items.Count.ToString();
                    tbHeJiShuLiang.Text = (int.Parse(tbHeJiShuLiang.Text) + ShuLiang).ToString();
                    tbHeJiMoney.Text = (float.Parse(tbHeJiMoney.Text) + float.Parse(HeJiMoney)).ToString();
                    tbYingShouMoney.Text = (float.Parse(tbHeJiMoney.Text) * (int.Parse(tbZheKou.Text) / 10.00) * (100 + float.Parse(tbShuiLv.Text)) / 100).ToString();
                    tbWeiShouMoney.Text = (float.Parse(tbYingShouMoney.Text) - float.Parse(tbShiShouMoney.Text)).ToString();
                }
                else
                {
                    MessageBox.Show("没有找到该药品!", "信息提示");
                    tbYaoName.Clear();
                    tbYaoName.Focus();
                }
                e.Handled = true;
                return;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (tbJingShouRen.Text.Trim() == "")
            {
                MessageBox.Show("请输入经手人名称!", "信息提示");
                tbJingShouRen.Focus();
                return;
            }
            if (listView1.Items.Count < 1)
            {
                MessageBox.Show("没有任何销售药品可以保存!","信息提示");
                tbYaoName.Clear();
                tbYaoName.Focus();
                return;
            }
            DataView dv = new DataView(ds.Tables["tb_stock"]);
            try
            {
                
                DataView dv1 = new DataView(ds.Tables["tb_client_arrerage"]);
                dv1.RowFilter = "客户编号 ='" + tbKeHuId.Text + "'";
                dv1.Sort = "日期,时间";
                float LeiJiMoney = 0;
                if (dv1.Count > 0 && dv1[dv1.Count-1]["累计余额"].ToString() != "")
                {
                    LeiJiMoney = float.Parse(dv1[dv1.Count - 1]["累计余额"].ToString());
                }
                for (int i = 0; i < listView1.Items.Count; i++)
                {
                    DataRow newRow = ds.Tables["tb_sell_detailed"].NewRow();
                    newRow["药品名称"] = listView1.Items[i].SubItems[1].Text;
                    newRow["药品编号"] = listView1.Items[i].SubItems[2].Text;
                    newRow["批号"] = listView1.Items[i].SubItems[3].Text;
                    newRow["规格"] = listView1.Items[i].SubItems[4].Text;
                    newRow["产地"] = listView1.Items[i].SubItems[5].Text;
                    newRow["单位"] = listView1.Items[i].SubItems[6].Text;
                    newRow["单价"] = listView1.Items[i].SubItems[7].Text;
                    newRow["数量"] = listView1.Items[i].SubItems[8].Text;
                    newRow["金额"] = listView1.Items[i].SubItems[9].Text;
                    newRow["销售类型"] = listView1.Items[i].SubItems[10].Text;
                    newRow["客户编号"] = tbKeHuId.Text;
                    newRow["客户名称"] = tbKeHuName.Text.Trim();
                    newRow["销售日期"] = tbLuDanTime.Text;
                    newRow["销售单据号"] = tbXiaoShaoDan.Text;
                    ds.Tables["tb_sell_detailed"].Rows.Add(newRow);
                    dv.RowFilter = "药品编号=" + listView1.Items[i].SubItems[2].Text;
                    dv[0]["库存数量"] = int.Parse(dv[0]["库存数量"].ToString()) - int.Parse(listView1.Items[i].SubItems[8].Text);
                    DataRow newRow1 = ds.Tables["tb_client_arrerage"].NewRow();
                    newRow1["日期"] = tbLuDanTime.Text;
                    newRow1["时间"] = DateTime.Now.ToShortTimeString();
                    newRow1["摘要"] = "销售:【" + tbKeHuName.Text.Trim() + "】的【" + listView1.Items[i].SubItems[1].Text + "," + listView1.Items[i].SubItems[3].Text + "】";
                    newRow1["数量"] = listView1.Items[i].SubItems[8].Text;
                    newRow1["单位"] = listView1.Items[i].SubItems[6].Text;
                    newRow1["单价"] = listView1.Items[i].SubItems[7].Text;
                    newRow1["金额小计"] = listView1.Items[i].SubItems[9].Text;
                    newRow1["欠款计帐"] = tbWeiShouMoney.Text;
                    //newRow1["收款合计"] = tbYingShouMoney.Text;
                    newRow1["累计余额"] = float.Parse(tbWeiShouMoney.Text) + LeiJiMoney;
                    newRow1["客户编号"] = tbKeHuId.Text;
                    newRow1["客户名称"] = tbKeHuName.Text;
                    newRow1["销售单据号"] = tbXiaoShaoDan.Text;
                    ds.Tables["tb_client_arrerage"].Rows.Add(newRow1);
                }
                DataRow newRow2 = ds.Tables["tb_sell_main"].NewRow();
                newRow2["销售单据号"] = tbXiaoShaoDan.Text;
                newRow2["品种数"] = tbPingZhong.Text;
                newRow2["数量"] = tbHeJiShuLiang.Text;
                newRow2["金额"] = tbHeJiMoney.Text;
                newRow2["折扣"] = tbZheKou.Text;
                newRow2["税率"] = tbShuiLv.Text;
                newRow2["应收"] = tbYingShouMoney.Text;
                newRow2["实收"] = tbShiShouMoney.Text;
                newRow2["未收"] = tbWeiShouMoney.Text;
                newRow2["客户编号"] = tbKeHuId.Text;
                newRow2["日期"] = tbLuDanTime.Text;
                newRow2["收款方式"] = cbShouKuanFangChi.Text;
                newRow2["经手人"] = tbJingShouRen.Text;
                if (float.Parse(tbWeiShouMoney.Text) > 0)
                    newRow2["是否结清"] = 0;
                else
                    newRow2["是否结清"] = 1;
                ds.Tables["tb_sell_main"].Rows.Add(newRow2);
                sell_da.Update(ds.Tables["tb_sell_detailed"]);
                ds.Tables["tb_sell_detailed"].AcceptChanges();
                stock_da.Update(ds.Tables["tb_stock"]);
                ds.Tables["tb_stock"].AcceptChanges();
                client_arrerage_da.Update(ds.Tables["tb_client_arrerage"]);
                ds.Tables["tb_client_arrerage"].AcceptChanges();
                sell_main_da.Update(ds.Tables["tb_sell_main"]);
                ds.Tables["tb_sell_main"].AcceptChanges();
            }
            catch (Exception err)
            {
                MessageBox.Show("操作出现错误:" + err.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            init();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("您确认要取消以上所有操作吗?", "信息提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                init();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void tbZheKou_TextChanged(object sender, EventArgs e)
        {
            if (tbZheKou.Text != "")
            {
                tbYingShouMoney.Text = (float.Parse(tbHeJiMoney.Text) * (int.Parse(tbZheKou.Text) / 10.00) * (100 + float.Parse(tbShuiLv.Text)) / 100).ToString();
                tbWeiShouMoney.Text = (float.Parse(tbYingShouMoney.Text) - float.Parse(tbShiShouMoney.Text)).ToString();
            }
        }

        private void tbZheKou_Leave(object sender, EventArgs e)
        {
            if (tbZheKou.Text == "")
                tbZheKou.Text = "10";
        }

        private void tbShuiLv_TextChanged(object sender, EventArgs e)
        {
            if (tbShuiLv.Text != "" && tbShuiLv.Text != ".")
            {
                tbYingShouMoney.Text = (float.Parse(tbHeJiMoney.Text) * (int.Parse(tbZheKou.Text) / 10.00) * (100 + float.Parse(tbShuiLv.Text)) / 100).ToString();
                tbWeiShouMoney.Text = (float.Parse(tbYingShouMoney.Text) - float.Parse(tbShiShouMoney.Text)).ToString();
            }
        }

        private void tbShiShouMoney_TextChanged(object sender, EventArgs e)
        {
            if (tbShiShouMoney.Text.Trim() != "" && tbShiShouMoney.Text != ".")
            {
                tbWeiShouMoney.Text = (float.Parse(tbYingShouMoney.Text) - float.Parse(tbShiShouMoney.Text)).ToString();
            }
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?