Beispiel #1
0
    def saveDataSet(self, dataSet):
        try:
            wx.SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
            self.parentView.setStatusState(2)

            dataSetPy = []
            dataSetPy.append({
                "tableName": "ui_userconfig",
                "updateType": "delete",
                "recordSet": dataSet["_userconfig"]
            })
            dataSetPy.append({
                "tableName": "ui_userconfig",
                "updateType": "update",
                "recordSet": dataSet["userconfig"]
            })

            conn = npiAdapter(self.parentView.application.app_settings["url"] +
                              "/" + self.parentView.application.
                              app_config["connection"]["npi_service"])
            response = conn.saveDataSet(self.parentView.getCredentials(),
                                        dataSetPy)
            if response == "error":
                return
            else:
                dataSet["_userconfig"] = []
                dataSet["changeData"] = False
                self.loadDataset(dataSet)

        except Exception, err:
            wx.MessageBox(str(err), "saveDataSet", wx.OK | wx.ICON_ERROR)
Beispiel #2
0
 def reloadData(self, dataSet):
   dataSetInfo = []
   dataSetInfo.append({"infoName":"groups", "infoType":"table", "classAlias":"models.groups", 
                       "filterStr":"deleted=0 and groupname in ('customer', 'nervatype', 'fieldtype', 'logstate', 'custtype')", 
                       "orderStr":"groupname, groupvalue"})
   paramList = []
   paramList.append({"name":"@customer_id", "value":dataSet["customer"][0].id, "wheretype":"in", "type":"integer"})
   sqlStr = self.parentView.getSql("fCustomer_getCalendarView")
   dataSetInfo.append({"infoName":"calendar_view", "infoType":"view", "sqlKey":None,
                         "sqlStr":sqlStr, "whereStr":"", "havingStr":"", "paramList":paramList})
   
   conn = npiAdapter(self.parentView.application.app_settings["url"]+"/"+
     self.parentView.application.app_config["connection"]["npi_service"])
   response = conn.loadDataSet(self.parentView.getCredentials(), dataSetInfo)
   if response=="error":
     return
   else:
     resultSet = response
     
   if resultSet.__class__.__name__!="list": 
     wx.MessageBox(str(resultSet), "loadDataset", wx.OK | wx.ICON_ERROR)
     return
   for recordSetInfo in resultSet:
     if recordSetInfo["infoName"]=="groups":
       dataSet["groups"] = self.parentView.dic2objList(recordSetInfo["recordSet"],recordSetInfo["infoName"])
       continue
     elif recordSetInfo["infoName"]=="calendar_view":
       dataSet["calendar_view"] = self.parentView.dic2objList(recordSetInfo["recordSet"],recordSetInfo["infoName"])
       continue
Beispiel #3
0
 def callLogin(self):
     try:
         conn = npiAdapter(
             self.application.app_settings["url"] + "/" +
             self.application.app_config["connection"]["npi_service"])
         login = conn.getLogin(self.application.app_settings["database"],
                               self.application.app_settings["username"],
                               self.application.app_settings["password"])
         if login == "error":
             return
         elif login["valid"] == True:
             self.user_config["locale"] = self.application.app_settings[
                 "locale"]
             self.user_config["url"] = self.application.app_settings["url"]
             self.user_config["database"] = self.application.app_settings[
                 "database"]
             self.user_config["username"] = self.application.app_settings[
                 "username"]
             self.user_config.write()
             self.application.app_settings["employee_id"] = login[
                 "employee"]["id"]
             self.application.app_settings["engine"] = login["engine"]
             self.login_ok = True
             self.Close()
         else:
             wx.MessageBox(
                 str(login["message"]),
                 str(self.application.app_config["application"]["name"]),
                 wx.OK | wx.ICON_ERROR)
     except Exception, err:
         wx.MessageBox(str(err), "callLogin", wx.OK | wx.ICON_ERROR)
Beispiel #4
0
 def deleteDataSet(self, dataSet, parent):
   delOK = False
   try:
     wx.SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
     self.parentView.setStatusState(2)
     conn = npiAdapter(self.parentView.application.app_settings["url"]+"/"+
       self.parentView.application.app_config["connection"]["npi_service"])
     
     paramList = []
     paramList.append({"name":"@customer_id", "value":dataSet["customer"][0].id, "wheretype":"in", "type":"integer"})
     sqlStr = self.parentView.getSql("fCustomer_getDeleteState")
     response = conn.loadView(self.parentView.getCredentials(), None, sqlStr, "", "", paramList)
     if response=="error":
       return
     elif response[0]["sco"]>0:
       wx.MessageBox(parent.getLocale("alert_delete_err"), parent.getLocale("alert_warning_lb"), wx.OK | wx.ICON_ERROR)
       return
     paramList = []
     paramList.append({"name":"@customer_id", "value":dataSet["customer"][0].id, "wheretype":"in", "type":"integer"})
     if dataSet["deletedFlag"]==True:
       sqlStr = self.parentView.getSql("fCustomer_getDeleteSql_delete")
     else:
       sqlStr = self.parentView.getSql("fCustomer_getDeleteSql_update")
     response = conn.executeSql(self.parentView.getCredentials(), None, sqlStr, paramList)
     if response=="error":
       delOK = False
     else:
       delOK = True    
   except Exception, err:
     wx.MessageBox(str(err), "deleteDataSet", wx.OK | wx.ICON_ERROR)
