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

📄 customerregoods.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 GoodsReportManage.Stock;
using GoodsReportManage.ItemClass;
using System.Data.SqlClient;

namespace GoodsReportManage.Sell
{
    public partial class CustomerReGoods : Form
    {
        public CustomerReGoods()
        {
            InitializeComponent();
        }

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

        /// <summary>
        /// 控制控件状态
        /// </summary>
        private void ControlStatus()
        {
            this.groupBox1.Enabled = !this.groupBox1.Enabled;
            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.dgvReGoodsInfo.Enabled = !this.dgvReGoodsInfo.Enabled;
        }

        /// <summary>
        /// 在控件中填充选中的DataGridView控件的数据
        /// </summary>
        private void FillControls()
        {
            try
            {
                this.labReGoodsID.Text = this.dgvReGoodsInfo[0, this.dgvReGoodsInfo.CurrentCell.RowIndex].Value.ToString();
                PropertyClass.GetDgvData = this.dgvReGoodsInfo[2, this.dgvReGoodsInfo.CurrentCell.RowIndex].Value.ToString();
                PropertyClass.GetSellPrice = this.dgvReGoodsInfo[8, this.dgvReGoodsInfo.CurrentCell.RowIndex].Value.ToString();
                PropertyClass.GetStockSpec = this.dgvReGoodsInfo[7, this.dgvReGoodsInfo.CurrentCell.RowIndex].Value.ToString();
                this.txtHasPay.Text = this.dgvReGoodsInfo[10, this.dgvReGoodsInfo.CurrentCell.RowIndex].Value.ToString();
                this.txtNeedPay.Text = this.dgvReGoodsInfo[9, this.dgvReGoodsInfo.CurrentCell.RowIndex].Value.ToString();
                this.txtNum.Text = this.dgvReGoodsInfo[5, this.dgvReGoodsInfo.CurrentCell.RowIndex].Value.ToString();
                this.txtResult.Text = this.dgvReGoodsInfo[11, this.dgvReGoodsInfo.CurrentCell.RowIndex].Value.ToString();
                this.cbxUnit.Text = this.dgvReGoodsInfo[6, this.dgvReGoodsInfo.CurrentCell.RowIndex].Value.ToString();
                this.cbxCustomerName.Text = this.dgvReGoodsInfo[3, this.dgvReGoodsInfo.CurrentCell.RowIndex].Value.ToString();
                this.dtBirthday.Value = Convert.ToDateTime(this.dgvReGoodsInfo[3, this.dgvReGoodsInfo.CurrentCell.RowIndex].Value.ToString());
            }
            catch { }
        }

        /// <summary>
        /// 将控件恢复到原始状态
        /// </summary>
        private void ClearControls()
        {
            this.cbxUnit.SelectedIndex = 0;
            this.cbxCustomerName.SelectedIndex = 0;
            this.txtGoodsName.Text = "";
            this.txtHasPay.Text = "";
            this.txtNeedPay.Text = "";
            this.txtNum.Text = "";
            this.txtReGoodsPrice.Text = "";
            this.txtResult.Text = "";
            this.txtSpec.Text = "";
            this.dtBirthday.Value = DateTime.Now;
            this.labReGoodsID.Text = "";
        }

        private void ReGoods_Load(object sender, EventArgs e)
        {
            this.timer1.Start();
            string P_Str_cmdtxt = "SELECT ReGoodsID as 退货ID,GoodsID as 进货ID,ReGoodsName as 商品名称,Name as 顾客姓名,ReGoodsTime as 退货日期";
            P_Str_cmdtxt += ",ReGoodsNum as 退货数量,ReGoodsUnit as 商品单位,ReGoodsSpec as 商品规格,ReGoodsPrice as 销售价格,NeedPay as 应付金额";
            P_Str_cmdtxt += ",HasPay as 实付金额,ReGoodsResult as 退货原因 FROM v_ReGoods WHERE ReGoodsSort='1'";
            this.dgvReGoodsInfo.DataSource = G_SqlClass.GetDs(P_Str_cmdtxt).Tables[0];
            G_OperationForm.BindComboBox("SELECT * FROM tb_Unit", cbxUnit, "UnitName");
            G_OperationForm.BindComboBox("SELECT * FROM tb_Customer", cbxCustomerName, "Name");
        }

