Exemplo n.º 1
0
        private void InsertButtonClick(object sender, EventArgs e)
        {
            //등록 프로세서
            ProductManagement pm = new ProductManagement(dbLoginInfo);
            FTPManager        fm = new FTPManager(Properties.Settings.Default.ftpAddress, Properties.Settings.Default.ftpID, Properties.Settings.Default.ftpPW, Properties.Settings.Default.ftpPort);
            int index, infoIndex;

            //1. DB에 제품정보를 등록한다.
            index = pm.InsertProductData(textBoxProductName.Text, GetIndex("브랜드"), GetIndex("카테고리"), Convert.ToDecimal(textBoxPrice.Text));
            if (index == -1)
            {
                MessageBox.Show("제품 등록에 실패하였습니다.");
                return;
            }
            //1-1. 제품 추가정보를 등록한다
            infoIndex = pm.InsertProductSubData(index, textBoxDiscount.Text);
            if (infoIndex == -1)
            {
                MessageBox.Show("제품정보 등록에 실패하였습니다.");
                pm.DeleteProductData(index);
                return;
            }
            //2. FTP에 올릴파일이름을 추출한다.
            ImageInfo info = GetImageInfo(index);

            //3. FTP에 파일을 업로드한다.
            if (!fm.UploadFiles(info.paths, info.names))
            {
                MessageBox.Show("이미지파일 업로드에 실패하였습니다.");
                pm.DeleteProductSubData(infoIndex);
                pm.DeleteProductData(index);
                return;
            }
            //4. DB에 URL을 등록한다.
            if (!pm.InsertProductImages(info.urls, index))
            {
                MessageBox.Show("이미지정보 등록에 실패하였습니다.");
                pm.DeleteProductSubData(infoIndex);
                pm.DeleteProductData(index);
                fm.DeleteFiles(info.names);
                return;
            }
            MessageBox.Show("등록 완료");

            ClearInsertInfo();
        }