Beispiel #5
0
    def loadDataset(self, dataSet):

        conn = sqlite3.connect('storage.db')  # @UndefinedVariable
        conn.row_factory = sqlite3.Row  # @UndefinedVariable

        cur = conn.cursor()
        sqlStr = self.parentView.getSql("fBrowser_getApplViews")
        for row in cur.execute(sqlStr, (dataSet["mainView"], )):
            item = {}
            fields = row.keys()
            for index in range(len(fields)):
                item[fields[index]] = row[index]
            dataSet["applviews"].append(dict2obj(item))

        sqlStr = self.parentView.getSql("fBrowser_getViewFields")
        for row in cur.execute(sqlStr, (dataSet["mainView"], )):
            item = {}
            fields = row.keys()
            for index in range(len(fields)):
                item[fields[index]] = row[index]
            dataSet["viewfields"].append(dict2obj(item))

        dataSet["userconfig"] = []
        conn.close()

        dataSetInfo = [{
            "infoName":
            "userconfig",
            "infoType":
            "table",
            "classAlias":
            "ui_userconfig",
            "filterStr":
            "employee_id=" +
            str(self.parentView.application.app_settings["employee_id"]) +
            " and (cfgroup='browserConfig' or section='" +
            dataSet["mainView"] + "') ",
            "orderStr":
            None
        }]

        conn = npiAdapter(self.parentView.application.app_settings["url"] +
                          "/" +
                          self.parentView.application.app_config["connection"]
                          ["npi_service"])
        response = conn.loadDataSet(self.parentView.getCredentials(),
                                    dataSetInfo)
        if response == "error":
            return
        else:
            for recordSetInfo in response:
                for record in recordSetInfo["recordSet"]:
                    dataSet[recordSetInfo["infoName"]].append(
                        dict2obj(record, "ui_" + recordSetInfo["infoName"]))

        dataSet["changeData"] = False
Beispiel #6
0
    def reloadData(self, dataSet):
        dataSetInfo = []
        dataSetInfo.append({
            "infoName": "groups",
            "infoType": "table",
            "classAlias": "models.groups",
            "filterStr":
            "deleted=0 and groupname in ('customer', 'nervatype', 'fieldtype', 'logstate', 'custtype')",
            "orderStr": "groupname, groupvalue"
        })
        paramList = []
        paramList.append({
            "name": "@customer_id",
            "value": dataSet["customer"][0].id,
            "wheretype": "in",
            "type": "integer"
        })
        sqlStr = self.parentView.getSql("fCustomer_getCalendarView")
        dataSetInfo.append({
            "infoName": "calendar_view",
            "infoType": "view",
            "sqlKey": None,
            "sqlStr": sqlStr,
            "whereStr": "",
            "havingStr": "",
            "paramList": paramList
        })

        conn = npiAdapter(self.parentView.application.app_settings["url"] +
                          "/" +
                          self.parentView.application.app_config["connection"]
                          ["npi_service"])
        response = conn.loadDataSet(self.parentView.getCredentials(),
                                    dataSetInfo)
        if response == "error":
            return
        else:
            resultSet = response

        if resultSet.__class__.__name__ != "list":
            wx.MessageBox(str(resultSet), "loadDataset", wx.OK | wx.ICON_ERROR)
            return
        for recordSetInfo in resultSet:
            if recordSetInfo["infoName"] == "groups":
                dataSet["groups"] = self.parentView.dic2objList(
                    recordSetInfo["recordSet"], recordSetInfo["infoName"])
                continue
            elif recordSetInfo["infoName"] == "calendar_view":
                dataSet["calendar_view"] = self.parentView.dic2objList(
                    recordSetInfo["recordSet"], recordSetInfo["infoName"])
                continue
Beispiel #7
0
 def loadResult(self, dataSet, sqlstr, param):
   try:
     wx.SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
     self.parentView.setStatusState(1)
     
     conn = npiAdapter(self.parentView.application.app_settings["url"]+"/"+
       self.parentView.application.app_config["connection"]["npi_service"])
     response = conn.loadView(self.parentView.getCredentials(), None, sqlstr, param["WhereString"], 
       param["HavingString"], param["paramList"])
     if response=="error":
       return
     else:
       dataSet["result"] = response
       
   except Exception, err:
     wx.MessageBox(str(err), "loadResult", wx.OK | wx.ICON_ERROR)
