예제 #1
0
파일: Form1.cs 프로젝트: sLevet/projetImage
        private int widthPBox1; // fix picture box size

        #endregion Fields

        #region Constructors

        // constructor
        public Form1()
        {
            InitializeComponent();
            currentIdPicture = -1;  // -1 --> not selected
            currentIdSketch = -1;   // -1 --> not selected
            dBMode = 1;             // by default 1 --> insert image in db , my  choice
            fFile = new FunctionsFile(this);
            fDb = new FunctionsDb(this);
            widthPBox1 = pictureBox1.Width;
            heightPBox1 = pictureBox1.Height;
        }
예제 #2
0
 public void LoadImageFromFileTestImgLoadedOk()
 {
     Form1 form1 = new Form1();
     FunctionsFile fFile = new FunctionsFile(form1);
     // load a picture in pictureBox
     string path = Environment.CurrentDirectory.ToString();
     int pos = path.IndexOf("TestResults");
     path = path.Substring(0, pos);
     path += "Tests_functionsFile\\pictures\\img507x433.png";//projetImage\Tests_functionsFile\pictures\img507x433.png
     //Console.WriteLine("***********" + path + "-*******");
     form1.getPictureBox().Load(path);
     // check picture loaded
     int imgHeight =form1.getPictureBox().Image.Height;
     int imgWidth = form1.getPictureBox().Image.Width;
     Assert.AreEqual(433, imgHeight);
     Assert.AreEqual(507, imgWidth);
 }
예제 #3
0
        //
        // Prepare to load a picture or a sketch from DB. Used to export file
        //
        public void prepareLoadImageFromDb(FunctionsFile fFile)
        {
            // select query
            this.dbMode = form1.DBMode;
            switch (dbMode)
            {
                case 3: query = "SELECT name, id FROM T_pictures";
                    break;
                case 4: query = "SELECT name, id FROM T_sketch WHERE fk_picture = "+form1.CurrentIdPicture;
                    break;
            }
            this.fFile = fFile;
            List<String> listPicturesName = new List<string>();         // store pictures' names and ids
            // first I load and check if pictures are present in DB
            SqlConnection cn = new SqlConnection();             // connection for sql
            try
            {
                string name = "", temp = "";
                int id;
                // open connection
                cn.ConnectionString = connectString;
                cn.Open();
                // query and parameters
                //query = "SELECT name, id FROM T_pictures";
                SqlCommand stmt = new SqlCommand(query, cn);
                rs = stmt.ExecuteReader();
                while (rs.Read())
                {
                    name = ((string)rs["name"]);
                    id = ((int)rs["id"]);
                    temp = id + "_" + name;
                    listPicturesName.Add(temp);

                }
                rs.Close();
                cn.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show("Sorry,not ok !!! " + e.ToString());
                cn.Close();
                rs.Close();
            }
            // if list.count = 0 --> no picture ---> display a warning and stop
            if (listPicturesName.Count() == 0)
            {
                MessageBox.Show("No picture in data base !");
                return;
            }
            // create a new form with picture's names. This allow to use same vars in form2
            Form2 form2 = new Form2(this);
            form2.Show();
            // fill combo list and select a default value
            string[] tabName = new string[listPicturesName.Count()];
            int pos = -1;
            foreach (String name in listPicturesName)
            {
                pos++;
                tabName[pos] = name;
            }
            form2.getComboBox().Items.AddRange(tabName);
            form2.getComboBox().SelectedIndex = 0;
        }