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

📄 propertypanel.cs

📁 社区管理系统
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DataBaseManagerLibrary;

namespace CaiWuControlLibrary1
{
   
        public partial class PropertyPanel : UserControl{
        private DataBaseManager DBManager;
        private Int64 dealID, insertDealID;
        private int selectedIndex;

        public PropertyPanel()
        {
            InitializeComponent();
           // String SqlConnectInfo = "server=localhost;database=test;uid=sa;pwd=''";
          //  DBManager = new DataBaseManager(SqlConnectInfo);
            reset();
            //setDataBaseManager(null);
        }
        public void setDataBaseManager(DataBaseManager DBManager){
            //String SqlConnectInfo = "server=(local);database=CommunityManagementSystem;uid=sa;pwd='586925'";
            //DBManager = new DataBaseManager(SqlConnectInfo);
            this.DBManager=DBManager;
        }
      //  public void setUserCategory(String userCategory) {
       //     this.userCategory = userCategory;
       // }
            private bool ErrorMessage(String msg)
            {
                MessageBox.Show(msg);
                return false;
            }
            private void dgvCW_CellClick(object sender, DataGridViewCellEventArgs e)
            {
                if (e.RowIndex == -1 || e.RowIndex >= dgvCW.Rows.Count - 1) return; //选择多行或选择列标签
                showDetailInfo(e.RowIndex);
                selectedIndex = e.RowIndex;
                tnCWnum.Text = (dgvCW.Rows[selectedIndex].Cells["财产编号"].Value).ToString();
                tnCWname.Text = (dgvCW.Rows[selectedIndex].Cells["财产名称"].Value).ToString();
                tnCWcount.Text = (dgvCW.Rows[selectedIndex].Cells["数量"].Value).ToString();
                dtCWdate.Text = (dgvCW.Rows[selectedIndex].Cells["增加日期"].Value).ToString();
                tnCWmon.Text = (dgvCW.Rows[selectedIndex].Cells["财产金额"].Value).ToString();
                tnCWtime.Text = (dgvCW.Rows[selectedIndex].Cells["使用次数"].Value).ToString();
            }
            private void btCWsel_Click_1(object sender, EventArgs e)
        {
            String cmd;
            if (checkInput("Select") == false) return;  //用户输入不合法,此函数主要检查输入的格式错误
            cmd = generateSelectCommand();     //根据输入情况生成相应的命令
            DataTable dataTable = DBManager.ExecuteSelectCommand(cmd);
            if (dataTable == null)
            {  //数据库出错
                MessageBox.Show(DBManager.errorMessage);
                return;
            }
            else if (dataTable.Rows.Count == 0)
            {//没有搜索到对应信息,显示一个空的dgvZK
                MessageBox.Show("no");
                dgvCW.DataSource = dataTable;
                return;
            }
            else
            {//至少找到一条信息,将信息显示到dgvZK,并将第一条信息详细列出
                dgvCW.DataSource = dataTable;
                showDetailInfo(0);
            }
        }
            private bool checkInput(String str)
            {
            tnCWnum.Text = tnCWnum.Text.Trim();//将多余的空格去掉  
              if (tnCWnum.Text != "")
            {
                try
                {
                    Int64.Parse(tnCWnum.Text);
                }
                catch
                {
                    MessageBox.Show("号码输入错误!");
                    return false;
                }
            }
            tnCWname.Text = tnCWname.Text.Trim();
            tnCWcount.Text = tnCWcount.Text.Trim();
            if (tnCWcount.Text != "")
            {
                try
                {
                    Int64.Parse(tnCWcount.Text);
                }
                catch
                {
                    MessageBox.Show("数目输入错误!");
                    return false;
                }
            }
           tnCWmon.Text = tnCWmon.Text.Trim();
            if (tnCWmon.Text != "") 
            {
                try
                {
                    float.Parse(tnCWmon.Text);
                }
                catch
                {
                    MessageBox.Show("金额输入错误!");
                    return false;
                }
            }
            tnCWtime.Text = tnCWtime.Text.Trim();
            if (tnCWtime.Text != "")
            {
                try
                {
                    Int64.Parse(tnCWtime.Text);
                }
                catch
                {
                    MessageBox.Show("次数输入错误!");
                    return false;
                }
            }
            if (str == "Insert" || str == "Modify")
            {//以下是在更新或插入时检查输入是否为空
                if (tnCWnum.Text == "") return ErrorMessage("财产编号为空");
                if (tnCWname.Text == "") return ErrorMessage("财产名称为空");
                if (tnCWcount.Text == "") return ErrorMessage("数量为空");
                if (tnCWmon.Text == "") return ErrorMessage("财产金额为空");
                if (tnCWtime.Text == "") return ErrorMessage("使用次数为空");
      
                if (dtCWdate.Value == null) return ErrorMessage("日期为空");

            } 
         
            return true;
        }
        private String generateSelectCommand()
        {
            String cmd = "Select 财产编号,财产名称,数量,增加日期,使用次数,财产金额 from 财产信息 ";
            bool cmdChanged = false;

            if (tnCWnum.Text != "")
            {
                if (cmdChanged)
                    cmd = cmd + " and 财产编号='" + tnCWnum.Text + "'";
                else
                {
                    cmd = cmd + "where 财产编号='" + tnCWnum.Text + "'";
                    cmdChanged = true;
                }
            }
 /*           if (tnCWname.Text != "")
            {
                if (cmdChanged)
                    cmd = cmd + " and 财产名称='" + tnCWname.Text + "'";
                else
                {
                    cmd = cmd + "where 财产名称='" + tnCWname.Text + "'";
                    cmdChanged = true;
                }
            }
            if (tnCWcount.Text != "")
            {
                if (cmdChanged)
                    cmd = cmd + " and 数量='" + tnCWcount.Text + "'";
                else
                {
                    cmd = cmd + "where 数量='" + tnCWcount.Text + "'";
                    cmdChanged = true;
                }
            }
            if (tnCWmon.Text != "")
            {
                if (cmdChanged)
                    cmd = cmd + " and 财产金额='" + tnCWmon.Text + "'";
                else
                {
                    cmd = cmd + "where 财产金额='" + tnCWmon.Text + "'";
                    cmdChanged = true;
                }
            }
            if (tnCWtime.Text != "")
            {
                if (cmdChanged)
                    cmd = cmd + " and 使用次数='" + tnCWtime.Text + "'";
                else
                {
                    cmd = cmd + "where 使用次数='" + tnCWtime.Text + "'";
                    cmdChanged = true;
                }
            }*/

            return cmd;

⌨️ 快捷键说明

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