Beispiel #8
0
    def deleteDataSet(self, dataSet, parent):
        delOK = False
        try:
            wx.SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
            self.parentView.setStatusState(2)
            conn = npiAdapter(self.parentView.application.app_settings["url"] +
                              "/" + self.parentView.application.
                              app_config["connection"]["npi_service"])

            paramList = []
            paramList.append({
                "name": "@customer_id",
                "value": dataSet["customer"][0].id,
                "wheretype": "in",
                "type": "integer"
            })
            sqlStr = self.parentView.getSql("fCustomer_getDeleteState")
            response = conn.loadView(self.parentView.getCredentials(), None,
                                     sqlStr, "", "", paramList)
            if response == "error":
                return
            elif response[0]["sco"] > 0:
                wx.MessageBox(parent.getLocale("alert_delete_err"),
                              parent.getLocale("alert_warning_lb"),
                              wx.OK | wx.ICON_ERROR)
                return
            paramList = []
            paramList.append({
                "name": "@customer_id",
                "value": dataSet["customer"][0].id,
                "wheretype": "in",
                "type": "integer"
            })
            if dataSet["deletedFlag"] == True:
                sqlStr = self.parentView.getSql(
                    "fCustomer_getDeleteSql_delete")
            else:
                sqlStr = self.parentView.getSql(
                    "fCustomer_getDeleteSql_update")
            response = conn.executeSql(self.parentView.getCredentials(), None,
                                       sqlStr, paramList)
            if response == "error":
                delOK = False
            else:
                delOK = True
        except Exception, err:
            wx.MessageBox(str(err), "deleteDataSet", wx.OK | wx.ICON_ERROR)
Beispiel #9
0
    def loadResult(self, dataSet, sqlstr, param):
        try:
            wx.SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
            self.parentView.setStatusState(1)

            conn = npiAdapter(self.parentView.application.app_settings["url"] +
                              "/" + self.parentView.application.
                              app_config["connection"]["npi_service"])
            response = conn.loadView(self.parentView.getCredentials(), None,
                                     sqlstr, param["WhereString"],
                                     param["HavingString"], param["paramList"])
            if response == "error":
                return
            else:
                dataSet["result"] = response

        except Exception, err:
            wx.MessageBox(str(err), "loadResult", wx.OK | wx.ICON_ERROR)
Beispiel #10
0
 def saveDataSet(self, dataSet):
   try:      
     wx.SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
     self.parentView.setStatusState(2)
       
     dataSetPy = []
     dataSetPy.append({"tableName":"ui_userconfig", "updateType":"delete", "recordSet":dataSet["_userconfig"]})
     dataSetPy.append({"tableName":"ui_userconfig", "updateType":"update", "recordSet":dataSet["userconfig"]})
     
     conn = npiAdapter(self.parentView.application.app_settings["url"]+"/"+
       self.parentView.application.app_config["connection"]["npi_service"])
     response = conn.saveDataSet(self.parentView.getCredentials(), dataSetPy)
     if response=="error":
       return
     else:
       dataSet["_userconfig"] = []
       dataSet["changeData"] = False
       self.loadDataset(dataSet)
       
   except Exception, err:
     wx.MessageBox(str(err), "saveDataSet", wx.OK | wx.ICON_ERROR)
Beispiel #11
0
  def loadDataset(self, dataSet):
    
    conn = sqlite3.connect('storage.db')  # @UndefinedVariable
    conn.row_factory = sqlite3.Row  # @UndefinedVariable
    
    cur = conn.cursor()
    sqlStr = self.parentView.getSql("fBrowser_getApplViews")
    for row in cur.execute(sqlStr, (dataSet["mainView"],)):
      item = {}; fields = row.keys()
      for index in range(len(fields)):
        item[fields[index]] = row[index]
      dataSet["applviews"].append(dict2obj(item))
    
    sqlStr = self.parentView.getSql("fBrowser_getViewFields")
    for row in cur.execute(sqlStr, (dataSet["mainView"],)):
      item = {}; fields = row.keys()
      for index in range(len(fields)):
        item[fields[index]] = row[index]
      dataSet["viewfields"].append(dict2obj(item))
    
    dataSet["userconfig"] = []
    conn.close()
    
    dataSetInfo = [{"infoName":"userconfig", "infoType":"table", "classAlias":"ui_userconfig", 
       "filterStr":"employee_id="+str(self.parentView.application.app_settings["employee_id"])+
       " and (cfgroup='browserConfig' or section='"+dataSet["mainView"]+"') ", 
       "orderStr":None}]
    
    conn = npiAdapter(self.parentView.application.app_settings["url"]+"/"+
      self.parentView.application.app_config["connection"]["npi_service"])
    response = conn.loadDataSet(self.parentView.getCredentials(), dataSetInfo)
    if response=="error":
      return
    else:
      for recordSetInfo in response:
        for record in recordSetInfo["recordSet"]:
          dataSet[recordSetInfo["infoName"]].append(dict2obj(record,"ui_"+recordSetInfo["infoName"]))

    dataSet["changeData"] = False
Beispiel #12
0
 def callLogin(self):
   try:
     conn = npiAdapter(self.application.app_settings["url"]+"/"+
         self.application.app_config["connection"]["npi_service"])
     login = conn.getLogin(self.application.app_settings["database"], 
                           self.application.app_settings["username"], 
                           self.application.app_settings["password"])
     if login=="error":
       return
     elif login["valid"]==True:
       self.user_config["locale"] = self.application.app_settings["locale"]
       self.user_config["url"] = self.application.app_settings["url"]
       self.user_config["database"] = self.application.app_settings["database"]
       self.user_config["username"] = self.application.app_settings["username"]
       self.user_config.write()
       self.application.app_settings["employee_id"] = login["employee"]["id"]
       self.application.app_settings["engine"] = login["engine"]
       self.login_ok = True
       self.Close()
     else:
       wx.MessageBox(str(login["message"]), str(self.application.app_config["application"]["name"]), wx.OK | wx.ICON_ERROR)
   except Exception, err:
     wx.MessageBox(str(err), "callLogin", wx.OK | wx.ICON_ERROR)
