package realcix20.classes;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import realcix20.classes.basic.BaseClass;
import realcix20.classes.basic.ClassManager;
import realcix20.classes.basic.Row;
import realcix20.guis.utils.DialogManager;
import realcix20.guis.utils.TxtManager;
import realcix20.guis.views.MainView;
import realcix20.utils.DAO;
import realcix20.utils.ObjectUtil;
import realcix20.utils.Resources;
public class TaxDepClass extends BaseClass {
public static void createTaxDepPartner(Row taxDepRow) {
String ns = "TAX";
String co = ObjectUtil.findNewCell(taxDepRow, "TAXDEP", "CO").getColumnValue().toString();
String taxDep = ObjectUtil.findNewCell(taxDepRow, "TAXDEP", "TAXDEP").getColumnValue().toString();
String p = co + "." + taxDep;
DAO dao = DAO.getInstance();
dao.update(Resources.INSERT_P_SQL);
dao.setString(1, ns);
dao.setString(2, p);
dao.setObject(3, null);
dao.setObject(4, null);
dao.setObject(5, null);
dao.setObject(6, null);
dao.setString(7, co);
dao.executeUpdate();
String defpa = "1";
String ownername = p;
String apLD = UserClass.getDEFLD("AP");
String txt256 = TxtManager.getTxt("VIEW.OBJECTEDIT.RUSER.DEFAULTACCOUNT");
PrivateKey prikey = null;
PublicKey pubkey = null;
try {
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
keyGen.initialize(1024);
KeyPair key = keyGen.generateKeyPair();
prikey = key.getPrivate();
pubkey = key.getPublic();
} catch (Exception e) {
e.printStackTrace();
}
boolean block = false;
dao.update(Resources.INSERT_PA_SQL);
dao.setObject(1, ns);
dao.setObject(2, p);
dao.setObject(3, defpa);
dao.setObject(4, ownername);
dao.setObject(5, null);
dao.setObject(6, apLD);
dao.setObject(7, txt256);
dao.setObject(8, prikey);
dao.setObject(9, pubkey);
dao.setObject(10, block);
dao.executeUpdate();
}
public static void deleteDependThings(Row taxDepRow) {
String co = ObjectUtil.findNewCell(taxDepRow, "TAXDEP", "CO").getColumnValue().toString();
String taxDep = ObjectUtil.findNewCell(taxDepRow, "TAXDEP", "TAXDEP").getColumnValue().toString();
String p = co + "." + taxDep;
PartnerClass partner = (PartnerClass)ClassManager.createClass(250);
StringBuffer sb = new StringBuffer("DELETE FROM " + partner.getMainTableName() + " WHERE NS='TAX' AND P=?");
String sql = sb.toString();
DAO dao = DAO.getInstance();
dao.setAutoCommit(false);
dao.update(sql);
dao.setObject(1, p);
dao.executeUpdate();
sb = new StringBuffer("DELETE FROM " + partner.getChildTableName() + " WHERE NS='TAX' AND P=?");
sql = sb.toString();
dao.update(sql);
dao.setObject(1, p);
dao.executeUpdate();
dao.commit();
dao.setAutoCommit(true);
}
public static boolean validateDelete(Row taxDepRow, MainView container) {
boolean result = true;
if (TaxTypeClass.isTaxDepUsedInTaxType(taxDepRow)) {
result = false;
DialogManager.showMessageDialog(container, TxtManager.getTxt("INFORMATION.CANNTDELETETAXDEPUSEDITAXT"));
}
if (result) {
int n = DialogManager.showYesNoDialog(container, TxtManager.getTxt("INFORMATION.DELETERELATIVEPWITHTAXDEP"));
result = (n == 0);
}
return result;
}
public TaxDepClass(int clsId) {
super(clsId);
}
}