Ejemplo n.º 1
0
        //登録
        private void b_regist_Click(object sender, EventArgs e)
        {
            //if (!mod.chackMessage("登録"))
            //    return;

            //入力チェック
            chk.clear();
            chk.addControl(d_tenpo);
            chk.addControl(t_costume_code);
            chk.addControl(t_costume);
            chk.addControl(t_size);
            chk.addControl(d_seibetsu);
            chk.addControl(t_brand);
            chk.addControl(t_rank);
            chk.addControl(d_siyoukahi);
            chk.addControl(t_price1);
            chk.addControl(t_price2);
            chk.addControl(t_price3);
            chk.addControl(t_color);
            chk.addControl(t_age);
            chk.addControl(t_bunrui);
            chk.addControl(t_mitame);
            chk.addControl(t_gara);
            chk.addControl(d_status);
            chk.addControl(t_image_file1);
            chk.addControl(t_initial_use_count);
            if (chk.check("W00000", chk.checkControlImportant))
            {
                return;
            }

            //桁数チェック
            //衣装コード
            chk.clear();
            chk.addControl(t_costume_code);
            if (chk.check("W00001", chk.checkTextboxLength, 8))
            {
                return;
            }

            //衣装名・ブランド名
            chk.clear();
            chk.addControl(t_costume);
            chk.addControl(t_brand);
            if (chk.check("W00001", chk.checkTextboxLength, 40))
            {
                return;
            }

            //年齢
            chk.clear();
            chk.addControl(t_age);
            if (chk.check("W00001", chk.checkTextboxLength, 2))
            {
                return;
            }

            //価格・色・分類・柄・サイズ・ランク
            chk.clear();
            chk.addControl(t_size);
            chk.addControl(t_rank);
            chk.addControl(t_price1);
            chk.addControl(t_price2);
            chk.addControl(t_price3);
            chk.addControl(t_color);
            chk.addControl(t_bunrui);
            chk.addControl(t_gara);
            if (chk.check("W00001", chk.checkTextboxLength, 10))
            {
                return;
            }

            //見た目
            chk.clear();
            chk.addControl(t_mitame);
            if (chk.check("W00001", chk.checkTextboxLength, 20))
            {
                return;
            }

            //摘要・イメージファイル
            chk.clear();
            chk.addControl(t_tekiyou);
            chk.addControl(t_image_file1);
            chk.addControl(t_image_file2);
            chk.addControl(t_image_file3);
            chk.addControl(t_image_file4);
            if (chk.check("W00001", chk.checkTextboxLength, 255))
            {
                return;
            }

            //イメージファイル
            //正規表現
            chk.clear();
            chk.addControl(t_image_file1);
            chk.addControl(t_image_file2);
            chk.addControl(t_image_file3);
            chk.addControl(t_image_file4);
            if (chk.check("W00003", chk.checkTextboxFormat, @"^[a-zA-Z0-9.]+$", @"英数字"))
            {
                return;
            }

            //貸出店舗・お客様表示用
            chk.clear();
            chk.addControl(t_kashidashi_tenpo);
            chk.addControl(t_customer_display);
            if (chk.check("W00001", chk.checkTextboxLength, 30))
            {
                return;
            }

            //正規表現
            //価格
            chk.clear();
            chk.addControl(t_price1);
            chk.addControl(t_price2);
            chk.addControl(t_price3);
            if (chk.check("W00003", chk.checkTextboxFormat, @"^\d{1,10}\z", @"0~9999999999"))
            {
                return;
            }

            //正規表現
            //年齢
            chk.clear();
            chk.addControl(t_age);
            if (chk.check("W00003", chk.checkTextboxFormat, @"^\d{1,3}?\z", @"0~999"))
            {
                return;
            }


            //正規表現
            //使用回数初期値
            chk.clear();
            chk.addControl(t_initial_use_count);
            if (chk.check("W00003", chk.checkTextboxFormat, @"^\d{1,4}?\z", @"0~9999"))
            {
                return;
            }


            var textBoxTextList = new[] { t_image_file1, t_image_file2, t_image_file3, t_image_file4 };

            //画像ファイルの重複
            chk.clear();
            chk.addControl(t_image_file1);
            chk.addControl(t_image_file2);
            chk.addControl(t_image_file3);
            chk.addControl(t_image_file4);
            if (chk.UniquCheck("I15002", chk.checkTextUniqueFormat, null))
            {
                return;
            }


            //画像をフォルダにコピー
            for (int i = 0; i < 4; i++)
            {
                string path        = imagePath[i];
                string textBoxText = textBoxTextList[i].Text;
                if (path == "")
                {
                    continue;
                }


                var storeName = d_tenpo.SelectedItem.ToString();
                var cosId     = t_costume_code.Text;
                var copyPath  = System.IO.Path.Combine(Costume_Image_Path, storeName, cosId);
                var copyPath2 = System.IO.Path.Combine(Costume_Image_Path, storeName, cosId, textBoxText);

                //画像の破損チェック
                try
                {
                    System.Drawing.Image.FromFile(path);
                }
                catch
                {
                    chk.clear();
                    chk.check("I15003", chk.checkTextboxFile, null);
                    Utile.Message.showMessageOK("I15003");
                    return;
                }

                if (!System.IO.Directory.Exists(copyPath))
                {
                    ;
                }
                {
                    Directory.CreateDirectory(copyPath);
                }

                if (!System.IO.File.Exists(copyPath2) && textBoxText != "")
                {
                    System.IO.File.Copy(path, copyPath2, true);
                }
            }


            DB.m_costume cos = new m_costume();
            if (totalPage == currentPage - 1)
            {
                //新規登録
                cos.store_code        = DB.m_store.getSingleName(d_tenpo.SelectedItem.ToString()).store_code;
                cos.costume_code      = t_costume_code.Text;
                cos.costume_name      = t_costume.Text;
                cos.size              = t_size.Text;
                cos.sex               = d_seibetsu.SelectedIndex.ToString();
                cos.brand_name        = t_brand.Text;
                cos.rank              = t_rank.Text;
                cos.usability         = d_siyoukahi.SelectedIndex.ToString();
                cos.price1            = int.Parse(t_price1.Text);
                cos.price2            = int.Parse(t_price2.Text);
                cos.price3            = int.Parse(t_price3.Text);
                cos.color             = t_color.Text;
                cos.target_age        = int.Parse(t_age.Text);
                cos.remarks           = t_tekiyou.Text;
                cos.image1            = t_image_file1.Text;
                cos.image2            = t_image_file2.Text;
                cos.image3            = t_image_file3.Text;
                cos.image4            = t_image_file4.Text;
                cos.Class             = t_bunrui.Text;
                cos.appearance        = t_mitame.Text;
                cos.handle            = t_gara.Text;
                d_status.DataSource   = Enum.GetValues(typeof(Utile.Data.衣装ステータス));
                cos.status            = d_status.SelectedIndex.ToString();
                cos.rental_store      = t_kashidashi_tenpo.Text;
                cos.customer_display  = t_customer_display.Text;
                cos.initial_use_count = int.Parse(t_initial_use_count.Text);  
            }
            else
            {
                //更新
                cos = costumeDBList[currentPage - 1];
                cos.costume_name      = t_costume.Text;
                cos.size              = t_size.Text;
                cos.sex               = d_seibetsu.SelectedIndex.ToString();
                cos.brand_name        = t_brand.Text;
                cos.rank              = t_rank.Text;
                cos.usability         = d_siyoukahi.SelectedIndex.ToString();
                cos.price1            = int.Parse(t_price1.Text);
                cos.price2            = int.Parse(t_price2.Text);
                cos.price3            = int.Parse(t_price3.Text);
                cos.color             = t_color.Text;
                cos.target_age        = int.Parse(t_age.Text);
                cos.remarks           = t_tekiyou.Text;
                cos.image1            = t_image_file1.Text;
                cos.image2            = t_image_file2.Text;
                cos.image3            = t_image_file3.Text;
                cos.image4            = t_image_file4.Text;
                cos.Class             = t_bunrui.Text;
                cos.appearance        = t_mitame.Text;
                cos.handle            = t_gara.Text;
                d_status.DataSource   = Enum.GetValues(typeof(Utile.Data.衣装ステータス));
                cos.status            = d_status.SelectedIndex.ToString();
                cos.rental_store      = t_kashidashi_tenpo.Text;
                cos.customer_display  = t_customer_display.Text;
                cos.initial_use_count = int.Parse(t_initial_use_count.Text);
            }

            cos.Command();

            this.PageRefresh();
            MainForm.backPage(this);
        }