C#

来源:互联网 发布:import org.json. 编辑:程序博客网 时间:2024/06/05 21:01

        /// <summary>

        /// 绑定报表

        /// </summary>

        /// <param name="crystalreportname">报表名称</param>

        /// <param name="selectionFormula">要执行的语句</param>

        /// <returns></returns>

        using CrystalDecisions.CrystalReports.Engine;

 

        public ReportDocument CrystalReports(string crystalreportname, string selectionFormula)

        {

            ReportDocument P_Doc = new ReportDocument();

            string reportPath = Application.StartupPath.Substring(0, Application.StartupPath.Substring(0, Application.StartupPath.LastIndexOf("//")).LastIndexOf("//"));

            reportPath += @"/CrystalReport/ReportDoc/" + crystalreportname;//获取报表路径

            P_Doc.Load(reportPath);//加载报表

            P_Doc.DataDefinition.RecordSelectionFormula = selectionFormula;

            return P_Doc;

        }

//查询语句

Select * from 表。试图 where 字段名 ‘%++%’;

string P_str_cmdtxt = "select * from v_GoodsIn where GoodsID like '%" + txtGoodsID.Text + "%' and GoodsName like '%" + txtGoodsName.Text + "%' and Name like '%" + txtEmployeeName.Text + "%'";

 

 

/// <summary>

        /// 判断数据字符是否为数字

        /// </summary>

        /// <param name="strCode">需要判断的字符串</param>

        /// <returns></returns>

        /// using System.Text.RegularExpressions;

        public bool isNumeric(string strCode)

        {

            if (strCode == null || strCode.Length == 0)

            {

                return false;

            }

            ASCIIEncoding ascii = new ASCIIEncoding ();

            byte[] byteStr=ascii.GetBytes(strCode);

            foreach(byte code in byteStr)

            {

                if(code < 48 || code > 57)

                {

                    return false;

                }

                return true;

 

            }

        }

 

/// <summary>

        ///字段的加减乘除语法

        /// </summary>

select 字段名 *字段名 as 商品进价金额, 字段名* (字段名-字段名) as 商品盈利额 from 表名 where GoodsID =

 

select GoodsNum * GoodsPrice as 商品进价金额,GoodsNum * (SellPrice-GoodsPrice) as 商品盈利额 from tb_Goods where GoodsID =11

 

查询第一条记录

select top 1 * from tb_Goods order by GoodsID desc

 

 

labReGoodsID.Text = "TH" + DateTime.Now.ToString("yyyyMMdd") + "-" + P_Int_Num.ToString();

运行为   TH20090504-1004

 

 

字段在在添加的时候自动加一

SqlDataReader P_dr = G_SqlClass.GetReader("select top 1 * from tb_ReGoods order by ReGoodsID desc");

            P_dr.Read();

            if (P_dr.HasRows)

            {

                string P_str_GoodsID = P_dr["ReGoodsId"].ToString();

                P_int_num = Convert.ToInt16(P_str_GoodsID.Substring(11) + 1);

            }

 

原创粉丝点击