Ejemplo n.º 1
0
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <param name="treatTime">Class instance of infectType infomation</param>
        /// <param name="scId">Id of the last insert row id</param>
        /// <returns></returns>
        public bool InsertTreatTime(TreatTime treatTime, ref int scId)
        {
            try
            {
                using (SqlCommand sqlcomm = SqlConn.CreateCommand())
                {
                    sqlcomm.CommandText =
                        @"INSERT INTO TREATTIME (ACTIVATED,NAME,BEGINTIME,ENDTIME,DESCRIPTION,RESERVED) VALUES 
                        (@ACTIVATED,@NAME,@BEGINTIME,@ENDTIME,@DESCRIPTION,@RESERVED) SET @ID = SCOPE_IDENTITY() ";
                    sqlcomm.Parameters.Add("@NAME", DbType.String);
                    if (treatTime.Name != null)
                    {
                        sqlcomm.Parameters["@NAME"].Value = treatTime.Name;
                    }
                    sqlcomm.Parameters.Add("@ACTIVATED", DbType.Boolean);
                    sqlcomm.Parameters["@ACTIVATED"].Value = treatTime.Activated;
                    sqlcomm.Parameters.Add("@BEGINTIME", DbType.String);
                    if (treatTime.BeginTime != null)
                    {
                        sqlcomm.Parameters["@BEGINTIME"].Value = treatTime.BeginTime;
                    }
                    sqlcomm.Parameters.Add("@ENDTIME", DbType.String);
                    if (treatTime.EndTime != null)
                    {
                        sqlcomm.Parameters["@ENDTIME"].Value = treatTime.EndTime;
                    }
                    sqlcomm.Parameters.Add("@DESCRIPTION", DbType.String);
                    if (treatTime.Description != null)
                    {
                        sqlcomm.Parameters["@DESCRIPTION"].Value = treatTime.Description;
                    }
                    sqlcomm.Parameters.Add("@RESERVED", DbType.String);
                    if (treatTime.Reserved != null)
                    {
                        sqlcomm.Parameters["@RESERVED"].Value = treatTime.Reserved;
                    }

                    sqlcomm.Parameters.Add("@ID", SqlDbType.Int).Direction = ParameterDirection.Output;

                    DatabaseOp.ExecuteNoneQuery(sqlcomm);

                    scId = (int)sqlcomm.Parameters["@ID"].Value;
                }
            }
            catch (Exception e)
            {
                MainWindow.Log.WriteErrorLog("TreatTimeDao.cs-InsertTreatTime", e);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <param name="TreatTime">Class instance of infectType infomation</param>
        /// <param name="scId">Id of the last insert row id</param>
        /// <returns></returns>
        public bool InsertTreatTime(TreatTime TreatTime, ref int scId)
        {
            try
            {
                using (SQLiteCommand sqlcomm = SqlConn.CreateCommand())
                {
                    sqlcomm.CommandText =
                        @"INSERT INTO TREATTIME (NAME,ACTIVATED,BEGINTIME,ENDTIME,DESCRIPTION,RESERVED) VALUES 
                        (@NAME,@ACTIVATED,@BEGINTIME,@ENDTIME,@DESCRIPTION,@RESERVED)";
                    sqlcomm.Parameters.Add("@NAME", DbType.String);
                    sqlcomm.Parameters["@NAME"].Value = TreatTime.Name;
                    sqlcomm.Parameters.Add("@ACTIVATED", DbType.Boolean);
                    sqlcomm.Parameters["@ACTIVATED"].Value = TreatTime.Activated;
                    sqlcomm.Parameters.Add("@DESCRIPTION", DbType.String);
                    sqlcomm.Parameters["@DESCRIPTION"].Value = TreatTime.Description;
                    sqlcomm.Parameters.Add("@BEGINTIME", DbType.String);
                    sqlcomm.Parameters["@BEGINTIME"].Value = TreatTime.BeginTime;
                    sqlcomm.Parameters.Add("@ENDTIME", DbType.String);
                    sqlcomm.Parameters["@ENDTIME"].Value = TreatTime.EndTime;
                    sqlcomm.Parameters.Add("@RESERVED", DbType.String);
                    sqlcomm.Parameters["@RESERVED"].Value = TreatTime.Reserved;
                    DatabaseOp.ExecuteNoneQuery(sqlcomm);

                    //set last insert id of this table this connection
                    SQLiteCommand comm = SqlConn.CreateCommand();
                    comm.CommandText = "Select last_insert_rowid() as TREATTIME;";
                    scId             = Convert.ToInt32(comm.ExecuteScalar());
                    comm.Dispose();
                }
            }
            catch (Exception e)
            {
                MainWindow.Log.WriteErrorLog("TreatTimeDao.cs-InsertTreatTime", e);
                return(false);
            }
            return(true);
        }