数据库存储中的统一管理办法 column:comm;[#]

来源:互联网 发布:软件技术培训呢 编辑:程序博客网 时间:2024/04/28 04:34

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Text;

namespace  tjsj._class
{
 /// <summary>
 /// useing 的摘要说明。
 /// </summary>
 public class useing
 {
  public dataManage dm= new dataManage("ConnMe");
  public useing()
  {
   //
   // TODO: 在此处添加构造函数逻辑
   //
  }
  string setfileDate()
  {
  
   string ifilename;
   DateTime idt = new DateTime();
   
   ifilename="H" +DateTime.Now.ToString().Trim() +".html";
   return ifilename;

  }
  /// <summary>
  /// 生成关于需要执行的sql语句
  /// </summary>
  /// <param name="p_table">操作对象的表名</param>
  /// <param name="p_where">条件判断是否含有此记录</param>
  /// <param name="p_coloun_value">行和列的对应值</param>
  /// <returns></returns>
  public string set_sql(string p_table,string p_where,string p_coloun_value )
  {
   string isql;
   bool itf;
   if (p_where.Equals(""))
   {
    itf=false;
    return set_sql(p_table,itf,p_coloun_value);
   }
    
   else
   {
    isql="select * from " +p_table.Trim() + " where " + p_where.Trim();
    dm.SetDataRead(isql);
    if (dm.myDataRead.Read()==false)
    {
     itf=false;
     return set_sql(p_table,itf,p_coloun_value);
    }
    else
    {
     itf=true;
     return set_sql(p_table,itf,p_coloun_value) +" where "+ p_where;
    }

   }//if-else

   
  }//sub
  /// <summary>
  /// 生成关于需要执行的sql语句
  /// </summary>
  /// <param name="p_table">操作对象的表名</param>
  /// <param name="p_where">是否含有记录 false:insert or true : update</param>
  /// <param name="p_coloun_value">行和列的对应值</param>
  /// <returns></returns>
  public string set_sql(string p_table,bool p_where,string p_coloun_value )
  {
   string i_coloun = "(",i_value ="(";
   string i_old,i_have;
   int i_count;

   if (p_where)//update
   {
    i_coloun = p_coloun_value.Substring(0,p_coloun_value.Length-1);
    i_coloun=i_coloun.Replace(":","='");
    i_coloun=i_coloun.Replace(";","',");
    i_coloun ="update " + p_table +" set " + i_coloun + "' " ;
    return i_coloun;


   }
   else//insert into
   {
    i_old=p_coloun_value;
    do
    {
     i_count=i_old.IndexOf(";");
     i_have=i_old.Substring(0,i_count);
     i_old=i_old.Substring(i_count+1);

     i_count=i_have.IndexOf(":");

     if(i_old.Length >1)
     {
      i_coloun += i_have.Substring(0,i_count) + ",";
      i_value +="'" + i_have.Substring(i_count+1) +"',";
     }
     else
     {
      i_coloun += i_have.Substring(0,i_count) + "";
      i_value +="'" + i_have.Substring(i_count+1) +"'";

     }
     
    }
    while (i_old.Length >1);
    i_coloun += ")";
    i_value +=")";

    i_coloun = "insert into " + p_table + i_coloun +" values" +i_value;
    return i_coloun;


   }
  }//sub  /// <summary>
  /// 生成关于需要执行的sql语句
  /// </summary>
  /// <param name="p_table">操作对象的表名</param>
  /// <param name="p_where">是否含有记录 false:insert or true : update</param>
  /// <param name="p_coloun_value">行和列的对应值</param>
  /// <returns></returns>
  public string set_sql_2(string p_table,bool p_where,string p_coloun_value )
  {
   string i_coloun = "(",i_value ="(";
   string i_old,i_have;
   int i_count;

   if (p_where)//update
   {
    i_coloun = p_coloun_value.Substring(0,p_coloun_value.Length-1);
    i_coloun=i_coloun.Replace(":","='");
    i_coloun=i_coloun.Replace("#","',");
    i_coloun ="update " + p_table +" set " + i_coloun + "' " ;
    return i_coloun;


   }
   else//insert into
   {
    i_old=p_coloun_value;
    do
    {
     i_count=i_old.IndexOf("#");
     i_have=i_old.Substring(0,i_count);
     i_old=i_old.Substring(i_count+1);

     i_count=i_have.IndexOf(":");

     if(i_old.Length >1)
     {
      i_coloun += i_have.Substring(0,i_count) + ",";
      i_value +="'" + i_have.Substring(i_count+1) +"',";
     }
     else
     {
      i_coloun += i_have.Substring(0,i_count) + "";
      i_value +="'" + i_have.Substring(i_count+1) +"'";

     }
     
    }
    while (i_old.Length >1);
    i_coloun += ")";
    i_value +=")";

    i_coloun = "insert into " + p_table + i_coloun +" values" +i_value;
    return i_coloun;


   }
  }//sub

  public string set_sql_2(string p_table,string p_where,string p_coloun_value )
  {
   string isql;
   bool itf;
   if (p_where.Equals(""))
   {
    itf=false;
    return set_sql_2(p_table,itf,p_coloun_value);
   }
    
   else
   {
    isql="select * from " +p_table.Trim() + " where " + p_where.Trim();
    dm.SetDataRead(isql);
    if (dm.myDataRead.Read()==false)
    {
     itf=false;
     return set_sql_2(p_table,itf,p_coloun_value);
    }
    else
    {
     itf=true;
     return set_sql_2(p_table,itf,p_coloun_value) +" where "+ p_where;
    }

   }//if-else

   
  }//sub
 }//class
}//namespance
 

原创粉丝点击