Beispiel #1
0
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() instanceof JMenuItem) {
     JMenuItem item = (JMenuItem) e.getSource();
     String name = item.getText();
     Profile profile = profiles.getProfile(name);
     Component[] components = selectorPanel.getComponents();
     for (int i = 0; i < components.length; i++) {
       Component comp = components[i];
       if (comp instanceof CPCheckBox) {
         CPCheckBox scb = (CPCheckBox) comp;
         String id = scb.element.id;
         boolean enb = profile.has(id);
         scb.setState(enb);
       }
     }
   }
 }
Beispiel #2
0
  public static void checkCompany(String name) {
    Boolean result = true;
    Profile profile = Profile.find("name=?", name).first();
    if (profile != null) {
      result = false;
    }

    renderJSON(result);
  }
Beispiel #3
0
  public static void show() {
    String username = session.get("username");
    if (username != null) {
      User user = User.getByUserName(username);
      Profile profile = Profile.find("user.id=?", user.id).first();

      render(profile);
    }
  }
Beispiel #4
0
  public static void toubiao() {
    String username = session.get("username");
    if (username != null) {
      User user = User.getByUserName(username);
      Profile profile = Profile.find("user.id=?", user.id).first();

      String payStyle = params.get("payStyle");
      String invoice = params.get("invoice");
      String comments = params.get("comments");
      String requestS = params.get("request");

      Request request = Request.findById(Long.valueOf(requestS));
      Toubiao toubiao = null;
      toubiao = Toubiao.find("request.id=? and profile.id=?", request.id, profile.id).first();
      if (toubiao == null) {
        toubiao = new Toubiao();
      }
      toubiao.profile = profile;
      toubiao.user = user;
      toubiao.request = request;
      toubiao.payStyle = payStyle;
      toubiao.invoice = invoice;
      toubiao.comments = comments;
      toubiao.again = false;
      toubiao.save();

      String price = "0";
      String price2 = "0";
      String price3 = "0";
      Baojia baojia = null;
      for (Specification spec : request.specifications) {
        price = params.get("price" + spec.id);
        price2 = params.get("price" + spec.id + "-2");
        price3 = params.get("price" + spec.id + "-3");
        baojia = Baojia.find("toubiao.id=? and specification.id=?", toubiao.id, spec.id).first();
        if (baojia == null) {
          baojia = new Baojia();
          baojia.toubiao = toubiao;
          baojia.specification = spec;
        }
        if (price != null && !"".equals(price) && !"0".equals(price))
          baojia.price = Double.valueOf(price);
        if (price2 != null && !"".equals(price2) && !"0".equals(price2))
          baojia.secondPrice = Double.valueOf(price2);
        if (price3 != null && !"".equals(price3) && !"0".equals(price3))
          baojia.thirdPrice = Double.valueOf(price3);
        baojia.save();

        if (!toubiao.baojias.contains(baojia)) {

          toubiao.baojias.add(baojia);
          toubiao.save();
        }
      }
    }
    redirect("/");
  }
