/// <summary> /// 得到一个对象实体 /// </summary> public AMS.Model.FileSharingInfo GetModel(string Name, int FileType) { //该表无主键信息,请自定义主键/条件字段 StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,Name,Remark,FileType,UpManID,FilePath,DownLoadCount from FileSharingInfo "); strSql.Append(" where Name=@Name"); strSql.Append(" and FileType=@FileType"); SqlParameter[] parameters = { new SqlParameter("@Name", SqlDbType.NVarChar), new SqlParameter("@FileType", SqlDbType.Int) }; parameters[0].Value = Name; parameters[1].Value = FileType; AMS.Model.FileSharingInfo model = new AMS.Model.FileSharingInfo(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Id"] != null && ds.Tables[0].Rows[0]["Id"].ToString() != "") { model.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString()); } if (ds.Tables[0].Rows[0]["Name"] != null && ds.Tables[0].Rows[0]["Name"].ToString() != "") { model.Name = ds.Tables[0].Rows[0]["Name"].ToString(); } if (ds.Tables[0].Rows[0]["Remark"] != null && ds.Tables[0].Rows[0]["Remark"].ToString() != "") { model.Remark = ds.Tables[0].Rows[0]["Remark"].ToString(); } if (ds.Tables[0].Rows[0]["FileType"] != null && ds.Tables[0].Rows[0]["FileType"].ToString() != "") { model.FileType = int.Parse(ds.Tables[0].Rows[0]["FileType"].ToString()); } if (ds.Tables[0].Rows[0]["UpManID"] != null && ds.Tables[0].Rows[0]["UpManID"].ToString() != "") { model.UpManID = int.Parse(ds.Tables[0].Rows[0]["UpManID"].ToString()); } if (ds.Tables[0].Rows[0]["FilePath"] != null && ds.Tables[0].Rows[0]["FilePath"].ToString() != "") { model.FilePath = ds.Tables[0].Rows[0]["FilePath"].ToString(); } if (ds.Tables[0].Rows[0]["DownLoadCount"] != null && ds.Tables[0].Rows[0]["DownLoadCount"].ToString() != "") { model.DownLoadCount = int.Parse(ds.Tables[0].Rows[0]["DownLoadCount"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(AMS.Model.FileSharingInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update FileSharingInfo set "); strSql.Append("Name=@Name,"); strSql.Append("Remark=@Remark,"); strSql.Append("FileType=@FileType,"); strSql.Append("UpManID=@UpManID,"); strSql.Append("FilePath=@FilePath,"); strSql.Append("DownLoadCount=@DownLoadCount,"); strSql.Append("Size=@Size"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4), new SqlParameter("@Name", SqlDbType.NVarChar, 300), new SqlParameter("@Remark", SqlDbType.NVarChar, 300), new SqlParameter("@FileType", SqlDbType.Int, 4), new SqlParameter("@UpManID", SqlDbType.Int, 4), new SqlParameter("@FilePath", SqlDbType.NVarChar, 300), new SqlParameter("@DownLoadCount", SqlDbType.Int, 4), new SqlParameter("@Size", SqlDbType.NVarChar, 500) }; parameters[0].Value = model.Id; parameters[1].Value = model.Name; parameters[2].Value = model.Remark; parameters[3].Value = model.FileType; parameters[4].Value = model.UpManID; parameters[5].Value = model.FilePath; parameters[6].Value = model.DownLoadCount; parameters[7].Value = model.Size; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 更新共享文件 /// </summary> /// <param name="model"></param> /// <returns></returns> public string UpdateSharingFile(Model.FileSharingInfo model) { try { AMS.Model.FileSharingInfo sameModel = dal_FileSharing.GetModel(model.Name, model.FileType.Value); if (sameModel != null && sameModel.Id != model.Id) { return("其他此类同名文件已存在!"); } if (!dal_FileSharing.Update(model)) { return("更新失败!"); } return(""); } catch (Exception ex) { return(ex.Message); } }
/// <summary> /// 共享文件(新增) /// </summary> /// <param name="model"></param> /// <returns></returns> public string AddNewSharingFile(Model.FileSharingInfo model) { try { AMS.Model.FileSharingInfo sameModel = dal_FileSharing.GetModel(model.Name, model.FileType.Value); if (sameModel != null) { return("此类同名文件已存在!"); } if (!dal_FileSharing.Add(model)) { return("添加失败!"); } return(""); } catch (Exception ex) { return(ex.Message); } }
/// <summary> /// 创建新文件 /// </summary> /// <returns></returns> public static string AddNewFile(AMS.Model.FileSharingInfo model) { AMS.IBllService.IAdvertManageBllService bllService = AMS.ServiceConnectChannel.AdvertManageBllServiceChannel.CreateServiceChannel(); try { return(bllService.AddNewSharingFile(model)); } catch (EndpointNotFoundException ex) { throw new AMS.Model.CustomerException("连接服务器失败"); } catch (CommunicationException ex) { throw ex; } catch (Exception ex) { throw ex; } finally { ICommunicationObject ICommObjectService = bllService as ICommunicationObject; try { if (ICommObjectService.State == CommunicationState.Faulted) { ICommObjectService.Abort(); } else { ICommObjectService.Close(); } } catch { ICommObjectService.Abort(); } } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(AMS.Model.FileSharingInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into FileSharingInfo("); strSql.Append("Name,Remark,FileType,UpManID,FilePath,DownLoadCount,Size)"); strSql.Append(" values ("); strSql.Append("@Name,@Remark,@FileType,@UpManID,@FilePath,@DownLoadCount,@Size)"); SqlParameter[] parameters = { new SqlParameter("@Name", SqlDbType.NVarChar, 300), new SqlParameter("@Remark", SqlDbType.NVarChar, 300), new SqlParameter("@FileType", SqlDbType.Int, 4), new SqlParameter("@UpManID", SqlDbType.Int, 4), new SqlParameter("@FilePath", SqlDbType.NVarChar, 300), new SqlParameter("@DownLoadCount", SqlDbType.Int, 4), new SqlParameter("@Size", SqlDbType.NVarChar, 500) }; parameters[0].Value = model.Name; parameters[1].Value = model.Remark; parameters[2].Value = model.FileType; parameters[3].Value = model.UpManID; parameters[4].Value = model.FilePath; parameters[5].Value = model.DownLoadCount; parameters[6].Value = model.Size; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }