/// <summary>
        /// 增加一条数据
        /// </summary>
        public decimal Add(Maticsoft.Model.SMT_RECORDCAP_IMAGE model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into SMT_RECORDCAP_IMAGE(");
            strSql.Append("CTRL_SN,RECORD_INDEX,RECORD_TIME,CAP_TIME,CAP_RELATIVE_URL)");
            strSql.Append(" values (");
            strSql.Append("@CTRL_SN,@RECORD_INDEX,@RECORD_TIME,@CAP_TIME,@CAP_RELATIVE_URL)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@CTRL_SN",          SqlDbType.VarChar,   100),
                new SqlParameter("@RECORD_INDEX",     SqlDbType.Decimal,     9),
                new SqlParameter("@RECORD_TIME",      SqlDbType.DateTime),
                new SqlParameter("@CAP_TIME",         SqlDbType.DateTime),
                new SqlParameter("@CAP_RELATIVE_URL", SqlDbType.NVarChar, 256)
            };
            parameters[0].Value = model.CTRL_SN;
            parameters[1].Value = model.RECORD_INDEX;
            parameters[2].Value = model.RECORD_TIME;
            parameters[3].Value = model.CAP_TIME;
            parameters[4].Value = model.CAP_RELATIVE_URL;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToDecimal(obj));
            }
        }
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Maticsoft.Model.SMT_RECORDCAP_IMAGE DataRowToModel(DataRow row)
 {
     Maticsoft.Model.SMT_RECORDCAP_IMAGE model = new Maticsoft.Model.SMT_RECORDCAP_IMAGE();
     if (row != null)
     {
         if (row["ID"] != null && row["ID"].ToString() != "")
         {
             model.ID = decimal.Parse(row["ID"].ToString());
         }
         if (row["CTRL_SN"] != null)
         {
             model.CTRL_SN = row["CTRL_SN"].ToString();
         }
         if (row["RECORD_INDEX"] != null && row["RECORD_INDEX"].ToString() != "")
         {
             model.RECORD_INDEX = decimal.Parse(row["RECORD_INDEX"].ToString());
         }
         if (row["RECORD_TIME"] != null && row["RECORD_TIME"].ToString() != "")
         {
             model.RECORD_TIME = DateTime.Parse(row["RECORD_TIME"].ToString());
         }
         if (row["CAP_TIME"] != null && row["CAP_TIME"].ToString() != "")
         {
             model.CAP_TIME = DateTime.Parse(row["CAP_TIME"].ToString());
         }
         if (row["CAP_RELATIVE_URL"] != null)
         {
             model.CAP_RELATIVE_URL = row["CAP_RELATIVE_URL"].ToString();
         }
     }
     return(model);
 }
Example #3
0
        private void DoCaptureImage(DoorCameraObject dco, ControllerState state)
        {
            ThreadPool.QueueUserWorkItem(new WaitCallback((o) =>
            {
                try
                {
                    var image = dco.camera.GetEngine().CaptureImage();
                    if (image == null)
                    {
                        log.Error("抓拍失败:" + dco.camera.IP);
                        return;
                    }
                    DateTime dt   = DateTime.Now;
                    string camstr = "";
                    if (!string.IsNullOrWhiteSpace(dco.camera.IP))
                    {
                        camstr = dco.camera.IP.Replace('.', '_');
                    }
                    else
                    {
                        camstr = "camera_null_ip";
                    }
                    string filePath = camstr + "\\" + dt.Year + "\\" + dt.Month + "\\" + dt.Day;
                    string fullPath = Path.Combine(ImageFolder, filePath);
                    if (!Directory.Exists(fullPath))
                    {
                        Directory.CreateDirectory(fullPath);
                    }

                    string pathName = Path.Combine(filePath, dt.ToString("yyyyMMddHHmmss_fff") + ".jpg");
                    fullPath        = Path.Combine(ImageFolder, pathName);
                    image.Save(fullPath, System.Drawing.Imaging.ImageFormat.Jpeg);
                    image.Dispose();
                    Maticsoft.BLL.SMT_RECORDCAP_IMAGE sriBll     = new Maticsoft.BLL.SMT_RECORDCAP_IMAGE();
                    Maticsoft.Model.SMT_RECORDCAP_IMAGE sriModel = new Maticsoft.Model.SMT_RECORDCAP_IMAGE();

                    sriModel.CAP_RELATIVE_URL = pathName;
                    sriModel.CAP_TIME         = dt;
                    sriModel.CTRL_SN          = dco.controller.sn;
                    sriModel.RECORD_INDEX     = state.lastRecordIndex;
                    sriModel.RECORD_TIME      = state.recordTime;

                    sriBll.Add(sriModel);
                }
                catch (Exception ex)
                {
                    log.Error("抓拍失败:" + dco.camera.IP, ex);
                }
            }));
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Maticsoft.Model.SMT_RECORDCAP_IMAGE model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update SMT_RECORDCAP_IMAGE set ");
            strSql.Append("CTRL_SN=@CTRL_SN,");
            strSql.Append("RECORD_INDEX=@RECORD_INDEX,");
            strSql.Append("RECORD_TIME=@RECORD_TIME,");
            strSql.Append("CAP_TIME=@CAP_TIME,");
            strSql.Append("CAP_RELATIVE_URL=@CAP_RELATIVE_URL");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@CTRL_SN",          SqlDbType.VarChar,   100),
                new SqlParameter("@RECORD_INDEX",     SqlDbType.Decimal,     9),
                new SqlParameter("@RECORD_TIME",      SqlDbType.DateTime),
                new SqlParameter("@CAP_TIME",         SqlDbType.DateTime),
                new SqlParameter("@CAP_RELATIVE_URL", SqlDbType.NVarChar,  256),
                new SqlParameter("@ID",               SqlDbType.Decimal, 9)
            };
            parameters[0].Value = model.CTRL_SN;
            parameters[1].Value = model.RECORD_INDEX;
            parameters[2].Value = model.RECORD_TIME;
            parameters[3].Value = model.CAP_TIME;
            parameters[4].Value = model.CAP_RELATIVE_URL;
            parameters[5].Value = model.ID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.SMT_RECORDCAP_IMAGE GetModel(decimal ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ID,CTRL_SN,RECORD_INDEX,RECORD_TIME,CAP_TIME,CAP_RELATIVE_URL from SMT_RECORDCAP_IMAGE ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.Decimal)
            };
            parameters[0].Value = ID;

            Maticsoft.Model.SMT_RECORDCAP_IMAGE model = new Maticsoft.Model.SMT_RECORDCAP_IMAGE();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }