Esempio n. 1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public string Add(业务.Model.检验值 model)
        {
            StringBuilder strSql  = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();

            if (model.接收数据 != null)
            {
                strSql1.Append("接收数据,");
                strSql2.Append("N'" + model.接收数据 + "',");
            }
            if (model.发射器编号 != null)
            {
                strSql1.Append("发射器编号,");
                strSql2.Append("" + model.发射器编号 + ",");
            }
            if (model.测量数值 != null)
            {
                strSql1.Append("测量数值,");
                strSql2.Append("" + model.测量数值 + ",");
            }
            if (model.原始值 != null)
            {
                strSql1.Append("原始值,");
                strSql2.Append("" + model.原始值 + ",");
            }
            if (model.dtmCreate != null)
            {
                strSql1.Append("dtmCreate,");
                strSql2.Append("getdate(),");
            }
            strSql.Append("insert into 检验值(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            strSql.Append(";select @@IDENTITY");
            return(strSql.ToString());
        }
Esempio n. 2
0
        private void SaveChkValue(string sProtValue)
        {
            try
            {
                if (sProtValue.Trim() == "")
                {
                    return;
                }


                SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString);
                conn.Open();
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    Model.检验值 mod = new 业务.Model.检验值();
                    mod.接收数据 = sProtValue;
                    int i发射头 = BaseFunction.ReturnInt(sProtValue.Substring(1, 2));

                    decimal d测量数值 = BaseFunction.ReturnDecimal(sProtValue.Substring(3, 8));


                    mod.发射器编号 = i发射头;
                    mod.测量数值  = d测量数值;
                    mod.原始值   = d测量数值;

                    sSQL = string.Format(sSQL, mod.发射器编号);

                    DAL.检验值 dal = new 业务.DAL.检验值();
                    sSQL = dal.Add(mod);
                    int iCou = DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    if (iCou > 0)
                    {
                        tran.Commit();

                        GetGrid();

                        txtChkValue.Text = "";
                        txtChkValue.Focus();
                    }
                }
                catch (Exception ee)
                {
                    tran.Rollback();

                    throw new Exception(ee.Message);
                }
                finally
                {
                    if (conn.State == ConnectionState.Open)
                    {
                        conn.Close();
                    }
                }
            }
            catch (Exception ee)
            {
                txtChkValue.Text = "";
                txtChkValue.Focus();
            }

            txtChkValue.Text = "";
        }