Beispiel #13
0
  def loadDataset(self, dataSet):
    dataSetInfo = []
    
    dataSetInfo.append({"infoName":"groups", "infoType":"table", "classAlias":"groups", 
                        "filterStr":"deleted=0 and groupname in ('customer', 'nervatype', 'fieldtype', 'logstate', 'custtype')", 
                        "orderStr":"groupname, groupvalue"})
    dataSetInfo.append({"infoName":"deffield", "infoType":"table", "classAlias":"deffield", 
                        "filterStr":"deleted=0 and nervatype = (select id from groups where groupname = 'nervatype' and groupvalue = 'customer')", 
                        "orderStr":"description"})
    dataSetInfo.append({"infoName":"fieldValues", "infoType":"table", "classAlias":"fieldvalue", 
                        "filterStr":"fieldname in('not_logical_delete', 'log_customer_update', 'log_customer_deleted', 'default_customer_report')", 
                        "orderStr":None})
    
    if dataSet["customer"][0].id!=-1:
      dataSetInfo.append({"infoName":"customer", "infoType":"table", "classAlias":"customer", 
                        "filterStr":"id="+str(dataSet["customer"][0].id), "orderStr":None})
      dataSetInfo.append({"infoName":"link", "infoType":"table", "classAlias":"link", 
                        "filterStr":"deleted=0 and nervatype_1 = (select id from groups where groupname = 'nervatype' and groupvalue = 'customer') " +
                        "and nervatype_2 = (select id from groups where groupname = 'nervatype' and groupvalue = 'groups') " +
                        "and ref_id_1="+str(dataSet["customer"][0].id), "orderStr":None})
      dataSetInfo.append({"infoName":"address", "infoType":"table", "classAlias":"address", 
                        "filterStr":"deleted = 0 and nervatype = (select id from groups where groupname = 'nervatype' and groupvalue = 'customer') " +
                        "and ref_id ="+str(dataSet["customer"][0].id), "orderStr":"id"})
      dataSetInfo.append({"infoName":"contact", "infoType":"table", "classAlias":"contact", 
                        "filterStr":"deleted = 0 and nervatype = (select id from groups where groupname = 'nervatype' and groupvalue = 'customer') " +
                        "and ref_id ="+str(dataSet["customer"][0].id), "orderStr":"id"})
      paramList = []
      paramList.append({"name":"@customer_id", "value":dataSet["customer"][0].id, "wheretype":"in", "type":"integer"})
      sqlStr = self.parentView.getSql("fCustomer_getDeffieldProp")
      dataSetInfo.append({"infoName":"deffield_prop", "infoType":"view", "sqlKey":None,
                          "sqlStr":sqlStr, "whereStr":"", "havingStr":"", "paramList":paramList})
      dataSetInfo.append({"infoName":"fieldvalue", "infoType":"table", "classAlias":"fieldvalue", 
                        "filterStr":"deleted = 0 and fieldname in (select fieldname from deffield where nervatype = " +
                        "(select id from groups where groupname = 'nervatype' and groupvalue = 'customer')) " +
                        "and ref_id="+str(dataSet["customer"][0].id), "orderStr":None})
      paramList = []
      paramList.append({"name":"@customer_id", "value":dataSet["customer"][0].id, "wheretype":"in", "type":"integer"})
      sqlStr = self.parentView.getSql("fCustomer_getCalendarView")
      dataSetInfo.append({"infoName":"calendar_view", "infoType":"view", "sqlKey":None,
                          "sqlStr":sqlStr, "whereStr":"", "havingStr":"", "paramList":paramList})
    else:
      dataSetInfo.append({"infoName":"custnumber", "infoType":"function", "functionName":"nextNumber",
                          "paramList":{"numberkey":"custnumber", "step":False}})
    
    conn = npiAdapter(self.parentView.application.app_settings["url"]+"/"+
      self.parentView.application.app_config["connection"]["npi_service"])
    response = conn.loadDataSet(self.parentView.getCredentials(), dataSetInfo)
    if response=="error":
      return
    else:
      resultSet = response
    
    for recordSetInfo in resultSet:
      if recordSetInfo["infoName"]=="groups":
        dataSet["groups"] = self.parentView.dic2objList(recordSetInfo["recordSet"],recordSetInfo["infoName"])
        if dataSet["customer"][0].id==-1:
          dataSet["customer"][0].custtype =  self.parentView.getItemFromKey2(dataSet["groups"], "groupname", "custtype", "groupvalue", "company").id
        continue
        
      if recordSetInfo["infoName"]=="fieldValues":
        for inivalue in recordSetInfo["recordSet"]:
          if inivalue["fieldname"]=="default_customer_report":
            pass
          elif inivalue["fieldname"]=="not_logical_delete":
            if inivalue["value"]=="true":
              dataSet["deletedFlag"] = True
          elif inivalue["fieldname"]=="log_customer_update":
            pass
        continue
      
      if recordSetInfo["infoName"]=="deffield":
        dataSet["deffield"] = self.parentView.dic2objList(recordSetInfo["recordSet"],recordSetInfo["infoName"])
        continue
      
      if recordSetInfo["infoName"]=="deffield_prop":
        dataSet["deffield_prop"] = self.parentView.dic2objList(recordSetInfo["recordSet"],recordSetInfo["infoName"])
      
      if recordSetInfo["infoName"]=="custnumber":
        dataSet["newCustnumber"] = recordSetInfo["recordSet"]
        dataSet["customer"][0].custnumber = dataSet["newCustnumber"]
        continue
      
      if recordSetInfo["infoName"]=="calendar_view":
        dataSet["calendar_view"] = self.parentView.dic2objList(recordSetInfo["recordSet"],recordSetInfo["infoName"])
        continue
        
      if recordSetInfo["infoName"]=="link":
        dataSet["link"] = self.parentView.dic2objList(recordSetInfo["recordSet"],recordSetInfo["infoName"])
        for item in recordSetInfo["recordSet"]:
          group = self.parentView.getItemFromKey(dataSet["groups"], "id", item.ref_id_2)
          if group:
            item.description = group.groupvalue
          else:
            item.description = "???"
        dataSet["linkId"]=len(dataSet["link"])
        continue

      elif recordSetInfo["infoName"]=="fieldvalue":
        dataSet["fieldvalue"] = self.parentView.dic2objList(recordSetInfo["recordSet"],recordSetInfo["infoName"])
        for item in dataSet["fieldvalue"]:
          item.fieldtype = self.parentView.getItemFromKey(dataSet["groups"], "id", self.parentView.getItemFromKey(dataSet["deffield"], "fieldname", item.fieldname).fieldtype).groupvalue
          item.description = self.parentView.getItemFromKey(dataSet["deffield"], "fieldname", item.fieldname).description
          item.visible = bool(self.parentView.getItemFromKey(dataSet["deffield"], "fieldname", item.fieldname).visible)
          item.readonly = bool(self.parentView.getItemFromKey(dataSet["deffield"], "fieldname", item.fieldname).visible)
          if item.fieldtype=="valuelist":
            item.valuelist = self.parentView.getItemFromKey(dataSet["deffield"], "fieldname", item.fieldname).valuelist
          if item.fieldtype in("customer","tool","trans","transitem","transmovement","transpayment","product","project","employee","place"):
            item.valuelist = self.parentView.getItemFromKey(dataSet["deffield_prop"], "id", item.fieldtype+"_"+item.value)["description"]
        dataSet["fieldvalueId"] = len(dataSet["fieldvalue"])
        continue
      
      elif recordSetInfo["infoName"]=="address":
        dataSet["address"] = self.parentView.dic2objList(recordSetInfo["recordSet"],recordSetInfo["infoName"])
        dataSet["addressId"] = len(dataSet["address"])
        continue

      elif recordSetInfo["infoName"]=="contact":
        dataSet["contact"] = self.parentView.dic2objList(recordSetInfo["recordSet"],recordSetInfo["infoName"])
        dataSet["contactId"] = len(dataSet["contact"])
        continue
      
      elif recordSetInfo["infoName"]=="customer":
        dataSet["customer"] = self.parentView.dic2objList(recordSetInfo["recordSet"],recordSetInfo["infoName"])
        continue  
    dataSet["changeData"] = False
