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

📄 frmginfomanage.cs

📁 企业客户资源管理系统 企业客户资源管理系统
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CRM.PInfoManage
{
    public partial class frmGInfoManage : Form
    {
        CRM.BaseClass.BaseOperate boperate = new CRM.BaseClass.BaseOperate();
        CRM.BaseClass.OperateAndValidate opAndvalidate = new CRM.BaseClass.OperateAndValidate();
        protected string M_str_sql = "select GID as 货物编号,GName as 货物名称,GType as 所属类别,GSpec as 货物规格,"
            + "GIPrice as 进货价格,GOPrice as 销售价格,GUnit as 计量单位,GRemark as 备注 from tb_GoodsInfo";
        protected string M_str_table = "tb_GoodsInfo";
        protected int M_int_judge;
        public frmGInfoManage()
        {
            InitializeComponent();
        }

        private void frmGInfoManage_Load(object sender, EventArgs e)
        {
            DataSet myds = boperate.getds(M_str_sql, M_str_table);
            dgvGInfo.DataSource = myds.Tables[0];
            if (myds.Tables[0].Rows.Count > 0)
                tsbtnDel.Enabled = true;
            else
                tsbtnDel.Enabled = false;
        }

        private void tsbtnAdd_Click(object sender, EventArgs e)
        {
            opAndvalidate.autoNum("select GID from tb_GoodsInfo", "tb_GoodsInfo", "GID", "HW", "1000001", txtGID);
            tsbtnSave.Enabled = true;
            M_int_judge = 0;
            ClearText();
        }

        private void tsbtnEdit_Click(object sender, EventArgs e)
        {
            tsbtnSave.Enabled = true;
            M_int_judge = 1;
        }

        private void tsbtnSave_Click(object sender, EventArgs e)
        {
            if (M_int_judge == 0)
            {
                if (txtGName.Text == "")
                {
                    MessageBox.Show("货物名称不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (txtInPrice.Text == "")
                {
                    MessageBox.Show("货物进货价格不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (txtOutPrice.Text == "")
                {
                    MessageBox.Show("货物销售价格不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    if (!opAndvalidate.validateNum(txtInPrice.Text.Trim()))
                    {
                        errorPrOutMoney.Clear();
                        errorPrInMoney.SetError(txtInPrice, "这里必须输入数字");
                    }
                    else if (!opAndvalidate.validateNum(txtOutPrice.Text.Trim()))
                    {
                        errorPrInMoney.Clear();
                        errorPrOutMoney.SetError(txtOutPrice, "这里必须输入数字");
                    }
                    else
                    {
                        errorPrInMoney.Clear();
                        errorPrOutMoney.Clear();
                        boperate.getcom("insert into tb_GoodsInfo(GID,GName,GType,GSpec,GIPrice,GOPrice,GUnit,GRemark) "
                            + "values('" + txtGID.Text.Trim() + "','" + txtGName.Text.Trim() + "','" + cboxGType.Text.Trim()
                            + "','" + txtGSpec.Text.Trim() + "'," + txtInPrice.Text.Trim() + "," + txtOutPrice.Text.Trim() + ",'"
                            + cboxGUnit.Text.Trim() + "','" + txtGRemark.Text.Trim() + "')");
                        frmGInfoManage_Load(sender, e);
                        MessageBox.Show("货物信息添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        tsbtnSave.Enabled = false;
                    }
                }
            }
            if (M_int_judge == 1)
            {
                if (txtGName.Text == "")
                {
                    MessageBox.Show("货物名称不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (txtInPrice.Text == "")
                {
                    MessageBox.Show("货物进货价格不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (txtOutPrice.Text == "")
                {
                    MessageBox.Show("货物销售价格不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    if (!opAndvalidate.validateNum(txtInPrice.Text.Trim()))
                    {
                        errorPrOutMoney.Clear();
                        errorPrInMoney.SetError(txtInPrice, "这里必须输入数字");
                    }
                    else if (!opAndvalidate.validateNum(txtOutPrice.Text.Trim()))
                    {
                        errorPrInMoney.Clear();
                        errorPrOutMoney.SetError(txtOutPrice, "这里必须输入数字");
                    }
                    else
                    {
                        errorPrInMoney.Clear();
                        errorPrOutMoney.Clear();
                        boperate.getcom("update tb_GoodsInfo set GName='" + txtGName.Text.Trim() + "',GType='" + cboxGType.Text.Trim()
                            + "',GSpec='" + txtGSpec.Text.Trim() + "',GIPrice=" + txtInPrice.Text.Trim() + ",GOPrice=" + txtOutPrice.Text.Trim()
                            + ",GUnit='" + cboxGUnit.Text.Trim() + "',GRemark='" + txtGRemark.Text.Trim() + "' where GID='" + txtGID.Text.Trim() + "'");
                        frmGInfoManage_Load(sender, e);
                        MessageBox.Show("货物信息修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        tsbtnSave.Enabled = false;
                    }
                }
            }
        }

        private void tsbtnDel_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("确定要删除该货物吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    boperate.getcom("delete from tb_GoodsInfo where GID='" + Convert.ToString(dgvGInfo[0, dgvGInfo.CurrentCell.RowIndex].Value).Trim() + "'");
                    frmGInfoManage_Load(sender, e);
                    MessageBox.Show("删除数据成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            }
        }

        private void tsbtnLook_Click(object sender, EventArgs e)
        {
            try
            {
                if (tstxtKeyWord.Text == "")
                {
                    frmGInfoManage_Load(sender, e);
                }
                if (tscboxCondition.Text.Trim() == "货物编号")
                {
                    DataSet myds = boperate.getds(M_str_sql + " where GID like '%" + tstxtKeyWord.Text.Trim() + "%'", M_str_table);
                    if (myds.Tables[0].Rows.Count > 0)
                        dgvGInfo.DataSource = myds.Tables[0];
                    else
                        MessageBox.Show("没有要查找的相关记录!");
                }
                if (tscboxCondition.Text.Trim() == "货物名称")
                {
                    DataSet myds = boperate.getds(M_str_sql + " where GName like '%" + tstxtKeyWord.Text.Trim() + "%'", M_str_table);
                    if (myds.Tables[0].Rows.Count > 0)
                        dgvGInfo.DataSource = myds.Tables[0];
                    else
                        MessageBox.Show("没有要查找的相关记录!");
                }
                if (tscboxCondition.Text.Trim() == "类别")
                {
                    DataSet myds = boperate.getds(M_str_sql + " where GType like '%" + tstxtKeyWord.Text.Trim() + "%'", M_str_table);
                    if (myds.Tables[0].Rows.Count > 0)
                        dgvGInfo.DataSource = myds.Tables[0];
                    else
                        MessageBox.Show("没有要查找的相关记录!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

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

        private void dgvGInfo_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            txtGID.Text = Convert.ToString(dgvGInfo[0, dgvGInfo.CurrentCell.RowIndex].Value).Trim();
            txtGName.Text = Convert.ToString(dgvGInfo[1, dgvGInfo.CurrentCell.RowIndex].Value).Trim();
            cboxGType.Text = Convert.ToString(dgvGInfo[2, dgvGInfo.CurrentCell.RowIndex].Value).Trim();
            txtGSpec.Text = Convert.ToString(dgvGInfo[3, dgvGInfo.CurrentCell.RowIndex].Value).Trim();
            txtInPrice.Text = Convert.ToString(dgvGInfo[4, dgvGInfo.CurrentCell.RowIndex].Value).Trim();
            txtOutPrice.Text = Convert.ToString(dgvGInfo[5, dgvGInfo.CurrentCell.RowIndex].Value).Trim();
            cboxGUnit.Text = Convert.ToString(dgvGInfo[6, dgvGInfo.CurrentCell.RowIndex].Value).Trim();
            txtGRemark.Text = Convert.ToString(dgvGInfo[7, dgvGInfo.CurrentCell.RowIndex].Value).Trim();
        }

        public void ClearText()
        {
            txtGName.Text = "";
            txtGSpec.Text = "";
            txtInPrice.Text = "";
            txtOutPrice.Text = "";
            txtGRemark.Text = "";
        }
    }
}

⌨️ 快捷键说明

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