/// <summary> /// Metodo per la numerazione personalizzata /// </summary> /// <returns></returns> private static object CalcID(DataRow R, DataColumn C, DataAccess Conn) { object esercizio = R["yassetload"]; QueryHelper QHS; QHS = Conn.GetQueryHelper(); string filter_patri = QHS.CmpEq("ayear", esercizio); //ricavo configurazione patrimonio DataTable t = Conn.RUN_SELECT("config", "*", null, filter_patri, null, false); if (t == null || t.Rows.Count == 0) { return(null); } string tiponumerazione = t.Rows[0]["asset_flagnumbering"].ToString().ToUpper(); string flagreset = t.Rows[0]["asset_flagrestart"].ToString().ToUpper(); string filter_esercbuonocarico = QHS.CmpEq("b.yassetload", esercizio); string filter_codicetipobuonocarico = QHS.CmpEq("b.idassetloadkind", R["idassetloadkind"]); string filter_esercbuonoscarico = QHS.CmpEq("b.yassetunload", esercizio); string sql_select1, sql_select2; string sql_from1, sql_from2; string sql_where1, sql_where2; string sql1 = "", sql2 = ""; //ricavo configurazione del codice tipo buono DataRow Rtipobuono = R.GetParentRow("assetloadkindassetload"); //ricavo info inventario string filter_inventario = QHS.CmpEq("idinventory", Rtipobuono["idinventory"]); DataTable Tinv = Conn.RUN_SELECT("inventory", "*", null, filter_inventario, null, false); switch (tiponumerazione.ToUpper()) { case "U": //numerazione unica if (flagreset == "N") { filter_esercbuonocarico = ""; filter_esercbuonoscarico = ""; } sql_select1 = "SELECT ISNULL(MAX(b.nassetload),0) + 1 "; sql_from1 = "FROM assetload b "; if (filter_esercbuonocarico != "") { sql_where1 = "WHERE " + filter_esercbuonocarico; } else { sql_where1 = ""; } sql1 = sql_select1 + sql_from1 + sql_where1; sql_select2 = "SELECT ISNULL(MAX(b.nassetunload),0) + 1 "; sql_from2 = "FROM assetunload b "; if (filter_esercbuonoscarico != "") { sql_where2 = "WHERE " + filter_esercbuonoscarico; } else { sql_where2 = ""; } sql2 = sql_select2 + sql_from2 + sql_where2; return(GetMax(sql1, sql2, Conn)); case "T": //per tipo inventario if (flagreset == "N") { filter_esercbuonocarico = ""; filter_esercbuonoscarico = ""; } string filter_tipoinventario = QHS.CmpEq("i.idinventorykind", Tinv.Rows[0]["idinventorykind"]); sql_select1 = "SELECT ISNULL(MAX(b.nassetload),0) + 1 "; sql_from1 = "FROM assetload b INNER JOIN assetloadkind t on b.idassetloadkind=t.idassetloadkind " + "INNER JOIN inventory i ON t.idinventory=i.idinventory " + "INNER JOIN inventorykind ti ON i.idinventorykind=ti.idinventorykind "; sql_where1 = "WHERE " + GetData.MergeFilters(filter_esercbuonocarico, filter_tipoinventario); sql1 = sql_select1 + sql_from1 + sql_where1; sql_select2 = "SELECT ISNULL(MAX(b.nassetunload),0) + 1 "; sql_from2 = "FROM assetunload b INNER JOIN assetunloadkind t on b.idassetunloadkind=t.idassetunloadkind " + "INNER JOIN inventory i ON t.idinventory=i.idinventory " + "INNER JOIN inventorykind ti ON i.idinventorykind=ti.idinventorykind "; sql_where2 = "WHERE " + GetData.MergeFilters(filter_esercbuonoscarico, filter_tipoinventario); sql2 = sql_select2 + sql_from2 + sql_where2; return(GetMax(sql1, sql2, Conn)); case "E": //per ente inventariale if (flagreset == "N") { filter_esercbuonocarico = ""; filter_esercbuonoscarico = ""; } string filter_ente = QHS.CmpEq("i.idinventoryagency", Tinv.Rows[0]["idinventoryagency"]); sql_select1 = "SELECT ISNULL(MAX(b.nassetload),0) + 1 "; sql_from1 = "FROM assetload b INNER JOIN assetloadkind t on b.idassetloadkind=t.idassetloadkind " + "INNER JOIN inventory i ON t.idinventory=i.idinventory " + "INNER JOIN inventorykind ti ON i.idinventorykind=ti.idinventorykind "; sql_where1 = "WHERE " + GetData.MergeFilters(filter_esercbuonocarico, filter_ente); sql1 = sql_select1 + sql_from1 + sql_where1; sql_select2 = "SELECT ISNULL(MAX(b.nassetunload),0) + 1 "; sql_from2 = "FROM assetunload b INNER JOIN assetunloadkind t on b.idassetunloadkind=t.idassetunloadkind " + "INNER JOIN inventory i ON t.idinventory=i.idinventory " + "INNER JOIN inventorykind ti ON i.idinventorykind=ti.idinventorykind "; sql_where2 = "WHERE " + GetData.MergeFilters(filter_esercbuonoscarico, filter_ente); sql2 = sql_select2 + sql_from2 + sql_where2; return(GetMax(sql1, sql2, Conn)); case "K": //per ente inventariale suddiviso per buono carico e buono scarico if (flagreset == "N") { filter_esercbuonocarico = ""; } filter_ente = QHS.CmpEq("i.idinventoryagency", Tinv.Rows[0]["idinventoryagency"]); sql_select1 = "SELECT ISNULL(MAX(b.nassetload),0) + 1 "; sql_from1 = "FROM assetload b INNER JOIN assetloadkind t on b.idassetloadkind=t.idassetloadkind " + "INNER JOIN inventory i ON t.idinventory=i.idinventory " + "INNER JOIN inventorykind ti ON i.idinventorykind=ti.idinventorykind "; sql_where1 = "WHERE " + GetData.MergeFilters(filter_esercbuonocarico, filter_ente); sql1 = sql_select1 + sql_from1 + sql_where1; DataTable tLoad = Conn.SQLRunner(sql1, true); if (tLoad == null || tLoad.Rows.Count == 0) { return(0); } return(tLoad.Rows[0][0]); case "B": default: //per tipo buono bool numassoluta = CfgFn.DecodeToBool(Rtipobuono["flag"], 1); int value_if_null = 0; int numiniziale = CfgFn.GetNoNullInt32(Rtipobuono["startnumber"]); value_if_null = numiniziale - 1; if (value_if_null < 0) { value_if_null = 0; } sql_select1 = "SELECT ISNULL(MAX(b.nassetload)," + value_if_null.ToString() + ") + 1 "; sql_from1 = "FROM assetload b "; sql_where1 = "WHERE " + filter_codicetipobuonocarico; if (!numassoluta) { sql_where1 += " AND " + filter_esercbuonocarico; } sql1 = sql_select1 + sql_from1 + sql_where1; DataTable T1 = Conn.SQLRunner(sql1, true); if (T1 == null || T1.Rows.Count == 0) { if (!numassoluta) { return(value_if_null + 1); } return(1); } return(T1.Rows[0][0]); //default: // QueryCreator.MarkEvent("meta_assetload.CalcID(): tiponumerazione non definita"); // return null; } }