Beispiel #14
0
  def saveDataSet(self, dataSet, parent):
    try:
      wx.SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
      self.parentView.setStatusState(2)
      
      if dataSet["customer"][0].custnumber!=dataSet["newCustnumber"]:
        #check customer no. to make unique
        filter = "custnumber='"+dataSet["customer"][0].custnumber+"'"  # @ReservedAssignment
        if dataSet["customer"][0].id>-1:
          filter += " and id <> " + str(dataSet["customer"][0].id)
        
        conn = npiAdapter(self.parentView.application.app_settings["url"]+"/"+
          self.parentView.application.app_config["connection"]["npi_service"])
        response = conn.loadTable(self.parentView.getCredentials(), "customer", filter)
        if response=="error":
          return
        elif len(response)>0:
          wx.MessageBox(parent.getLocale("alert_err_iscustnumber"), parent.getLocale("alert_warning_lb"), 
                        wx.OK | wx.ICON_ERROR )
          return
      else:
        #recall and step new customer no.
        conn = npiAdapter(self.parentView.application.app_settings["url"]+"/"+
          self.parentView.application.app_config["connection"]["npi_service"])
        response = conn.callFunction(self.parentView.getCredentials(), 
          "nextNumber", {"numberkey":"custnumber", "step":True})
        if response=="error":
          return
        else:
          if len(response)>0:
            dataSet["customer"][0].custnumber = response[0]
          else:
            wx.MessageBox("Error", "loadDataset", wx.OK | wx.ICON_ERROR)
            return
          
      #save head data
      conn = npiAdapter(self.parentView.application.app_settings["url"]+"/"+
        self.parentView.application.app_config["connection"]["npi_service"])
      response = conn.saveRecord(self.parentView.getCredentials(), dataSet["customer"][0])
      if response=="error":
        return

      if dataSet["customer"][0].id==-1:
        #new customer, replace the temp id
        dataSet["customer"][0].id = response["id"]
        for item in dataSet["address"]:
          item.ref_id = dataSet["customer"][0].id
        for item in dataSet["contact"]:
          item.ref_id = dataSet["customer"][0].id
        for item in dataSet["fieldvalue"]:
          item.ref_id = dataSet["customer"][0].id
        for item in dataSet["link"]:
          item.ref_id_1 = dataSet["customer"][0].id
          
      dataSetInfo = []
      dataSetInfo.append({"tableName":"link", "updateType":"delete", "recordSet":dataSet["_link"]})
      dataSetInfo.append({"tableName":"address", "updateType":"delete", "recordSet":dataSet["_address"]})
      dataSetInfo.append({"tableName":"contact", "updateType":"delete", "recordSet":dataSet["_contact"]})
      dataSetInfo.append({"tableName":"fieldvalue", "updateType":"delete", "recordSet":dataSet["_fieldvalue"]})
          
      dataSetInfo.append({"tableName":"link", "updateType":"update", "recordSet":dataSet["link"]})
      dataSetInfo.append({"tableName":"address", "updateType":"update", "recordSet":dataSet["address"]})
      dataSetInfo.append({"tableName":"contact", "updateType":"update", "recordSet":dataSet["contact"]})
      dataSetInfo.append({"tableName":"fieldvalue", "updateType":"update", "recordSet":dataSet["fieldvalue"]})
      
      #save rows
      conn = npiAdapter(self.parentView.application.app_settings["url"]+"/"+
        self.parentView.application.app_config["connection"]["npi_service"])
      response = conn.saveDataSet(self.parentView.getCredentials(), dataSetInfo)
      if response=="error":
        return
      else:
        dataSet["_link"] = []
        dataSet["_address"] = []
        dataSet["_contact"] = []
        dataSet["_fieldvalue"] = []
        dataSet["changeData"] = False
        self.loadDataset(dataSet)
                      
    except Exception, err:
      wx.MessageBox(str(err), "saveDataSet", wx.OK | wx.ICON_ERROR)