Beispiel #5
0
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() instanceof JMenuItem) {
     JMenuItem item = (JMenuItem) e.getSource();
     String name = item.getText();
     if (name.equals("New...")) {
       name = JOptionPane.showInputDialog(selectorPanel, "Enter a name for the new profile.");
     }
     if ((name == null) || name.trim().equals("")) return;
     Profile profile = new Profile(name);
     Component[] components = selectorPanel.getComponents();
     for (int i = 0; i < components.length; i++) {
       Component comp = components[i];
       if (comp instanceof CPCheckBox) {
         CPCheckBox scb = (CPCheckBox) comp;
         String id = scb.element.id;
         if (scb.isSelected()) profile.add(id);
       }
     }
     profiles.add(profile);
   }
 }
  public static void main(String args[]) {
    ProfileInspector profileInspector = new ProfileInspector();
    Profile resultingProfile = null;

    if (args.length < 1 || args[0].indexOf("help") >= 0) {
      usage();
      System.exit(0);
    } else {
      try {
        ArgumentProcessor.processArgs(args, ARG_DEFS, profileInspector);
        resultingProfile = profileInspector.processProfile();
      } catch (ArgumentErrorException e) {
        System.err.println("Error processing command-line arguments: " + e.getMessage());
        usage();
        System.exit(255);
      } catch (Exception e) {
        System.err.println("Error proccessing:");
        e.printStackTrace();
        System.exit(1);
      }

      System.out.println(resultingProfile.getHumanOutput());
    }
  }
  public String getHumanOutput() {
    String results = "";
    Set<String> leftOverCategoryNames = this.environment.getCategories().keySet();

    for (ProfileFile[] round : this.files) {
      for (ProfileFile file : round) {
        String fileName = file.getFileName();
        results += "###### " + fileName + "\n";
        if (file.getType() == ProfileFile.TYPE_2D) {
          Vector<String> values = this.environment.getVars(fileName, "list");
          results += Profile.array2DToString(values, "", "\n", "\n") + "\n";
          leftOverCategoryNames.remove(fileName);
        } else if (file.getType() == ProfileFile.TYPE_3D) {
          HashMap<String, Vector<String>> category = this.environment.getCategoryKeys(fileName);
          results += Profile.array3DToString(category, " ", " ", "") + "\n";
          leftOverCategoryNames.remove(fileName);
        } else if (file.getType() == ProfileFile.TYPE_KEYVAL_BASH) {
          HashMap<String, Vector<String>> category = this.environment.getCategoryKeys(fileName);
          results += Profile.array3DToString(category, "=\"", " ", "\"") + "\n";
          leftOverCategoryNames.remove(fileName);
        }
      }
    }

    if (verbose) {
      // Warn about unhandled data
      for (String categoryName : leftOverCategoryNames) {
        HashMap<String, Vector<String>> keys = this.environment.getCategoryKeys(categoryName);
        Set<String> keyNames = keys.keySet();
        for (String keyName : keyNames) {
          System.err.println("Warning: unhandled data: " + keyName);
        }
      }
    }
    return results;
  }
Beispiel #8
0
  public static void forget() throws Throwable {

    String username = params.get("username");
    String mobile = params.get("mobile");

    Profile p = Profile.find("user.username=? and contact_phone=?", username, mobile).first();
    if (p == null) {
      flash.error("用户名和手机不匹配,请确认您输入的信息");
      flash.put("username", username);
      toForget();
    } else {
      // SendSMS
      SendMessage m = new SendMessage();
      m.sendSms(p.contact_phone, "您的密码为:" + p.user.password, "0000009");
      flash.success("您的密码已发送您的手机,请查收");
      flash.put("username", username);
      Secure.login();
    }
  }
