📄 customerw.java
字号:
out.println(barberstring+","+barber[i].isState());
}
out.close();
}
catch(IOException e0)
{
JOptionPane.showMessageDialog(null,"写数据错误!程序即将结束!");
System.exit(0);
}
}
public void writedata(String filename)
{
try
{
PrintWriter out = new PrintWriter(new FileWriter(filename));
out.println(customer_total_num + "," +customer_total_time+ "," +customer_total_queue+","+total_money+","+grade1_money+","+grade2_money+ ","+grade3_money+","+need_time);
out.close();
}
catch(IOException e0)
{
JOptionPane.showMessageDialog(null,"写数据错误!程序即将结束!");
System.exit(0);
}
}
public void writedata2(String filename)
{
try
{
PrintWriter out = new PrintWriter(new FileWriter(filename));
long thistime=Calendar.getInstance().getTimeInMillis();
long temp1,temp2;
temp1=temp2=0;
for(int wwww=0;wwww<200&&customer[wwww].getGrade()!=0;wwww++)
{
if(customer[wwww].isState())
{
if(customer[wwww].getGrade()==1)
temp1=service[customer[wwww].getService()].getService_1_time()*1000-(thistime-customer[wwww].getStart_time());
if(customer[wwww].getGrade()==2)
temp1=service[customer[wwww].getService()].getService_2_time()*1000-(thistime-customer[wwww].getStart_time());
if(customer[wwww].getGrade()==3)
temp1=service[customer[wwww].getService()].getService_3_time()*1000-(thistime-customer[wwww].getStart_time());
if(temp1>temp2)
temp2=temp1;
}
}
need_time=temp2/1000;
out.println(customer_total_num + "," +customer_total_time+ "," +customer_total_queue+","+total_money+","+grade1_money+","+grade2_money+ ","+grade3_money+","+need_time);
out.close();
}
catch(IOException e0)
{
JOptionPane.showMessageDialog(null,"写数据错误!程序即将结束!");
System.exit(0);
}
}
private class CustomerLeave implements ActionListener //这是顾客离开的类
{
private String customer_l_id="";
private long out_time;
private long stay_time=0; //逗留时间以秒计算
private long temp;
private int grade=0;
private String barber_id="";
public void actionPerformed(ActionEvent event)
{
leave();
writedata(datafile);
writedata_customer(customer,"customer.txt");
writedata_customer(customer_1,"customer1.txt");
writedata_customer(customer_2,"customer2.txt");
writedata_customer(customer_3,"customer3.txt");
writedata_barber("barber2.txt");
}
private void leave()
{
customer_l_id=jTextField.getText();
if(customer_l_id.equals(""))
{
JOptionPane.showMessageDialog(null,"请输入顾客的id");
return ;
}
out_time=Calendar.getInstance().getTimeInMillis();
int i;
for(i=0;i<200&&(!customer[i].getId().equals(customer_l_id));i++){}//找到该顾客
if(i==200)
{
JOptionPane.showMessageDialog(null,"该顾客不存在!");
return ;
}
else
{
grade=customer[i].getGrade();
temp=customer[i].getIn_time();
temp=out_time-temp;
stay_time=temp/1000;
customer_total_time+=stay_time;//算入总时间
//下面开始删除顾客
if(grade==1)
{
if(customer[i].isState())//如果顾客正在进行服务
{
barber_id=customer[i].getBarber_id();//对应的理发师
for(int bbbb=0;bbbb<50;bbbb++)
{
if(barber_id.equals(barber[bbbb].getId()))
{
barber[bbbb].setState(false);
// JOptionPane.showMessageDialog(null, barber[bbbb].isState());
break;
}
}
JOptionPane.showMessageDialog(null,"该顾客共花费"+service[customer[i].getService()].getService_1_money()+"元");
for(int j=i;j<199&&customer[j].getGrade()!=0;j++)//删除顾客
{
customer[j]=customer[j+1];
}
}
else
{
String sss=customer[i].getId();
for(int j=i;j<199&&customer[j].getGrade()!=0;j++)
{
customer[j]=customer[j+1];
}
for(int qqqq=0;qqqq<200;qqqq++)
{
if(customer_1[qqqq].getId().equals(sss))
{
for(int j=qqqq;j<199&&customer_1[j].getGrade()!=0;j++)//删除顾客
{
customer_1[j]=customer_1[j+1];
}
break;
}
}
JOptionPane.showMessageDialog(null,"该顾客还没有进行理发就走了");
return;
}
}
if(grade==2)
{
if(customer[i].isState())//如果顾客正在进行服务
{
barber_id=customer[i].getBarber_id();//对应的理发师
JOptionPane.showMessageDialog(null,"该顾客共花费"+service[customer[i].getService()].getService_2_money()+"元");
for(int bbbb=0;bbbb<50;bbbb++)
{
if(barber_id.equals(customer[i].getBarber_id()))
{
barber[bbbb].setState(false);
break;
}
}
for(int j=i;j<199&&customer[j].getGrade()!=0;j++)//删除顾客
{
customer[j]=customer[j+1];
}
}
else
{
String sss=customer[i].getId();
for(int j=i;j<199&&customer[j].getGrade()!=0;j++)
{
customer[j]=customer[j+1];
}
for(int qqqq=0;qqqq<200;qqqq++)
{
if(customer_2[qqqq].getId().equals(sss))
{
for(int j=qqqq;j<199&&customer_2[j].getGrade()!=0;j++)//删除顾客
{
customer_2[j]=customer_2[j+1];
}
break;
}
}
JOptionPane.showMessageDialog(null,"该顾客还没有进行理发就走了");
return;
}
}
if(grade==3)
{
barber_id=customer[i].getBarber_id();//对应的理发师
if(customer[i].isState())//如果顾客正在进行服务
{
barber_id=customer[i].getBarber_id();//对应的理发师
for(int bbbb=0;bbbb<50;bbbb++)
{
if(barber_id.equals(barber[bbbb].getId()))
{
barber[bbbb].setState(false);
break;
}
}
JOptionPane.showMessageDialog(null,"该顾客共花费"+service[customer[i].getService()].getService_3_money()+"元");
for(int j=i;j<199&&customer[j].getGrade()!=0;j++)//删除顾客
{
customer[j]=customer[j+1];
}
}
else
{
String sss=customer[i].getId();
for(int j=i;j<199&&customer[j].getGrade()!=0;j++)
{
customer[j]=customer[j+1];
}
for(int qqqq=0;qqqq<200;qqqq++)
{
if(customer_3[qqqq].getId().equals(sss))
{
for(int j=qqqq;j<199&&customer_3[j].getGrade()!=0;j++)//删除顾客
{
customer_3[j]=customer_3[j+1];
}
break;
}
}
JOptionPane.showMessageDialog(null,"该顾客还没有进行理发就走了");
return;
}
}
//顾客已经删除
//下面开始查找理发师是否适应其他在排队的顾客
if(grade==1)
{
int c;
for(c=0;c<50&&!barber[c].getId().equals(barber_id);c++){}
if(c==50)
{
JOptionPane.showMessageDialog(null,"该理发师不存在!");
return ;
}
int d;
//查找是否有顾客与该理发师对应
for(d=0;customer_1[d].getGrade()!=0&&barber[c].getService(customer_1[d].getService())==0&&d<200;d++){}
if(d<200&&customer_1[d].getGrade()!=0)
{
customer_1[d].setState(true);
int pppp;
for(pppp=0;pppp<200&&!customer[pppp].getId().equals(customer_1[d].getId());pppp++){}
if(customer[pppp].getId().equals(customer_1[d].getId()))
{
total_money+=service[customer[pppp].getService()].getService_1_money();
grade1_money+=service[customer[pppp].getService()].getService_1_money();
customer[pppp].setBarber_id(barber[c].getId());
customer[pppp].setStart_time(out_time);
customer[pppp].setState(true);
}
customer_1[d].setBarber_id(barber[c].getId());
barber[c].setState(true);
JOptionPane.showMessageDialog(null,"请"+customer_1[d].getId()+"顾客去"+barber[c].getName()+"理发师那里理发!");
customer_1[d].setStart_time(out_time);//设置顾客开始时间
do
{
customer_1[d]=customer_1[d+1];
d++;
}while(customer_1[d].getGrade()!=0&&d<199);
}
}
if(grade==2)
{
int c;
for(c=0;c<50&&!barber[c].getId().equals(barber_id);c++){}
if(c==50)
{
JOptionPane.showMessageDialog(null,"该理发师不存在!");
return ;
}
int d;
//查找是否有顾客与该理发师对应
for(d=0;customer_2[d].getGrade()!=0&&barber[c].getService(customer_2[d].getService())==0&&d<200;d++){}
if(d<200&&customer_2[d].getGrade()!=0)
{
int pppp;
for(pppp=0;pppp<200&&!customer[pppp].getId().equals(customer_2[d].getId());pppp++){}
if(customer[pppp].getId().equals(customer_1[d].getId()))
{
total_money+=service[customer[pppp].getService()].getService_2_money();
grade1_money+=service[customer[pppp].getService()].getService_2_money();
customer[pppp].setBarber_id(barber[c].getId());
customer[pppp].setStart_time(out_time);
customer[pppp].setState(true);
}
customer_2[d].setState(true);
customer_2[d].setBarber_id(barber[c].getId());
barber[c].setState(true);
JOptionPane.showMessageDialog(null,"请"+customer_2[d].getId()+"顾客去"+barber[c].getName()+"理发师那里理发!");
customer_2[d].setStart_time(out_time);//设置顾客开始时间
do
{
customer_2[d]=customer_2[d+1];
d++;
}while(customer_2[d].getGrade()!=0&&d<199);
}
}
if(grade==3)
{
int c;
for(c=0;c<50&&!barber[c].getId().equals(barber_id);c++){}
if(c==50)
{
JOptionPane.showMessageDialog(null,"该理发师不存在!");
return ;
}
int d;
//查找是否有顾客与该理发师对应
for(d=0;customer_3[d].getGrade()!=0&&barber[c].getService(customer_3[d].getService())==0&&d<200;d++){}
if(d<200&&customer_3[d].getGrade()!=0)
{
customer_3[d].setState(true);
customer_3[d].setBarber_id(barber[c].getId());
barber[c].setState(true);
int pppp;
for(pppp=0;pppp<200&&!customer[pppp].getId().equals(customer_3[d].getId());pppp++){}
if(customer[pppp].getId().equals(customer_1[d].getId()))
{
total_money+=service[customer[pppp].getService()].getService_3_money();
grade1_money+=service[customer[pppp].getService()].getService_3_money();
customer[pppp].setBarber_id(barber[c].getId());
customer[pppp].setStart_time(out_time);
customer[pppp].setState(true);
}
JOptionPane.showMessageDialog(null,"请"+customer_3[d].getId()+"顾客去"+barber[c].getName()+"理发师那里理发!");
customer_3[d].setStart_time(out_time);//设置顾客开始时间
do
{
customer_3[d]=customer_3[d+1];
d++;
}while(customer_3[d].getGrade()!=0&&d<199);
}
}
}
}
}
/**
* This method initializes jTextArea
*
* @return javax.swing.JTextArea
*/
private JTextArea getJTextArea() {
if (jTextArea == null) {
jTextArea = new JTextArea();
jTextArea.setBounds(new Rectangle(63, 53, 36, 126));
jTextArea.setText("顾\n客\n信\n息");
jTextArea.setFont(new Font("\u534e\u6587\u7425\u73c0", Font.BOLD, 24));
jTextArea.setForeground(new Color(204, 204, 0));
jTextArea.setEditable(false);
jTextArea.setBackground(new Color(0, 51, 51));
}
return jTextArea;
}
} // @jve:decl-index=0:visual-constraint="303,127"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -