⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 goodsin.cs

📁 csharp 商品进销存报表系统 提供学习
💻 CS
📖 第 1 页 / 共 2 页
字号:
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;  //添加引用
using GoodsReportManage.ItemClass;

namespace GoodsReportManage.Goods
{
    public partial class GoodsIn : Form
    {
        public GoodsIn()
        {
            InitializeComponent();
        }

        SqlBaseClass G_SqlClass = new SqlBaseClass();  //声明数据库操作类的对象
        WinOperationClass G_OperationForm = new WinOperationClass();  //声明对窗体操作的类对象
        int G_Int_status;  //保存工具栏按钮操作状态

        /// <summary>
        /// 控制控件状态
        /// </summary>
        private void ControlStatus()
        {
            this.toolSave.Enabled = !this.toolSave.Enabled;
            this.toolAdd.Enabled = !this.toolAdd.Enabled;
            this.toolCancel.Enabled = !this.toolCancel.Enabled;
            this.toolAmend.Enabled = !this.toolAmend.Enabled;
            this.txtGoodsName.ReadOnly = !this.txtGoodsName.ReadOnly;
            this.txtHasPay.ReadOnly = !this.txtHasPay.ReadOnly;
            this.txtRemark.ReadOnly = !this.txtRemark.ReadOnly;
            this.txtSellPrice.ReadOnly = !this.txtSellPrice.ReadOnly;
            this.txtSpec.ReadOnly = !this.txtSpec.ReadOnly;
            this.txtGoodsInPrice.ReadOnly = !this.txtGoodsInPrice.ReadOnly;
            this.dtBirthday.Enabled = !this.dtBirthday.Enabled;
            this.txtNum.ReadOnly = !this.txtNum.ReadOnly;
            this.cbxDepot.Enabled = !this.cbxDepot.Enabled;
            this.cbxCompanyName.Enabled = !this.cbxCompanyName.Enabled;
            this.cbxUnit.Enabled = !this.cbxUnit.Enabled;
            this.cbxEmployeeName.Enabled = !this.cbxEmployeeName.Enabled;

            this.dgvGoodsInfo.Enabled = !this.dgvGoodsInfo.Enabled;
        }

        /// <summary>
        /// 在控件中填充选中的DataGridView控件的数据
        /// </summary>
        private void FillControls()
        {
            try
            {
                GoodsMoney();
                this.labGoodsID.Text = this.dgvGoodsInfo[0, this.dgvGoodsInfo.CurrentCell.RowIndex].Value.ToString();
                this.txtGoodsInPrice.Text = this.dgvGoodsInfo[6, this.dgvGoodsInfo.CurrentCell.RowIndex].Value.ToString();
                this.txtGoodsName.Text = this.dgvGoodsInfo[1, this.dgvGoodsInfo.CurrentCell.RowIndex].Value.ToString();
                this.txtHasPay.Text = this.dgvGoodsInfo[11, this.dgvGoodsInfo.CurrentCell.RowIndex].Value.ToString();
                this.txtNeedPay.Text = this.dgvGoodsInfo[10, this.dgvGoodsInfo.CurrentCell.RowIndex].Value.ToString();
                this.txtNum.Text = this.dgvGoodsInfo[4, this.dgvGoodsInfo.CurrentCell.RowIndex].Value.ToString();
                this.txtRemark.Text = this.dgvGoodsInfo[12, this.dgvGoodsInfo.CurrentCell.RowIndex].Value.ToString();
                this.txtSellPrice.Text = this.dgvGoodsInfo[9, this.dgvGoodsInfo.CurrentCell.RowIndex].Value.ToString();
                this.txtSpec.Text = this.dgvGoodsInfo[8, this.dgvGoodsInfo.CurrentCell.RowIndex].Value.ToString();
                this.cbxCompanyName.Text = this.dgvGoodsInfo[3, this.dgvGoodsInfo.CurrentCell.RowIndex].Value.ToString();
                this.cbxDepot.Text = this.dgvGoodsInfo[7, this.dgvGoodsInfo.CurrentCell.RowIndex].Value.ToString();
                this.cbxUnit.Text = this.dgvGoodsInfo[5, this.dgvGoodsInfo.CurrentCell.RowIndex].Value.ToString();
                this.dtBirthday.Value = Convert.ToDateTime(this.dgvGoodsInfo[2, this.dgvGoodsInfo.CurrentCell.RowIndex].Value.ToString());
                string P_Str_cmdtxt = "SELECT GoodsID,UserID FROM tb_Goods WHERE GoodsID='" + this.dgvGoodsInfo[0, this.dgvGoodsInfo.CurrentCell.RowIndex].Value.ToString() + "'";
                SqlDataReader P_dr = G_SqlClass.GetReader(P_Str_cmdtxt);
                P_dr.Read();
                if (P_dr.HasRows)
                {
                    string P_Str_cmdtxt2 = "SELECT UserID,Name FROM tb_User WHERE UserID='" + P_dr["UserID"].ToString() + "'";
                    SqlDataReader P_dr2 = G_SqlClass.GetReader(P_Str_cmdtxt2);
                    P_dr2.Read();
                    if (P_dr2.HasRows)
                    {
                        cbxEmployeeName.Text = P_dr2["Name"].ToString();
                    }
                    P_dr2.Close();
                }
                P_dr.Close();
            }
            catch { }
        }

