Exemplo n.º 1
0
        private void DGV_Matchs_SelectionChanged(object sender, EventArgs e)
        {
            PB_EquipeHome.Image = null;
            PB_EquipeAway.Image = null;


            if (DGV_Matchs.SelectedRows.Count > 0)
            {
                OracleCommand oraImage = oracon.CreateCommand();
                oraImage.CommandText = "SELECT (SELECT Logo FROM Equipe WHERE NomEquipe=:NomEquipe1), (SELECT Logo FROM Equipe WHERE NomEquipe=:NomEquipe2) FROM DUAL";
                oraImage.Parameters.Add(new OracleParameter(":NomEquipe1", DGV_Matchs.SelectedRows[0].Cells[1].Value.ToString()));
                oraImage.Parameters.Add(new OracleParameter(":NomEquipe2", DGV_Matchs.SelectedRows[0].Cells[2].Value.ToString()));

                FillStats();

                LB_NbButsHome.Text = DGV_Matchs.SelectedRows[0].Cells[5].Value.ToString();
                LB_NbButsAway.Text = DGV_Matchs.SelectedRows[0].Cells[6].Value.ToString();
                TB_Receveur.Text   = DGV_Matchs.SelectedRows[0].Cells[1].Value.ToString();
                TB_Visiteur.Text   = DGV_Matchs.SelectedRows[0].Cells[2].Value.ToString();
                using (OracleDataReader oraReader = oraImage.ExecuteReader())
                {
                    if (oraReader.Read())
                    {
                        OracleBlob oraBlob = oraReader.GetOracleBlob(0);
                        if (!oraBlob.IsNull)
                        {
                            using (MemoryStream ms = new MemoryStream())
                            {
                                byte[] buffer = new byte[8 * 1024];
                                int    read   = 0;
                                while ((read = oraBlob.Read(buffer, 0, 8 * 1024)) > 0)
                                {
                                    ms.Write(buffer, 0, read);
                                }
                                PB_EquipeHome.Image = Image.FromStream(ms);
                            }
                        }

                        oraBlob = oraReader.GetOracleBlob(1);
                        if (!oraBlob.IsNull)
                        {
                            using (MemoryStream ms = new MemoryStream())
                            {
                                byte[] buffer = new byte[8 * 1024];
                                int    read   = 0;
                                while ((read = oraBlob.Read(buffer, 0, 8 * 1024)) > 0)
                                {
                                    ms.Write(buffer, 0, read);
                                }
                                PB_EquipeAway.Image = Image.FromStream(ms);
                            }
                        }
                    }
                }
            }
        }
        public static byte[] ExecuteDataReader(string sql, string connStr, params OracleParameter[] parameters)
        {
            using (OracleConnection conn = new OracleConnection(connStr))
            {
                conn.Open();
                using (OracleCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = sql;
                    cmd.Parameters.AddRange(parameters);
                    OracleDataReader reader = cmd.ExecuteReader();

                    MemoryStream ms = new MemoryStream();

                    if (reader.Read())
                    {
                        OracleBlob blob   = (OracleBlob)reader.GetOracleBlob(0);
                        Byte[]     buffer = new Byte[blob.Length];
                        blob.Read(buffer, 0, Convert.ToInt32(blob.Length));
                        ms.Write(buffer, 0, Convert.ToInt32(blob.Length));
                        blob.Close();
                    }
                    reader.Close();
                    ms.Position = 0;
                    byte[] result = new byte[ms.Length];
                    ms.Read(result, 0, result.Length);
                    return(result);
                }
            }
        }
Exemplo n.º 3
0
        private byte[] GetSinoSZDefineReport_Excel(MD_ReportItem _reportItem)
        {
            byte[] cbuffer = null;

            using (OracleConnection cn = OracleHelper.OpenConnection())
            {
                long          actual = 0;
                OracleCommand _cmd   = new OracleCommand();
                _cmd.CommandText = SQL_GetSinoSZDefineReport_Excel;
                _cmd.CommandType = CommandType.Text;
                _cmd.Connection  = cn;
                _cmd.Parameters.Add(":BBMC", _reportItem.ReportName.ReportName);
                _cmd.Parameters.Add(":TJDW", _reportItem.ReportDWID);
                _cmd.Parameters.Add(":KSRQ", _reportItem.StartDate);
                _cmd.Parameters.Add(":JZRQ", _reportItem.EndDate);

                OracleDataReader myOracleDataReader = _cmd.ExecuteReader();
                bool             _readflag          = myOracleDataReader.Read();
                OracleBlob       myOracleClob       = myOracleDataReader.GetOracleBlob(0);
                long             lobLength          = myOracleClob.Length;
                cbuffer = new byte[lobLength];
                actual  = myOracleClob.Read(cbuffer, 0, cbuffer.Length);

                myOracleDataReader.Close();

                return(cbuffer);
            }
        }
