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

📄 frmbinfomanage.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 frmBInfoManage : Form
    {
        CRM.BaseClass.BaseOperate boperate = new CRM.BaseClass.BaseOperate();
        CRM.BaseClass.OperateAndValidate opAndvalidate = new CRM.BaseClass.OperateAndValidate();
        protected string M_str_sql = "select CName as 企业名称,CManager as 法人代表,CPhone as 联系电话,CPostCode as 邮政编码,"
            + "CFax as 传真号码,CEmail as Email地址,CNAddress as 企业网址,CAddress as 联系地址,CRemark as 备注 from tb_CInfo";
        protected string M_str_table = "tb_CInfo";
        protected int M_int_judge;
        public frmBInfoManage()
        {
            InitializeComponent();
        }

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

        private void tsbtnAdd_Click(object sender, EventArgs e)
        {
            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 (txtCName.Text == "")
                {
                    MessageBox.Show("企业名称不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    if (!opAndvalidate.validatePhone(txtCPhone.Text.Trim()))
                    {
                        errorBCFax.Clear();
                        errorBCPostCode.Clear();
                        errorBCEmail.Clear();
                        errorBCNAddress.Clear();
                        errorBCPhone.SetError(txtCPhone, "电话号码格式不正确");
                    }
                    else if (!opAndvalidate.validateFax(txtCFax.Text.Trim()))
                    {
                        errorBCPhone.Clear();
                        errorBCPostCode.Clear();
                        errorBCEmail.Clear();
                        errorBCNAddress.Clear();
                        errorBCFax.SetError(txtCFax, "传真号码输入格式不正确");
                    }
                    else if (!opAndvalidate.validatePostCode(txtCPostCode.Text.Trim()))
                    {
                        errorBCFax.Clear();
                        errorBCPhone.Clear();
                        errorBCEmail.Clear();
                        errorBCNAddress.Clear();
                        errorBCPostCode.SetError(txtCPostCode, "邮编输入格式不正确");
                    }
                    else if (!opAndvalidate.validateEmail(txtCEmail.Text.Trim()))
                    {
                        errorBCFax.Clear();
                        errorBCPhone.Clear();
                        errorBCPostCode.Clear();
                        errorBCNAddress.Clear();
                        errorBCEmail.SetError(txtCEmail, "E-mail地址输入格式不正确");
                    }
                    else if (!opAndvalidate.validateNAddress(txtCNAddress.Text.Trim()))
                    {
                        errorBCFax.Clear();
                        errorBCPhone.Clear();
                        errorBCPostCode.Clear();
                        errorBCEmail.Clear();
                        errorBCNAddress.SetError(txtCNAddress, "企业网址输入格式不正确");
                    }
                    else
                    {
                        errorBCFax.Clear();
                        errorBCPhone.Clear();
                        errorBCPostCode.Clear();
                        errorBCEmail.Clear();
                        errorBCNAddress.Clear();
                        boperate.getcom("insert into tb_CInfo(CName,CManager,CPhone,CPostCode,CFax,CEmail,CNAddress,CAddress,CRemark) "
                            + "values('" + txtCName.Text.Trim() + "','" + txtCManager.Text.Trim() + "','" + txtCPhone.Text.Trim()
                            + "','" + txtCPostCode.Text.Trim() + "','" + txtCFax.Text.Trim() + "','" + txtCEmail.Text.Trim() + "','"
                            + txtCNAddress.Text.Trim() + "','" + txtCAddress.Text.Trim() + "','" + txtCRemark.Text.Trim() + "')");
                        frmBInfoManage_Load(sender, e);
                        MessageBox.Show("企业信息添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        tsbtnSave.Enabled = false;
                    }
                }
            }
            if (M_int_judge == 1)
            {
                if (txtCName.Text == "")
                {
                    MessageBox.Show("企业名称不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    if (!opAndvalidate.validatePhone(txtCPhone.Text.Trim()))
                    {
                        errorBCFax.Clear();
                        errorBCPostCode.Clear();
                        errorBCEmail.Clear();
                        errorBCNAddress.Clear();
                        errorBCPhone.SetError(txtCPhone, "电话号码格式不正确");
                    }
                    else if (!opAndvalidate.validateFax(txtCFax.Text.Trim()))
                    {
                        errorBCPhone.Clear();
                        errorBCPostCode.Clear();
                        errorBCEmail.Clear();
                        errorBCNAddress.Clear();
                        errorBCFax.SetError(txtCFax, "传真号码输入格式不正确");
                    }
                    else if (!opAndvalidate.validatePostCode(txtCPostCode.Text.Trim()))
                    {
                        errorBCFax.Clear();
                        errorBCPhone.Clear();
                        errorBCEmail.Clear();
                        errorBCNAddress.Clear();
                        errorBCPostCode.SetError(txtCPostCode, "邮编输入格式不正确");
                    }
                    else if (!opAndvalidate.validateEmail(txtCEmail.Text.Trim()))
                    {
                        errorBCFax.Clear();
                        errorBCPhone.Clear();
                        errorBCPostCode.Clear();
                        errorBCNAddress.Clear();
                        errorBCEmail.SetError(txtCEmail, "E-mail地址输入格式不正确");
                    }
                    else if (!opAndvalidate.validateNAddress(txtCNAddress.Text.Trim()))
                    {
                        errorBCFax.Clear();
                        errorBCPhone.Clear();
                        errorBCPostCode.Clear();
                        errorBCEmail.Clear();
                        errorBCNAddress.SetError(txtCNAddress, "企业网址输入格式不正确");
                    }
                    else
                    {
                        errorBCFax.Clear();
                        errorBCPhone.Clear();
                        errorBCPostCode.Clear();
                        errorBCEmail.Clear();
                        errorBCNAddress.Clear();
                        boperate.getcom("update tb_CInfo set CName='" + txtCName.Text.Trim() + "',CManager='" + txtCManager.Text.Trim()
                            + "',CPhone='" + txtCPhone.Text.Trim() + "',CPostCode='" + txtCPostCode.Text.Trim() + "',CFax='" + txtCFax.Text.Trim()
                            + "',CEmail='" + txtCEmail.Text.Trim() + "',CNAddress='" + txtCNAddress.Text.Trim() + "',CAddress='" 
                            + txtCAddress.Text.Trim() + "',CRemark='" + txtCRemark.Text.Trim() + "' where CName='" + txtCName.Text.Trim() + "'");
                        frmBInfoManage_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_CInfo where CName='" + Convert.ToString(dgvCInfo[0, dgvCInfo.CurrentCell.RowIndex].Value).Trim() + "'");
                    frmBInfoManage_Load(sender, e);
                    MessageBox.Show("删除数据成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            }
        }

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

        private void dgvCInfo_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            txtCName.Text = Convert.ToString(dgvCInfo[0, dgvCInfo.CurrentCell.RowIndex].Value).Trim();
            txtCManager.Text = Convert.ToString(dgvCInfo[1, dgvCInfo.CurrentCell.RowIndex].Value).Trim();
            txtCPhone.Text = Convert.ToString(dgvCInfo[2, dgvCInfo.CurrentCell.RowIndex].Value).Trim();
            txtCPostCode.Text = Convert.ToString(dgvCInfo[3, dgvCInfo.CurrentCell.RowIndex].Value).Trim();
            txtCFax.Text = Convert.ToString(dgvCInfo[4, dgvCInfo.CurrentCell.RowIndex].Value).Trim();
            txtCEmail.Text = Convert.ToString(dgvCInfo[5, dgvCInfo.CurrentCell.RowIndex].Value).Trim();
            txtCNAddress.Text = Convert.ToString(dgvCInfo[6, dgvCInfo.CurrentCell.RowIndex].Value).Trim();
            txtCAddress.Text = Convert.ToString(dgvCInfo[7, dgvCInfo.CurrentCell.RowIndex].Value).Trim();
            txtCRemark.Text = Convert.ToString(dgvCInfo[8, dgvCInfo.CurrentCell.RowIndex].Value).Trim();
        }

        public void ClearText()
        {
            txtCName.Text = "";
            txtCManager.Text = "";
            txtCPhone.Text = "";
            txtCFax.Text = "";
            txtCPostCode.Text = "";
            txtCAddress.Text = "";
            txtCEmail.Text = "";
            txtCNAddress.Text = "";
            txtCRemark.Text = "";
        }
    }
}

⌨️ 快捷键说明

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