Beispiel #9
0
  public static void imp(File file) {
    String result = "";
    String profiles = "";
    int imported = 0;
    int missed = 0;

    if (file != null) {

      Config config = Config.find("1=1").first();

      FileInputStream fileInputStream = null;
      HSSFWorkbook workbook = null;
      try {
        fileInputStream = new FileInputStream(file);
        workbook = new HSSFWorkbook(fileInputStream);
      } catch (FileNotFoundException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }

      Profile profile = null;
      User user = null;
      String value = "";
      Material material = null;

      SendMessage m = new SendMessage();
      for (int x = 0; x < workbook.getNumberOfSheets(); x++) {

        HSSFSheet worksheet = workbook.getSheetAt(x);
        HSSFRow row = null;
        HSSFCell cell = null;
        DecimalFormat df = new DecimalFormat("#");
        df.setMaximumFractionDigits(0);

        for (int i = 1; i < worksheet.getLastRowNum(); i++) {
          String unit = "万元";
          String business = "0";
          try {
            row = worksheet.getRow(i);
            if (row.getLastCellNum() < 22) {
              continue;
            }
            cell = row.getCell(0);
            value = cell.getStringCellValue();
            user = User.find("username=?", value).first();
            if (user == null) {
              user = new User(value, getRandomPwd(), ApplicationRole.getByName("user"));
              user.save();
            }

            profile = Profile.find("user.id=?", user.id).first();
            if (profile == null) {
              profile = new Profile();
              profile.user = user;
            }

            profile.is_audit = 1;
            cell = row.getCell(1);
            value = cell.getStringCellValue();
            profile.name = value;

            cell = row.getCell(2);
            value = cell.getStringCellValue();
            material = Material.find("name=?", value).first();
            if (material == null) {
              material = new Material();
              material.name = value;
              material.save();
            }
            if (!profile.materials.contains(material)) profile.materials.add(material);

            cell = row.getCell(3);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }

            cell = row.getCell(4);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }

            cell = row.getCell(5);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            profile.registration_number = value;

            cell = row.getCell(6);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              df.setMaximumFractionDigits(2);
              value = String.valueOf(df.format(cell.getNumericCellValue()));
            } else {
              value = cell.getStringCellValue();
            }
            if (value.contains("美元")) {
              value = value.replace("(美元)", "").trim();
              unit = "万美元";
            }
            profile.registration_assets = value;
            profile.registration_assets_unit = unit;

            df.setMaximumFractionDigits(0);
            cell = row.getCell(7);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            profile.registration_address = value;

            cell = row.getCell(8);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            profile.bank_name = value;

            cell = row.getCell(9);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            profile.account_name = value;

            cell = row.getCell(10);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            profile.tfn = value;

            cell = row.getCell(11);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            profile.factory_name = value;

            cell = row.getCell(12);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            profile.factory_address = value;

            cell = row.getCell(13);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(df.format(cell.getNumericCellValue()));
            } else {
              value = cell.getStringCellValue();
            }
            profile.first_supply = value.replaceAll("年", "");

            cell = row.getCell(14);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            profile.legal_person = value;

            cell = row.getCell(15);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            profile.contact_name = value;

            cell = row.getCell(16);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            profile.contact_job = value;

            cell = row.getCell(17);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(df.format(cell.getNumericCellValue()));
            } else {
              value = cell.getStringCellValue();
            }
            profile.contact_phone = value;

            cell = row.getCell(18);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            profile.sales_name = value;

            cell = row.getCell(19);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            profile.sales_job = value;

            cell = row.getCell(20);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(df.format(cell.getNumericCellValue()));
            } else {
              value = cell.getStringCellValue();
            }
            profile.sales_phone = value;

            cell = row.getCell(21);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            if (value.equals("自营")) {
              business = "1";
            } else if (value.equals("经销")) {
              business = "2";
            } else if (value.equals("挂靠")) {
              business = "3";
            } else {
              business = "0";
            }
            profile.business_model = business;
            profile.save();
            imported += 1;

            if (profile.contact_phone != null) {
              String message =
                  "您的信息已导入,用户名:" + user.username + ",密码:" + user.password + ",请登录比价平台上传资质文件";
              if (config.msg_import != null && !"".equals(config.msg_import)) {
                message =
                    config
                        .msg_import
                        .replace("{username}", user.username)
                        .replace("{passowrd}", user.password);
              }
              m.sendSms(profile.contact_phone, message, "0000001");
              if (profile.contact_email != null && !"".equals(profile.contact_phone)) {
                m.sendMail(
                    profile.contact_email,
                    "[" + Messages.get("application.name") + "]信息导入",
                    message);
              }
            }
          } catch (Exception e) {
            missed += 1;
            if (!"".equals(profiles)) {
              profiles += "," + profile.name;
            } else {
              profiles += profile.name;
            }
            e.printStackTrace();
          }
        }
      }

      result = "成功导入" + imported + "条记录,丢失" + missed + "条记录。";
      if (!"".equals(profiles)) {
        result += "丢失导入的供应商为:" + profiles;
      }
    }
    redirect("/admin/profiles?result=" + URLEncoder.encode(result));
  }
Beispiel #10
0
  public static void save() throws Throwable {
    String username = params.get("username");
    String name = params.get("name");
    String password = params.get("password");
    String[] materials = params.getAll("material");
    String registration_number = params.get("registration_number");
    String registration_assets = params.get("registration_assets");
    String registration_assets_unit = params.get("registration_assets_unit");
    String registration_address = params.get("registration_address");
    String bank_name = params.get("bank_name");
    String account_name = params.get("account_name");
    String tfn = params.get("tfn");
    String legal_person = params.get("legal_person");
    String factory_name = params.get("factory_name");
    String factory_address = params.get("factory_address");
    String first_supply = params.get("first_supply");
    String business_model = params.get("business_model");
    String contact_name = params.get("contact_name");
    String contact_job = params.get("contact_job");
    String contact_phone = params.get("contact_phone");
    String contact_email = params.get("contact_email");
    String sales_name = params.get("sales_name");
    String sales_job = params.get("sales_job");
    String sales_phone = params.get("sales_phone");
    String[] files = params.getAll("files");

    User user = null;
    Material m = null;
    Files file = null;
    if (username != null && password != null && !"".equals(username) && !"".equals(password)) {
      user = User.find("username=?", username).first();
      if (user == null) {
        user = new User(username, password, ApplicationRole.getByName("user"));
        user.save();
      }

      Profile profile = Profile.find("user.id=?", user.id).first();
      if (profile == null) {
        profile = new Profile();
        profile.user = user;
      }

      if (materials != null) {
        for (String material_id : materials) {
          m = Material.find("id=?", Long.valueOf(material_id.trim())).first();
          if (m != null) profile.materials.add(m);
        }
      }
      profile.name = name;
      profile.registration_number = registration_number;
      profile.registration_assets = registration_assets;
      profile.registration_address = registration_address;
      profile.registration_assets_unit = registration_assets_unit;
      profile.bank_name = bank_name;
      profile.account_name = account_name;
      profile.tfn = tfn;
      profile.legal_person = legal_person;
      profile.factory_name = factory_name;
      profile.factory_address = factory_address;
      profile.first_supply = first_supply;
      profile.business_model = business_model;
      profile.contact_name = contact_name;
      profile.contact_job = contact_job;
      profile.contact_phone = contact_phone;
      profile.contact_email = contact_email;
      profile.sales_name = sales_name;
      profile.sales_job = sales_job;
      profile.sales_phone = sales_phone;

      if (files != null) {
        for (String f : files) {
          file = Files.find("id=?", Long.valueOf(f)).first();
          if (file != null) {
            profile.files.add(file);
          }
        }
      }

      profile.save();
    }

    session.put("username", username);

    Secure.redirectToOriginalURL();
  }
