Exemplo n.º 1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int AddReadHistory(MDSelfServiceMachine.MDReadHistory model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into TAB_ReadHistory(");
            strSql.Append("strFileGUID,strTrainmanGUID,DtReadTime,SiteGUID)");
            strSql.Append(" values (");
            strSql.Append("@strFileGUID,@strTrainmanGUID,@DtReadTime,@SiteGUID)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@strFileGUID",     SqlDbType.VarChar, 50),
                new SqlParameter("@strTrainmanGUID", SqlDbType.VarChar, 50),
                new SqlParameter("@DtReadTime",      SqlDbType.VarChar, 50),
                new SqlParameter("@SiteGUID",        SqlDbType.VarChar, 50)
            };
            parameters[0].Value = model.strFileGUID;
            parameters[1].Value = model.strTrainmanGUID;
            parameters[2].Value = model.DtReadTime;
            parameters[3].Value = model.SiteGUID;
            object obj = SqlHelper.ExecuteScalar(SqlHelper.ConnString, CommandType.Text, strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
        // 保存阅读记录
        public JsonModel SaveReadings(string Data)
        {
            MDSelfServiceMachine.MDReadHistory readingHistory = new MDSelfServiceMachine.MDReadHistory();
            DBReadingRecord dbs     = new DBReadingRecord();
            Reading         reading = Newtonsoft.Json.JsonConvert.DeserializeObject <Reading>(Data);
            JsonModel       model   = new JsonModel();

            try
            {
                if (reading.data != null && reading.data.ReaderArray != null)
                {
                    foreach (fReader trainman in reading.data.ReaderArray)
                    {
                        if (reading.data.TypeList != null)
                        {
                            foreach (fTypeList fType in reading.data.TypeList)
                            {
                                foreach (rFile file in fType.FileList)
                                {
                                    readingHistory                 = new MDSelfServiceMachine.MDReadHistory();
                                    readingHistory.SiteGUID        = trainman.cid;
                                    readingHistory.strTrainmanGUID = trainman.TrainmanGUID;
                                    readingHistory.strFileGUID     = file.strFileGUID;
                                    readingHistory.DtReadTime      = file.dtReadTime;
                                    dbs.AddReadHistory(readingHistory);
                                    //更新阅读计划里边的第一次阅读时间、阅读次数
                                    dbs.UpdateReadTime(file.strFileGUID, trainman.TrainmanGUID, file.dtReadTime);
                                }
                            }
                        }
                    }
                }
                model.result    = "0";
                model.returnStr = "提交成功";
            }
            catch (Exception ex)
            {
                TF.CommonUtility.LogClass.logex(ex, "");
                model.result    = "1";
                model.returnStr = "提交失败:" + ex.Message;
            }
            return(model);
        }