コード例 #1
0
        //保存按钮
        public void button1_Click(object sender, EventArgs e)
        {
            try
            {
                myhostsEntities db = new myhostsEntities();

                HOSTS one = new HOSTS();

                one.DESCRIPTION = zname.Text;
                one.IP          = zip.Text;
                one.USERNAME    = zuser.Text;
                one.PASSWORD    = mytools.EncryptDES(zpass.Text, "56eg56eg");
                one.SID         = zsid.Text;
                one.PORT        = zport.Text;
                one.OTHER       = zother.Text;

                db.HOSTS.AddObject(one);
                db.SaveChanges();
                MessageBox.Show("新增成功!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
コード例 #2
0
        /// <summary>
        /// 创建新的 HOSTS 对象。
        /// </summary>
        /// <param name="id">ID 属性的初始值。</param>
        /// <param name="dESCRIPTION">DESCRIPTION 属性的初始值。</param>
        public static HOSTS CreateHOSTS(global::System.Int64 id, global::System.String dESCRIPTION)
        {
            HOSTS hOSTS = new HOSTS();

            hOSTS.ID          = id;
            hOSTS.DESCRIPTION = dESCRIPTION;
            return(hOSTS);
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: basis100/OracleSpaceTool
        //对ORACLE数据库查询
        public void silent_oracle(object xxx)
        {
            List <TABLESPACE> list = new List <TABLESPACE>();

            HOSTS one = (HOSTS)xxx;

            String zip   = one.IP;
            String zuser = one.USERNAME;
            String zpass = mytools.DecryptDES(one.PASSWORD, "56eg56eg");
            String zsid  = one.SID;
            String zport = one.PORT;

            string s_conn = "Data Source=(DESCRIPTION="
                            + "(ADDRESS=(PROTOCOL=TCP)(HOST=" + zip.Trim() + ")(PORT=" + zport.Trim() + "))"
                            + "(CONNECT_DATA=(SERVICE_NAME=" + zsid.Trim() + ")));"
                            + "User Id=" + zuser.Trim() + ";Password="******";";

            OracleConnection conn = new OracleConnection(s_conn);

            try
            {
                conn.Open();

                if (!conn.State.ToString().Equals("Open"))
                {
                    return;
                }

                //取一般表空间
                string sql = "SELECT A.TABLESPACE_NAME, round(A.BYTES/1024/1024) TOTAL_MB, round(B.BYTES/1024/1024) USED_MB, round(C.BYTES/1024/1024) FREE_MB,round((B.BYTES*100)/A.BYTES) USED_PER,round((C.BYTES*100)/A.BYTES) FREE_PER FROM SYS.SM$TS_AVAIL A,SYS.SM$TS_USED B,SYS.SM$TS_FREE C WHERE A.TABLESPACE_NAME=B.TABLESPACE_NAME AND A.TABLESPACE_NAME=C.TABLESPACE_NAME";

                OracleCommand    comm = new OracleCommand(sql, conn);
                OracleDataReader r    = comm.ExecuteReader();

                while (r.Read())
                {
                    list.Add(new TABLESPACE
                    {
                        NAME  = r.IsDBNull(0) ? "" : r.GetString(0),
                        TOTAL = r.IsDBNull(1) ? 0 : r.GetInt32(1),
                        USED  = r.IsDBNull(2) ? 0 : r.GetInt32(2),
                        FREE  = r.IsDBNull(3) ? 0 : r.GetInt32(3),
                        PUSER = r.IsDBNull(4) ? 0 : r.GetInt32(4),
                        PFREE = r.IsDBNull(5) ? 0 : r.GetInt32(5)
                    });
                }

                r.Close();
                comm.Cancel();


                //取临时表空间
                OracleCommand    cmd = new OracleCommand("SELECT round(BYTES/1024/1024) From v$tempfile", conn);
                OracleDataReader rr  = cmd.ExecuteReader();

                while (rr.Read())
                {
                    list.Add(new TABLESPACE
                    {
                        NAME  = "TEMP",
                        TOTAL = rr.IsDBNull(0) ? 0 : rr.GetInt32(0),
                    });
                }

                rr.Close();
                cmd.Cancel();

                ///////////////////////////

                myhostsEntities db = new myhostsEntities();

                DateTime thistime = DateTime.Now;

                foreach (var line in list)
                {
                    TABLESPACE c = new TABLESPACE();

                    c.HOSTID   = one.ID;
                    c.NAME     = line.NAME;
                    c.TOTAL    = line.TOTAL;
                    c.USED     = line.USED;
                    c.FREE     = line.FREE;
                    c.PUSER    = line.PUSER;
                    c.PFREE    = line.PFREE;
                    c.SAVETIME = thistime;

                    db.TABLESPACE.AddObject(c);
                }

                db.SaveChanges();


                conn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(one.DESCRIPTION + " " + ex.Message.ToString());
            }

            finally
            {
                conn.Close();
                conn.Dispose();
                DBOK++;
                toolStripStatusLabel6.Text = string.Format("DB current/total:{0}/{1}", DBS.ToString(), DBOK.ToString());
            }
        }
コード例 #4
0
 /// <summary>
 /// 用于向 HOSTS EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet&lt;T&gt; 属性的 .Add 方法。
 /// </summary>
 public void AddToHOSTS(HOSTS hOSTS)
 {
     base.AddObject("HOSTS", hOSTS);
 }