示例#1
0
        private void btn_done_Click(object sender, EventArgs e)
        {
            //TODO: i want to add here .. if camImages == null then form1.frec.savereadyimageslist(camimages,name); else form1.frec.savelist(images, name);
            if (!(cameraImages.Count == 0))
            {
                images = Form1.frec.SaveReadyImageList(cameraImages, txt_name.Text);
            }
            else if (!(images.Count == 0))
            {
                images = Form1.frec.SaveList(images, txt_name.Text);
            }
            else
                return;

            for (int i = 0; i < images.Count; i++ )
            {
                if (images[i] == "")
                {
                    images.RemoveAt(i);
                    i--;
                }
            }

            name = txt_name.Text;
            Users u = new Users(-1, name, txt_phone.Text, txt_address.Text);
            
            //Add the name and the images to the file return bool and display a message box

            int count = images.Count;
            List<Images> imagesList = new List<Images>();
            for (int i = 0; i < count; i++)
            {
                imagesList.Add(new Images(-1, images[i], -1));
            }
            if(imagesList.Count != 0)
            {
                Form1.database.Insert(new Person(u, imagesList));
                Form1.itc.AddItem(Form1.database.Persons.Count - 1 /*your id here*/, name, new Bitmap(images[0]));
                MessageBox.Show("Added succesfly");
            }

            else
            {   
                MessageBox.Show("Sorry you have to Enter a new name and at least 1 image");
            }
            txt_name.Text = string.Empty;
            txt_address.Text = string.Empty;
            txt_phone.Text = string.Empty;
            images = new List<string>();
        }
        private void btn_done_Click(object sender, EventArgs e)
        {
            bool nameEdit = true, imageEdit = true;
            if (imageAdded)
            {
                if (!(cameraImages.Count == 0))
                {
                    images = Form1.frec.SaveReadyImageList(cameraImages, txt_name.Text);
                }
                else if (!(images.Count == 0))
                {
                    images = Form1.frec.SaveList(images, txt_name.Text);
                }
                else
                    return;

                for (int i = 0; i < images.Count; i++)
                {
                    if (images[i] == "")
                    {
                        images.RemoveAt(i);
                        i--;
                    }
                }

                int count = images.Count;

                for (int i = 0; i < count; i++)
                {
                    Form1.database.InsertImage(p.User.UserID, images[i], true);
                }

                //imageEdit = Form1.db.EditDictionary(prevName, imagePaths);
            }

            if (prevName != txt_name.Text || prevAddress != txt_address.Text || prevPhone != txt_phone.Text)
            {
                Users u = new Users(p.User.UserID, txt_name.Text, txt_phone.Text, txt_address.Text);
                Form1.database.UpdateUserInfo(p.User.UserID, u);
                //nameEdit = Form1.db.EditDictionary(prevName, txt_name.Text);
                lbl_name.Text = txt_name.Text;
                lbl_address.Text = txt_address.Text;
                lbl_phone.Text = txt_phone.Text;
                ((Item)Form1.itc.items[Form1.itc.selectedItem]).LblName.Text = txt_name.Text;
            }

            if (nameEdit && imageEdit)
            {
                lbl_name.Show();
                txt_name.Hide();
                button2.Hide();
                button1.Hide();
                lbl_address.Show();
                lbl_phone.Show();
                txt_phone.Hide();
                txt_address.Hide();
                lbl_edit.Show();
                btn_done.Hide();
                btn_AddImage.Hide();
                RemoveAllLabels();
                MessageBox.Show("Edited Successfuly");
            }
            else
                MessageBox.Show("sorry the name you have entered already founded");

        }
示例#3
0
 public Person(Users user, List<Images> images)
 {
     this.User = user;
     this.Images = images;
 }
示例#4
0
        //====================================================================================================================

        /// <summary>
        /// Updates the user info.
        /// </summary>
        /// <param name="oldPID">The old PID.</param>
        /// <param name="newPerson">The new person.</param>
        public void UpdateUserInfo(int oldPID, Users newPerson)
        {
            Person oldP;
            int id = -1;

            foreach (Person per in Persons)
            {
                id++;

                if (per.User.UserID == oldPID)
                {
                    break;
                }
            }

            oldP = new Person(Persons[id].User, Persons[id].Images);

            persons[id].User = newPerson;

            try
            {
                con.Open();
                string Update = @"update Users Set UserName = @name, UserPhone = @phone, UserAddress = @address  WHERE UserID = @ID";
                SqlCeCommand cmd = new SqlCeCommand(Update, con);
                cmd.Parameters.Add(new SqlCeParameter("@ID", oldPID));
                cmd.Parameters.Add(new SqlCeParameter("@name", newPerson.Name));
                cmd.Parameters.Add(new SqlCeParameter("@phone", newPerson.PhoneNo));
                cmd.Parameters.Add(new SqlCeParameter("@address", newPerson.Address));
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
               // throw new Exception(ex.Message, ex);
            }
            finally
            {
                con.Close();
            }
        }