        private void toolSave_Click(object sender, EventArgs e)
        {
            string P_Str_condition, P_Str_cmdtxt;
            switch (G_Int_status)
            {
                case 1:
                    if (this.cbxCustomerName.SelectedValue.ToString() != "")
                    {
                        if (this.txtGoodsName.Text == "")
                        {
                            MessageBox.Show("商品名称不能为空!", "提示对话框", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        if (this.txtNum.Text == "")
                        {
                            MessageBox.Show("商品数量不能为空!", "提示对话框", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        if (this.txtReGoodsPrice.Text == "")
                        {
                            MessageBox.Show("商品进价不能为空!", "提示对话框", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        if (!G_OperationForm.IsNumeric(this.txtNum.Text) && !G_OperationForm.IsNumeric(this.txtHasPay.Text)
                            && !G_OperationForm.IsNumeric(this.txtReGoodsPrice.Text))
                        {
                            MessageBox.Show("您输入的数据格式有误!", "提示对话框", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }

                        string P_Str_Id = String.Empty;
  
                        //检索数据库中对应客户的ID
                        string P_Str_cmdtxt2 = "SELECT CustomerID,Name FROM tb_Customer WHERE Name='"+this.cbxCustomerName.SelectedValue.ToString()+"'";
                        SqlDataReader P_dr = G_SqlClass.GetReader(P_Str_cmdtxt2);
                        P_dr.Read();
                        if (P_dr.HasRows)
                        {
                            P_Str_Id = P_dr["CustomerID"].ToString();
                        }
                        P_dr.Close();
                        //下面是要执行的SQL语句
                        P_Str_cmdtxt = "INSERT INTO tb_ReGoods(ReGoodsID,GoodsID,UserID,CustomerID,ReGoodsName,ReGoodsSpec,ReGoodsNum,ReGoodsUnit";
                        P_Str_cmdtxt += ",ReGoodsTime,ReGoodsPrice,NeedPay,HasPay,ReGoodsResult,ReGoodsSort,StockID) VALUES('" + this.labReGoodsID.Text + "'";
                        P_Str_cmdtxt += ",'" + PropertyClass.GetGoodsID + "','" + PropertyClass.SendUserIDValue + "'," + P_Str_Id + "";
                        P_Str_cmdtxt += ",'" + this.txtGoodsName.Text + "','" + this.txtSpec.Text + "','" + this.txtNum.Text + "'";
                        P_Str_cmdtxt += ",'" + this.cbxUnit.SelectedValue.ToString() + "','" + this.dtBirthday.Value.ToString("yyyy-MM-dd") + "'";
                        P_Str_cmdtxt += "," + Convert.ToDecimal(this.txtReGoodsPrice.Text) + "," + Convert.ToDecimal(this.txtNeedPay.Text) + "," + Convert.ToDecimal(this.txtHasPay.Text) + "";
                        P_Str_cmdtxt += ",'" + this.txtResult.Text + "','1','" + PropertyClass.GetStockID + "')";

                        if (this.txtGoodsName.Text == "")
                        {
                            MessageBox.Show("商品名称不能为空!", "提示对话框", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        else
                        {
                            SqlDataReader P_dr2 = G_SqlClass.GetReader("select GoodsID,GoodsNum from tb_Sell where GoodsID='" 
                                + PropertyClass.GetGoodsID + "' and GoodsNum<'" + Convert.ToInt32(txtNum.Text.Trim()) + "'");
                            P_dr2.Read();
                            if (P_dr2.HasRows)
                            {
                                MessageBox.Show("没有销售过这么多商品,请重新填写退货数量!");
                                txtNum.Text = "";
                                txtNum.Focus();
                            }
                            else
                            {

⌨️ 快捷键说明

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