Beispiel #15
0
    def loadDataset(self, dataSet):
        dataSetInfo = []

        dataSetInfo.append({
            "infoName": "groups",
            "infoType": "table",
            "classAlias": "groups",
            "filterStr":
            "deleted=0 and groupname in ('customer', 'nervatype', 'fieldtype', 'logstate', 'custtype')",
            "orderStr": "groupname, groupvalue"
        })
        dataSetInfo.append({
            "infoName": "deffield",
            "infoType": "table",
            "classAlias": "deffield",
            "filterStr":
            "deleted=0 and nervatype = (select id from groups where groupname = 'nervatype' and groupvalue = 'customer')",
            "orderStr": "description"
        })
        dataSetInfo.append({
            "infoName": "fieldValues",
            "infoType": "table",
            "classAlias": "fieldvalue",
            "filterStr":
            "fieldname in('not_logical_delete', 'log_customer_update', 'log_customer_deleted', 'default_customer_report')",
            "orderStr": None
        })

        if dataSet["customer"][0].id != -1:
            dataSetInfo.append({
                "infoName":
                "customer",
                "infoType":
                "table",
                "classAlias":
                "customer",
                "filterStr":
                "id=" + str(dataSet["customer"][0].id),
                "orderStr":
                None
            })
            dataSetInfo.append({
                "infoName":
                "link",
                "infoType":
                "table",
                "classAlias":
                "link",
                "filterStr":
                "deleted=0 and nervatype_1 = (select id from groups where groupname = 'nervatype' and groupvalue = 'customer') "
                +
                "and nervatype_2 = (select id from groups where groupname = 'nervatype' and groupvalue = 'groups') "
                + "and ref_id_1=" + str(dataSet["customer"][0].id),
                "orderStr":
                None
            })
            dataSetInfo.append({
                "infoName":
                "address",
                "infoType":
                "table",
                "classAlias":
                "address",
                "filterStr":
                "deleted = 0 and nervatype = (select id from groups where groupname = 'nervatype' and groupvalue = 'customer') "
                + "and ref_id =" + str(dataSet["customer"][0].id),
                "orderStr":
                "id"
            })
            dataSetInfo.append({
                "infoName":
                "contact",
                "infoType":
                "table",
                "classAlias":
                "contact",
                "filterStr":
                "deleted = 0 and nervatype = (select id from groups where groupname = 'nervatype' and groupvalue = 'customer') "
                + "and ref_id =" + str(dataSet["customer"][0].id),
                "orderStr":
                "id"
            })
            paramList = []
            paramList.append({
                "name": "@customer_id",
                "value": dataSet["customer"][0].id,
                "wheretype": "in",
                "type": "integer"
            })
            sqlStr = self.parentView.getSql("fCustomer_getDeffieldProp")
            dataSetInfo.append({
                "infoName": "deffield_prop",
                "infoType": "view",
                "sqlKey": None,
                "sqlStr": sqlStr,
                "whereStr": "",
                "havingStr": "",
                "paramList": paramList
            })
            dataSetInfo.append({
                "infoName":
                "fieldvalue",
                "infoType":
                "table",
                "classAlias":
                "fieldvalue",
                "filterStr":
                "deleted = 0 and fieldname in (select fieldname from deffield where nervatype = "
                +
                "(select id from groups where groupname = 'nervatype' and groupvalue = 'customer')) "
                + "and ref_id=" + str(dataSet["customer"][0].id),
                "orderStr":
                None
            })
            paramList = []
            paramList.append({
                "name": "@customer_id",
                "value": dataSet["customer"][0].id,
                "wheretype": "in",
                "type": "integer"
            })
            sqlStr = self.parentView.getSql("fCustomer_getCalendarView")
            dataSetInfo.append({
                "infoName": "calendar_view",
                "infoType": "view",
                "sqlKey": None,
                "sqlStr": sqlStr,
                "whereStr": "",
                "havingStr": "",
                "paramList": paramList
            })
        else:
            dataSetInfo.append({
                "infoName": "custnumber",
                "infoType": "function",
                "functionName": "nextNumber",
                "paramList": {
                    "id": "customer_number",
                    "step": False
                }
            })

        conn = npiAdapter(self.parentView.application.app_settings["url"] +
                          "/" +
                          self.parentView.application.app_config["connection"]
                          ["npi_service"])
        response = conn.loadDataSet(self.parentView.getCredentials(),
                                    dataSetInfo)
        if response == "error":
            return
        else:
            resultSet = response

        for recordSetInfo in resultSet:
            if recordSetInfo["infoName"] == "groups":
                dataSet["groups"] = self.parentView.dic2objList(
                    recordSetInfo["recordSet"], recordSetInfo["infoName"])
                if dataSet["customer"][0].id == -1:
                    dataSet["customer"][
                        0].custtype = self.parentView.getItemFromKey2(
                            dataSet["groups"], "groupname", "custtype",
                            "groupvalue", "company").id
                continue

            if recordSetInfo["infoName"] == "fieldValues":
                for inivalue in recordSetInfo["recordSet"]:
                    if inivalue["fieldname"] == "default_customer_report":
                        pass
                    elif inivalue["fieldname"] == "not_logical_delete":
                        if inivalue["value"] == "true":
                            dataSet["deletedFlag"] = True
                    elif inivalue["fieldname"] == "log_customer_update":
                        pass
                continue

            if recordSetInfo["infoName"] == "deffield":
                dataSet["deffield"] = self.parentView.dic2objList(
                    recordSetInfo["recordSet"], recordSetInfo["infoName"])
                continue

            if recordSetInfo["infoName"] == "deffield_prop":
                dataSet["deffield_prop"] = self.parentView.dic2objList(
                    recordSetInfo["recordSet"], recordSetInfo["infoName"])

            if recordSetInfo["infoName"] == "custnumber":
                dataSet["newCustnumber"] = recordSetInfo["recordSet"]
                dataSet["customer"][0].custnumber = dataSet["newCustnumber"]
                continue

            if recordSetInfo["infoName"] == "calendar_view":
                dataSet["calendar_view"] = self.parentView.dic2objList(
                    recordSetInfo["recordSet"], recordSetInfo["infoName"])
                continue

            if recordSetInfo["infoName"] == "link":
                dataSet["link"] = self.parentView.dic2objList(
                    recordSetInfo["recordSet"], recordSetInfo["infoName"])
                for item in recordSetInfo["recordSet"]:
                    group = self.parentView.getItemFromKey(
                        dataSet["groups"], "id", item.ref_id_2)
                    if group:
                        item.description = group.groupvalue
                    else:
                        item.description = "???"
                dataSet["linkId"] = len(dataSet["link"])
                continue

            elif recordSetInfo["infoName"] == "fieldvalue":
                dataSet["fieldvalue"] = self.parentView.dic2objList(
                    recordSetInfo["recordSet"], recordSetInfo["infoName"])
                for item in dataSet["fieldvalue"]:
                    item.fieldtype = self.parentView.getItemFromKey(
                        dataSet["groups"], "id",
                        self.parentView.getItemFromKey(
                            dataSet["deffield"], "fieldname",
                            item.fieldname).fieldtype).groupvalue
                    item.description = self.parentView.getItemFromKey(
                        dataSet["deffield"], "fieldname",
                        item.fieldname).description
                    item.visible = bool(
                        self.parentView.getItemFromKey(dataSet["deffield"],
                                                       "fieldname",
                                                       item.fieldname).visible)
                    item.readonly = bool(
                        self.parentView.getItemFromKey(dataSet["deffield"],
                                                       "fieldname",
                                                       item.fieldname).visible)
                    if item.fieldtype == "valuelist":
                        item.valuelist = self.parentView.getItemFromKey(
                            dataSet["deffield"], "fieldname",
                            item.fieldname).valuelist
                    if item.fieldtype in ("customer", "tool", "trans",
                                          "transitem", "transmovement",
                                          "transpayment", "product", "project",
                                          "employee", "place"):
                        item.valuelist = self.parentView.getItemFromKey(
                            dataSet["deffield_prop"], "id",
                            item.fieldtype + "_" + item.value)["description"]
                dataSet["fieldvalueId"] = len(dataSet["fieldvalue"])
                continue

            elif recordSetInfo["infoName"] == "address":
                dataSet["address"] = self.parentView.dic2objList(
                    recordSetInfo["recordSet"], recordSetInfo["infoName"])
                dataSet["addressId"] = len(dataSet["address"])
                continue

            elif recordSetInfo["infoName"] == "contact":
                dataSet["contact"] = self.parentView.dic2objList(
                    recordSetInfo["recordSet"], recordSetInfo["infoName"])
                dataSet["contactId"] = len(dataSet["contact"])
                continue

            elif recordSetInfo["infoName"] == "customer":
                dataSet["customer"] = self.parentView.dic2objList(
                    recordSetInfo["recordSet"], recordSetInfo["infoName"])
                continue
        dataSet["changeData"] = False
