public JpForm(String ld_sno) { if (ld_sno == "") { sno = ""; cid = ""; aid = -1; ip = ""; ht_content.Clear(); qdate = ""; adate = ""; //hits = 0; publish = 0; } else { String sql = "Select * from JpForm where sno=@sno"; DAO db = new DAO(); SqlParameter[] prams ={ db.MakeInParam("@sno",SqlDbType.VarChar,ld_sno) }; DataTable art = db.GetDataTable(sql, prams); if (art.Rows.Count > 0) { sno = art.Rows[0]["sno"].ToString(); aid = Int32.Parse(art.Rows[0]["aid"].ToString()); cid = art.Rows[0]["cid"].ToString(); ip = art.Rows[0]["ip"].ToString(); qdate = art.Rows[0]["qdate"].ToString(); adate = art.Rows[0]["adate"].ToString(); //hits = Int32.Parse(art.Rows[0]["hits"].ToString()); publish = Int32.Parse(art.Rows[0]["publish"].ToString()); byte[] imagebin = (byte[])art.Rows[0]["xmlcontent"]; BinaryFormatter Formatter = new BinaryFormatter(); JpStream jpstream = new JpStream(); Stream stream = jpstream.BytesToStream(imagebin); ht_content = (System.Collections.Hashtable)Formatter.Deserialize(stream); stream.Close(); } } }
public void Update() { MemoryStream ms = new MemoryStream(); DAO db = new DAO(); try { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(ms, this.ht_content); JpStream jpstream = new JpStream(); byte[] imagebin = jpstream.StreamToBytes(ms); String sql = "UPDATE JpForm SET adate=getdate(),publish=@publish,xmlcontent=@xmlcontent "; sql += " where sno=@sno"; SqlParameter[] prams ={ db.MakeInParam("@xmlcontent",SqlDbType.Image,imagebin), db.MakeInParam("@publish",SqlDbType.Int,publish), db.MakeInParam("@sno",SqlDbType.VarChar,sno), }; db.Execute(sql, prams); } catch { } finally { ms.Close(); db.Close(); } }
public String Insert() { MemoryStream ms = new MemoryStream(); try { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(ms, this.ht_content); JpStream jpstream = new JpStream(); byte[] imagebin = jpstream.StreamToBytes(ms); String sql = "INSERT INTO JpForm(sno,cid,aid,ip,qdate,publish,xmlcontent)"; sql += " VALUES(@sno,@cid,@aid,@ip,getdate(),@publish,@xmlcontent)"; //GUID = System.Guid.NewGuid().ToString() ; DAO db = new DAO(); SqlParameter[] prams ={ db.MakeInParam("@sno",SqlDbType.VarChar,sno), db.MakeInParam("@cid",SqlDbType.VarChar,cid), db.MakeInParam("@aid",SqlDbType.Int,aid), db.MakeInParam("@ip",SqlDbType.VarChar,ip), db.MakeInParam("@publish",SqlDbType.Int,publish), db.MakeInParam("@xmlcontent",SqlDbType.Image,imagebin), }; db.Execute(sql, prams); db.Close(); sql = "Select sno from JpForm where sno=@sno"; SqlParameter[] prams1 ={ db.MakeInParam("@sno",SqlDbType.VarChar,sno), }; DataTable dt = db.GetDataTable(sql, prams1); if (dt.Rows.Count > 0) { this.sno = dt.Rows[0]["sno"].ToString(); } return sno; } catch { return ""; } finally { ms.Close(); } }