Example #1
0
        public async void dataGridCategory_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            selectedItem = new ItemClass();
            int          rowIndex = e.RowIndex;
            string       srcFileName, trgFileName;
            DropboxTools dropboxTools = new DropboxTools();

            if (rowIndex >= 0)
            {
                selectedItem.itemName   = dataGridCategory.Rows[rowIndex].Cells[0].Value.ToString();
                selectedItem.itemPrice  = Convert.ToDouble(dataGridCategory.Rows[rowIndex].Cells[1].Value.ToString());
                selectedItem.itemNumber = Convert.ToInt32(dataGridCategory.Rows[rowIndex].Cells[2].Value.ToString());

                srcFileName = Global.AppDirectory + selectedItem.itemNumber + Global.AppExtension;
                trgFileName = Global.GetTemporaryDownloadPath() + selectedItem.itemNumber + Global.AppExtension;
                try
                {
                    await dropboxTools.DownloadToPictureBox(srcFileName, trgFileName, pictureBoxItem);
                }
                catch
                {
                    // Error
                }
            }
        }
        private async void buttonSubmit_Click(object sender, EventArgs e)
        {
            // Check name text box
            if (String.IsNullOrEmpty(textboxName.Text))
            {
                MessageBox.Show("Please enter the product name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Check price text box
            if (String.IsNullOrEmpty(textboxPrice.Text))
            {
                MessageBox.Show("Please enter the product price", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Check number text box
            if (String.IsNullOrEmpty(textboxNumber.Text))
            {
                MessageBox.Show("Please enter the product number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Check category combo box
            if (String.IsNullOrEmpty(comboBoxCategory.Text))
            {
                MessageBox.Show("Please enter the product category", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Check picture box
            if (pictureBoxImport.Image == null)
            {
                MessageBox.Show("Please select an image", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            DropboxTools dropboxTools = new DropboxTools();

            anItem.itemName     = textboxName.Text;
            anItem.itemNumber   = Convert.ToInt32(textboxNumber.Text);
            anItem.itemPrice    = Convert.ToDouble(textboxPrice.Text);
            anItem.itemCategory = comboBoxCategory.Text;

            bool wasSuccessful = anItem.InsertToDatabase(anItem);

            try
            {
                this.Enabled = false;
                await dropboxTools.Upload(openFileDialogImport.FileName, Path.Combine(Global.AppDirectory, textboxNumber.Text + Global.AppExtension));
            }
            catch
            {
                wasSuccessful = false;
            }

            if (wasSuccessful)
            {
                MessageBox.Show("Successful");
            }

            this.Hide();
            var formTemp = new ManagementItemView();

            formTemp.Show();
        }