        private void GoodsMoney()
        {
            string P_Str_cmdtxt = "SELECT GoodsNum*GoodsPrice AS 商品进价金额,GoodsNum*(SellPrice-GoodsPrice) AS 商品盈利额";
            P_Str_cmdtxt += " FROM tb_Goods WHERE GoodsID = '"+this.dgvGoodsInfo[0, this.dgvGoodsInfo.CurrentCell.RowIndex].Value.ToString() + "'";
            DataSet P_ds = G_SqlClass.GetDs(P_Str_cmdtxt);
            this.labGoodsIn.Text = P_ds.Tables[0].Rows[0][0].ToString();
            this.labGain.Text = P_ds.Tables[0].Rows[0][1].ToString();

            string P_Str_cmdtxt1 = "SELECT SUM(商品进价金额),SUM(商品盈利额) FROM (SELECT GoodsNum*GoodsPrice AS 商品进价金额,GoodsNum*(SellPrice-GoodsPrice) AS 商品盈利额 FROM tb_Goods) DERIVEDTBL";
            DataSet P_ds1 = G_SqlClass.GetDs(P_Str_cmdtxt1);

            this.labInTotalM.Text = P_ds1.Tables[0].Rows[0][0].ToString();
            this.lalTotalG.Text = P_ds1.Tables[0].Rows[0][1].ToString();
        }

        /// <summary>
        /// 将控件恢复到原始状态
        /// </summary>
        private void ClearControls()
        {
            this.cbxCompanyName.SelectedIndex = 0;
            this.cbxUnit.SelectedIndex = 0;
            this.cbxDepot.SelectedIndex = 0;

            this.txtGoodsInPrice.Text = "";
            this.txtGoodsName.Text = "";
            this.txtHasPay.Text = "";
            this.txtNeedPay.Text = "";
            this.txtNum.Text = "";
            this.txtRemark.Text = "";
            this.txtSellPrice.Text = "";
            this.txtSpec.Text = "";

            this.labGoodsID.Text = "";
        }

        private void GoodsIn_Load(object sender, EventArgs e)
        {
            string cmdtxt = "SELECT GoodsID as 商品ID,GoodsName as 商品名称,GoodsTime as 进货日期,CompanyName as 供应商名称";
            cmdtxt += ",GoodsNum as 进货数量,GoodsUnit as 商品单位,GoodsPrice as 商品进价,DepotName as 所属仓库,GoodsSpec as 商品规格";
            cmdtxt += ",SellPrice as 销售价格,NeedPay as 应付金额,HasPay as 实付金额,Remark as 备注 FROM tb_Goods";
            this.dgvGoodsInfo.DataSource = G_SqlClass.GetDs(cmdtxt).Tables[0];

            G_OperationForm.BindComboBox("SELECT * FROM tb_Company", cbxCompanyName, "CompanyName");  //绑定ComboBox控件
            G_OperationForm.BindComboBox("SELECT * FROM tb_Unit", cbxUnit, "UnitName");
            G_OperationForm.BindComboBox("SELECT * FROM tb_Depot", cbxDepot, "DepotSort");
            G_OperationForm.BindComboBox("SELECT * FROM tb_User",cbxEmployeeName, "Name");
        }

        private void toolSave_Click(object sender, EventArgs e)
        {
            string P_Str_condition, P_Str_cmdtxt;
            switch (G_Int_status)
            {
                case 1:
                    if (this.cbxEmployeeName.SelectedValue.ToString() != "")
                    {
                        string P_Str_Id = String.Empty;

                        //检索数据库中对应客户的ID
                        string P_Str_cmdtxt2 = "SELECT UserID,Name FROM tb_User WHERE Name='" + this.cbxEmployeeName.SelectedValue.ToString() + "'";
                        SqlDataReader P_dr = G_SqlClass.GetReader(P_Str_cmdtxt2);
                        P_dr.Read();
                        if (P_dr.HasRows)
                        {
                            P_Str_Id = P_dr["UserID"].ToString();
                        }
                        P_dr.Close();
                        //下面是要执行的SQL语句
                        P_Str_cmdtxt = "INSERT INTO tb_Goods(GoodsID,UserID,CompanyName,DepotName,GoodsName,GoodsNum,GoodsUnit,GoodsTime,GoodsSpec,GoodsPrice,SellPrice";
                        P_Str_cmdtxt += ",Remark,NeedPay,HasPay) VALUES('" + this.labGoodsID.Text + "','" + P_Str_Id + "'";
                        P_Str_cmdtxt += ",'" + this.cbxCompanyName.SelectedValue.ToString() + "','" + this.cbxDepot.SelectedValue.ToString() + "'";
                        P_Str_cmdtxt += ",'" + this.txtGoodsName.Text + "','" + this.txtNum.Text + "','" + this.cbxUnit.SelectedValue.ToString() + "'";
                        P_Str_cmdtxt += ",'" + this.dtBirthday.Value.ToString("yyyy-MM-dd") + "','" + this.txtSpec.Text + "'," + this.txtGoodsInPrice.Text + "";
                        P_Str_cmdtxt += "," + this.txtSellPrice.Text + ",'" + this.txtRemark.Text + "'";
                        P_Str_cmdtxt += "," + this.txtNeedPay.Text + "," + this.txtHasPay.Text + ")";

                        if (this.txtGoodsName.Text == "")
                        {
                            MessageBox.Show("商品名称不能为空!", "提示对话框", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        if (this.txtNum.Text == "")
                        {
                            MessageBox.Show("商品数量不能为空!", "提示对话框", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;

⌨️ 快捷键说明

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