Beispiel #11
0
  public static void main(String[] args) {
    ExtendedProperties pp = parseArguments(args);
    Properties jadeProps = pp.extractSubset("jade.");
    System.out.println("JADE PROPERTIES: " + jadeProps);

    int contentSize = DEFAULT_CONTENT_SIZE;
    try {
      contentSize = Integer.parseInt(pp.getProperty(CONTENT_SIZE));
    } catch (Exception e) {
      // Keep default
    }
    content = new byte[contentSize];

    timeInterval = DEFAULT_TIME_INTERVAL;
    try {
      timeInterval = Long.parseLong(pp.getProperty(TIME_INTERVAL));
    } catch (Exception e) {
      // Keep default
    }

    nIterations = DEFAULT_N_ITERATIONS;
    try {
      nIterations = Integer.parseInt(pp.getProperty(N_ITERATIONS));
    } catch (Exception e) {
      // Keep default
    }

    nCouples = DEFAULT_N_COUPLES;
    try {
      nCouples = Integer.parseInt(pp.getProperty(N_COUPLES));
    } catch (Exception e) {
      // Keep default
    }

    base = DEFAULT_BASE;
    try {
      base = Integer.parseInt(pp.getProperty(BASE));
    } catch (Exception e) {
      // Keep default
    }

    mode = READY_GO_MODE;
    try {
      String modeStr = pp.getProperty(MODE);
      if (SLOW_MODE_S.equals(modeStr)) {
        mode = SLOW_MODE;
      } else if (FAST_MODE_S.equals(modeStr)) {
        mode = FAST_MODE;
      } else if (STEP_BY_STEP_MODE_S.equals(modeStr)) {
        mode = STEP_BY_STEP_MODE;
      }
    } catch (Exception e) {
      // Keep default
    }
    // Prepare the inputReader to get user inputs if necessary
    if (mode == READY_GO_MODE || mode == STEP_BY_STEP_MODE) {
      inputReader = new BufferedReader(new InputStreamReader(System.in));
    }

    randomStart = "true".equals(pp.getProperty(RANDOM_START_S, "false"));

    measure = BITRATE_MEASURE;
    try {
      String measureStr = pp.getProperty(MEASURE);
      if (RTT_MEASURE_S.equals(measureStr)) {
        measure = RTT_MEASURE;
      }
    } catch (Exception e) {
      // Keep default
    }

    String prefix = Profile.getDefaultNetworkName();
    for (int i = base; i < base + nCouples; i++) {
      initCouple(jadeProps, prefix, i);
      switch (mode) {
        case SLOW_MODE:
          waitABit();
          break;
        case STEP_BY_STEP_MODE:
          prompt("Couple #" + i + " started. Press enter to continue");
          break;
        default:
          Thread.currentThread().yield();
      }
    }

    waitUntilReady();
    if (mode == READY_GO_MODE) {
      prompt("All " + nCouples + " couples ready. Press enter to go");
    }
    start();
    if (nIterations > 0) {
      System.out.println("Measurement started....");
    }

    if (timeInterval == STEPBYSTEP_TIME_INTERVAL) {
      int i = 0;
      while (true) {
        waitUntilReady();
        prompt("Iteration # " + i + " terminated by all couples. Press enter to go");
        ++i;
        start();
      }
    }
  }