Exemplo n.º 4
0
        private void DGV_Equipes_SelectionChanged(object sender, EventArgs e)
        {
            image           = null;
            PB_Equipe.Image = null;

            if (DGV_Equipes.SelectedRows.Count > 0)
            {
                OracleCommand oraImage = oracon.CreateCommand();
                oraImage.CommandText = "SELECT Logo FROM Equipe WHERE NomEquipe=:NomEquipe";
                oraImage.Parameters.Add(new OracleParameter(":NomEquipe", DGV_Equipes.SelectedRows[0].Cells[0].Value.ToString()));
                using (OracleDataReader oraReader = oraImage.ExecuteReader())
                {
                    if (oraReader.Read())
                    {
                        OracleBlob oraBlob = oraReader.GetOracleBlob(0); // à voir l'index du blob
                        if (!oraBlob.IsNull)
                        {
                            using (MemoryStream ms = new MemoryStream())
                            {
                                byte[] buffer = new byte[8 * 1024];
                                int    read   = 0;
                                while ((read = oraBlob.Read(buffer, 0, 8 * 1024)) > 0)
                                {
                                    ms.Write(buffer, 0, read);
                                }
                                image           = ms.ToArray();
                                PB_Equipe.Image = Image.FromStream(ms);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Select an Oracle Blob value
        /// </summary>
        /// <param name="table"></param>
        /// <param name="matchCol"></param>
        /// <param name="typeCol"></param>
        /// <param name="contentCol"></param>
        /// <param name="matchVal"></param>

        public static void SelectOracleBlob(
            string table,
            string matchCol,
            string typeCol,
            string contentCol,
            string matchVal,
            out string typeVal,
            out byte[] ba)
        {
            typeVal = null;
            ba      = null;

            string sql =
                "select " + typeCol + ", " + contentCol + " " +
                "from " + table + " " +
                "where " + matchCol + " = :0";

            DbCommandMx drd = new DbCommandMx();

            drd.PrepareMultipleParameter(sql, 1);

            for (int step = 1; step <= 2; step++) // try two different forms of matchVal
            {
                if (step == 2)                    // try alternate form of spaces
                {
                    if (matchVal.Contains("%20"))
                    {
                        matchVal = matchVal.Replace("%20", " ");                         // convert html spaces to regular spaces
                    }
                    else
                    {
                        matchVal = matchVal.Replace(" ", "%20");                      // convert regular spaces to html spaces
                    }
                }

                drd.ExecuteReader(matchVal);
                if (!drd.Read())
                {
                    continue;
                }

                typeVal = drd.GetString(0);
                if (drd.Rdr.IsDBNull(1))
                {
                    break;
                }

                OracleBlob ob = drd.OracleRdr.GetOracleBlob(1);
                if (ob != null && ob.Length >= 0)
                {
                    ba = new byte[ob.Length];
                    ob.Read(ba, 0, (int)ob.Length);
                }

                break;                 // have value
            }

            drd.Dispose();
            return;
        }
Exemplo n.º 6
0
        public byte[] GetChunk(int bytes)
        {
            var buffer    = new byte[bytes];
            var bytesRead = _blob.Read(buffer, 0, bytes);
            var result    = new byte[bytesRead];

            Array.Copy(buffer, 0, result, 0, bytesRead);
            return(result);
        }
Exemplo n.º 7
0
        public void OracleProcedure(string ConnectionString, string ProcedureName, string OutBlobParam)
        {
            OracleConnection OracleCon = new OracleConnection(ConnectionString);
            //GIVE PROCEDURE NAME
            OracleCommand cmd = new OracleCommand(ProcedureName, OracleCon);

            cmd.CommandType = CommandType.StoredProcedure;

            //ASSIGN PARAMETERS TO BE PASSED
            //cmd.Parameters.Add("sdisk", OracleDbType.Char).Value = "D";
            //cmd.Parameters.Add("PARAM2", OracleDbType.Varchar2).Value = "VAL2";

            //THIS PARAMETER MAY BE USED TO RETURN RESULT OF PROCEDURE CALL
            cmd.Parameters.Add(OutBlobParam, OracleDbType.Blob);
            cmd.Parameters[OutBlobParam].Direction = ParameterDirection.Output;

            //USE THIS PARAMETER CASE CURSOR IS RETURNED FROM PROCEDURE
            //cmd.Parameters.Add("vCHASSIS_RESULT", OracleDbType.RefCursor, ParameterDirection.InputOutput);

            try
            {
                OracleCon.Open();

                //CALL PROCEDURE
                OracleDataAdapter da = new OracleDataAdapter(cmd);
                cmd.ExecuteNonQuery();

                /* 1й способ */
                OracleBlob myBlob = (OracleBlob)(cmd.Parameters[OutBlobParam].Value);
                byte[]     MyData = new byte[myBlob.Length];
                myBlob.Read(MyData, 0, (int)myBlob.Length);
                FileStream fs = new FileStream(path + "\\" + Program.reportFileName, FileMode.Create, FileAccess.Write);
                fs.Write(MyData, 0, (int)myBlob.Length);
                fs.Close();

                /* 2й способ */
                //byte[] MyData = new byte[0];
                //MyData = (byte[])((OracleBlob)(cmd.Parameters["bblob"].Value)).Value;
                //int ArraySize = new int();
                //ArraySize = MyData.GetUpperBound(0);
                //FileStream fs = new FileStream(@"C:\report.xlsx", FileMode.Create, FileAccess.Write);
                //fs.Write(MyData, 0, ArraySize);
                //fs.Close();
            }
            catch (OracleException oe)
            {
                logger.Info("Ошибка подключения к БД Oracle." + '\n' + oe.Message);
            }
            finally
            {
                if (OracleCon != null)
                {
                    OracleCon.Close();
                    OracleCon.Dispose();
                }
            }
        }
        private void FormEmployConsuInfo_Load(object sender, EventArgs e)
        {
            consumerTableAdapter1.Fill(dataSet11.CONSUMER);
            ConsumerTable = dataSet11.Tables["consumer"];
            fineTableAdapter1.Fill(dataSet11.FINE);
            FineTable = dataSet11.Tables["fine"];

            string str = "consu_id='" + name + "'";

            DataRow[] foundRows = ConsumerTable.Select(str);
            foreach (DataRow mydataRow in foundRows)
            {
                textBoxID.Text      = mydataRow["consu_id"].ToString();
                textBoxName.Text    = mydataRow["consu_name"].ToString();
                textBoxEmail.Text   = mydataRow["consu_email"].ToString();
                textBoxMileage.Text = mydataRow["consu_mileage"].ToString();
                if (mydataRow["consu_blackconsumer"].ToString().Equals("T"))
                {
                    checkBox1.Checked = true;
                }
            }

            oracleConnection1.Open();
            oracleCommand2.Connection  = oracleConnection1;
            oracleCommand2.CommandText = "SELECT * FROM ConsuPictures WHERE consu_id = '" + textBoxID.Text + "'";
            OracleDataReader rdr = oracleCommand2.ExecuteReader();

            if (rdr.HasRows) // 검색 결과가 있으면
            {
                while (rdr.Read())
                {
                    //BLOB_DEMO (blob_id, file_name, media_file)
                    OracleBlob blobData = rdr.GetOracleBlob(2); // 0, 1, 2 즉 3번째 컬럼이 blob
                    byte[]     conten   = new Byte[blobData.Length];
                    int        i        = blobData.Read(conten, 0, Convert.ToInt32(blobData.Length));

                    System.IO.MemoryStream memStream = new System.IO.MemoryStream(conten);

                    // blob에서 가져온 이미지를 화면에 출력
                    pictureBox3.Image    = Image.FromStream(memStream);
                    pictureBox3.SizeMode = PictureBoxSizeMode.StretchImage;
                }
            }
            oracleConnection1.Close();
        }
Exemplo n.º 9
0
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            consumerTableAdapter1.Fill(dataSet11.CONSUMER);
            ConsuTable = dataSet11.Tables["CONSUMER"];
            string str = "consu_id='" + listBox1.Items[listBox1.SelectedIndex] + "'";

            DataRow[] foundRows = ConsuTable.Select(str);

            foreach (DataRow mydataRow in foundRows)
            {
                textBoxID.Text            = mydataRow["consu_id"].ToString();
                textBoxName.Text          = mydataRow["consu_name"].ToString();
                textBoxEmail.Text         = mydataRow["consu_email"].ToString();
                dateTimePickerBirth.Value = Convert.ToDateTime(mydataRow["consu_birth"]);
            }

            oracleConnection1.Open();
            oracleCommand2.Connection  = oracleConnection1;
            oracleCommand2.CommandText = "SELECT * FROM ConsuPictures WHERE consu_id = '" + textBoxID.Text + "'";
            OracleDataReader rdr = oracleCommand2.ExecuteReader();

            if (rdr.HasRows) // 검색 결과가 있으면
            {
                while (rdr.Read())
                {
                    //BLOB_DEMO (blob_id, file_name, media_file)
                    OracleBlob blobData = rdr.GetOracleBlob(2);
                    byte[]     conten   = new Byte[blobData.Length];
                    int        i        = blobData.Read(conten, 0, Convert.ToInt32(blobData.Length));

                    System.IO.MemoryStream memStream = new System.IO.MemoryStream(conten);

                    // blob에서 가져온 이미지를 화면에 출력
                    pictureBox4.Image    = Image.FromStream(memStream);
                    pictureBox4.SizeMode = PictureBoxSizeMode.StretchImage;
                }
            }
            else
            {
                pictureBox4.Image = System.Drawing.Image.FromFile("C:\\boss2.png");
            }
            oracleConnection1.Close();
        }
Exemplo n.º 10
0
 public static Task <int> ReadAsynchronous(this OracleBlob blob, byte[] buffer, int offset, int count, CancellationToken cancellationToken)
 {
     return(App.ExecuteAsynchronous(delegate { }, () => blob.Read(buffer, offset, count), cancellationToken));
 }
Exemplo n.º 11
0
        public static dynamic OracleDBTypeToNative(OracleParameter param)
        {
            switch (param.OracleDbTypeEx)
            {
            case OracleDbType.Array:
            case OracleDbType.BFile:
            case OracleDbType.BinaryDouble:
            case OracleDbType.BinaryFloat:
            case OracleDbType.Ref:
            case OracleDbType.RefCursor:
            case OracleDbType.XmlType:
                return(param.Value);

            case OracleDbType.LongRaw:
            case OracleDbType.Raw:
            case OracleDbType.Blob:
                if (param.Value == null)
                {
                    return(default(byte[]));
                }
                else
                {
                    /*TODO: this is an extremely naive implementation, and will eat RAM if large BLOBS are used.
                     *      Currently, I'm limiting at 10MB of data (defined in a const inside _Common.cs),
                     *      and raising an error if this limit is exceeded. */
                    byte[] BlobBytes;

                    OracleBlob Blob = (OracleBlob)param.Value;
                    if (Blob.Length < Max_Blob_Size)
                    {
                        BlobBytes = new byte[Blob.Length];
                        Blob.Read(BlobBytes, 0, (int)Blob.Length);
                        return(BlobBytes);
                    }
                    else
                    {
                        throw new NotSupportedException("This function will return a maximum of " + Max_Blob_Size + " bytes to avoid excessive RAM consumption.");
                    }
                }

            //this case will probably never work, so I may as well ignore it

            /*case OracleDbType.Byte:
             *  if(param.Value == null)
             *  {
             *      return default(byte);
             *  }
             *  else
             *  {
             *      return (byte)param.Value;
             *  }*/
            case OracleDbType.Char:
            case OracleDbType.NChar:
            case OracleDbType.NVarchar2:
            case OracleDbType.Varchar2:
                OracleString paramValueString = (OracleString)param.Value;
                if (paramValueString == null || paramValueString.IsNull)
                {
                    return(string.Empty);
                }
                else
                {
                    return(paramValueString.Value);
                }

            case OracleDbType.Clob:
            case OracleDbType.NClob:
                if (param.Value == null)
                {
                    return(default(string));
                }
                else
                {
                    return(((OracleClob)param.Value).Value);
                }

            case OracleDbType.Date:
                OracleDate paramValueDate = (OracleDate)param.Value;
                if (paramValueDate == null || paramValueDate.IsNull)
                {
                    return(default(DateTime));
                }
                else
                {
                    return(paramValueDate.Value);
                }

            case OracleDbType.IntervalDS:
                if (param.Value == null)
                {
                    return(default(TimeSpan));
                }
                else
                {
                    return(((OracleIntervalDS)param.Value).Value);
                }

            case OracleDbType.IntervalYM:
                if (param.Value == null)
                {
                    return(default(TimeSpan));
                }
                else
                {
                    return(((OracleIntervalYM)param.Value).Value);
                }

            case OracleDbType.TimeStamp:
                if (param.Value == null)
                {
                    return(default(DateTime));
                }
                else
                {
                    return(((OracleTimeStamp)param.Value).Value);
                }

            case OracleDbType.TimeStampLTZ:
                if (param.Value == null)
                {
                    return(default(DateTime));
                }
                else
                {
                    return(((OracleTimeStampLTZ)param.Value).Value);
                }

            case OracleDbType.TimeStampTZ:
                if (param.Value == null)
                {
                    return(default(DateTime));
                }
                else
                {
                    return(((OracleTimeStampTZ)param.Value).Value);
                }

            case OracleDbType.Int16:
            case OracleDbType.Int32:
                OracleDecimal paramValueInt32 = (OracleDecimal)param.Value;
                if (paramValueInt32 == null || paramValueInt32.IsNull)
                {
                    return(default(int));
                }
                else
                {
                    return(paramValueInt32.ToInt32());
                }

            case OracleDbType.Int64:
                OracleDecimal paramValueInt64 = (OracleDecimal)param.Value;
                if (paramValueInt64 == null || paramValueInt64.IsNull)
                {
                    return(default(Int64));
                }
                else
                {
                    return(paramValueInt64.ToInt64());
                }

            case OracleDbType.Decimal:
                OracleDecimal paramValueDecimal = (OracleDecimal)param.Value;
                if (paramValueDecimal == null || paramValueDecimal.IsNull)
                {
                    return(default(decimal));
                }
                else
                {
                    return(paramValueDecimal.Value);
                }

            case OracleDbType.Double:
            case OracleDbType.Single:     //we don't care internally about single.
                if (param.Value == null)
                {
                    return(default(double));
                }
                else
                {
                    return(((OracleDecimal)param.Value).ToDouble());
                }

            default:
                throw new NotImplementedException("Type not handled yet");
            }
        }
Exemplo n.º 12
0
        /***********************************************************************
        * This method is called when an Item is selected from 'productCbBx'
        * drop down list. The purpose of this method to demonstrate how to
        * fetch BLOB lob as an OracleLOB (ODP .Net Data Type) using an OracleDataReader.
        * The flow of the method is as follows:
        * 1. Clear the contents of Ad Text Box, Existing Ad Image and
        *    New Ad Image.
        * 2. Populate OracleDataReader with data from 'PrintMedia' table, through
        *    ExecuteReader method of OracleCommand object. The data is fetched based
        *    on the Product selected from 'productCbBx' list.
        * 3. Assign value for Ad Text from the OracleDataReader.
        * 4. Ad Image(BLOB) is read into a Byte array, then used to construct
        *    MemoryStream and passed to PictureBox.
        * Hence displaying the existing advertisement information for the
        * Product selected from drop down list box.
        ***********************************************************************/
        private void ProductCbBx_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            //For fetching read only rows from datasource
            OracleDataReader viewPicReader;

            //For executing SQL statements against datasource
            OracleCommand viewPicCmd;

            //To store MessageBox result
            DialogResult x;

            //If Ad Image or Ad Text is changed then promt user to save.
            if (strImageName != "" || strExistText != adTextBx.Text)
            {
                //MessageBox prompting user whether he/she wishes to save changes made
                x = MessageBox.Show("Do you want to save changes ?", "Save Dialog", MessageBoxButtons.YesNo);

                //If the user wishes to save changes
                if (x == DialogResult.Yes)
                {
                    //call the method for insertion or updation of advertisement
                    updateData();

                    //Reset variable
                    intProdID = int.Parse(productCbBx.GetItemText(productCbBx.SelectedValue));
                }
                //If the user doesn't wish to save changes
                else
                {
                    //Reset variables
                    strImageName = "";
                    intProdID    = int.Parse(productCbBx.GetItemText(productCbBx.SelectedValue));
                }
            }
            try

            {
                //Step 1.//
                //Clear contents
                adTextBx.Text            = "";
                existingImagePicBx.Image = null;
                newImagePicBx.Image      = null;
                strImageName             = "";
                curAdID      = "";
                strExistText = "";


                //Fetch Product Details using OracleCommand for the selected product from the list
                viewPicCmd = new OracleCommand("SELECT " +
                                               "Ad_ID , " +
                                               "Ad_Text, " +
                                               "Ad_Image " +
                                               "FROM PrintMedia " +
                                               "WHERE product_id =" + productCbBx.GetItemText(productCbBx.SelectedValue), conn);

                //Set OracleConnection for this instance of OracleCommand
                viewPicCmd.Connection = conn;

                //Set Command type as text
                viewPicCmd.CommandType = CommandType.Text;

                //Sends the CommandText to the Connection and builds an OleDbDataReader
                viewPicReader = viewPicCmd.ExecuteReader();

                //Read data
                Boolean recordExist = viewPicReader.Read();

                // MessageBox.Show(viewPicReader.GetInt32(0).ToString());
                //If data exists
                if (recordExist)
                {
                    //Store current Advertisement value
                    curAdID = viewPicReader.GetInt32(0).ToString();

                    //If Ad Text exists
                    if (viewPicReader.GetValue(1).ToString() != "")
                    {
                        //Assign the 'Ad Text' TextBox to Advertisement text fetched from database
                        adTextBx.Text = viewPicReader.GetString(1);

                        //set variable
                        strExistText = viewPicReader.GetString(1);
                    }


                    //If Ad Image exists
                    if (viewPicReader.GetValue(2).ToString() != "")
                    {
                        //Fetch the BLOB data through OracleDataReader using OracleBlob type
                        OracleBlob blob = viewPicReader.GetOracleBlob(2);


                        //Create a byte array of the size of the Blob obtained
                        Byte[] byteBLOBData = new Byte[blob.Length];

                        //Read blob data into byte array
                        int i = blob.Read(byteBLOBData, 0, System.Convert.ToInt32(blob.Length));

                        //Get the primitive byte data into in-memory data stream
                        MemoryStream stmBLOBData = new MemoryStream(byteBLOBData);

                        //Assign the 'Existing Ad Image' to the memory stream
                        existingImagePicBx.Image = Image.FromStream(stmBLOBData);

                        //Fit the image to the picture box size
                        existingImagePicBx.SizeMode = PictureBoxSizeMode.StretchImage;
                    }
                    //close the OracleDataReader
                    viewPicReader.Close();
                }

                //Reset  variable
                intProdID = int.Parse(productCbBx.GetItemText(productCbBx.SelectedValue));
            }
            //Catch exception when accessing arrary element out of bound
            catch (System.IndexOutOfRangeException rangeException)
            {
                //Do nothing
                rangeException.ToString();
            }
            catch (Exception ex)
            {
                //Display error message
                System.Windows.Forms.MessageBox.Show(ex.ToString());
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// db¿¡ ÀúÀåµÈ ÆÄÀÏ image¸¦ ±¸ÇÑ´Ù.
        /// </summary>
        /// <param name="strConn"></param>
        /// <param name="strUpdateType"></param>
        /// <param name="strFileName"></param>
        /// <param name="strPath"></param>
        /// <returns>CRCƒ„</returns>
        public static string FileInfo_GetFile(OracleDB.strConnect strConn, string strUpdateType, string strFileName, string strPath,
                                              int intTotalSize, delFileInfo_GetFile del)
        {
            OracleDB clsDB = new OracleDB(strConn.strTNS, strConn.strID, strConn.strPass);

            OracleParameter[] param = new OracleParameter[] {
                new OracleParameter("ps_UpdateType", OracleDbType.Varchar2, 20),
                new OracleParameter("ps_FileName", OracleDbType.Varchar2, 100),
                new OracleParameter("ps_FileImage", OracleDbType.Blob)
            };


            param[2].Direction = ParameterDirection.Output;
            param[0].Value     = strUpdateType;
            param[1].Value     = strFileName;

            clsDB.BeginTransaction();

            clsDB.intExcute_StoredProcedure("AutoUpdater_PKG.FileInfo_GetFileImage", param);

            OracleBlob Lob = (OracleBlob)param[2].Value;

            int blockSize = 15000;
            //Àӽà µð·ºÅ丮¿¡ ÀúÀå ÇÑ´Ù.

            int intRecevedFileSize = 0;

            FileInfo fi = new FileInfo(strPath + strFileName);

            if (!Directory.Exists(fi.DirectoryName))
            {
                Directory.CreateDirectory(fi.DirectoryName);
            }

            using (FileStream fs = new FileStream(strPath + strFileName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
            {
                using (BinaryWriter Bw = new BinaryWriter(fs))
                {
                    try
                    {
                        byte[] byteArray = new byte[blockSize];
                        int    bytes;

                        while ((bytes = Lob.Read(byteArray, 0, byteArray.Length)) > 0)
                        {
                            Bw.Write(byteArray, 0, bytes);

                            // ¿©±â¼­ bytesÁ¤º¸¸¦ ´©ÀûÇسª°¡¸é¼­, ÇØ´ç ´©ÀûÁ¤º¸¸¦ ½º·¹µå¸¦ ÅëÇØ
                            // »ç¿ëÀÚ¿¡°Ô º¸¿©ÁÖ¸é, ´Ù¿î·Îµå ÁøÇà»óȲÀ» Ç¥ÇöÇÒ ¼ö ÀÖ°Ú´Ù.(ÇØ´ç ±¸Çö »çÇ×Àº »ý·«)

                            intRecevedFileSize += bytes;

                            if (del != null)
                            {
                                del(strFileName, intTotalSize, intRecevedFileSize);
                            }
                        }
                    }
                    catch
                    {
                        throw;
                    }
                    finally
                    {
                        Bw.Flush();
                        fs.Flush();

                        Bw.Close();
                        fs.Close();

                        fs.Dispose();

                        clsDB.RollBackTransaction();
                    }
                }
            }



            return(system.clsFile.Get_Crc32(fi));
        }
Exemplo n.º 14
0
        // ReSharper disable once UnusedParameter.Local
        static void Main(string[] args)
        {
            List <string> listaDzialek = new List <string>();

            try
            {
                using (StreamReader sr = new StreamReader("listaDLK.txt"))
                {
                    while (sr.Peek() >= 0)
                    {
                        string linia = sr.ReadLine();

                        if (linia != null && linia.Length >= 15)
                        {
                            listaDzialek.Add(linia);
                        }
                    }
                }
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("Brak pliku w katalogu programu: listaDLK.txt\n");
                return;
            }

            string connectionString = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.110.6)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=EWID)));User Id=ewid4;Password=2015geo;";

            using (OracleConnection conn = new OracleConnection(connectionString))
            {
                try
                {
                    conn.Open();

                    using (OracleCommand cmd = new OracleCommand())
                    {
                        cmd.Connection = conn;

                        foreach (string dzialka in listaDzialek)
                        {
                            Console.Write("Wydawanie GML dla dzialki: " + dzialka + "...");

                            cmd.CommandType = CommandType.Text;
                            cmd.CommandText = "begin ewd.gml_pomin_dane_os := 1; end;";

                            cmd.ExecuteNonQuery();

                            cmd.CommandText = "GML_EGB_DZIALKI";
                            cmd.CommandType = CommandType.StoredProcedure;

                            OracleParameter result = new OracleParameter("result", OracleDbType.Blob)
                            {
                                Direction = ParameterDirection.ReturnValue
                            };
                            cmd.Parameters.Add(result);

                            OracleParameter zapytanie = new OracleParameter("zapytanie", OracleDbType.Varchar2)
                            {
                                Direction = ParameterDirection.Input,
                                Value     = "SELECT dzialka_id FROM kdzialka where zmiana_kas_id is null AND EW_DLK_IDG5(mslink) = '" + dzialka + "'"
                            };
                            cmd.Parameters.Add(zapytanie);

                            OracleParameter naDzien = new OracleParameter("na_dzien", OracleDbType.Date)
                            {
                                Direction = ParameterDirection.Input,
                                Value     = DateTime.Now
                            };
                            cmd.Parameters.Add(naDzien);

                            OracleParameter xmlHeader = new OracleParameter("xml_header", OracleDbType.Int32)
                            {
                                Direction = ParameterDirection.Input,
                                Value     = 1
                            };
                            cmd.Parameters.Add(xmlHeader);

                            OracleParameter danePowiazane = new OracleParameter("dane_powiazane", OracleDbType.Int32)
                            {
                                Direction = ParameterDirection.Input,
                                Value     = 0
                            };
                            cmd.Parameters.Add(danePowiazane);

                            OracleParameter danePodmiotowe = new OracleParameter("dane_podmiotowe", OracleDbType.Int32)
                            {
                                Direction = ParameterDirection.Input,
                                Value     = 0
                            };
                            cmd.Parameters.Add(danePodmiotowe);

                            OracleParameter wszystkiePunktyGraniczne = new OracleParameter("wszystkie_punkty_graniczne", OracleDbType.Int32)
                            {
                                Direction = ParameterDirection.Input,
                                Value     = 0
                            };
                            cmd.Parameters.Add(wszystkiePunktyGraniczne);

                            OracleParameter wydajBudynki = new OracleParameter("wydaj_budynki", OracleDbType.Int32)
                            {
                                Direction = ParameterDirection.Input,
                                Value     = 0
                            };
                            cmd.Parameters.Add(wydajBudynki);

                            cmd.ExecuteNonQuery();

                            OracleBlob blob = (OracleBlob)cmd.Parameters[0].Value;

                            byte[] filedata = new byte[blob.Length];

                            blob.Read(filedata, 0, Convert.ToInt32(blob.Length));

                            using (FileStream fs = new FileStream(dzialka.Replace("/", "_") + ".gml", FileMode.Create))
                            {
                                fs.Write(filedata, 0, filedata.Length);
                            }

                            cmd.Parameters.Clear();

                            Console.WriteLine("OK");
                        }
                    }

                    Console.ReadKey();
                }
                catch (OracleException ex)
                {
                    Console.WriteLine(@"Database error: " + ex.Message);
                }
                catch (Exception ex) // catches any other error
                {
                    Console.WriteLine(@"Programe error: " + ex.Message);
                }
            }
        }
Exemplo n.º 15
0
        private void button7_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("This test will assume that a BLOB has been uploaded into the Products table for the product ID 'E1'. Please upload a BLOB if you have not. You can do so using the sample in Chapter 4. Would you like to proceed?", "Notice", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.No)
            {
                return;
            }
            //We first read the full contents of the file into a byte array
            Stopwatch _stopwatch = new Stopwatch();
            String    _Results;
            String    _connstring = "Data Source=localhost/NEWDB;User Id=EDZEHOO;Password=PASS123;";

            try
            {
                OracleConnection _connObj = new OracleConnection(_connstring);
                OracleDataReader _rdrObj;
                _connObj.Open();
                OracleCommand _cmdObj = _connObj.CreateCommand();
                //Disable the Cache
                _cmdObj.CommandText = "ALTER TABLE ProductFiles MODIFY LOB(FileAttachment) (NOCACHE)";
                _cmdObj.ExecuteNonQuery();
                _cmdObj.CommandText = "SELECT FileAttachment FROM ProductFiles WHERE ProductID=:ProductID";
                _cmdObj.Parameters.Add(new OracleParameter("ProductID", "E1"));
                _stopwatch.Start();
                for (int i = 1; i <= 100; i++)
                {
                    _rdrObj = _cmdObj.ExecuteReader();
                    if (_rdrObj.HasRows)
                    {
                        if (_rdrObj.Read())
                        {
                            OracleBlob _blobObj =
                                _rdrObj.GetOracleBlob(_rdrObj.GetOrdinal
                                                          ("FileAttachment"));
                            byte[] dest = new byte[_blobObj.Length];
                            _blobObj.Read(dest, 0, (int)_blobObj.Length);
                        }
                    }
                    else
                    {
                        MessageBox.Show("The BLOB was not found!");
                    }
                }
                _stopwatch.Stop();
                _cmdObj.Dispose();
                _Results = "Without LOB caching:\t" +
                           _stopwatch.Elapsed.TotalSeconds.ToString() + " seconds\n";
                //Enable the Cache
                _cmdObj             = _connObj.CreateCommand();
                _cmdObj.CommandText = "ALTER TABLE ProductFiles MODIFY LOB(FileAttachment) (CACHE)";
                _cmdObj.ExecuteNonQuery();
                _cmdObj.CommandText = "SELECT FileAttachment FROM ProductFiles WHERE ProductID=:ProductID";
                _cmdObj.Parameters.Add(new OracleParameter("ProductID", "E1"));
                _stopwatch.Reset();
                _stopwatch.Start();
                for (int i = 1; i <= 100; i++)
                {
                    _rdrObj = _cmdObj.ExecuteReader();
                    if (_rdrObj.HasRows)
                    {
                        if (_rdrObj.Read())
                        {
                            OracleBlob _blobObj =
                                _rdrObj.GetOracleBlob(_rdrObj.GetOrdinal("FileAttachment"));
                            byte[] dest = new byte[_blobObj.Length];
                            _blobObj.Read(dest, 0, (int)_blobObj.Length);
                        }
                    }
                    else
                    {
                        MessageBox.Show("The BLOB was not found!");
                    }
                }
                _stopwatch.Stop();
                _Results = _Results + "With LOB Caching:\t" +
                           _stopwatch.Elapsed.TotalSeconds.ToString() + " seconds\n";
                MessageBox.Show(_Results);
                _connObj.Close();
                _connObj.Dispose();
                _connObj = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }