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

📄 getsubject.cs

📁 财务凭证管理系统主要由【系统管理】、【凭证管理】、【科目信息】、【账目查询】和【报表】等模块组成。进入该系统后
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using property.model.SubjectInfo;
using property.model.GetConnection;
using System.Data;
using System.Windows.Forms;
namespace property.control.Subject
{
    class GetSubject
    {
        SqlCommand cmd = null;
        SqlConnection con = null;
        DataSet ds = new DataSet();
        SubInfo sub = new SubInfo();//调用实体类联接数据库
        GetConnection getCon = new GetConnection();//调用实体类联接数据库
        #region //添加  public string subjectInsert(SubInfo sub)
        public string subjectInsert(SubInfo sub)
        {
            string P_str_result = null;
            try
            {
                P_str_result = this.FindID(sub.getsubId());//调用函数,检查编号是否存在重复
                if (P_str_result == "NO")// 不重复可用=“OK”时重复
                {
                    con = getCon.GetCon();
                    cmd = new SqlCommand();
                    string P_str_insert = "insert into tb_subjectInfo (subId,subGkb,subName,subMoney,subPage)";
                    P_str_insert+="values('" + sub.getsubId() + "','" + sub.getsubGkb() + "','" + sub.getsubName() + "','"+sub.getsubMoney()+"','" + sub.getsubPage() + "')";
                    cmd.CommandText = P_str_insert;
                    cmd.Connection = con;
                    int P_int_inst = cmd.ExecuteNonQuery();
                    if (P_int_inst == 1)
                    {
                        P_str_result = "insetOk";
                    }// end block if 
                    else
                    {
                        P_str_result = "insetNo";
                    }// end blcok if 
                    cmd.Connection.Close();
                    con.Close();
                }// end blokc if 
                return P_str_result;
            }// end block try
            catch (Exception e)
            {
                P_str_result = "addError";
                return P_str_result;
            }// end blokc catch

        }//end block method subjectInsert
        #endregion
        #region//修改  public string SubjectUpdate(SubInfo sub)
        public string SubjectUpdate(SubInfo sub)
        {
            string P_str_result = null;
            try
            {
                con = getCon.GetCon();
                cmd = new SqlCommand();
                string P_str_update = "update tb_subjectInfo set subGkb='" + sub.getsubGkb() + "',subName='" + sub.getsubName() + "',subMoney='" + sub.getsubMoney() + "',subPage='" + sub.getsubPage() + "' where subId='" + sub.getsubId() + "'";
                cmd.CommandText = P_str_update;
                cmd.Connection = con;
                int P_int_inst = cmd.ExecuteNonQuery();
                if (P_int_inst == 1)
                {
                    P_str_result = "updateOk";
                }
                else
                {
                    P_str_result = "updateNO";
                }// end blcok if 
                cmd.Connection.Close();
                con.Close();
                return P_str_result;
            }// end block try
            catch (Exception e)
            {
                P_str_result = "updateError";
                return P_str_result;
            }// end blokc catch
        }//end block Menthod SubjectUpdate()
        #endregion
        #region//修改初期金额   public string MoneyUpdate(SubInfo sub)
        public string MoneyUpdate(SubInfo sub)
        {
            string P_str_result = null;
            try
            {
                con = getCon.GetCon();
                cmd = new SqlCommand();
                string P_str_update = "update tb_subjectInfo set subMoney='" + sub.getsubMoney() + "' where subId='" + sub.getsubId() + "'";
                cmd.CommandText = P_str_update;
                cmd.Connection = con;
                int P_int_inst = cmd.ExecuteNonQuery();
                if (P_int_inst == 1)
                {
                    P_str_result = "updateOk";
                }
                else
                {
                    P_str_result = "updateNO";
                }// end blcok if 
                cmd.Connection.Close();
                con.Close();
                return P_str_result;
            }// end block try
            catch (Exception e)
            {
                P_str_result = "updateError";
                return P_str_result;
            }// end blokc catch
        }//end block Menthod SubjectUpdate()
        #endregion
        #region //册除   public string SubjectDelet(SubInfo sub)
        public string SubjectDelet(SubInfo sub)
        {
            string P_str_result = null;
            try
            {
                con = getCon.GetCon();
                cmd = new SqlCommand();
                string P_str_delete = "delete from tb_subjectInfo where subId='" + sub.getsubId() + "'";
                cmd.CommandText = P_str_delete;
                cmd.Connection = con;
                int P_int_inst = cmd.ExecuteNonQuery();
                if (P_int_inst == 1)
                {
                    P_str_result = "deleteOk";
                }
                else
                {
                    P_str_result = "deleteNO";
                }// end blcok if 
                cmd.Connection.Close();
                con.Close();
                return P_str_result;
            }// end block try
            catch (Exception e)
            {
                P_str_result = "deleteError";
                return P_str_result;
            }// end blokc catch

        }// end block mehtod
        #endregion
        #region //判断表中是否有记录 //查找表中是否有记录 public int getSeelectinInfo()
        public int getSeelectinInfo()
        {
            int P_int_result;
            try
            {
                con = getCon.GetCon();
                cmd = new SqlCommand();
                string P_str_select = "select count(*) from tb_subjectInfo";
                cmd.CommandText = P_str_select;
                cmd.Connection = con;
                int P_int_Select = (int)cmd.ExecuteScalar();
                // int t = com.ExecuteNonQuery();
                cmd.Connection.Close();
                con.Close();
                if (P_int_Select != 0) //表示有
                {
                    P_int_result = 1;
                }
                else
                {
                    P_int_result = 0;//表示没有
                }//end block else if 
                return P_int_result;

            }
            catch (Exception e)
            {

                P_int_result = 2;//表示错误
                return P_int_result;

            }//end block 

        }// end block int getSeelectinInfo()
        #endregion
        #region//查找编号是否存在表中以存在 public string FindID(int P_int_subid)
        public string FindID(int P_int_subid)
        {
            string P_str_result = null;
            // int P_int_select=this.subjectInsert\
            try
            {
                int P_int_select = getSeelectinInfo();//查找表是否有记录
                if (P_int_select == 1)//表示表中有记录可以查找是否重复
                {
                    con = getCon.GetCon();
                    cmd = new SqlCommand();
                    string P_str_select = "select count(*) from tb_subjectInfo where subId='" + P_int_subid + "'";
                    cmd.CommandText = P_str_select;
                    cmd.Connection = con;
                    int P_int_Select = (int)cmd.ExecuteScalar();
                    cmd.Connection.Close();
                    con.Close();
                    if (P_int_Select == 1)
                    {
                        P_str_result = "OK";
                    }
                    else
                    {
                        P_str_result = "NO";
                    }//end block else if 

                }// end block if 
                if (P_int_select == 0)//表示表中没有要找的记录此编号可用记录,此时只能是第一次添加
                { P_str_result = "NO"; }
                return P_str_result;
            }
            catch (Exception e)
            {
               return e.ToString();
            }//end block 
        }//end block FindID
        #endregion
        #region //查找科目是编号最大的处理返回 //不用了解   public string FinMaxSubId()
        public string FinMaxSubId()
        {

            string P_str_result = null;
            try
            {
                con = getCon.GetCon();
                cmd = new SqlCommand();
                string P_str_select = "select Max(subId) from tb_subjectInfo";
                cmd.CommandText = P_str_select;
                cmd.Connection = con;
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    P_str_result = dr[0].ToString();
                }//end block if 
                dr.Close();
                if (P_str_result != "")
                { P_str_result = "selectOk"; }
                // else{P_str_result = "selectNO";}
                /* int P_int_inst = (int)cmd.ExecuteScalar();
                 if (P_int_inst ==1)
                 {
                     P_str_result = "selectOk";
                 }
                 if (P_int_inst == 0)
                 {
                     P_str_result = "selectNO";
                 }// end blcok if 
                 * */

                cmd.Connection.Close();
                con.Close();
                return P_str_result;
            }// end block try
            catch (Exception e)
            {
                P_str_result = "selectError";
                return P_str_result;
            }// end blokc catch


        }// end block mehtdo 
        #endregion
        #region //自动编号 public int getSubId()
        public int getSubId()
        {
            int P_int_result = this.getSeelectinInfo();//查找表中是否有记录
            try
            {
                if (P_int_result == 1)// 表示表中以有记录
                {
                    // string P_str_FinMax = this.FinMaxSubId();//设用方法查的是否有最大值
                    //  if (P_str_FinMax == "selectOk")
                    // {
                    con = getCon.GetCon();
                    cmd = new SqlCommand();
                    string P_str_select = "select max(subId) from tb_subjectInfo";
                    cmd.CommandText = P_str_select;
                    cmd.Connection = con;
                    SqlDataReader dr = cmd.ExecuteReader();
                    while (dr.Read())

⌨️ 快捷键说明

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