Beispiel #1
0
        private void insertImageData()
        {
            try
            {
                if (imageName != "")
                {
                    //Initialize a file stream to read the image file
                    FileStream fs = new FileStream(imageName, FileMode.Open, FileAccess.Read);

                    //Initialize a byte array with size of stream
                    byte[] imgByteArr = new byte[fs.Length];

                    //Read data from the file stream and put into the byte array
                    fs.Read(imgByteArr, 0, Convert.ToInt32(fs.Length));

                    //Close a file stream
                    fs.Close();

                    using (SqlConnection conn = new SqlConnection(constr))
                    {
                        conn.Open();
                        string sql = "insert into tbl_Image(id,img) values('" + strName + "',@img)";
                        using (SqlCommand cmd = new SqlCommand(sql, conn))
                        {
                            //Pass byte array into database
                            cmd.Parameters.Add(new SqlParameter("img", imgByteArr));
                            int result = cmd.ExecuteNonQuery();
                            if (result == 1)
                            {
                                TimeSpan        scaleDuration     = new TimeSpan(0, 0, 0, 0, 1000);
                                DoubleAnimation ProgressAnimation = new DoubleAnimation(0, 100, scaleDuration, FillBehavior.Stop);
                                ProgressBar2.BeginAnimation(ProgressBar.ValueProperty, ProgressAnimation);

                                MessageBox.Show("Image added successfully.");
                                BindImageList();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #2
0
        public void startrun2()
        {
            OnRun++;
            sd2.Visibility = System.Windows.Visibility.Visible;
            sp2.Visibility = System.Windows.Visibility.Visible;

            this.Height += 74;
            ProcessStartInfo startUWG = new ProcessStartInfo();

            //startUWG.FileName = "C:\\Users\\anakano\\Documents\\Research\\UWG2.1\\For_Installer\\UWGv2.0.exe";
            startUWG.FileName = "UWGEngine.exe";
            //make sure there is space in between each of the four inputs and that folder extension ends with \\
            startUWG.Arguments = ep + "\\ " + ef2 + " " + xp2 + "\\ " + xf2 + " " + rp + "\\ " + rf2 + " " + mon + " " + day + " " + dur;
            //startUWG.Arguments = this.epwPath + this.epwFileName + this.xmlPath + this.xmlFilename;
            startUWG.UseShellExecute        = false;
            startUWG.CreateNoWindow         = true;
            startUWG.RedirectStandardOutput = true;
            double maxx = System.Convert.ToDouble(dur);

            ProgressBar2.Maximum = System.Convert.ToDouble(dur);
            UWGs2  = Process.Start(startUWG);
            UWGst2 = 1;
            UWGs2.EnableRaisingEvents = true;
            UWGs2.Exited += new EventHandler(onClose);
            StreamReader UWGreader = UWGs2.StandardOutput;

            new Thread(() =>
            {
                String UWGreaderst;
                int value = 0;
                while (!UWGreader.EndOfStream)
                {
                    UWGreaderst = UWGreader.ReadLine();
                    this.Dispatcher.Invoke(new Action(() =>
                    {
                        if (UWGreaderst == "le")
                        {
                            ProgressBar2.IsIndeterminate = false;
                            RunningInfo2.Text            = "Loading EPW file...";
                            DoubleAnimation ani          = new DoubleAnimation(maxx, TimeSpan.FromSeconds(15));
                            ProgressBar2.BeginAnimation(ProgressBar.ValueProperty, ani);
                        }
                        if (UWGreaderst == "lx")
                        {
                            RunningInfo2.Text    = "Loading XML file...";
                            DoubleAnimation ani1 = new DoubleAnimation(0, TimeSpan.FromSeconds(0));
                            ProgressBar2.BeginAnimation(ProgressBar.ValueProperty, ani1);
                            DoubleAnimation ani2 = new DoubleAnimation(maxx, TimeSpan.FromSeconds(15));
                            ProgressBar2.BeginAnimation(ProgressBar.ValueProperty, ani2);
                        }
                        if (UWGreaderst == "start")
                        {
                            DoubleAnimation ani1 = new DoubleAnimation(0, TimeSpan.FromSeconds(0));
                            ProgressBar2.BeginAnimation(ProgressBar.ValueProperty, ani1);
                            ProgressBar2.Value = 0;
                            RunningInfo2.Text  = "Generating Day " + System.Convert.ToString(1) + "...";
                        }
                        if (UWGreaderst == "+")
                        {
                            value++;
                            ProgressBar2.Visibility = System.Windows.Visibility.Visible;
                            //                   ProgressBar.Value = value;
                            DoubleAnimation ani = new DoubleAnimation(value, TimeSpan.FromSeconds(.5));
                            ProgressBar2.BeginAnimation(ProgressBar.ValueProperty, ani);
                            if (value == System.Convert.ToDouble(dur))
                            {
                                value = value - 1;
                            }
                            RunningInfo2.Text = "Generating Day " + System.Convert.ToString(value + 1) + "...";
                        }
                        if (UWGreaderst == "end")
                        {
                            RunningInfo2.Text = "Writing new EPW file";
                        }
                        if (UWGreaderst == "over")
                        {
                            UWGst2            = 0;
                            RunningInfo2.Text = "Generating finished!";
                            System.IO.File.Delete(System.IO.Path.Combine(ep, ef2));
                        }
                    }));
                }
            }).Start();
        }