Beispiel #16
0
    def saveDataSet(self, dataSet, parent):
        try:
            wx.SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
            self.parentView.setStatusState(2)

            if dataSet["customer"][0].custnumber != dataSet["newCustnumber"]:
                #check customer no. to make unique
                filter = "custnumber='" + dataSet["customer"][
                    0].custnumber + "'"  # @ReservedAssignment
                if dataSet["customer"][0].id > -1:
                    filter += " and id <> " + str(dataSet["customer"][0].id)

                conn = npiAdapter(
                    self.parentView.application.app_settings["url"] + "/" +
                    self.parentView.application.app_config["connection"]
                    ["npi_service"])
                response = conn.loadTable(self.parentView.getCredentials(),
                                          "customer", filter)
                if response == "error":
                    return
                elif len(response) > 0:
                    wx.MessageBox(parent.getLocale("alert_err_iscustnumber"),
                                  parent.getLocale("alert_warning_lb"),
                                  wx.OK | wx.ICON_ERROR)
                    return
            else:
                #recall and step new customer no.
                conn = npiAdapter(
                    self.parentView.application.app_settings["url"] + "/" +
                    self.parentView.application.app_config["connection"]
                    ["npi_service"])
                response = conn.callFunction(self.parentView.getCredentials(),
                                             "nextNumber", {
                                                 "id": "customer_number",
                                                 "step": True
                                             })
                if response == "error":
                    return
                else:
                    if len(response) > 0:
                        dataSet["customer"][0].custnumber = response[0]
                    else:
                        wx.MessageBox("Error", "loadDataset",
                                      wx.OK | wx.ICON_ERROR)
                        return

            #save head data
            conn = npiAdapter(self.parentView.application.app_settings["url"] +
                              "/" + self.parentView.application.
                              app_config["connection"]["npi_service"])
            response = conn.saveRecord(self.parentView.getCredentials(),
                                       dataSet["customer"][0])
            if response == "error":
                return

            if dataSet["customer"][0].id == -1:
                #new customer, replace the temp id
                dataSet["customer"][0].id = response["id"]
                for item in dataSet["address"]:
                    item.ref_id = dataSet["customer"][0].id
                for item in dataSet["contact"]:
                    item.ref_id = dataSet["customer"][0].id
                for item in dataSet["fieldvalue"]:
                    item.ref_id = dataSet["customer"][0].id
                for item in dataSet["link"]:
                    item.ref_id_1 = dataSet["customer"][0].id

            dataSetInfo = []
            dataSetInfo.append({
                "tableName": "link",
                "updateType": "delete",
                "recordSet": dataSet["_link"]
            })
            dataSetInfo.append({
                "tableName": "address",
                "updateType": "delete",
                "recordSet": dataSet["_address"]
            })
            dataSetInfo.append({
                "tableName": "contact",
                "updateType": "delete",
                "recordSet": dataSet["_contact"]
            })
            dataSetInfo.append({
                "tableName": "fieldvalue",
                "updateType": "delete",
                "recordSet": dataSet["_fieldvalue"]
            })

            dataSetInfo.append({
                "tableName": "link",
                "updateType": "update",
                "recordSet": dataSet["link"]
            })
            dataSetInfo.append({
                "tableName": "address",
                "updateType": "update",
                "recordSet": dataSet["address"]
            })
            dataSetInfo.append({
                "tableName": "contact",
                "updateType": "update",
                "recordSet": dataSet["contact"]
            })
            dataSetInfo.append({
                "tableName": "fieldvalue",
                "updateType": "update",
                "recordSet": dataSet["fieldvalue"]
            })

            #save rows
            conn = npiAdapter(self.parentView.application.app_settings["url"] +
                              "/" + self.parentView.application.
                              app_config["connection"]["npi_service"])
            response = conn.saveDataSet(self.parentView.getCredentials(),
                                        dataSetInfo)
            if response == "error":
                return
            else:
                dataSet["_link"] = []
                dataSet["_address"] = []
                dataSet["_contact"] = []
                dataSet["_fieldvalue"] = []
                dataSet["changeData"] = False
                self.loadDataset(dataSet)

        except Exception, err:
            wx.MessageBox(str(err), "saveDataSet", wx.OK | wx.ICON_ERROR)