purchaseaddframe.java 11.0 KB
Newer Older
高电平's avatar
高电平 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
package supermarket.GUI;

import supermarket.commodify.*;
import supermarket.purchase.*;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class purchaseaddframe {
    JFrame purchaseadd = new JFrame("进货管理");
    JLabel cid = new JLabel("商品编号");
    JLabel num = new JLabel("进货数量");
    JLabel date = new JLabel("进货日期");

    JTextField cid_tx = new JTextField();
    JTextField num_tx = new JTextField();

    JComboBox year = new JComboBox();
    JComboBox month = new JComboBox();
    JComboBox day = new JComboBox();

    JButton sure = new JButton("确认");
    JButton cancel = new JButton("取消");
    public void Add() {
        cid.setFont(new Font("微软雅黑",Font.PLAIN,15));
        cid.setBounds(41,60,60,30);
        cid_tx.setBounds(111,60,240,30);
        num.setFont(new Font("微软雅黑",Font.PLAIN,15));
        num.setBounds(41,100,60,30);
        num_tx.setBounds(111,100,240,30);
        date.setFont(new Font("微软雅黑",Font.PLAIN,15));
        date.setBounds(41,140,60,30);


        year.setBounds(111,140,100,30);
        for(int i=1990;i<2050;i++)
        {
            year.addItem(i+"年");
        }
        month.setBounds(211,140,70,30);
        for(int i=1;i<13;i++)
        {
            if(i<10)
            {
                month.addItem("0"+i+"月");
            }
            else
            {
                month.addItem(i+"月");
            }

        }
        year.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                day.removeAllItems();
                String y = (String) year.getSelectedItem();
                y = y.substring(0,4);
                int year = Integer.parseInt(y);
                if((year % 4==0 && year%100!=0) || year%400==0)
                {
                    month.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            day.removeAllItems();
                            String m = (String) month.getSelectedItem();
                            switch (m)
                            {
                                case "02月":
                                    for(int i=1;i<30;i++)
                                    {
                                        if(i<10)
                                        {
                                            day.addItem("0"+i+"日");
                                        }
                                        else
                                        {
                                            day.addItem(i+"日");
                                        }

                                    }
                                    break;
                                case "01月","03月","05月","07月","08月","10月","12月":
                                    for(int i=1;i<32;i++)
                                    {
                                        if(i<10)
                                        {
                                            day.addItem("0"+i+"日");
                                        }
                                        else
                                        {
                                            day.addItem(i+"日");
                                        }
                                    }
                                    break;
                                case "04月","06月","09月","11月":
                                    for(int i=1;i<31;i++)
                                    {
                                        if(i<10)
                                        {
                                            day.addItem("0"+i+"日");
                                        }
                                        else
                                        {
                                            day.addItem(i+"日");
                                        }
                                    }
                                    break;
                            }
                        }
                    });
                }
                else
                {
                    month.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            day.removeAllItems();
                            String m = (String) month.getSelectedItem();
                            switch (m)
                            {
                                case "02月":
                                    for(int i=1;i<29;i++)
                                    {
                                        if(i<10)
                                        {
                                            day.addItem("0"+i+"日");
                                        }
                                        else
                                        {
                                            day.addItem(i+"日");
                                        }
                                    }
                                    break;
                                case "01月","03月","05月","07月","08月","10月","12月":
                                    for(int i=1;i<32;i++)
                                    {
                                        if(i<10)
                                        {
                                            day.addItem("0"+i+"日");
                                        }
                                        else
                                        {
                                            day.addItem(i+"日");
                                        }
                                    }
                                    break;
                                case "04月","06月","09月","11月":
                                    for(int i=1;i<31;i++)
                                    {
                                        if(i<10)
                                        {
                                            day.addItem("0"+i+"日");
                                        }
                                        else
                                        {
                                            day.addItem(i+"日");
                                        }
                                    }
                                    break;
                            }
                        }
                    });
                }
            }
        });

        day.setBounds(281,140,70,30);

        sure.setBounds(111, 200, 75, 30);
        sure.addActionListener(new sureButton(cid_tx,num_tx,year,month,day));
        cancel.setBounds(274, 200, 75, 30);
        cancel.addActionListener(new cancelButton());

        purchaseadd.setBounds(744, 374, 429, 359);
        purchaseadd.setResizable(false);
        purchaseadd.setLayout(null);
        purchaseadd.setVisible(true);
        purchaseadd.add(cid);
        purchaseadd.add(num);
        purchaseadd.add(date);
        purchaseadd.add(cid_tx);
        purchaseadd.add(num_tx);
        purchaseadd.add(year);
        purchaseadd.add(month);
        purchaseadd.add(day);
        purchaseadd.add(sure);
        purchaseadd.add(cancel);

        purchaseadd.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    }
    private class sureButton implements ActionListener
    {
        private JTextField cid_tx = new JTextField();
        private JTextField num_tx = new JTextField();
        private JComboBox year = new JComboBox();
        private JComboBox month = new JComboBox();
        private JComboBox day = new JComboBox();

        public sureButton(JTextField cid_tx, JTextField num_tx, JComboBox year, JComboBox month, JComboBox day) {
            this.cid_tx = cid_tx;
            this.num_tx = num_tx;
            this.year = year;
            this.month = month;
            this.day = day;
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            JDialog comp = new JDialog();
            JButton sure = new JButton("确定");
            JLabel tip = new JLabel();
            JLabel tip2 = new JLabel();
            sure.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    comp.dispose();
                }
            });
            sure.setBounds(60, 80, 60, 20);
            tip.setFont(new Font("微软雅黑", Font.PLAIN, 15));
            tip.setBounds(50, 10, 100, 30);
            tip2.setFont(new Font("微软雅黑", Font.PLAIN, 15));
            tip2.setBounds(50, 40, 100, 30);
            comp.setLayout(null);
            comp.setResizable(false);
            comp.setBounds(859, 474, 200, 160);
            comp.add(tip);
            comp.add(tip2);
            comp.add(sure);
            String cid = cid_tx.getText();
            String num = num_tx.getText();
            String y = (String) year.getSelectedItem();
            String m = (String) month.getSelectedItem();
            String d = (String) day.getSelectedItem();
            String date = y + m + d;
            String id = y.substring(0,4) + m.substring(0,2) + d.substring(0,2);
            if(cid.equals("") || num.equals(""))
            {
                tip.setText("请输入正确");
                tip2.setText("的进货信息");
            }
            else
            {
                int CID = Integer.parseInt(cid);
                int NUM = Integer.parseInt(num);
                commodifyDAOImpl cd = new commodifyDAOImpl();
                if(cd.selectById(CID).isEmpty())
                {
                    tip.setText("请输入正确");
                    tip2.setText("的商品编号");
                }
                else
                {
                    purchaseDAOImpl pd = new purchaseDAOImpl();
                    purchase purchase = new purchase();
                    purchase.setCid(CID);
                    purchase.setNum(NUM);
                    purchase.setDate(date);
                    purchase.setId(id);
                    if(pd.Addpurchase(purchase))
                    {
                        int store = cd.selectNum(CID) + NUM;
                        cd.updateNum(store, CID);
                        tip.setText("进货订单");
                        tip2.setText("添加成功");
                    }
                    else
                    {
                        tip.setText("进货订单");
                        tip2.setText("添加失败");
                    }
                }
            }
            comp.setVisible(true);
        }
    }

    private class cancelButton implements ActionListener
    {
        @Override
        public void actionPerformed(ActionEvent e) {
            purchaseadd.dispose();

        }
    }
}